mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { z } from "zod";
|
|
import {
|
|
VENDOR_PREFERRED_CONTACT_VALUES,
|
|
type VendorPreferredContact,
|
|
} from "@/domain/vendors/types/vendor";
|
|
|
|
const httpsUrl = z
|
|
.string()
|
|
.trim()
|
|
.refine(
|
|
(value) => value === "" || /^https:\/\/.+/i.test(value),
|
|
"Google Maps URL must use HTTPS",
|
|
);
|
|
|
|
const northAmericanPhone = z.string().refine((value) => {
|
|
if (value === "") return true;
|
|
const digits = value.replace(/\D+/g, "");
|
|
return digits.length === 10 || (digits.length === 11 && digits.startsWith("1"));
|
|
}, "Enter a 10-digit phone number");
|
|
|
|
export const vendorSchema = z.object({
|
|
companyName: z.string().min(1, "Company is required"),
|
|
contactName: z.string().min(1, "Technician name is required"),
|
|
email: z.union([z.string().email("Invalid email"), z.literal("")]).optional(),
|
|
phone: northAmericanPhone.optional(),
|
|
companyPhone: northAmericanPhone.optional(),
|
|
googleMapsUrl: httpsUrl.optional(),
|
|
notes: z.string().optional(),
|
|
totalJobs: z.number().optional(),
|
|
address: z.string().optional(),
|
|
city: z.string().optional(),
|
|
state: z.string().optional(),
|
|
zip: z.string().optional(),
|
|
tradeSpecialties: z.string().optional(),
|
|
isActive: z.boolean().optional(),
|
|
companyId: z.union([z.string(), z.number()]).nullable().optional(),
|
|
preferredContact: z
|
|
.enum(VENDOR_PREFERRED_CONTACT_VALUES as [VendorPreferredContact, ...VendorPreferredContact[]])
|
|
.optional(),
|
|
});
|
|
|
|
export type VendorFormValues = z.infer<typeof vendorSchema>;
|