Skip to content

Commit

Permalink
confirmation page addjusted to the new payload shape
Browse files Browse the repository at this point in the history
  • Loading branch information
burczu committed Feb 14, 2025
1 parent b60d7ac commit 5b29968
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,128 @@ import {useOnyx} from 'react-native-onyx';
import ConfirmationStep from '@components/SubStepForms/ConfirmationStep';
import useLocalize from '@hooks/useLocalize';
import type {SubStepProps} from '@hooks/useSubStep/types';
import getAddressValuesForSignerInfo from '@pages/ReimbursementAccount/NonUSD/utils/getAddressValuesForSignerInfo';
import getSubstepValues from '@pages/ReimbursementAccount/utils/getSubstepValues';
import getNeededDocumentsStatusForSignerInfo from '@pages/ReimbursementAccount/NonUSD/utils/getNeededDocumentsStatusForSignerInfo';
import getValuesForSignerInfo from '@pages/ReimbursementAccount/NonUSD/utils/getValuesForSignerInfo';
import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';

type ConfirmationProps = SubStepProps;

const SINGER_INFO_STEP_KEYS = INPUT_IDS.ADDITIONAL_DATA.CORPAY;
const {SIGNER_FULL_NAME, SIGNER_JOB_TITLE, SIGNER_DATE_OF_BIRTH, SIGNER_COMPLETE_RESIDENTIAL_ADDRESS, SIGNER_COPY_OF_ID, SIGNER_ADDRESS_PROOF, OWNS_MORE_THAN_25_PERCENT} =
INPUT_IDS.ADDITIONAL_DATA.CORPAY;
const {OWNS_MORE_THAN_25_PERCENT} = INPUT_IDS.ADDITIONAL_DATA.CORPAY;

function Confirmation({onNext, onMove, isEditing}: ConfirmationProps) {
const {translate} = useLocalize();

const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [reimbursementAccountDraft] = useOnyx(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT);
const isUserOwner = reimbursementAccount?.achData?.additionalData?.corpay?.[OWNS_MORE_THAN_25_PERCENT] ?? reimbursementAccountDraft?.[OWNS_MORE_THAN_25_PERCENT] ?? false;
const addressPrefix = SIGNER_COMPLETE_RESIDENTIAL_ADDRESS;
const values = useMemo(() => getSubstepValues(SINGER_INFO_STEP_KEYS, reimbursementAccountDraft, reimbursementAccount), [reimbursementAccount, reimbursementAccountDraft]);
const addressValues = useMemo(() => getAddressValuesForSignerInfo(addressPrefix, reimbursementAccountDraft), [addressPrefix, reimbursementAccountDraft]);
const values = useMemo(() => getValuesForSignerInfo(['currentUser'], reimbursementAccountDraft), []);

const IDs = values[SIGNER_COPY_OF_ID];
const proofs = values[SIGNER_ADDRESS_PROOF];
const policyID = reimbursementAccount?.achData?.policyID;
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const currency = policy?.outputCurrency ?? '';
const countryStepCountryValue = reimbursementAccountDraft?.[INPUT_IDS.ADDITIONAL_DATA.COUNTRY] ?? '';
const isDocumentNeededStatus = getNeededDocumentsStatusForSignerInfo(currency, countryStepCountryValue);

const summaryItems = [
{
title: values[SIGNER_JOB_TITLE],
title: values.jobTitle,
description: translate('signerInfoStep.jobTitle'),
shouldShowRightIcon: true,
onPress: () => {
onMove(1);
},
},
{
title: IDs ? IDs.map((id) => id.name).join(', ') : '',
description: translate('signerInfoStep.id'),
title: values.jobTitle,
description: translate('signerInfoStep.occupation'),
shouldShowRightIcon: true,
onPress: () => {
onMove(4);
onMove(2);
},
},
{
title: proofs ? proofs.map((proof) => proof.name).join(', ') : '',
];

if (isDocumentNeededStatus.isCopyOfIDNeeded && values.copyOfId.length > 0) {
summaryItems.push({
title: values.copyOfId.map((id) => id.name).join(', '),
description: translate('signerInfoStep.id'),
shouldShowRightIcon: true,
onPress: () => {
onMove(5);
},
});
}

if (isDocumentNeededStatus.isAddressProofNeeded && values.addressProof.length > 0) {
summaryItems.push({
title: values.addressProof.map((proof) => proof.name).join(', '),
description: translate('signerInfoStep.proofOf'),
shouldShowRightIcon: true,
onPress: () => {
onMove(4);
onMove(5);
},
},
];
});
}

if (isDocumentNeededStatus.isProofOfDirecorsNeeded && values.proofOfDirectors.length > 0) {
summaryItems.push({
title: values.proofOfDirectors.map((proof) => proof.name).join(', '),
description: translate('signerInfoStep.proofOfDirectors'),
shouldShowRightIcon: true,
onPress: () => {
onMove(5);
},
});
}

if (isDocumentNeededStatus.isCodiceFiscaleNeeded && values.codiceFisclaleTaxID.length > 0) {
summaryItems.push({
title: values.proofOfDirectors.map((proof) => proof.name).join(', '),
description: translate('signerInfoStep.codiceFiscale'),
shouldShowRightIcon: true,
onPress: () => {
onMove(5);
},
});
}

if (isDocumentNeededStatus.isPRDandFSGNeeded && values.PRDandFSG.length > 0) {
summaryItems.push({
title: values.proofOfDirectors.map((proof) => proof.name).join(', '),
description: translate('signerInfoStep.PRDandSFD'),
shouldShowRightIcon: true,
onPress: () => {
onMove(5);
},
});
}

if (!isUserOwner) {
summaryItems.unshift({
title: `${values[SIGNER_FULL_NAME]}`,
title: values.fullName,
description: translate('signerInfoStep.legalName'),
shouldShowRightIcon: true,
onPress: () => {
onMove(0);
},
});

summaryItems.splice(2, 0, {
title: values[SIGNER_DATE_OF_BIRTH],
summaryItems.splice(3, 0, {
title: values.dateOfBirth,
description: translate('common.dob'),
shouldShowRightIcon: true,
onPress: () => {
onMove(2);
onMove(3);
},
});

summaryItems.splice(3, 0, {
title: `${addressValues.street}, ${addressValues.city}, ${addressValues.state}, ${addressValues.zipCode}`,
summaryItems.splice(4, 0, {
title: `${values.street}, ${values.city}, ${values.state}, ${values.zipCode}`,
description: translate('ownershipInfoStep.address'),
shouldShowRightIcon: true,
onPress: () => {
onMove(3);
onMove(4);
},
});
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {ReimbursementAccountForm} from '@src/types/form';
import CONST from '@src/CONST';
import type {FileObject} from '@components/AttachmentModal';

type SignerInfoDirector = {
fullName: string;
jobTitle: string;
occupation: string;
};

type SignerInfoValues = {
dateOfBirth: string;
fullName: string;
jobTitle: string;
city: string;
state: string;
street: string;
zipCode: string;
directors: SignerInfoDirector[];
proofOfDirectors: FileObject[];
copyOfId: FileObject[];
addressProof: FileObject[];
codiceFisclaleTaxID: FileObject[];
PRDandFSG: FileObject[];
};

function getValuesForSignerInfo(directorIDs: string[], reimbursementAccountDraft: OnyxEntry<ReimbursementAccountForm>): SignerInfoValues {
if (!reimbursementAccountDraft) {
return {
dateOfBirth: '',
fullName: '',
jobTitle: '',
city: '',
state: '',
street: '',
zipCode: '',
directors: [],
proofOfDirectors: [],
copyOfId: [],
addressProof: [],
codiceFisclaleTaxID: [],
PRDandFSG: [],
};
}

const directorsPrefix = CONST.NON_USD_BANK_ACCOUNT.SIGNER_INFO_STEP.SIGNER_INFO_DATA.PREFIX;
const signerPrefix = 'signer';
const signerInfoKeys = CONST.NON_USD_BANK_ACCOUNT.SIGNER_INFO_STEP.SIGNER_INFO_DATA;

return {
dateOfBirth: reimbursementAccountDraft[signerInfoKeys.DATE_OF_BIRTH] ?? '',
fullName: reimbursementAccountDraft[signerInfoKeys.FULL_NAME] ?? '',
jobTitle: reimbursementAccountDraft[signerInfoKeys.JOB_TITLE] ?? '',
city: reimbursementAccountDraft[signerInfoKeys.CITY] ?? '',
state: reimbursementAccountDraft[signerInfoKeys.STATE] ?? '',
street: reimbursementAccountDraft[signerInfoKeys.STREET] ?? '',
zipCode: reimbursementAccountDraft[signerInfoKeys.ZIP_CODE] ?? '',
directors: directorIDs.map((directorID) => {
const directorKey = `${directorsPrefix}_${directorID}`;

return {
fullName: reimbursementAccountDraft[`${directorKey}_${signerInfoKeys.DIRECTOR_FULL_NAME}`] ?? '',
jobTitle: reimbursementAccountDraft[`${directorKey}_${signerInfoKeys.DIRECTOR_JOB_TITLE}`] ?? '',
occupation: reimbursementAccountDraft[`${directorKey}_${signerInfoKeys.DIRECTOR_OCCUPATION}`] ?? '',
} as SignerInfoDirector;
}),
proofOfDirectors: reimbursementAccountDraft[`${signerPrefix}_${signerInfoKeys.PROOF_OF_DIRECTORS}`] ?? [],
copyOfId: reimbursementAccountDraft[`${signerPrefix}_${signerInfoKeys.COPY_OF_ID}`] ?? [],
addressProof: reimbursementAccountDraft[`${signerPrefix}_${signerInfoKeys.ADDRESS_PROOF}`] ?? [],
codiceFisclaleTaxID: reimbursementAccountDraft[`${signerPrefix}_${signerInfoKeys.CODICE_FISCALE}`] ?? [],
PRDandFSG: reimbursementAccountDraft[`${signerPrefix}_${signerInfoKeys.PRD_AND_SFG}`] ?? [],
} as SignerInfoValues;
}

export default getValuesForSignerInfo;

0 comments on commit 5b29968

Please sign in to comment.