feat(status-page): add step-wizard progress indicator to create flow
This commit is contained in:
1 parent
7df3ee6ecd
commit
7617929700
2 files changed
+63
-6
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
import { BasePage, ConfigBox } from "@/Components/design-elements";
|
import { BasePage, ConfigBox, StepProgress } from "@/Components/design-elements";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { logger } from "@/Utils/logger";
|
import { logger } from "@/Utils/logger";
|
||||||
import { SPACING, LAYOUT } from "@/Utils/Theme/constants";
|
import { SPACING, LAYOUT } from "@/Utils/Theme/constants";
|
||||||
@@ -26,6 +26,7 @@ import { useForm, Controller } from "react-hook-form";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useStatusPageForm } from "@/Hooks/useStatusPageForm";
|
import { useStatusPageForm } from "@/Hooks/useStatusPageForm";
|
||||||
import type { StatusPageFormData } from "@/Validation/statusPage";
|
import type { StatusPageFormData } from "@/Validation/statusPage";
|
||||||
|
import { statusPageStepCount, statusPageStepFieldsFor } from "@/Validation/statusPage";
|
||||||
import { useGet, usePost, usePut, useDelete } from "@/Hooks/UseApi";
|
import { useGet, usePost, usePut, useDelete } from "@/Hooks/UseApi";
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
import type { Monitor } from "@/Types/Monitor";
|
||||||
import type { MonitorDisplayType, StatusPageResponse } from "@/Types/StatusPage";
|
import type { MonitorDisplayType, StatusPageResponse } from "@/Types/StatusPage";
|
||||||
@@ -86,13 +87,27 @@ const CreateStatusPage = () => {
|
|||||||
defaultValues: defaults,
|
defaultValues: defaults,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { control, reset, handleSubmit } = form;
|
const { control, reset, handleSubmit, trigger } = form;
|
||||||
|
|
||||||
// Reset form when defaults change (from fetched data)
|
// Reset form when defaults change (from fetched data)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
reset(defaults);
|
reset(defaults);
|
||||||
}, [defaults, reset]);
|
}, [defaults, reset]);
|
||||||
|
|
||||||
|
// Multi-step wizard, create only. The configure (edit) flow keeps the flat
|
||||||
|
// form, where showStep() is always true.
|
||||||
|
const [currentStep, setCurrentStep] = useState(0);
|
||||||
|
const showStep = (step: number) => !isCreate || currentStep === step;
|
||||||
|
const totalSteps = statusPageStepCount();
|
||||||
|
|
||||||
|
const handleNext = async () => {
|
||||||
|
const isValid = await trigger(statusPageStepFieldsFor(currentStep));
|
||||||
|
if (isValid) {
|
||||||
|
setCurrentStep((step) => step + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handleBack = () => setCurrentStep((step) => step - 1);
|
||||||
|
|
||||||
const watchedMonitorIds: string[] = form.watch("monitors") ?? [];
|
const watchedMonitorIds: string[] = form.watch("monitors") ?? [];
|
||||||
const computedTypes: MonitorDisplayType[] = useMemo(() => {
|
const computedTypes: MonitorDisplayType[] = useMemo(() => {
|
||||||
const selectedMonitors = (watchedMonitorIds ?? [])
|
const selectedMonitors = (watchedMonitorIds ?? [])
|
||||||
@@ -200,6 +215,13 @@ const CreateStatusPage = () => {
|
|||||||
onSubmit={handleSubmit(onSubmit, onError)}
|
onSubmit={handleSubmit(onSubmit, onError)}
|
||||||
>
|
>
|
||||||
{!isCreate && <HeaderConfigStatusControls onDelete={handleDeleteClick} />}
|
{!isCreate && <HeaderConfigStatusControls onDelete={handleDeleteClick} />}
|
||||||
|
{isCreate && (
|
||||||
|
<StepProgress
|
||||||
|
steps={totalSteps}
|
||||||
|
current={currentStep}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{showStep(0) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.statusPages.form.access.title")}
|
title={t("pages.statusPages.form.access.title")}
|
||||||
subtitle={t("pages.statusPages.form.access.description")}
|
subtitle={t("pages.statusPages.form.access.description")}
|
||||||
@@ -225,6 +247,8 @@ const CreateStatusPage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{showStep(0) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.statusPages.form.basicInfo.title")}
|
title={t("pages.statusPages.form.basicInfo.title")}
|
||||||
subtitle={t("pages.statusPages.form.basicInfo.description")}
|
subtitle={t("pages.statusPages.form.basicInfo.description")}
|
||||||
@@ -263,6 +287,8 @@ const CreateStatusPage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{showStep(0) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.statusPages.form.monitors.title")}
|
title={t("pages.statusPages.form.monitors.title")}
|
||||||
subtitle={t("pages.statusPages.form.monitors.description")}
|
subtitle={t("pages.statusPages.form.monitors.description")}
|
||||||
@@ -375,6 +401,8 @@ const CreateStatusPage = () => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{showStep(0) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.statusPages.form.timezone.title")}
|
title={t("pages.statusPages.form.timezone.title")}
|
||||||
subtitle={t("pages.statusPages.form.timezone.description")}
|
subtitle={t("pages.statusPages.form.timezone.description")}
|
||||||
@@ -406,6 +434,8 @@ const CreateStatusPage = () => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{showStep(1) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.statusPages.form.appearance.title")}
|
title={t("pages.statusPages.form.appearance.title")}
|
||||||
subtitle={t("pages.statusPages.form.appearance.description")}
|
subtitle={t("pages.statusPages.form.appearance.description")}
|
||||||
@@ -447,6 +477,8 @@ const CreateStatusPage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{showStep(1) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.statusPages.form.theme.title")}
|
title={t("pages.statusPages.form.theme.title")}
|
||||||
subtitle={t("pages.statusPages.form.theme.description")}
|
subtitle={t("pages.statusPages.form.theme.description")}
|
||||||
@@ -471,6 +503,8 @@ const CreateStatusPage = () => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{showStep(1) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.statusPages.form.features.title")}
|
title={t("pages.statusPages.form.features.title")}
|
||||||
subtitle={t("pages.statusPages.form.features.description")}
|
subtitle={t("pages.statusPages.form.features.description")}
|
||||||
@@ -545,11 +579,35 @@ const CreateStatusPage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
justifyContent="flex-end"
|
justifyContent={isCreate ? "space-between" : "flex-end"}
|
||||||
>
|
>
|
||||||
|
{isCreate && (
|
||||||
<Button
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outlined"
|
||||||
|
color="secondary"
|
||||||
|
disabled={currentStep === 0}
|
||||||
|
onClick={handleBack}
|
||||||
|
>
|
||||||
|
{t("common.buttons.back")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{isCreate && currentStep < totalSteps - 1 ? (
|
||||||
|
<Button
|
||||||
|
key="wizard-next"
|
||||||
|
type="button"
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleNext}
|
||||||
|
>
|
||||||
|
{t("common.buttons.next")}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
key="wizard-save"
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@@ -557,6 +615,7 @@ const CreateStatusPage = () => {
|
|||||||
>
|
>
|
||||||
{t("common.buttons.save")}
|
{t("common.buttons.save")}
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isDeleteDialogOpen}
|
open={isDeleteDialogOpen}
|
||||||
|
|||||||
@@ -66,9 +66,7 @@ const fieldSteps = (): [name: FieldPath<StatusPageFormData>, step: number][] =>
|
|||||||
|
|
||||||
// The fields that belong to a given wizard step. Derived from the schema so it
|
// The fields that belong to a given wizard step. Derived from the schema so it
|
||||||
// can't drift from the field definitions.
|
// can't drift from the field definitions.
|
||||||
export const statusPageStepFieldsFor = (
|
export const statusPageStepFieldsFor = (step: number): FieldPath<StatusPageFormData>[] =>
|
||||||
step: number
|
|
||||||
): FieldPath<StatusPageFormData>[] =>
|
|
||||||
fieldSteps()
|
fieldSteps()
|
||||||
.filter(([, fieldStep]) => fieldStep === step)
|
.filter(([, fieldStep]) => fieldStep === step)
|
||||||
.map(([name]) => name);
|
.map(([name]) => name);
|
||||||
|
|||||||
Reference in new issue
Block a user