mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 14:52:06 +00:00
Some checks are pending
* feat(locations): derive site areas from state * chore(locations): keep ticket keys out of source comments * feat(locations): manage ordered site contacts --------- Co-authored-by: Codex Review Integration <codex-review@local.invalid>
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { z } from "zod";
|
|
import { US_STATE_CODES } from "@/data/areas";
|
|
import { LOCATION_STATUS_OPTIONS } from "@/domain/locations/types/location";
|
|
|
|
export const locationContactSchema = z.object({
|
|
id: z.number().int().positive().optional(),
|
|
name: z
|
|
.string()
|
|
.trim()
|
|
.min(1, "Contact person is required")
|
|
.max(100, "Contact person cannot exceed 100 characters"),
|
|
phone: z.string().trim().min(1, "Phone is required").max(20, "Phone cannot exceed 20 characters"),
|
|
});
|
|
|
|
export const locationSchema = z.object({
|
|
name: z.string().min(1, "Name is required"),
|
|
accountId: z.string().optional(),
|
|
address: z.string().min(1, "Address is required"),
|
|
city: z.string().min(1, "City is required"),
|
|
state: z
|
|
.union([z.enum(US_STATE_CODES), z.literal("")])
|
|
.refine((state): boolean => state !== "", { message: "State is required" }),
|
|
zipCode: z.string().min(1, "Zip code is required"),
|
|
contacts: z.array(locationContactSchema).min(1, "At least one contact is required"),
|
|
contactEmail: z.string().min(1, "Contact email is required").email("Invalid email address"),
|
|
status: z.enum(LOCATION_STATUS_OPTIONS, { message: "Status is required" }),
|
|
});
|
|
|
|
export type LocationFormValues = z.infer<typeof locationSchema>;
|
|
export type LocationContactFormValues = z.infer<typeof locationContactSchema>;
|
|
|
|
export const locationDefaultValues: LocationFormValues = {
|
|
name: "",
|
|
accountId: "",
|
|
address: "",
|
|
city: "",
|
|
state: "",
|
|
zipCode: "",
|
|
contacts: [{ name: "", phone: "" }],
|
|
contactEmail: "",
|
|
status: "Active",
|
|
};
|