File size: 2,240 Bytes
ea8dde3
 
3ff6ff5
 
 
 
 
 
 
 
 
 
ea8dde3
 
 
3ff6ff5
ea8dde3
 
 
 
 
 
 
 
3ff6ff5
ea8dde3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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>;