@@ -157,6 +157,7 @@ export function PaymentReceivedForm({ resourceId, initialData, onSuccess, defaul
|
||||
name="customer"
|
||||
label="Customer"
|
||||
placeholder="Select customer"
|
||||
required
|
||||
queryKey={[CUSTOMER_ROUTES.INDEX]}
|
||||
listFn={() => api.customers.list()}
|
||||
mapOption={(item: any) => ({
|
||||
@@ -193,6 +194,7 @@ export function PaymentReceivedForm({ resourceId, initialData, onSuccess, defaul
|
||||
name="payment_mode"
|
||||
label="Payment Mode"
|
||||
placeholder="Select payment mode"
|
||||
required
|
||||
queryKey={[PAYMENT_MODE_ROUTES.INDEX]}
|
||||
listFn={() => api.paymentModes.list()}
|
||||
mapOption={mapLookupOption}
|
||||
|
||||
@@ -4,17 +4,38 @@ 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,
|
||||
payment_mode: relationFieldSchema,
|
||||
customer: relationFieldSchema,
|
||||
payment_mode: requiredRelationFieldSchema,
|
||||
customer: requiredRelationFieldSchema,
|
||||
|
||||
// ── Payment info ──
|
||||
amount_received: z.string().min(1, "Amount is required"),
|
||||
payment_number: z.string().optional(),
|
||||
payment_date: z.string().min(1, "Payment date is required"),
|
||||
note: z.string().optional(),
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user