Spaces:
Runtime error

File size: 2,404 Bytes
ad79323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
import { z } from "zod";

import {
  customerDatePresetValues,
  customerGenderValues,
  sessionDatePresetValues,
} from "@/lib/constants";

const phoneRegex = /^[0-9+\s()\-]+$/;

export const customerSchema = z.object({
  firstName: z
    .string()
    .trim()
    .min(2, "ุงู„ุงุณู… ุงู„ุฃูˆู„ ู„ุงุฒู… ูŠูƒูˆู† ุญุฑููŠู† ุนู„ู‰ ุงู„ุฃู‚ู„.")
    .max(60, "ุงู„ุงุณู… ุงู„ุฃูˆู„ ุทูˆูŠู„ ุฒูŠุงุฏุฉ ุนู† ุงู„ู„ุฒูˆู…."),
  middleName: z
    .string()
    .trim()
    .max(60, "ุงู„ุงุณู… ุงู„ุฃูˆุณุท ุทูˆูŠู„ ุฒูŠุงุฏุฉ ุนู† ุงู„ู„ุฒูˆู….")
    .optional()
    .or(z.literal("")),
  lastName: z
    .string()
    .trim()
    .min(2, "ุงุณู… ุงู„ุนูŠู„ุฉ ู„ุงุฒู… ูŠูƒูˆู† ุญุฑููŠู† ุนู„ู‰ ุงู„ุฃู‚ู„.")
    .max(60, "ุงุณู… ุงู„ุนูŠู„ุฉ ุทูˆูŠู„ ุฒูŠุงุฏุฉ ุนู† ุงู„ู„ุฒูˆู…."),
  gender: z.enum(customerGenderValues, {
    error: "ุงุฎุชุงุฑ ุงู„ู†ูˆุน.",
  }),
  phone: z
    .string()
    .trim()
    .min(7, "ุฑู‚ู… ุงู„ู…ูˆุจุงูŠู„ ู‚ุตูŠุฑ ุฌุฏู‹ุง.")
    .max(30, "ุฑู‚ู… ุงู„ู…ูˆุจุงูŠู„ ุทูˆูŠู„ ุฒูŠุงุฏุฉ ุนู† ุงู„ู„ุฒูˆู….")
    .regex(phoneRegex, "ุฑู‚ู… ุงู„ู…ูˆุจุงูŠู„ ู„ุงุฒู… ูŠุญุชูˆูŠ ุนู„ู‰ ุฃุฑู‚ุงู… ูˆุฑู…ูˆุฒ ุตุญูŠุญุฉ ุจุณ."),
});

export const customerListQuerySchema = z.object({
  search: z.string().trim().max(100).optional().catch(undefined),
  gender: z.enum(customerGenderValues).optional().catch(undefined),
  createdPreset: z
    .enum(customerDatePresetValues)
    .optional()
    .catch(undefined)
    .default("all"),
  page: z.coerce.number().int().min(1).optional().catch(1).default(1),
});

export const customerDetailsQuerySchema = z.object({
  tab: z
    .enum(["info", "cases", "sessions", "archive"])
    .optional()
    .catch(undefined),
  caseSearch: z.string().trim().max(100).optional().catch(undefined),
  caseType: z
    .enum(["CIVIL", "CRIMINAL", "PERSONAL_STATUS"])
    .optional()
    .catch(undefined),
  archiveSearch: z.string().trim().max(100).optional().catch(undefined),
  archiveFileId: z.string().trim().optional().catch(undefined),
  sessionPreset: z
    .enum(sessionDatePresetValues)
    .optional()
    .catch(undefined)
    .default("all"),
  sessionId: z.string().trim().optional().catch(undefined),
});

export type CustomerInput = z.infer<typeof customerSchema>;
export type CustomerListQueryInput = z.infer<typeof customerListQuerySchema>;
export type CustomerDetailsQueryInput = z.infer<typeof customerDetailsQuerySchema>;