Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,13 @@ const CONST = {
PERSONAL: 'PERSONAL',
},
},
NON_USD_BANK_ACCOUNT: {
CORPAY_DOCUMENT: {
ALLOWED_FILE_TYPES: ['pdf', 'jpg', 'jpeg', 'png'],
FILE_LIMIT: 1,
MAX_FILE_SIZE: 2097152,
Comment thread
madmax330 marked this conversation as resolved.
TOTAL_FILES_SIZE_LIMIT: 5242880,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'Explanation of change' in the PRs description already touches on that but this PR doesn't fix it - I think it could've but its outside of the scope of this issue.

CONST is defined but it's not referenced anywhere and despite the texts on the pages we do not enforce this total 5mb file size, anywhere, at all.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will fix this in another PR

},
NON_USD_BANK_ACCOUNT: {
PURPOSE_OF_TRANSACTION_ID: 'Intercompany_Payment',
CURRENT_USER_KEY: 'currentUser',
CORPAY_UNDEFINED_OPTION_VALUE: 'Undefined',
Expand Down
12 changes: 9 additions & 3 deletions src/components/SubStepForms/DocusignFullStep.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, {useCallback, useState} from 'react';
import React, {useCallback, useRef, useState} from 'react';
import Button from '@components/Button';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxKeys, FormOnyxValues} from '@components/Form/types';
import type {FormInputErrors, FormOnyxKeys, FormOnyxValues, FormRef} from '@components/Form/types';
import InteractiveStepWrapper from '@components/InteractiveStepWrapper';
import Text from '@components/Text';
import UploadFile from '@components/UploadFile';
Expand Down Expand Up @@ -61,6 +61,8 @@ function DocusignFullStep<TFormID extends keyof OnyxFormValuesMapping>({
const styles = useThemeStyles();
const {environmentURL} = useEnvironment();

const formRef = useRef<FormRef | null>(null);

const [uploadedFiles, setUploadedFiles] = useState<FileObject[]>(defaultValue);

const validate = useCallback(
Expand All @@ -87,6 +89,8 @@ function DocusignFullStep<TFormID extends keyof OnyxFormValuesMapping>({
return;
}

formRef.current?.resetFormFieldError(inputID as string);
clearErrors(formID);
setErrorFields(formID, {[inputID]: {onUpload: error}});
};

Expand All @@ -106,6 +110,7 @@ function DocusignFullStep<TFormID extends keyof OnyxFormValuesMapping>({
startStepIndex={startStepIndex}
>
<FormProvider
ref={formRef}
formID={formID}
submitButtonText={translate('common.submit')}
onSubmit={onSubmit}
Expand Down Expand Up @@ -148,13 +153,14 @@ function DocusignFullStep<TFormID extends keyof OnyxFormValuesMapping>({
onRemove={(fileName) => {
handleRemoveFile(fileName);
}}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={uploadedFiles}
inputID={inputID as string}
setError={(error) => {
setUploadError(error);
}}
fileLimit={1}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
/>
</FormProvider>
</InteractiveStepWrapper>
Expand Down
12 changes: 12 additions & 0 deletions src/components/UploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type UploadFileProps = {

/** The total size limit of the files that can be selected. */
totalFilesSizeLimit?: number;

/** The maximum size of a single file that can be selected. */
maxFileSize?: number;
};

function UploadFile({
Expand All @@ -63,6 +66,7 @@ function UploadFile({
onInputChange = () => {},
totalFilesSizeLimit = 0,
fileLimit = 0,
maxFileSize = 0,
}: UploadFileProps) {
const icons = useMemoizedLazyExpensifyIcons(['Close', 'Paperclip']);
const {translate} = useLocalize();
Expand All @@ -73,6 +77,14 @@ function UploadFile({

const totalSize = resultedFiles.reduce((sum, file) => sum + (file.size ?? 0), 0);

if (maxFileSize) {
const oversizedFile = files.find((file) => (file.size ?? 0) > maxFileSize);
if (oversizedFile) {
setError(translate('attachmentPicker.sizeExceededWithLimit', maxFileSize / (1024 * 1024)));
return;
}
}

if (totalFilesSizeLimit) {
if (totalSize > totalFilesSizeLimit) {
setError(translate('attachmentPicker.sizeExceededWithValue', totalFilesSizeLimit / (1024 * 1024)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function UploadDocuments({onNext, isEditing, policyID}: UploadDocumentsProps) {
onRemove={(fileName) => {
handleRemoveFile(fileName, uploadedIDs, copyOfIDInputID, setUploadedID);
}}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={uploadedIDs}
inputID={copyOfIDInputID}
setError={(error) => {
Expand Down Expand Up @@ -168,7 +168,7 @@ function UploadDocuments({onNext, isEditing, policyID}: UploadDocumentsProps) {
onRemove={(fileName) => {
handleRemoveFile(fileName, uploadedProofsOfAddress, addressProofInputID, setUploadedProofOfAddress);
}}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={uploadedProofsOfAddress}
inputID={addressProofInputID}
setError={(error) => {
Expand All @@ -195,7 +195,7 @@ function UploadDocuments({onNext, isEditing, policyID}: UploadDocumentsProps) {
onRemove={(fileName) => {
handleRemoveFile(fileName, uploadedProofsOfDirectors, directorsProofInputID, setUploadedProofsOfDirectors);
}}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={uploadedProofsOfDirectors}
inputID={directorsProofInputID}
setError={(error) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, {useCallback, useMemo, useState} from 'react';
import React, {useCallback, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import type {FormInputErrors, FormOnyxValues, FormRef} from '@components/Form/types';
import Text from '@components/Text';
import UploadFile from '@components/UploadFile';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -13,7 +13,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {getFieldRequiredErrors} from '@libs/ValidationUtils';
import getCurrencyForNonUSDBankAccount from '@pages/ReimbursementAccount/NonUSD/utils/getCurrencyForNonUSDBankAccount';
import getNeededDocumentsStatusForBeneficialOwner from '@pages/ReimbursementAccount/NonUSD/utils/getNeededDocumentsStatusForBeneficialOwner';
import {clearErrorFields, setDraftValues, setErrorFields} from '@userActions/FormActions';
import {clearErrorFields, clearErrors, setDraftValues, setErrorFields} from '@userActions/FormActions';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {FileObject} from '@src/types/utils/Attachment';
Expand Down Expand Up @@ -45,6 +45,8 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
[codiceFiscaleInputID]: Array.isArray(reimbursementAccountDraft?.[codiceFiscaleInputID]) ? (reimbursementAccountDraft?.[codiceFiscaleInputID] ?? []) : [],
};

const formRef = useRef<FormRef | null>(null);

const [uploadedProofOfOwnership, setUploadedProofOfOwnership] = useState<FileObject[]>(defaultValues[proofOfOwnershipInputID]);
const [uploadedCopyOfID, setUploadedCopyOfID] = useState<FileObject[]>(defaultValues[copyOfIDInputID]);
const [uploadedAddressProof, setUploadedAddressProof] = useState<FileObject[]>(defaultValues[addressProofInputID]);
Expand Down Expand Up @@ -78,6 +80,8 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
return;
}

formRef.current?.resetFormFieldError(inputID);
clearErrors(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM);
setErrorFields(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM, {[inputID]: {onUpload: error}});
};

Expand All @@ -97,6 +101,7 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {

return (
<FormProvider
ref={formRef}
formID={ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM}
submitButtonText={translate(isEditing ? 'common.confirm' : 'common.next')}
validate={validate}
Expand Down Expand Up @@ -124,8 +129,9 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
setError={(error) => {
setUploadError(error, proofOfOwnershipInputID);
}}
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
fileLimit={CONST.CORPAY_DOCUMENT.FILE_LIMIT}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={defaultValues[proofOfOwnershipInputID]}
inputID={proofOfOwnershipInputID}
/>
Expand All @@ -152,8 +158,9 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
setError={(error) => {
setUploadError(error, copyOfIDInputID);
}}
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
fileLimit={CONST.CORPAY_DOCUMENT.FILE_LIMIT}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={defaultValues[copyOfIDInputID]}
inputID={copyOfIDInputID}
/>
Expand All @@ -178,8 +185,9 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
setError={(error) => {
setUploadError(error, addressProofInputID);
}}
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
fileLimit={CONST.CORPAY_DOCUMENT.FILE_LIMIT}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={defaultValues[addressProofInputID]}
inputID={addressProofInputID}
/>
Expand All @@ -204,8 +212,9 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
setError={(error) => {
setUploadError(error, codiceFiscaleInputID);
}}
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
fileLimit={CONST.CORPAY_DOCUMENT.FILE_LIMIT}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={defaultValues[codiceFiscaleInputID]}
inputID={codiceFiscaleInputID}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, {useEffect, useState} from 'react';
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import Button from '@components/Button';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxKeys, FormOnyxValues} from '@components/Form/types';
import type {FormInputErrors, FormOnyxKeys, FormOnyxValues, FormRef} from '@components/Form/types';
import Text from '@components/Text';
import UploadFile from '@components/UploadFile';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -17,7 +17,7 @@ import {getFieldRequiredErrors} from '@libs/ValidationUtils';
import getCurrencyForNonUSDBankAccount from '@pages/ReimbursementAccount/NonUSD/utils/getCurrencyForNonUSDBankAccount';
import getNeededDocumentsStatusForSignerInfo from '@pages/ReimbursementAccount/utils/getNeededDocumentsStatusForSignerInfo';
import WhyLink from '@pages/ReimbursementAccount/WhyLink';
import {clearErrorFields, setDraftValues, setErrorFields} from '@userActions/FormActions';
import {clearErrorFields, clearErrors, setDraftValues, setErrorFields} from '@userActions/FormActions';
import {openExternalLink} from '@userActions/Link';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -50,6 +50,8 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
[CODICE_FISCALE]: Array.isArray(reimbursementAccountDraft?.[CODICE_FISCALE]) ? (reimbursementAccountDraft?.[CODICE_FISCALE] ?? []) : [],
};

const formRef = useRef<FormRef | null>(null);

const [uploadedIDs, setUploadedID] = useState<FileObject[]>(defaultValues[COPY_OF_ID]);
const [uploadedProofsOfAddress, setUploadedProofOfAddress] = useState<FileObject[]>(defaultValues[ADDRESS_PROOF]);
const [uploadedProofsOfDirectors, setUploadedProofsOfDirectors] = useState<FileObject[]>(defaultValues[PROOF_OF_DIRECTORS]);
Expand Down Expand Up @@ -97,6 +99,8 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
return;
}

formRef.current?.resetFormFieldError(inputID);
clearErrors(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM);
setErrorFields(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM, {[inputID]: {onUpload: error}});
};

Expand All @@ -108,6 +112,7 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {

return (
<FormProvider
ref={formRef}
formID={ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM}
submitButtonText={translate(isEditing ? 'common.confirm' : 'common.next')}
onSubmit={handleSubmitWithDownload}
Expand All @@ -131,13 +136,14 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
onRemove={(fileName) => {
handleRemoveFile(fileName, uploadedIDs, COPY_OF_ID, setUploadedID);
}}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={uploadedIDs}
inputID={COPY_OF_ID}
setError={(error) => {
setUploadError(error, COPY_OF_ID);
}}
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
fileLimit={CONST.CORPAY_DOCUMENT.FILE_LIMIT}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
/>
<Text style={[styles.mutedTextLabel, styles.mt6]}>{translate('ownershipInfoStep.copyOfIDDescription')}</Text>
{(isDocumentNeededStatus.isAddressProofNeeded ||
Expand All @@ -159,13 +165,14 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
onRemove={(fileName) => {
handleRemoveFile(fileName, uploadedProofsOfAddress, ADDRESS_PROOF, setUploadedProofOfAddress);
}}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={uploadedProofsOfAddress}
inputID={ADDRESS_PROOF}
setError={(error) => {
setUploadError(error, ADDRESS_PROOF);
}}
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
fileLimit={CONST.CORPAY_DOCUMENT.FILE_LIMIT}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
/>
<Text style={[styles.mutedTextLabel, styles.mt6]}>{translate('ownershipInfoStep.proofOfAddressDescription')}</Text>
{(isDocumentNeededStatus.isProofOfDirectorsNeeded || isDocumentNeededStatus.isCodiceFiscaleNeeded || isDocumentNeededStatus.isPRDAndFSGNeeded) && (
Expand All @@ -186,13 +193,14 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
onRemove={(fileName) => {
handleRemoveFile(fileName, uploadedProofsOfDirectors, PROOF_OF_DIRECTORS, setUploadedProofsOfDirectors);
}}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={uploadedProofsOfDirectors}
inputID={PROOF_OF_DIRECTORS}
setError={(error) => {
setUploadError(error, PROOF_OF_DIRECTORS);
}}
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
fileLimit={CONST.CORPAY_DOCUMENT.FILE_LIMIT}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
/>
<Text style={[styles.mutedTextLabel, styles.mt6]}>{translate('signerInfoStep.proofOfDirectorsDescription')}</Text>
{(isDocumentNeededStatus.isCodiceFiscaleNeeded || isDocumentNeededStatus.isPRDAndFSGNeeded) && <View style={[styles.sectionDividerLine, styles.mt6, styles.mb6]} />}
Expand All @@ -211,13 +219,14 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
onRemove={(fileName) => {
handleRemoveFile(fileName, uploadedCodiceFiscale, CODICE_FISCALE, setUploadedCodiceFiscale);
}}
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
acceptedFileTypes={[...CONST.CORPAY_DOCUMENT.ALLOWED_FILE_TYPES]}
value={uploadedCodiceFiscale}
inputID={CODICE_FISCALE}
setError={(error) => {
setUploadError(error, CODICE_FISCALE);
}}
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
fileLimit={CONST.CORPAY_DOCUMENT.FILE_LIMIT}
maxFileSize={CONST.CORPAY_DOCUMENT.MAX_FILE_SIZE}
/>
<Text style={[styles.mutedTextLabel, styles.mt6]}>{translate('signerInfoStep.codiceFiscaleDescription')}</Text>
{isDocumentNeededStatus.isPRDAndFSGNeeded && <View style={[styles.sectionDividerLine, styles.mt6, styles.mb6]} />}
Expand Down
Loading