From 85ecf8a07345ce4dcfcf97b35991a58470d89a09 Mon Sep 17 00:00:00 2001 From: BlueZeeKing Date: Tue, 31 Oct 2023 18:23:43 -0400 Subject: [PATCH] Migrate to new TRPC backend --- .../app/modules/[id]/_components/add-task.tsx | 34 +++++++-------- .../modules/[id]/_components/task-item.tsx | 14 +++---- .../app/modules/[id]/_components/tasks.tsx | 8 ++-- src/app/(dashboard)/app/modules/[id]/page.tsx | 10 ++--- src/db/schema/module.ts | 2 +- src/server/api/routers/module.ts | 6 +-- src/server/api/routers/task.ts | 42 ++++++++++++++++--- 7 files changed, 74 insertions(+), 42 deletions(-) diff --git a/src/app/(dashboard)/app/modules/[id]/_components/add-task.tsx b/src/app/(dashboard)/app/modules/[id]/_components/add-task.tsx index e3a4250d..5226bc9d 100644 --- a/src/app/(dashboard)/app/modules/[id]/_components/add-task.tsx +++ b/src/app/(dashboard)/app/modules/[id]/_components/add-task.tsx @@ -28,16 +28,16 @@ export default function AddTask(props: { reset, } = useZodForm({ schema: z.object({ - name: z.string(), + title: z.string(), note: z.string().optional(), - dueAt: z + dueDate: z .string() .refine((str) => !isNaN(Date.parse(str)), { message: "Invalid date" }), - priority: z.enum(["low", "high", "medium"]), + priority: z.enum(["LOW", "HIGH", "MEDIUM"]), }), }); - const { mutateAsync, isLoading } = trpc.todos.create.new.useMutation(); + const { mutateAsync, isLoading } = trpc.task.post.create.useMutation(); const utils = trpc.useUtils(); return ( @@ -50,12 +50,12 @@ export default function AddTask(props: { onSubmit={handleSubmit(async (data) => { await mutateAsync({ moduleId: props.moduleId, - name: data.name, + title: data.title, priority: data.priority, - note: data.note, - dueAt: new Date(Date.parse(data.dueAt)), + notes: data.note ?? "", + dueDate: new Date(Date.parse(data.dueDate)).toString(), }); - await utils.todos.invalidate(); + await utils.task.invalidate(); onClose(); reset(); @@ -71,9 +71,9 @@ export default function AddTask(props: { variant="bordered" labelPlacement="outside" isRequired - isInvalid={!!errors.name} - errorMessage={errors.name?.message} - {...register("name")} + isInvalid={!!errors.title} + errorMessage={errors.title?.message} + {...register("title")} />