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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
import { z } from 'zod';
export const registerSchema = z
.object({
name: z.string().min(1, { message: 'Nama harus diisi' }),
email: z
.string()
.min(1, { message: 'Email harus diisi' })
.email({ message: 'Email harus menggunakan format example@mail.com' }),
password: z.string().min(6, { message: 'Password minimal 6 karakter' }),
phone: z
.string()
.min(1, { message: 'Nomor telepon harus diisi' })
.refine((val) => /^\d{10,12}$/.test(val), {
message: 'Format nomor telepon tidak valid, contoh: 081234567890',
}),
type_acc: z.string().optional(),
nama_wajib_pajak: z.string().optional(),
is_pkp: z.string(),
is_terdaftar: z.string(),
sppkp_document: z.string().optional(),
npwp_document: z.string().optional(),
industry_id: z.string().optional(),
email_partner: z.string().optional(),
business_name: z.string().optional(),
company_type_id: z.string().optional(),
npwp: z.string().optional(),
})
.superRefine((data, ctx) => {
if (data.type_acc === 'business') {
if (data.is_terdaftar === 'false') {
if (data.is_pkp === 'false') {
if (!data.business_name) {
ctx.addIssue({
code: 'custom',
path: ['business_name'],
message: 'Nama perusahaan harus diisi',
});
}
if (!data.company_type_id) {
ctx.addIssue({
code: 'custom',
path: ['company_type_id'],
message: 'Badan usaha wajib dipilih',
});
}
if (!data.industry_id) {
ctx.addIssue({
code: 'custom',
path: ['industry_id'],
message: 'Jenis usaha harus dipilih',
});
}
} else {
const requiredFields: { field: keyof typeof data; message: string }[] = [
{ field: 'business_name', message: 'Nama perusahaan harus diisi' },
{ field: 'company_type_id', message: 'Badan usaha wajib dipilih' },
{ field: 'industry_id', message: 'Jenis usaha harus dipilih' },
{ field: 'sppkp_document', message: 'Document harus diisi' },
{ field: 'npwp_document', message: 'Document harus diisi' },
{ field: 'npwp', message: 'Format NPWP tidak valid, NPWP harus terdiri dari 15 digit angka.' },
{ field: 'nama_wajib_pajak', message: 'Nama wajib pajak harus diisi' },
];
requiredFields.forEach(({ field, message }) => {
if (!data[field]) {
ctx.addIssue({
code: 'custom',
path: [field],
message,
});
}
});
if (!data.email_partner || !z.string().email().safeParse(data.email_partner).success) {
ctx.addIssue({
code: 'custom',
path: ['email_partner'],
message: 'Email partner harus diisi dengan format example@mail.com',
});
}
}
}else{
if (data.is_pkp === 'false') {
if (!data.business_name) {
ctx.addIssue({
code: 'custom',
path: ['business_name'],
message: 'Nama perusahaan harus diisi',
});
}
} else {
if (!data.business_name) {
ctx.addIssue({
code: 'custom',
path: ['business_name'],
message: 'Nama perusahaan harus diisi',
});
}
}
}
// Remove this unconditional issue addition to prevent blocking form submission
// ctx.addIssue({
// code: 'custom',
// path: ['business_name'],
// message: 'Nama perusahaan harus diisi',
// });
}else{
}
});
|