initial commit

This commit is contained in:
Alex Holliday committed 2025-11-13 13:47:26 -08:00
1 parent 7cb985116e
commit 75acf7b38f
955 files changed
+37333 -87054

No files matched your search

@@ -0,0 +1,46 @@
import { StatusPageForm } from "@/pages/status-page/StatusPageForm";
import { useParams } from "react-router";
import { useNavigate } from "react-router";
import { z } from "zod";
import { usePatch, useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/hooks/UseApi";
import { statusPageSchema } from "@/validation/zod";
import type { IMonitor } from "@/types/monitor";
import type { IStatusPageWithMonitors } from "@/types/status-page";
type FormValues = z.infer<typeof statusPageSchema>;
const StatusPageConfigPage = () => {
const navigate = useNavigate();
const { id } = useParams();
const { patch, loading } = usePatch<FormValues, IStatusPageWithMonitors>();
const { response, isValidating } =
useGet<ApiResponse<IMonitor[]>>("/monitors");
const { response: statusPageResponse } = useGet<ApiResponse<any>>(
`/status-pages/${id}`
);
const monitors = response?.data || [];
const initialData = statusPageResponse?.data;
initialData.monitors =
initialData?.monitors?.map((monitor: IMonitor) => monitor?._id) || [];
const onSubmit = async (data: FormValues) => {
const res = await patch(`/status-pages/${id}`, data);
if (res) {
navigate(-1);
}
};
return (
<StatusPageForm
initialData={initialData}
monitorOptions={monitors}
onSubmit={onSubmit}
loading={loading || isValidating}
/>
);
};
export default StatusPageConfigPage;
@@ -0,0 +1,36 @@
import { StatusPageForm } from "@/pages/status-page/StatusPageForm";
import { useNavigate } from "react-router";
import { z } from "zod";
import { usePost, useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/hooks/UseApi";
import { statusPageSchema } from "@/validation/zod";
import type { IMonitor } from "@/types/monitor";
type FormValues = z.infer<typeof statusPageSchema>;
const StatusPageCreatePage = () => {
const navigate = useNavigate();
const { post, loading } = usePost<FormValues, IMonitor[]>();
const { response, isValidating } =
useGet<ApiResponse<IMonitor[]>>("/monitors");
const monitors = response?.data || [];
const onSubmit = async (data: FormValues) => {
const res = await post("/status-pages", data);
if (res) {
navigate(-1);
}
};
return (
<StatusPageForm
monitorOptions={monitors}
onSubmit={onSubmit}
loading={loading || isValidating}
/>
);
};
export default StatusPageCreatePage;
@@ -0,0 +1,42 @@
import Stack from "@mui/material/Stack";
import { StatusHeader } from "@/components/status-pages/StatusHeader";
import { StatusPageRow } from "@/components/status-pages/StatusPageRow";
import { BasePage } from "@/components/design-elements";
import { useTheme } from "@mui/material/styles";
import type { IMonitor } from "@/types/monitor";
import { useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/hooks/UseApi";
import { useParams } from "react-router";
import type { IStatusPageWithMonitors } from "@/types/status-page";
import { NameHeader } from "@/components/status-pages/NameHeader";
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
const StatusPages = () => {
const theme = useTheme();
const { id } = useParams();
const { response } = useGet<ApiResponse<IStatusPageWithMonitors>>(
`/status-pages/${id}`,
{},
{ refreshInterval: GLOBAL_REFRESH, keepPreviousData: true }
);
const statusPage = response?.data;
const monitors: IMonitor[] = statusPage?.monitors || [];
if (!statusPage) {
return null;
}
return (
<BasePage alignItems={"center"}>
<Stack minWidth={"66vw"} spacing={theme.spacing(8)}>
<NameHeader statusPage={statusPage} />
<StatusHeader statusPage={statusPage} />
{monitors?.map((monitor: IMonitor) => {
return <StatusPageRow key={monitor?._id} monitor={monitor} />;
})}
</Stack>
</BasePage>
);
};
export default StatusPages;
@@ -0,0 +1,213 @@
import Stack from "@mui/material/Stack";
import { Button, FormControlLabel } from "@/components/inputs";
import { ConfigBox, BasePage } from "@/components/design-elements";
import { TextInput, AutoComplete, Checkbox } from "@/components/inputs";
import Typography from "@mui/material/Typography";
import { Trash2 } from "lucide-react";
import { useTheme } from "@mui/material/styles";
import { zodResolver } from "@hookform/resolvers/zod";
import { useTranslation } from "react-i18next";
import { z } from "zod";
import { statusPageSchema } from "@/validation/zod";
import {
useForm,
Controller,
useWatch,
type SubmitHandler,
} from "react-hook-form";
import { useEffect } from "react";
import { useInitForm } from "@/hooks/forms/UseInitStatusPageForm";
import type { IMonitor } from "@/types/monitor";
type FormValues = z.infer<typeof statusPageSchema>;
export const StatusPageForm = ({
initialData,
monitorOptions,
onSubmit,
loading,
}: {
mode?: string;
monitorOptions: IMonitor[];
initialData?: Partial<FormValues>;
onSubmit: SubmitHandler<FormValues>;
loading: boolean;
}) => {
const { t } = useTranslation();
const { defaults } = useInitForm({ initialData: initialData });
const theme = useTheme();
const {
handleSubmit,
control,
reset,
setValue,
formState: { errors },
} = useForm<FormValues>({
resolver: zodResolver(statusPageSchema),
defaultValues: defaults,
mode: "onChange",
});
useEffect(() => {
reset(defaults);
}, [initialData, reset, defaults]);
const onError = (errors: any) => {
console.log(errors);
};
const monitors = useWatch({
control,
name: "monitors",
});
return (
<BasePage component={"form"} onSubmit={handleSubmit(onSubmit, onError)}>
<ConfigBox
title={t("createStatusPage.basicConfigTitle")}
subtitle={t("createStatusPage.basicConfigDescription")}
rightContent={
<Stack gap={theme.spacing(8)}>
<Controller
name="name"
control={control}
render={({ field }) => (
<TextInput
{...field}
type="text"
fieldLabel={t("createStatusPage.nameConfigLabel")}
fullWidth
error={!!errors.name}
helperText={errors.name ? errors.name.message : ""}
/>
)}
/>
<Controller
name="description"
control={control}
render={({ field }) => (
<TextInput
{...field}
type="text"
fieldLabel={t("createStatusPage.descriptionConfigLabel")}
fullWidth
error={!!errors.description}
helperText={
errors.description ? errors.description.message : ""
}
/>
)}
/>
</Stack>
}
/>
<ConfigBox
title={t("createStatusPage.urlConfigTitle")}
subtitle={t("createStatusPage.urlConfigDescription")}
rightContent={
<Controller
name="url"
control={control}
render={({ field }) => (
<TextInput
{...field}
type="text"
fieldLabel={t("createStatusPage.urlConfigTitle")}
fullWidth
error={!!errors.url}
helperText={errors.url ? errors.url.message : ""}
/>
)}
/>
}
/>
<ConfigBox
title={t("createStatusPage.accessConfigTitle")}
subtitle={t("createStatusPage.accessConfigDescription")}
rightContent={
<Controller
name="isPublished"
control={control}
render={({ field }) => (
<FormControlLabel
label={t("createStatusPage.publishedConfigLabel")}
control={
<Checkbox
{...field}
checked={field.value}
onChange={(e) => field.onChange(e.target.checked)}
/>
}
/>
)}
/>
}
/>
<ConfigBox
title={t("createMaintenanceWindowPage.monitorsTitle")}
subtitle={t("createMaintenanceWindowPage.monitorsDescription")}
rightContent={
<Stack>
<Controller
name="monitors"
control={control}
defaultValue={[]}
render={({ field }) => (
<AutoComplete
multiple
options={monitorOptions}
getOptionLabel={(option) => option.name}
value={monitorOptions.filter((o: any) =>
(field.value || []).includes(o._id)
)}
onChange={(_, newValue) => {
field.onChange(newValue.map((o: any) => o._id));
}}
/>
)}
/>
<Stack gap={theme.spacing(2)} mt={theme.spacing(2)}>
{monitors.map((monitorId) => {
const option = monitorOptions.find((o) => o._id === monitorId);
if (!option) return null;
return (
<Stack
width={"100%"}
justifyContent={"space-between"}
direction="row"
key={monitorId}
>
<Typography>{option.name}</Typography>
<Trash2
size={20}
strokeWidth={1.5}
onClick={() => {
const updated = monitors.filter(
(id) => id !== monitorId
);
setValue("monitors", updated);
}}
style={{ cursor: "pointer" }}
/>
</Stack>
);
})}
</Stack>
</Stack>
}
/>
<Stack direction="row" justifyContent="flex-end">
<Button
loading={loading}
type="submit"
variant="contained"
color="accent"
>
{t("settingsSave")}
</Button>
</Stack>
</BasePage>
);
};
@@ -0,0 +1,42 @@
import Stack from "@mui/material/Stack";
import { StatusHeader } from "@/components/status-pages/StatusHeader";
import { StatusPageRow } from "@/components/status-pages/StatusPageRow";
import { BasePage } from "@/components/design-elements";
import { useTheme } from "@mui/material/styles";
import type { IMonitor } from "@/types/monitor";
import { useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/hooks/UseApi";
import { useParams } from "react-router";
import type { IStatusPageWithMonitors } from "@/types/status-page";
import { NameHeader } from "@/components/status-pages/NameHeader";
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
const StatusPages = () => {
const theme = useTheme();
const { url } = useParams();
const { response } = useGet<ApiResponse<IStatusPageWithMonitors>>(
`/status-pages/public/${url}`,
{},
{ refreshInterval: GLOBAL_REFRESH, keepPreviousData: true }
);
const statusPage = response?.data;
const monitors: IMonitor[] = statusPage?.monitors || [];
if (!statusPage) {
return null;
}
return (
<BasePage alignItems={"center"} paddingTop={theme.spacing(20)}>
<Stack minWidth={"66vw"} spacing={theme.spacing(8)}>
<NameHeader statusPage={statusPage} />
<StatusHeader statusPage={statusPage} />
{monitors?.map((monitor: IMonitor) => {
return <StatusPageRow key={monitor?._id} monitor={monitor} />;
})}
</Stack>
</BasePage>
);
};
export default StatusPages;
Whitespace-only changes.
@@ -0,0 +1,147 @@
import { HeaderCreate } from "@/components/notification-channels/HeaderCreate";
import Typography from "@mui/material/Typography";
import { BasePageWithStates, InfoBox } from "@/components/design-elements";
import { Table } from "@/components/design-elements";
import { ActionsMenu } from "@/components/actions-menu";
import { Dialog } from "@/components/inputs";
import { useState } from "react";
import { useTheme } from "@mui/material/styles";
import { useNavigate } from "react-router";
import type { ActionMenuItem } from "@/components/actions-menu";
import type { Header } from "@/components/design-elements/Table";
import type { IStatusPage } from "@/types/status-page";
import { useGet, useDelete } from "@/hooks/UseApi";
import type { ApiResponse } from "@/hooks/UseApi";
import { useTranslation } from "react-i18next";
const StatusPages = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const theme = useTheme();
const [selectedStatusPage, setSelectedStatusPage] =
useState<IStatusPage | null>(null);
const open = Boolean(selectedStatusPage);
const { response, isValidating, error, refetch } = useGet<
ApiResponse<IStatusPage[]>
>("/status-pages", {}, {});
const statusPages = response?.data || [];
const { deleteFn, loading: deleting } = useDelete<any>();
const getActions = (statusPage: IStatusPage): ActionMenuItem[] => {
return [
{
id: 1,
label: "Configure",
action: () => {
navigate(`/status-pages/${statusPage._id}/configure`);
},
closeMenu: true,
},
{
id: 7,
label: <Typography color={theme.palette.error.main}>Remove</Typography>,
action: async () => {
setSelectedStatusPage(statusPage);
},
closeMenu: true,
},
];
};
const getHeaders = () => {
const headers: Header<IStatusPage>[] = [
{
id: "name",
content: "Name",
render: (row) => {
return <Typography>{row?.name}</Typography>;
},
},
{
id: "published",
content: "Published",
render: (row) => {
const published = row.isPublished ? "Yes" : "No";
return <Typography>{published}</Typography>;
},
},
{
id: "url",
content: "Public URL",
render: (row) => {
return (
<Typography textTransform={"capitalize"}>{row?.url}</Typography>
);
},
},
{
id: "actions",
content: t("actions"),
render: (row) => {
return <ActionsMenu items={getActions(row)} />;
},
},
];
return headers;
};
const headers = getHeaders();
const handleConfirm = async () => {
if (!selectedStatusPage) return;
const res = await deleteFn(`/status-pages/${selectedStatusPage._id}`);
if (res) {
setSelectedStatusPage(null);
refetch();
}
};
const handleCancel = () => {
setSelectedStatusPage(null);
};
return (
<BasePageWithStates
page="Status Pages"
loading={false}
bullets={
t("statusPage.fallback.checks", { returnObjects: true }) as string[]
}
error={error}
items={statusPages}
actionButtonText="Create a new status page"
actionLink="/status-pages/create"
>
<InfoBox
title="Public Status Pages"
description="Create beautiful, branded status pages to keep your users informed about service health. Share real-time status updates and incident reports with your customers."
/>
<HeaderCreate
label={"Create a new Status Page"}
isLoading={isValidating || deleting}
path="/status-pages/create"
/>
<Table
headers={headers}
data={statusPages}
onRowClick={(row) => {
navigate(`/status-pages/${row._id}`);
}}
/>
<Dialog
title={t("createStatusPage.dialogDeleteTitle")}
content={t("createStatusPage.dialogDeleteContent")}
open={open}
onConfirm={handleConfirm}
onCancel={handleCancel}
/>
</BasePageWithStates>
);
};
export default StatusPages;