From d0d0ac05d854c267600f7bd5a7bbf3fcf7a800ea Mon Sep 17 00:00:00 2001 From: axgu Date: Thu, 20 Jun 2024 11:37:49 -0400 Subject: [PATCH] include fields for id details and color description --- prisma/schema.prisma | 35 +++++++++-------- src/lib/schemas.ts | 3 ++ src/pages/manage/items/[itemId].tsx | 59 +++++++++++++++++++++++++++-- src/pages/manage/items/create.tsx | 51 +++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 19 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7d07833..00e1fa3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -97,22 +97,25 @@ enum Permission { } model Item { - id String @id @default(cuid()) - name String - foundDate DateTime - foundLocation Location - foundDescription String - shortDescription String - categories Category[] - color Color - value Value - identifiable Boolean - retrieveLocation RetrieveLocation - itemLocation String - longDescription String? - auditLogs AuditLog[] - status Status - createdAt DateTime @default(now()) + id String @id @default(cuid()) + name String + foundDate DateTime + foundLocation Location + foundDescription String + shortDescription String + categories Category[] + color Color + otherColorDescription String? + value Value + identifiable Boolean + identification String? + ownerNotified String? + retrieveLocation RetrieveLocation + itemLocation String + longDescription String? + auditLogs AuditLog[] + status Status + createdAt DateTime @default(now()) } model AuditLog { diff --git a/src/lib/schemas.ts b/src/lib/schemas.ts index 5013aeb..828d749 100644 --- a/src/lib/schemas.ts +++ b/src/lib/schemas.ts @@ -18,11 +18,14 @@ export const ItemSchema = z.object({ shortDescription: z.string().min(3), categories: z.array(z.nativeEnum(Category)), color: z.nativeEnum(Color), + otherColorDescription: z.string(), value: z.nativeEnum(Value, { required_error: 'Required', invalid_type_error: 'Required' }), identifiable: z.boolean(), + identification: z.string(), + ownerNotified: z.string(), itemLocation: z.string().min(3), retrieveLocation: z.nativeEnum(RetrieveLocation), longDescription: z.string().nullish(), diff --git a/src/pages/manage/items/[itemId].tsx b/src/pages/manage/items/[itemId].tsx index 46cd340..1b39e02 100644 --- a/src/pages/manage/items/[itemId].tsx +++ b/src/pages/manage/items/[itemId].tsx @@ -4,6 +4,7 @@ import { Item, ItemInteraction, Location, + RetrieveLocation, Value } from '@prisma/client'; import MyListbox from 'components/Form/Listbox'; @@ -13,7 +14,7 @@ import { ItemSchema } from 'lib/schemas'; import { useRouter } from 'next/router'; import { NextPageWithLayout } from 'pages/_app'; import { toast } from 'react-toastify'; -import { Categories, Colors, Locations } from 'types'; +import { Categories, Colors, Locations, RetrieveLocations } from 'types'; import { trpc } from 'utils/trpc'; type EditItemFormProps = { @@ -30,6 +31,10 @@ function EditItemForm({ item }: EditItemFormProps) { .substring(0, 16) as unknown as Date } }); + + const idDetails = methods.watch('identifiable'); + const selectedColor = methods.watch('color'); + const auditCreateMutation = trpc.audit.create.useMutation(); const context = trpc.useContext(); const itemMutation = trpc.item.update.useMutation({ @@ -159,6 +164,22 @@ function EditItemForm({ item }: EditItemFormProps) { {methods.formState.errors.color?.message} + {selectedColor === 'OTHER' ? ( +
+ + + +
+ ) : null}
+ {idDetails ? ( +
+
+ + + +
+
+ + + +
+
+ ) : null}
Locations[prop]} + values={Object.values(RetrieveLocation)} + displayValue={(prop) => RetrieveLocations[prop]} keyValue={(prop) => prop} name="retrieveLocation" control={methods.control} diff --git a/src/pages/manage/items/create.tsx b/src/pages/manage/items/create.tsx index b47f40f..265d6f9 100644 --- a/src/pages/manage/items/create.tsx +++ b/src/pages/manage/items/create.tsx @@ -40,6 +40,9 @@ const CreateItem: NextPageWithLayout = () => { const methods = useZodForm({ schema: ItemCreateSchema }); + const idDetails = methods.watch('identifiable'); + const selectedColor = methods.watch('color'); + return (

Add Item

@@ -176,6 +179,22 @@ const CreateItem: NextPageWithLayout = () => { {methods.formState.errors.color?.message}
+ {selectedColor === 'OTHER' ? ( +
+ + + +
+ ) : null}
+ {idDetails ? ( +
+
+ + + +
+
+ + + +
+
+ ) : null}