diff --git a/app/actions.ts b/app/actions.ts index c8d0932..80ae2f6 100644 --- a/app/actions.ts +++ b/app/actions.ts @@ -17,6 +17,7 @@ export async function submitRequest(_state: FormState, formData: FormData): Prom const input = parse(RequestInput, { title: formData.get("title"), category: formData.get("category"), + costCenter: String(formData.get("costCenter") ?? "").trim() || undefined, amount: amount === "" ? undefined : Number(amount), justification: formData.get("justification"), }); diff --git a/app/api/requests/openapi.ts b/app/api/requests/openapi.ts index 0ddd733..e26f207 100644 --- a/app/api/requests/openapi.ts +++ b/app/api/requests/openapi.ts @@ -10,6 +10,7 @@ export const RequestJson = z.object({ id: z.uuid(), title: z.string(), category: z.enum(CATEGORIES), + costCenter: z.string().nullable(), amount: z.number().nullable(), justification: z.string(), status: z.enum(STATUSES), diff --git a/app/requests/[id]/page.tsx b/app/requests/[id]/page.tsx index 9db0e04..ab19e14 100644 --- a/app/requests/[id]/page.tsx +++ b/app/requests/[id]/page.tsx @@ -37,6 +37,7 @@ export default async function RequestPage({ params }: PageProps<"/requests/[id]"
Category
{categoryLabel(request.category)}
+ {request.costCenter &&
Cost center
{request.costCenter}
}
Amount
{formatAmount(request.amount)}
Requested by
{request.requestedByName}
diff --git a/app/requests/forms.tsx b/app/requests/forms.tsx index cc1b983..6b5084f 100644 --- a/app/requests/forms.tsx +++ b/app/requests/forms.tsx @@ -20,6 +20,10 @@ export function NewRequestForm() { +
+ + +
diff --git a/db/schema.ts b/db/schema.ts index 7278445..ce539bb 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -19,6 +19,7 @@ export const requests = pgTable("requests", { id: uuid("id").defaultRandom().primaryKey(), title: text("title").notNull(), category: text("category").notNull(), + costCenter: text("cost_center"), amount: numeric("amount", { precision: 12, scale: 2, mode: "number" }), justification: text("justification").notNull(), status: text("status").notNull().default("pending"), diff --git a/lib/requests.ts b/lib/requests.ts index 1bd8569..0abd8cf 100644 --- a/lib/requests.ts +++ b/lib/requests.ts @@ -32,6 +32,7 @@ export const RequestInput = z.object({ title: text(MAX_TITLE_LENGTH, `Give the request a title up to ${MAX_TITLE_LENGTH} characters.`) .meta({ description: "What is being asked for, in one line." }), category: z.enum(CATEGORIES, { error: "Pick a category." }), + costCenter: z.string().trim().min(1).max(80).optional(), amount: z.number({ error: "Enter the amount as a number, or leave it blank." }) .nonnegative({ error: "The amount cannot be negative." }) .max(9_999_999_999, { error: "The amount is too large." }) diff --git a/tests/api.test.ts b/tests/api.test.ts index b97e2ec..88bae71 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -28,6 +28,7 @@ const pending: ApprovalRequest = { id: "0b8f3c2e-6a1d-4f5b-9c7e-2d4a6b8c0e1f", title: "New laptop", category: "purchase", + costCenter: null, amount: 1499.5, justification: "Current one is five years old.", status: "pending",