+3
-3
@@ -107,11 +107,11 @@ export function VendorForm({ resourceId, initialData, onSuccess }: VendorFormPro
|
||||
<FieldGroup>
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<RhfTextField name="first_name" label="First Name" placeholder="John" required />
|
||||
<RhfTextField name="last_name" label="Last Name" placeholder="Doe" />
|
||||
<RhfTextField name="last_name" label="Last Name" placeholder="Doe" required />
|
||||
</div>
|
||||
|
||||
<RhfTextField name="company_name" label="Company Name" placeholder="Acme Supplies" />
|
||||
<RhfTextField name="email" label="Email" placeholder="vendor@example.com" type="email" />
|
||||
<RhfTextField name="company_name" label="Company Name" placeholder="Acme Supplies" required />
|
||||
<RhfTextField name="email" label="Email" placeholder="vendor@example.com" type="email" required />
|
||||
|
||||
<Button type="submit" variant="default" disabled={isPending}>
|
||||
{isEditing ? <Save /> : <Plus />}
|
||||
|
||||
+21
-6
@@ -1,12 +1,27 @@
|
||||
import { z } from "zod"
|
||||
|
||||
const optionalStringMaxSchema = (max: number) =>
|
||||
z.preprocess(
|
||||
(value) => (value === "" || value == null ? undefined : value),
|
||||
z.string().max(max, `Must be at most ${max} characters`).optional(),
|
||||
)
|
||||
|
||||
const optionalNumberSchema = z.preprocess(
|
||||
(value) => (value === "" || value == null ? undefined : value),
|
||||
z.coerce.number().int().optional(),
|
||||
)
|
||||
|
||||
const vendorFormSchema = z.object({
|
||||
first_name: z.string().min(1, "First name is required"),
|
||||
last_name: z.string().optional(),
|
||||
company_name: z.string().optional(),
|
||||
email: z
|
||||
.union([z.string().email("Enter a valid email address"), z.literal("")])
|
||||
.optional(),
|
||||
first_name: z.string().trim().min(1, "First name is required").max(50, "First name must be at most 50 characters"),
|
||||
last_name: z.string().trim().min(1, "Last name is required").max(50, "Last name must be at most 50 characters"),
|
||||
company_name: z.string().trim().min(1, "Company name is required").max(50, "Company name must be at most 50 characters"),
|
||||
email: z.string().trim().min(1, "Email is required").email("Enter a valid email address").max(100, "Email must be at most 100 characters"),
|
||||
salutation: optionalStringMaxSchema(50),
|
||||
phone: optionalStringMaxSchema(20),
|
||||
alternate_phone: optionalStringMaxSchema(20),
|
||||
opening_balance: optionalNumberSchema,
|
||||
credit_limit: optionalNumberSchema,
|
||||
website: optionalStringMaxSchema(255),
|
||||
})
|
||||
|
||||
type VendorFormValues = z.infer<typeof vendorFormSchema>
|
||||
|
||||
Reference in New Issue
Block a user