Skip to content

Commit

Permalink
include fields for id details and color description
Browse files Browse the repository at this point in the history
  • Loading branch information
axgu committed Jun 20, 2024
1 parent 23d602d commit d0d0ac0
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 19 deletions.
35 changes: 19 additions & 16 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
59 changes: 56 additions & 3 deletions src/pages/manage/items/[itemId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Item,
ItemInteraction,
Location,
RetrieveLocation,
Value
} from '@prisma/client';
import MyListbox from 'components/Form/Listbox';
Expand All @@ -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 = {
Expand All @@ -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({
Expand Down Expand Up @@ -159,6 +164,22 @@ function EditItemForm({ item }: EditItemFormProps) {
{methods.formState.errors.color?.message}
</label>
</div>
{selectedColor === 'OTHER' ? (
<div>
<label className="label">
<span className="label-text">Color Details</span>
</label>
<input
type="text"
placeholder="Type here"
className="input-bordered input input-sm w-full"
{...methods.register('otherColorDescription')}
/>
<label className="text-xs text-error">
{methods.formState.errors.otherColorDescription?.message}
</label>
</div>
) : null}
<div>
<label className="label">
<span className="label-text">Value</span>
Expand Down Expand Up @@ -194,13 +215,45 @@ function EditItemForm({ item }: EditItemFormProps) {
{methods.formState.errors.identifiable?.message}
</label>
</div>
{idDetails ? (
<div>
<div>
<label className="label">
<span className="label-text">Identification</span>
</label>
<input
type="text"
placeholder="Andrew ID or driver's license number"
className="input-bordered input input-sm w-full"
{...methods.register('identification')}
/>
<label className="text-xs text-error">
{methods.formState.errors.identification?.message}
</label>
</div>
<div>
<label className="label">
<span className="label-text">Owner Notified?</span>
</label>
<input
type="text"
placeholder="Ex. Yes-emailed, No, N/A, etc."
className="input-bordered input input-sm w-full"
{...methods.register('ownerNotified')}
/>
<label className="text-xs text-error">
{methods.formState.errors.ownerNotified?.message}
</label>
</div>
</div>
) : null}
<div>
<label className="label">
<span className="label-text">Retrieve From</span>
</label>
<MyListbox
values={Object.values(Location)}
displayValue={(prop) => Locations[prop]}
values={Object.values(RetrieveLocation)}
displayValue={(prop) => RetrieveLocations[prop]}
keyValue={(prop) => prop}
name="retrieveLocation"
control={methods.control}
Expand Down
51 changes: 51 additions & 0 deletions src/pages/manage/items/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const CreateItem: NextPageWithLayout = () => {

const methods = useZodForm({ schema: ItemCreateSchema });

const idDetails = methods.watch('identifiable');
const selectedColor = methods.watch('color');

return (
<div className="mx-auto max-w-lg">
<h3 className="text-2xl font-bold">Add Item</h3>
Expand Down Expand Up @@ -176,6 +179,22 @@ const CreateItem: NextPageWithLayout = () => {
{methods.formState.errors.color?.message}
</label>
</div>
{selectedColor === 'OTHER' ? (
<div>
<label className="label">
<span className="label-text">Color Details</span>
</label>
<input
type="text"
placeholder="Type here"
className="input-bordered input input-sm w-full"
{...methods.register('otherColorDescription')}
/>
<label className="text-xs text-error">
{methods.formState.errors.otherColorDescription?.message}
</label>
</div>
) : null}
<div>
<label className="label">
<span className="label-text">
Expand Down Expand Up @@ -213,6 +232,38 @@ const CreateItem: NextPageWithLayout = () => {
{methods.formState.errors.identifiable?.message}
</label>
</div>
{idDetails ? (
<div>
<div>
<label className="label">
<span className="label-text">Identification</span>
</label>
<input
type="text"
placeholder="Andrew ID or driver's license number"
className="input-bordered input input-sm w-full"
{...methods.register('identification')}
/>
<label className="text-xs text-error">
{methods.formState.errors.identification?.message}
</label>
</div>
<div>
<label className="label">
<span className="label-text">Owner Notified?</span>
</label>
<input
type="text"
placeholder="Ex. Yes-emailed, No, N/A, etc."
className="input-bordered input input-sm w-full"
{...methods.register('ownerNotified')}
/>
<label className="text-xs text-error">
{methods.formState.errors.ownerNotified?.message}
</label>
</div>
</div>
) : null}
<div>
<label className="label">
<span className="label-text">
Expand Down

0 comments on commit d0d0ac0

Please sign in to comment.