fix: fix monitor list create page add monitor list not work problem

This commit is contained in:
moonrailgun 2023-12-23 23:25:53 +08:00
parent f749f720db
commit 42eb5779b2
3 changed files with 26 additions and 19 deletions

View File

@ -10,6 +10,7 @@ const { Text } = Typography;
export interface MonitorStatusPageEditFormValues { export interface MonitorStatusPageEditFormValues {
title: string; title: string;
slug: string; slug: string;
monitorList: PrismaJson.MonitorStatusPageList;
} }
interface MonitorStatusPageEditFormProps { interface MonitorStatusPageEditFormProps {

View File

@ -3,12 +3,10 @@ import { useNavigate } from 'react-router';
import { useCurrentWorkspaceId } from '../../store/user'; import { useCurrentWorkspaceId } from '../../store/user';
import { trpc } from '../../api/trpc'; import { trpc } from '../../api/trpc';
import { useEvent } from '../../hooks/useEvent'; import { useEvent } from '../../hooks/useEvent';
import { MonitorStatusPageEditForm } from '../../components/monitor/StatusPage/EditForm'; import {
MonitorStatusPageEditForm,
interface Values { MonitorStatusPageEditFormValues,
title: string; } from '../../components/monitor/StatusPage/EditForm';
slug: string;
}
export const MonitorPageAdd: React.FC = React.memo(() => { export const MonitorPageAdd: React.FC = React.memo(() => {
const workspaceId = useCurrentWorkspaceId()!; const workspaceId = useCurrentWorkspaceId()!;
@ -17,17 +15,18 @@ export const MonitorPageAdd: React.FC = React.memo(() => {
const createPageMutation = trpc.monitor.createPage.useMutation(); const createPageMutation = trpc.monitor.createPage.useMutation();
const trpcUtils = trpc.useContext(); const trpcUtils = trpc.useContext();
const handleFinish = useEvent(async (values: Values) => { const handleFinish = useEvent(
await createPageMutation.mutateAsync({ async (values: MonitorStatusPageEditFormValues) => {
workspaceId, await createPageMutation.mutateAsync({
title: values.title, ...values,
slug: values.slug, workspaceId,
}); });
trpcUtils.monitor.getAllPages.refetch(); trpcUtils.monitor.getAllPages.refetch();
navigate('/monitor/pages'); navigate('/monitor/pages');
}); }
);
return ( return (
<div className="px-8 py-4"> <div className="px-8 py-4">

View File

@ -500,10 +500,17 @@ export const monitorRouter = router({
}) })
) )
.input( .input(
z.object({ z
slug: z.string(), .object({
title: z.string(), slug: z.string(),
}) title: z.string(),
})
.merge(
MonitorStatusPageModelSchema.pick({
description: true,
monitorList: true,
}).partial()
)
) )
.output(MonitorStatusPageModelSchema) .output(MonitorStatusPageModelSchema)
.mutation(async ({ input }) => { .mutation(async ({ input }) => {