garage-erp/apps/dashboard/modules/payment-received/payment-received.schema.ts
Najjar\NajjarV02 11d920ba6a fix(dashboard): resolve Asma tester-reported UI issues
- 3.1 currency: replace hardcoded $ with AED <Money/> in item & job-card price cells
- 5.1 calendar: /calendars now renders the month calendar (was redirect to list)
- 7.2 nav: remove dead Time Clocks / Time Sheets links (no routes, 404)
- 5.4 check-in: enforce required department at schema level
- 5.6 payments received: add invoice picker so the invoice is marked Paid
- 5.2 share link: forward ws workspace param from the public inspection page

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 14:58:18 +04:00

46 lines
1.4 KiB
TypeScript

import { z } from "zod"
const relationFieldSchema = z
.object({ value: z.string(), label: z.string() })
.nullable()
const requiredRelationFieldSchema = relationFieldSchema.superRefine((value, ctx) => {
if (!value?.value) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "This field is required",
})
}
})
const optionalDateSchema = z.preprocess(
(value) => (value === "" || value == null ? undefined : value),
z.string().date().optional(),
)
const optionalStringMax255Schema = z.preprocess(
(value) => (value === "" || value == null ? undefined : value),
z.string().max(255, "Must be at most 255 characters").optional(),
)
const paymentReceivedFormSchema = z.object({
// ── Relations ──
job_card: relationFieldSchema,
invoice: relationFieldSchema,
payment_mode: requiredRelationFieldSchema,
customer: requiredRelationFieldSchema,
// ── Payment info ──
amount_received: z.coerce.number().min(0, "Amount received must be 0 or more"),
payment_number: optionalStringMax255Schema,
payment_date: optionalDateSchema,
reference_date: optionalDateSchema,
deposit_to: optionalStringMax255Schema,
note: optionalStringMax255Schema,
})
type PaymentReceivedFormValues = z.infer<typeof paymentReceivedFormSchema>
export { paymentReceivedFormSchema, relationFieldSchema }
export type { PaymentReceivedFormValues }