status pages
This commit is contained in:
1 parent
602597abe2
commit
e5ef14215f
14 files changed
+77
-60
No files matched your search
@@ -5,24 +5,27 @@ import { useNavigate } from "react-router";
|
||||
import { usePatch, useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/types/api";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
||||
import type {
|
||||
IStatusPage,
|
||||
IStatusPageWithChecksMap,
|
||||
} from "@/types/status-page";
|
||||
import type { FormValues } from "@/pages/status-page/StatusPageForm";
|
||||
|
||||
const StatusPageConfigPage = () => {
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams();
|
||||
|
||||
const { patch, loading } = usePatch<FormValues, IStatusPageWithMonitors>();
|
||||
const { patch, loading } = usePatch<FormValues, IStatusPage>();
|
||||
const { response, isValidating } =
|
||||
useGet<ApiResponse<IMonitor[]>>("/monitors");
|
||||
const { response: statusPageResponse } = useGet<ApiResponse<any>>(
|
||||
`/status-pages/${id}`
|
||||
);
|
||||
const { response: statusPageResponse } = useGet<
|
||||
ApiResponse<IStatusPageWithChecksMap>
|
||||
>(`/status-pages/${id}`);
|
||||
|
||||
const monitors = response?.data || [];
|
||||
const initialData = statusPageResponse?.data || {};
|
||||
const initialData: any = statusPageResponse?.data?.statusPage || {};
|
||||
initialData.monitors =
|
||||
initialData?.monitors?.map((monitor: IMonitor) => monitor?._id) || [];
|
||||
initialData?.monitors?.map((monitor: any) => monitor?._id) || [];
|
||||
|
||||
const onSubmit = async (data: FormValues) => {
|
||||
const res = await patch(`/status-pages/${id}`, data);
|
||||
|
||||
@@ -4,11 +4,10 @@ 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 "@/types/api";
|
||||
import { useParams } from "react-router";
|
||||
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
||||
import type { IStatusPageWithChecksMap } from "@/types/status-page";
|
||||
import { NameHeader } from "@/components/status-pages/NameHeader";
|
||||
import { config } from "@/config/index";
|
||||
|
||||
@@ -16,13 +15,14 @@ const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||
const StatusPages = () => {
|
||||
const theme = useTheme();
|
||||
const { id } = useParams();
|
||||
const { response, loading } = useGet<ApiResponse<IStatusPageWithMonitors>>(
|
||||
const { response, loading } = useGet<ApiResponse<IStatusPageWithChecksMap>>(
|
||||
`/status-pages/${id}`,
|
||||
{},
|
||||
{ refreshInterval: GLOBAL_REFRESH, keepPreviousData: true }
|
||||
);
|
||||
const statusPage = response?.data;
|
||||
const monitors: IMonitor[] = statusPage?.monitors || [];
|
||||
const statusPage = response?.data?.statusPage;
|
||||
const monitors = statusPage?.monitors || [];
|
||||
const checksMap: Record<string, any[]> = response?.data?.checksMap || {};
|
||||
|
||||
if (!statusPage) {
|
||||
return null;
|
||||
@@ -33,8 +33,15 @@ const StatusPages = () => {
|
||||
<Stack minWidth={"66vw"} spacing={theme.spacing(8)}>
|
||||
<NameHeader statusPage={statusPage} />
|
||||
<StatusHeader statusPage={statusPage} />
|
||||
{monitors?.map((monitor: IMonitor) => {
|
||||
return <StatusPageRow key={monitor?._id} monitor={monitor} />;
|
||||
{monitors?.map((monitor: any) => {
|
||||
const checks = checksMap?.[monitor?._id as any] || [];
|
||||
return (
|
||||
<StatusPageRow
|
||||
key={monitor?._id}
|
||||
monitor={monitor}
|
||||
checks={checks}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
</BasePage>
|
||||
|
||||
@@ -160,17 +160,17 @@ export const StatusPageForm = ({
|
||||
options={monitorOptions}
|
||||
getOptionLabel={(option) => option.name}
|
||||
value={monitorOptions.filter((o: any) =>
|
||||
(field.value || []).includes(o._id)
|
||||
(field.value || []).includes(o.id)
|
||||
)}
|
||||
onChange={(_, newValue) => {
|
||||
field.onChange(newValue.map((o: any) => o._id));
|
||||
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);
|
||||
const option = monitorOptions.find((o) => o.id === monitorId);
|
||||
if (!option) return null;
|
||||
return (
|
||||
<Stack
|
||||
|
||||
@@ -4,11 +4,10 @@ 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 "@/types/api";
|
||||
import { useParams } from "react-router";
|
||||
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
||||
import type { IStatusPageWithChecksMap } from "@/types/status-page";
|
||||
import { NameHeader } from "@/components/status-pages/NameHeader";
|
||||
import { config } from "@/config/index";
|
||||
|
||||
@@ -16,13 +15,14 @@ const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||
const StatusPages = () => {
|
||||
const theme = useTheme();
|
||||
const { url } = useParams();
|
||||
const { response } = useGet<ApiResponse<IStatusPageWithMonitors>>(
|
||||
const { response } = useGet<ApiResponse<IStatusPageWithChecksMap>>(
|
||||
`/status-pages/public/${url}`,
|
||||
{},
|
||||
{ refreshInterval: GLOBAL_REFRESH, keepPreviousData: true }
|
||||
);
|
||||
const statusPage = response?.data;
|
||||
const monitors: IMonitor[] = statusPage?.monitors || [];
|
||||
const statusPage = response?.data?.statusPage;
|
||||
const monitors = statusPage?.monitors || [];
|
||||
const checksMap: Record<string, any[]> = response?.data?.checksMap || {};
|
||||
|
||||
if (!statusPage) {
|
||||
return null;
|
||||
@@ -33,8 +33,16 @@ const StatusPages = () => {
|
||||
<Stack minWidth={"66vw"} spacing={theme.spacing(8)}>
|
||||
<NameHeader statusPage={statusPage} />
|
||||
<StatusHeader statusPage={statusPage} />
|
||||
{monitors?.map((monitor: IMonitor) => {
|
||||
return <StatusPageRow key={monitor?._id} monitor={monitor} />;
|
||||
{monitors?.map((monitor: any) => {
|
||||
const checks = checksMap?.[monitor?._id as any] || [];
|
||||
|
||||
return (
|
||||
<StatusPageRow
|
||||
key={monitor?.id}
|
||||
monitor={monitor}
|
||||
checks={checks}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
</BasePage>
|
||||
|
||||
Reference in new issue
Block a user