65 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import { z } from "zod";
 | 
						|
export const ContactSchema = z
 | 
						|
  .object({
 | 
						|
    name: z.string().min(1, "Name is required"),
 | 
						|
    organization: z.string().min(1, "Organization name is required"),
 | 
						|
    contactCategoryId: z.string().nullable().optional(),
 | 
						|
    address: z.string().optional(),
 | 
						|
    description: z.string().min(1, { message: "Description is required" }),
 | 
						|
    projectIds: z.array(z.string()).nullable().optional(), // min(1, "Project is required")
 | 
						|
    contactEmails: z
 | 
						|
      .array(
 | 
						|
        z.object({
 | 
						|
          label: z.string(),
 | 
						|
           emailAddress: z.string().email("Invalid email").or(z.literal("")),
 | 
						|
        })
 | 
						|
      )
 | 
						|
      .optional()
 | 
						|
      .default([]),
 | 
						|
 | 
						|
    contactPhones: z
 | 
						|
      .array(
 | 
						|
        z.object({
 | 
						|
          label: z.string(),
 | 
						|
          phoneNumber: z
 | 
						|
            .string()
 | 
						|
            .min(6, "Invalid Number")
 | 
						|
            .max(13, "Invalid Number")
 | 
						|
            .regex(/^[\d\s+()-]+$/, "Invalid phone number format").or(z.literal("")),
 | 
						|
        })
 | 
						|
      )
 | 
						|
      .optional()
 | 
						|
      .default([]),
 | 
						|
 | 
						|
    tags: z
 | 
						|
      .array(
 | 
						|
        z.object({
 | 
						|
          id: z.string().nullable(),
 | 
						|
          name: z.string(),
 | 
						|
        })
 | 
						|
      )
 | 
						|
      .min(1, { message: "At least one tag is required" }),
 | 
						|
bucketIds: z.array(z.string()).nonempty({ message: "At least one label is required" })
 | 
						|
  })
 | 
						|
 | 
						|
//    .refine((data) => {
 | 
						|
//   const hasValidEmail = (data.contactEmails || []).some(
 | 
						|
//     (e) => e.emailAddress?.trim() !== ""
 | 
						|
//   );
 | 
						|
//   const hasValidPhone = (data.contactPhones || []).some(
 | 
						|
//     (p) => p.phoneNumber?.trim() !== ""
 | 
						|
//   );
 | 
						|
 | 
						|
//   return hasValidEmail || hasValidPhone;
 | 
						|
// }, {
 | 
						|
//   message: "At least one contact (email or phone) is required",
 | 
						|
//   path: ["contactPhone"],
 | 
						|
// });
 | 
						|
 | 
						|
 | 
						|
// Buckets
 | 
						|
 | 
						|
export const bucketScheam = z.object( {
 | 
						|
  name: z.string().min( 1, {message: "Name is required"} ),
 | 
						|
  description:z.string().min(1,{message:"Description is required"})
 | 
						|
}) |