Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
import { convertPersianToEnglish } from '@/helpers'
|
|
import { texts } from '@/texts'
|
|
|
|
const toEnglishDigits = (value: string) => convertPersianToEnglish(value).trim()
|
|
const v = texts.validation.identity
|
|
const nationalId = texts.validation.nationalId
|
|
|
|
export const IdentityVerificationFormValidation = z
|
|
.object({
|
|
nationalCode: z
|
|
.string()
|
|
.min(1, nationalId.nationalCodeRequired)
|
|
.refine((value) => /^\d{10}$/.test(toEnglishDigits(value)), {
|
|
message: nationalId.nationalCodeDigits,
|
|
}),
|
|
contractAccepted: z.boolean().optional(),
|
|
})
|
|
.superRefine((values, ctx) => {
|
|
if (values.contractAccepted !== true) {
|
|
ctx.addIssue({
|
|
code: 'custom',
|
|
path: ['contractAccepted'],
|
|
message: v.contractRequired,
|
|
})
|
|
}
|
|
})
|
|
|
|
export const IdentityContractOtpValidation = z.object({
|
|
code: z
|
|
.string()
|
|
.min(1, v.otpRequired)
|
|
.refine((value) => /^\d{4}$/.test(toEnglishDigits(value)), {
|
|
message: v.otpDigits,
|
|
}),
|
|
})
|
|
|
|
export type IdentityVerificationFormValues = z.infer<typeof IdentityVerificationFormValidation>
|
|
export type IdentityContractOtpValues = z.infer<typeof IdentityContractOtpValidation>
|
|
|
|
export const normalizeNationalCode = (value: string) => toEnglishDigits(value)
|
|
export const normalizeOtpCode = (value: string) => toEnglishDigits(value)
|