diff --git a/Client/.env.production b/Client/.env.production index a5bce84e1..2ae6d13cd 100644 --- a/Client/.env.production +++ b/Client/.env.production @@ -1 +1,2 @@ VITE_APP_API_BASE_URL=UPTIME_APP_API_BASE_URL +VITE_STATUS_PAGE_SUBDOMAIN_PREFIX=UPTIME_STATUS_PAGE_SUBDOMAIN_PREFIX diff --git a/Client/src/Components/TabPanels/Status/ContentPanel.jsx b/Client/src/Components/TabPanels/Status/ContentPanel.jsx index e0f382a58..78bba8d72 100644 --- a/Client/src/Components/TabPanels/Status/ContentPanel.jsx +++ b/Client/src/Components/TabPanels/Status/ContentPanel.jsx @@ -150,7 +150,7 @@ const ContentPanel = () => { > { onClick={handleAddNew} disabled={monitors.length === 0 || monitors.length <= cards.length} > - Add New + Add new {cards.length > 0 && ( diff --git a/Client/src/Components/TabPanels/Status/GeneralSettingsPanel.jsx b/Client/src/Components/TabPanels/Status/GeneralSettingsPanel.jsx index e446895eb..cedcbc986 100644 --- a/Client/src/Components/TabPanels/Status/GeneralSettingsPanel.jsx +++ b/Client/src/Components/TabPanels/Status/GeneralSettingsPanel.jsx @@ -29,6 +29,8 @@ const GeneralSettingsPanel = () => { const [progress, setProgress] = useState({ value: 0, isLoading: false }); const intervalRef = useRef(null); + const SUBDOAMIN_PREFIX = + import.meta.env.VITE_STATUS_PAGE_SUBDOMAIN_PREFIX ?? "http://localhost/"; // Clears specific error from errors state const clearError = (err) => { @@ -178,7 +180,7 @@ const GeneralSettingsPanel = () => { value={form.url} startAdornment={ } diff --git a/Client/src/Pages/Status/CreateStatus/index.jsx b/Client/src/Pages/Status/CreateStatus/index.jsx index 2f0ab71d7..a19f6b428 100644 --- a/Client/src/Pages/Status/CreateStatus/index.jsx +++ b/Client/src/Pages/Status/CreateStatus/index.jsx @@ -20,150 +20,154 @@ import { networkService } from "../../../main"; */ const CreateStatus = ({ initForm }) => { - const theme = useTheme(); - const mode = useSelector((state) => state.ui.mode); - const { authToken } = useSelector((state) => state.auth); - const {apiBaseUrl} = useSelector((state) => state.settings); - const [tabIdx, setTabIdx] = useState(0); - const [errors, setErrors] = useState({}); - const error_tab_maping = [["companyName","url","timezone","color","publish","logo"],["monitors", - "showUptimePercentage", "showBarcode"]] - const tabList = ["General Settings", "Contents"]; - const hasInitForm = initForm && Object.keys(initForm).length > 0; - const [form, setForm] = useState( - hasInitForm - ? initForm - : { - companyName: "", - url: "", - timezone: "America/Toronto", - color: "#4169E1", - //which fields matching below? - //publish: false, - logo: null, - monitors: [], - // showUptimePercentage: false, - // showBarcode: false, - } - ); - const setActiveTabOnErrors = () => { - let newIdx = -1; - Object.keys(errors).map((id) => { - if (newIdx !== -1) return; - error_tab_maping.map((val, idx) => { - let anyMatch = val.some((vl) => vl == id); - if (anyMatch) { - newIdx = idx; - return; - } + const theme = useTheme(); + const mode = useSelector((state) => state.ui.mode); + const { authToken } = useSelector((state) => state.auth); + const [tabIdx, setTabIdx] = useState(0); + const [errors, setErrors] = useState({}); + const error_tab_maping = [ + ["companyName", "url", "timezone", "color", "publish", "logo"], + ["monitors", "showUptimePercentage", "showBarcode"], + ]; + const tabList = ["General Settings", "Contents"]; + const hasInitForm = initForm && Object.keys(initForm).length > 0; + const [form, setForm] = useState( + hasInitForm + ? initForm + : { + companyName: "", + url: "", + timezone: "America/Toronto", + color: "#4169E1", + //which fields matching below? + //publish: false, + logo: null, + monitors: [], + // showUptimePercentage: false, + // showBarcode: false, + } + ); + const setActiveTabOnErrors = () => { + let newIdx = -1; + Object.keys(errors).map((id) => { + if (newIdx !== -1) return; + error_tab_maping.map((val, idx) => { + let anyMatch = val.some((vl) => vl == id); + if (anyMatch) { + newIdx = idx; + return; + } + }); }); - }); - if (newIdx !== -1) setTabIdx(newIdx); - }; - - const handleTabChange = (_, newTab) => { - setTabIdx(tabList.indexOf(newTab)); - }; - - const handleSubmit = async (e) => { - e.preventDefault(); - let localData = { - ...form, - monitors: - form.monitors[0] && Object.keys(form.monitors[0]).includes("_id") - ? form.monitors.map((m) => m._id) - : form.monitors, - theme: mode, - logo: { type: form.logo?.type ?? "", size: form.logo?.size ?? "" }, + if (newIdx !== -1) setTabIdx(newIdx); }; - //delete localData.logo - if (hasValidationErrors(localData, publicPageGeneralSettingsValidation, setErrors)) { - setActiveTabOnErrors(); - return; - } - //form.logo = { ...logo, size: formatBytes(logo?.size) }; - let config = { authToken: authToken, url: "status-page", data: localData }; - try { - const res = await networkService.createStatusPage(config); - if (!res.status === 200) { - throw new Error("Failed to create status page"); + const handleTabChange = (_, newTab) => { + setTabIdx(tabList.indexOf(newTab)); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + let localData = { + ...form, + monitors: + form.monitors[0] && Object.keys(form.monitors[0]).includes("_id") + ? form.monitors.map((m) => m._id) + : form.monitors, + theme: mode, + logo: { type: form.logo?.type ?? "", size: form.logo?.size ?? "" }, + }; + //delete localData.logo + if ( + hasValidationErrors(localData, publicPageGeneralSettingsValidation, setErrors) + ) { + setActiveTabOnErrors(); + return; } - createToast({ body: "Status page created successfully!" }); - } catch (e) { - createToast({ body: e.message || "Error creating status page" }); - } - }; - return ( - - - - - {tabList.map((label, index) => ( - - ))} - - - - {tabIdx == 0 ? : } - - + //form.logo = { ...logo, size: formatBytes(logo?.size) }; + let config = { authToken: authToken, url: "status-page", data: localData }; + try { + const res = await networkService.createStatusPage(config); + if (!res.status === 200) { + throw new Error("Failed to create status page"); + } + createToast({ body: "Status page created successfully!" }); + } catch (e) { + createToast({ body: e.message || "Error creating status page" }); + } + }; + + return ( - + + - - ); -}; + ); + }; CreateStatus.propTypes = { initForm: PropTypes.object diff --git a/Docker/dist/docker-compose.yaml b/Docker/dist/docker-compose.yaml index f12c0979d..8afa3c241 100644 --- a/Docker/dist/docker-compose.yaml +++ b/Docker/dist/docker-compose.yaml @@ -4,6 +4,7 @@ services: restart: always environment: UPTIME_APP_API_BASE_URL: "http://localhost:5000/api/v1" + UPTIME_STATUS_PAGE_SUBDOMAIN_PREFIX: "http://uptimegenie.com/" ports: - "80:80" - "443:443" diff --git a/Docker/prod/docker-compose.yaml b/Docker/prod/docker-compose.yaml index 67bfe42e8..1fb6a5d05 100644 --- a/Docker/prod/docker-compose.yaml +++ b/Docker/prod/docker-compose.yaml @@ -4,6 +4,7 @@ services: restart: always environment: UPTIME_APP_API_BASE_URL: "https://checkmate-demo.bluewavelabs.ca/api/v1" + UPTIME_STATUS_PAGE_SUBDOMAIN_PREFIX: "http://uptimegenie.com/" ports: - "80:80" - "443:443" diff --git a/Docker/test/docker-compose.yaml b/Docker/test/docker-compose.yaml index 9f51edab8..5a0080101 100644 --- a/Docker/test/docker-compose.yaml +++ b/Docker/test/docker-compose.yaml @@ -4,6 +4,7 @@ services: restart: always environment: UPTIME_APP_API_BASE_URL: "https://checkmate-test.bluewavelabs.ca/api/v1" + UPTIME_STATUS_PAGE_SUBDOMAIN_PREFIX: "http://uptimegenie.com/" ports: - "80:80" - "443:443" diff --git a/Docker/test/prod/docker-compose.yaml b/Docker/test/prod/docker-compose.yaml index e262ef1a2..ba88f3b67 100644 --- a/Docker/test/prod/docker-compose.yaml +++ b/Docker/test/prod/docker-compose.yaml @@ -3,6 +3,7 @@ services: image: uptime_client:latest environment: UPTIME_APP_API_BASE_URL: "https://checkmate-demo.bluewavelabs.ca/api/v1" + UPTIME_STATUS_PAGE_SUBDOMAIN_PREFIX: "http://uptimegenie.com/" ports: - "80:80" - "443:443"