status page
This commit is contained in:
1 parent
8fb13273bf
commit
6dcfb67246
7 files changed
+22
-28
No files matched your search
@@ -1,14 +1,12 @@
|
|||||||
import { statusPageSchema } from "@/validation/zod";
|
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
import type { FormValues } from "@/pages/status-page/StatusPageForm";
|
||||||
import { z } from "zod";
|
|
||||||
export const useInitForm = ({
|
export const useInitForm = ({
|
||||||
initialData,
|
initialData,
|
||||||
}: {
|
}: {
|
||||||
initialData: Partial<z.infer<typeof statusPageSchema>> | undefined;
|
initialData: Partial<FormValues> | undefined;
|
||||||
}) => {
|
}) => {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const defaults: z.infer<typeof statusPageSchema> = {
|
const defaults: FormValues = {
|
||||||
name: initialData?.name || "",
|
name: initialData?.name || "",
|
||||||
description: initialData?.description || "",
|
description: initialData?.description || "",
|
||||||
url: initialData?.url || Math.floor(Math.random() * 1000000).toFixed(0),
|
url: initialData?.url || Math.floor(Math.random() * 1000000).toFixed(0),
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ import { StatusPageForm } from "@/pages/status-page/StatusPageForm";
|
|||||||
|
|
||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { z } from "zod";
|
|
||||||
import { usePatch, useGet } from "@/hooks/UseApi";
|
import { usePatch, useGet } from "@/hooks/UseApi";
|
||||||
import type { ApiResponse } from "@/types/api";
|
import type { ApiResponse } from "@/types/api";
|
||||||
import { statusPageSchema } from "@/validation/zod";
|
|
||||||
import type { IMonitor } from "@/types/monitor";
|
import type { IMonitor } from "@/types/monitor";
|
||||||
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
||||||
|
import type { FormValues } from "@/pages/status-page/StatusPageForm";
|
||||||
type FormValues = z.infer<typeof statusPageSchema>;
|
|
||||||
|
|
||||||
const StatusPageConfigPage = () => {
|
const StatusPageConfigPage = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import { StatusPageForm } from "@/pages/status-page/StatusPageForm";
|
import { StatusPageForm } from "@/pages/status-page/StatusPageForm";
|
||||||
|
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { z } from "zod";
|
|
||||||
import { usePost, useGet } from "@/hooks/UseApi";
|
import { usePost, useGet } from "@/hooks/UseApi";
|
||||||
import type { ApiResponse } from "@/types/api";
|
import type { ApiResponse } from "@/types/api";
|
||||||
import { statusPageSchema } from "@/validation/zod";
|
|
||||||
import type { IMonitor } from "@/types/monitor";
|
import type { IMonitor } from "@/types/monitor";
|
||||||
|
import type { FormValues } from "@/pages/status-page/StatusPageForm";
|
||||||
type FormValues = z.infer<typeof statusPageSchema>;
|
|
||||||
|
|
||||||
const StatusPageCreatePage = () => {
|
const StatusPageCreatePage = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { useTheme } from "@mui/material/styles";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { statusPageSchema } from "@/validation/zod";
|
import { statusPageSchema } from "@/validation";
|
||||||
import {
|
import {
|
||||||
useForm,
|
useForm,
|
||||||
Controller,
|
Controller,
|
||||||
@@ -20,7 +20,7 @@ import { useEffect } from "react";
|
|||||||
import { useInitForm } from "@/hooks/forms/UseInitStatusPageForm";
|
import { useInitForm } from "@/hooks/forms/UseInitStatusPageForm";
|
||||||
import type { IMonitor } from "@/types/monitor";
|
import type { IMonitor } from "@/types/monitor";
|
||||||
|
|
||||||
type FormValues = z.infer<typeof statusPageSchema>;
|
export type FormValues = z.infer<typeof statusPageSchema>;
|
||||||
|
|
||||||
export const StatusPageForm = ({
|
export const StatusPageForm = ({
|
||||||
initialData,
|
initialData,
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ export * from "./notification-channel";
|
|||||||
export * from "./maintenance";
|
export * from "./maintenance";
|
||||||
export * from "./team";
|
export * from "./team";
|
||||||
export * from "./system-settings";
|
export * from "./system-settings";
|
||||||
|
export * from "./status-page";
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const statusPageUrlRegex = /^[A-Za-z0-9]+$/;
|
||||||
|
|
||||||
|
export const statusPageSchema = z.object({
|
||||||
|
name: z.string().min(1, "Status page name is required"),
|
||||||
|
description: z.string().optional(),
|
||||||
|
url: z
|
||||||
|
.string()
|
||||||
|
.min(1, "URL is required")
|
||||||
|
.regex(statusPageUrlRegex, "Invalid URL"),
|
||||||
|
isPublished: z.boolean().optional(),
|
||||||
|
monitors: z.array(z.string()),
|
||||||
|
});
|
||||||
@@ -7,19 +7,6 @@ export const inviteSchema = z.object({
|
|||||||
orgRoleId: z.string().optional(),
|
orgRoleId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const statusPageUrlRegex = /^[A-Za-z0-9]+$/;
|
|
||||||
|
|
||||||
export const statusPageSchema = z.object({
|
|
||||||
name: z.string().min(1, "Status page name is required"),
|
|
||||||
description: z.string().optional(),
|
|
||||||
url: z
|
|
||||||
.string()
|
|
||||||
.min(1, "URL is required")
|
|
||||||
.regex(statusPageUrlRegex, "Invalid URL"),
|
|
||||||
isPublished: z.boolean().optional(),
|
|
||||||
monitors: z.array(z.string()),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const recoverySchema = z.object({
|
export const recoverySchema = z.object({
|
||||||
email: z.email({ message: "Invalid email address" }).trim().toLowerCase(),
|
email: z.email({ message: "Invalid email address" }).trim().toLowerCase(),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user