From 20ff017fd2353e377211a4456aa42f8f20438606 Mon Sep 17 00:00:00 2001 From: Thisyahlen Date: Wed, 22 Nov 2023 11:54:06 +0800 Subject: [PATCH] chore: fix remaining validations for idv page --- .../components/FlowField/FlowTextField.tsx | 3 +- .../IDVDocumentUpload/IDVDocumentUpload.tsx | 38 +++++++++++++------ .../PersonalDetails/PersonalDetails.tsx | 3 +- .../src/features/accounts/validations.ts | 6 +-- .../cfd/flows/Verification/Verification.tsx | 4 +- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/packages/wallets/src/components/FlowField/FlowTextField.tsx b/packages/wallets/src/components/FlowField/FlowTextField.tsx index 3951d646d95c..def1cc5c9a89 100644 --- a/packages/wallets/src/components/FlowField/FlowTextField.tsx +++ b/packages/wallets/src/components/FlowField/FlowTextField.tsx @@ -17,7 +17,7 @@ export interface TFlowFieldProps extends WalletTextFieldProps { */ const FlowTextField = forwardRef( ( - { defaultValue, errorMessage, isInvalid, name, validationSchema, ...rest }: TFlowFieldProps, + { defaultValue, disabled, errorMessage, isInvalid, name, validationSchema, ...rest }: TFlowFieldProps, ref: Ref ) => { const [hasTouched, setHasTouched] = useState(false); @@ -47,6 +47,7 @@ const FlowTextField = forwardRef( > = { rejected: 'We were unable to verify the identity document with the details provided.', }; +// Temporary list of document types till we get the API +const documentTypeList = [ + { text: 'Drivers License', value: 'driverLicense' }, + { text: 'Passport', value: 'passport' }, + { text: 'Social Security and National Insurance Trust (SSNIT)', value: 'ssnit' }, +]; + const ErrorMessage: React.FC<{ status: TErrorMessageProps }> = ({ status }) => { const { isMobile } = useDevice(); @@ -32,12 +39,17 @@ const ErrorMessage: React.FC<{ status: TErrorMessageProps }> = ({ status }) => { const IDVDocumentUpload = () => { const { data: poiStatus } = usePOI(); - const { setFormValues } = useFlow(); + const { formValues, setFormValues } = useFlow(); - const [selectedDocument, setSelectedDocument] = useState('documentNumber'); + const textToValueMapper = documentTypeList.reduce((acc, curr) => { + acc[curr.text] = curr.value; + return acc; + }, {} as Record); const validationSchema = useMemo(() => { - switch (selectedDocument) { + const documentType = textToValueMapper[formValues?.documentType]; + + switch (documentType) { case 'driverLicense': return drivingLicenseValidator; case 'passport': @@ -47,7 +59,7 @@ const IDVDocumentUpload = () => { default: return requiredValidator; } - }, [selectedDocument]); + }, [formValues?.documentType, textToValueMapper]); const status = poiStatus?.current.status; @@ -61,20 +73,22 @@ const IDVDocumentUpload = () => { Identity verification { + setFormValues('documentType', inputValue); + }} onSelect={selectedItem => { - setSelectedDocument(selectedItem); setFormValues('documentType', selectedItem); }} - value={undefined} + value={formValues?.documentType} + variant='comboBox' /> { variant='comboBox' /> ({ text: residence.text as ReactNode, @@ -69,7 +70,7 @@ const PersonalDetails = () => { /> diff --git a/packages/wallets/src/features/accounts/validations.ts b/packages/wallets/src/features/accounts/validations.ts index c7ca86f49e3f..db5b0bd3ed16 100644 --- a/packages/wallets/src/features/accounts/validations.ts +++ b/packages/wallets/src/features/accounts/validations.ts @@ -1,17 +1,17 @@ import * as Yup from 'yup'; export const drivingLicenseValidator = Yup.string() - .matches(/^[A-Z]/, 'Please enter the correct format. Example: B1234567') + .matches(/^[A-Z]\d{7}$/, 'Please enter the correct format. Example: B1234567') .max(8) .required('Please enter your Driver License number. Example: B1234567'); export const passportValidator = Yup.string() - .matches(/^[A-Z]/, 'Please enter the correct format. Example: G1234567') + .matches(/^[A-Z]\d{7}$/, 'Please enter the correct format. Example: G1234567') .max(8) .required('Please enter your Passport number. Example: G1234567'); export const ssnitValidator = Yup.string() - .matches(/^[A-Z]/, 'Please enter the correct format. Example: C123456789012') + .matches(/^[A-Z]\d{12}$/, 'Please enter the correct format. Example: C123456789012') .max(13) .required('Please enter your SSNIT number. Example: C123456789012'); diff --git a/packages/wallets/src/features/cfd/flows/Verification/Verification.tsx b/packages/wallets/src/features/cfd/flows/Verification/Verification.tsx index 5918c81cab8f..d50131403632 100644 --- a/packages/wallets/src/features/cfd/flows/Verification/Verification.tsx +++ b/packages/wallets/src/features/cfd/flows/Verification/Verification.tsx @@ -112,9 +112,7 @@ const Verification: FC = ({ selectedJurisdiction }) => { show(); } } else if (currentScreenId === 'poaScreen') { - if (!getSettings?.has_submitted_personal_details) { - switchScreen('personalDetailsScreen'); - } + switchScreen('personalDetailsScreen'); } else if (currentScreenId === 'personalDetailsScreen') { show(); } else {