- Update to add status page subdomain as env variable

- Adjust Server lists and Add new layout etc
- Adjust Save button
This commit is contained in:
Shemy Gan committed 2025-01-03 14:26:41 -05:00
1 parent 8b72f8447d
commit 5226f3c9b1
8 files changed
+149 -138

No files matched your search

+1
View File
@@ -1 +1,2 @@
VITE_APP_API_BASE_URL=UPTIME_APP_API_BASE_URL
VITE_STATUS_PAGE_SUBDOMAIN_PREFIX=UPTIME_STATUS_PAGE_SUBDOMAIN_PREFIX
@@ -150,7 +150,7 @@ const ContentPanel = () => {
>
<Stack
direction="row"
justifyContent="space-around"
justifyContent="space-between"
>
<Typography
component="p"
@@ -163,7 +163,7 @@ const ContentPanel = () => {
onClick={handleAddNew}
disabled={monitors.length === 0 || monitors.length <= cards.length}
>
Add New
Add new
</Button>
</Stack>
{cards.length > 0 && (
@@ -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={
<HttpAdornment
prefix={"http://uptimegenie.com/"}
prefix={SUBDOAMIN_PREFIX}
https={false}
/>
}
+139 -135
View File
@@ -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 (
<Box
className="status"
px={theme.spacing(20)}
py={theme.spacing(12)}
border={1}
borderColor={theme.palette.border.light}
borderRadius={theme.shape.borderRadius}
backgroundColor={theme.palette.background.main}
>
<TabContext value={tabList[tabIdx]}>
<Box
sx={{
borderBottom: 1,
borderColor: theme.palette.border.light,
"& .MuiTabs-root": { height: "fit-content", minHeight: "0" },
}}
>
<TabList
onChange={handleTabChange}
aria-label="status tabs"
>
{tabList.map((label, index) => (
<Tab
label={label}
key={index}
value={label}
sx={{
fontSize: 13,
color: theme.palette.text.tertiary,
textTransform: "none",
minWidth: "fit-content",
minHeight: 0,
paddingLeft: 0,
paddingY: theme.spacing(4),
fontWeight: 400,
marginRight: theme.spacing(8),
"&:focus": {
outline: "none",
},
}}
/>
))}
</TabList>
</Box>
<StatusFormProvider
form={form}
setForm={setForm}
errors={errors}
setErrors={setErrors}
>
{tabIdx == 0 ? <GeneralSettingsPanel /> : <ContentPanel />}
</StatusFormProvider>
</TabContext>
//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 (
<Stack
direction="row"
justifyContent="flex-end"
className="status"
px={theme.spacing(20)}
py={theme.spacing(12)}
gap={theme.spacing(12)}
border={1}
borderColor={theme.palette.border.light}
borderRadius={theme.shape.borderRadius}
backgroundColor={theme.palette.background.main}
>
<Button
variant="contained"
color="primary"
onClick={handleSubmit}
<TabContext value={tabList[tabIdx]}>
<Box
sx={{
borderBottom: 1,
borderColor: theme.palette.border.light,
"& .MuiTabs-root": { height: "fit-content", minHeight: "0" },
}}
>
<TabList
onChange={handleTabChange}
aria-label="status tabs"
>
{tabList.map((label, index) => (
<Tab
label={label}
key={index}
value={label}
sx={{
fontSize: 13,
color: theme.palette.text.tertiary,
textTransform: "none",
minWidth: "fit-content",
minHeight: 0,
paddingLeft: 0,
paddingY: theme.spacing(4),
fontWeight: 400,
marginRight: theme.spacing(8),
"&:focus": {
outline: "none",
},
}}
/>
))}
</TabList>
</Box>
<StatusFormProvider
form={form}
setForm={setForm}
errors={errors}
setErrors={setErrors}
>
{tabIdx == 0 ? <GeneralSettingsPanel /> : <ContentPanel />}
</StatusFormProvider>
</TabContext>
<Stack
direction="row"
justifyContent="flex-end"
>
Save
</Button>
<Button
variant="contained"
color="primary"
onClick={handleSubmit}
>
Save
</Button>
</Stack>
</Stack>
</Box>
);
};
);
};
CreateStatus.propTypes = {
initForm: PropTypes.object
+1
View File
@@ -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"
+1
View File
@@ -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"
+1
View File
@@ -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"
+1
View File
@@ -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"