Untitled

mail@pastecode.io avatar
unknown
typescript
16 days ago
1.0 kB
2
Indexable
Never
import { yupResolver } from '@hookform/resolvers/yup';
import { boolean, object, string } from 'yup';
import * as yup from 'yup';

const peselOrNipRegex = {
  PESEL: /^[0-9]{11}$/,
  NIP: /^[0-9]{10}$/,
};

export const personalizationSchema = object({
  address: string().required('Address is required'),
  fullName: string().required('Full Name is required'),
  gender: string().required('Gender is required'),
  motherName: string().required("Mother's Name is required"),
  identificationType: string().oneOf(['NIP', 'PESEL']).required('Identification Type is required'),
  identification: string().when('identificationType', {
    is: 'PESEL',
    then: (schema) =>
      schema.matches(peselOrNipRegex.PESEL, 'Pesel must be exactly 11 digits').required('Pesel is required'),
    otherwise: (schema) =>
      schema.matches(peselOrNipRegex.NIP, 'NIP must be exactly 10 digits').required('NIP is required'),
  }),
  isCompanyAccount: boolean().required('Company Account status is required'),
});
Leave a Comment