Spaces:
Running
Running
| import { z } from "zod"; | |
| const phoneRegex = /^\+?[\d\s\-().]{7,20}$/; | |
| const phoneField = z | |
| .string() | |
| .refine((val) => !val || phoneRegex.test(val), { | |
| message: "Invalid phone number", | |
| }) | |
| .optional() | |
| .nullable(); | |
| export const companySchema = z.object({ | |
| name: z.string().min(1, "Name is required"), | |
| domain: z.string().optional().nullable(), | |
| phone: phoneField, | |
| address: z.string().optional().nullable(), | |
| notes: z.string().optional().nullable(), | |
| }); | |
| export const contactSchema = z.object({ | |
| firstName: z.string().min(1, "First name is required"), | |
| lastName: z.string().min(1, "Last name is required"), | |
| email: z.string().email().optional().nullable().or(z.literal("")), | |
| phone: phoneField, | |
| jobTitle: z.string().optional().nullable(), | |
| companyId: z.number().optional().nullable(), | |
| }); | |
| export const dealSchema = z.object({ | |
| title: z.string().min(1, "Title is required"), | |
| value: z.number().min(0).default(0), | |
| status: z.enum(["open", "won", "lost"]).default("open"), | |
| expectedCloseDate: z.string().optional().nullable(), | |
| stageId: z.number(), | |
| contactId: z.number().optional().nullable(), | |
| companyId: z.number().optional().nullable(), | |
| pipelineId: z.number(), | |
| }); | |
| export const dealReorderSchema = z.object({ | |
| dealId: z.number(), | |
| newStageId: z.number(), | |
| newPosition: z.number(), | |
| }); | |
| export const activitySchema = z.object({ | |
| type: z.enum(["call", "email", "meeting", "task", "note"]), | |
| subject: z.string().min(1, "Subject is required"), | |
| description: z.string().optional().nullable(), | |
| dueDate: z.string().optional().nullable(), | |
| isDone: z.boolean().default(false), | |
| dealId: z.number().optional().nullable(), | |
| contactId: z.number().optional().nullable(), | |
| companyId: z.number().optional().nullable(), | |
| }); | |
| export const stageSchema = z.object({ | |
| name: z.string().min(1, "Name is required"), | |
| position: z.number().min(0), | |
| probability: z.number().min(0).max(100).default(0), | |
| pipelineId: z.number(), | |
| }); | |
| export type CompanyInput = z.infer<typeof companySchema>; | |
| export type ContactInput = z.infer<typeof contactSchema>; | |
| export type DealInput = z.infer<typeof dealSchema>; | |
| export type ActivityInput = z.infer<typeof activitySchema>; | |
| export type StageInput = z.infer<typeof stageSchema>; | |