Skip to content

Commit

Permalink
feat: Add Corpay bank info step and update file upload logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pasyukevich committed Nov 5, 2024
1 parent 038b21b commit 543f72d
Show file tree
Hide file tree
Showing 13 changed files with 640 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ const CONST = {
ALLOWED_FILE_TYPES: ['pdf', 'jpg', 'jpeg', 'png'],
FILE_LIMIT: 10,
TOTAL_FILES_SIZE_LIMIT: 5242880,
BANK_INFO_STEP_ACCOUNT_HOLDER_KEY_PREFIX: 'accountHolder',
STEP: {
COUNTRY: 'CountryStep',
BANK_INFO: 'BankInfoStep',
Expand Down
11 changes: 7 additions & 4 deletions src/components/UploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function UploadFile({
const theme = useTheme();

const handleFileUpload = (files: FileObject[]) => {
const totalSize = files.reduce((sum, file) => sum + (file.size ?? 0), 0);
const resultedFiles = [...uploadedFiles, ...files];

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

if (totalFilesSizeLimit) {
if (totalSize > totalFilesSizeLimit) {
Expand All @@ -78,7 +80,7 @@ function UploadFile({
}
}

if (fileLimit && files.length > 0 && files.length > fileLimit) {
if (fileLimit && resultedFiles.length > 0 && resultedFiles.length > fileLimit) {
setError(translate('attachmentPicker.tooManyFiles', {fileLimit}));
return;
}
Expand All @@ -98,6 +100,7 @@ function UploadFile({

onInputChange(newFilesToUpload);
onUpload(newFilesToUpload);
setError('');
};

return (
Expand Down Expand Up @@ -137,7 +140,7 @@ function UploadFile({
{file.name}
</Text>
<PressableWithFeedback
onPress={() => onRemove(file?.uri ?? '')}
onPress={() => onRemove(file?.name ?? '')}
role={CONST.ROLE.BUTTON}
accessibilityLabel={translate('common.remove')}
>
Expand All @@ -151,7 +154,7 @@ function UploadFile({
))}
{errorText !== '' && (
<DotIndicatorMessage
textStyles={[styles.formError]}
style={[styles.formError, styles.mt3]}
type="error"
messages={{errorText}}
/>
Expand Down
18 changes: 18 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import type {
InvalidPropertyParams,
InvalidValueParams,
IssueVirtualCardParams,
LastFourDigitsParams,
LastSyncAccountingParams,
LastSyncDateParams,
LocalTimeParams,
Expand Down Expand Up @@ -2255,6 +2256,23 @@ const translations = {
findCountry: 'Find country',
selectCountry: 'Select country',
},
bankInfoStep: {
whatAreYour: 'What are your business bank account details?',
letsDoubleCheck: 'Let’s double check that everything looks fine.',
thisBankAccount: 'This bank account will be used for business payments on your workspace',
transitNumber: 'Transit number',
institutionNumber: 'Institution number',
accountNumber: 'Account number',
routingNumber: 'Routing number',
accountName: 'Account name',
bankStatement: 'Bank statement',
whyDoWeAsk: 'Why do we ask for this?',
chooseFile: 'Choose file',
uploadYourLatest: 'Upload your latest statement',
pleaseUpload: ({lastFourDigits}: LastFourDigitsParams) => `Please upload the most recent monthly statement for your business bank account ending in ${lastFourDigits}.`,
bankInfo: 'Bank info',
confirmBankInfo: 'Confirm bank info',
},
signerInfoStep: {
signerInfo: 'Signer info',
},
Expand Down
5 changes: 5 additions & 0 deletions src/languages/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,10 @@ type FileLimitParams = {
fileLimit: number;
};

type LastFourDigitsParams = {
lastFourDigits: string;
};

type CompanyCardBankName = {
bankName: string;
};
Expand Down Expand Up @@ -637,6 +641,7 @@ export type {
HeldRequestParams,
InstantSummaryParams,
IssueVirtualCardParams,
LastFourDigitsParams,
LocalTimeParams,
LogSizeParams,
LoggedInAsParams,
Expand Down
229 changes: 229 additions & 0 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,234 @@ function validateBankAccount(bankAccountID: number, validateCode: string, policy
API.write(WRITE_COMMANDS.VALIDATE_BANK_ACCOUNT_WITH_TRANSACTIONS, parameters, onyxData);
}

function getCorpayBankAccountFields(country: string, currency: string) {
// TODO - Use parameters when API is ready
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const parameters: 'GetCorpayBankAccountFieldsParams' = {

Check failure on line 349 in src/libs/actions/BankAccounts.ts

View workflow job for this annotation

GitHub Actions / typecheck

Type '{ countryISO: string; currency: string; isWithdrawal: boolean; isBusinessBankAccount: boolean; }' is not assignable to type '"GetCorpayBankAccountFieldsParams"'.
countryISO: country,
currency,
isWithdrawal: true,
isBusinessBankAccount: true,
};

// return API.read(READ_COMMANDS.GET_CORPAY_BANK_ACCOUNT_FIELDS, parameters);
return {
bankCountry: 'AU',
bankCurrency: 'AUD',
classification: 'Business',
destinationCountry: 'AU',
formFields: [
{
errorMessage: 'Name is invalid. Value should be 3 to 100 characters long.',
id: 'accountHolderName',
isRequired: true,
isRequiredInValueSet: true,
label: 'Account Holder Name',
regEx: '^.{3,100}$',
validationRules: [
{
errorMessage: 'Name is invalid. Value should be 3 to 100 characters long.',
regEx: '^.{3,100}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
defaultValue: 'AU',
id: 'accountHolderCountry',
isRequired: true,
isRequiredInValueSet: true,
label: 'Account Holder Country',
regEx: '^.{2,2}$',
validationRules: [
{
regEx: '^.{2,2}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
errorMessage: 'PO Box address isn\u2019t allowed. Address Line 1 must be less than 1000 characters',
id: 'accountHolderAddress1',
isRequired: true,
isRequiredInValueSet: true,
label: 'Account Holder Address',
regEx: '^(?!.*\\b(P\\.?\\s?O\\.?\\s?Box|P\\.?\\s?O\\.?\\s?B\\.?|P\\.?\\s?O\\.?\\s?Bx|PO\\.?\\s?Box|PO\\.?\\s?B\\.?|PO\\.?\\s?Bx|Post\\s?Office\\s?Box|Box\\s?No\\.?|Box\\s?#|Box\\s?\\d+|Lockbox|P\\.?\\s?O\\.?\\s?B\\.?|P\\.?\\s?O\\.?\\s?Bx|P\\s?O\\s?Box\\s?No\\.?)\\b).{0,1000}$',
validationRules: [
{
errorMessage: 'PO Box address isn\u2019t allowed. Address Line 1 must be less than 1000 characters',
regEx: '^(?!.*\\b(P\\.?\\s?O\\.?\\s?Box|P\\.?\\s?O\\.?\\s?B\\.?|P\\.?\\s?O\\.?\\s?Bx|PO\\.?\\s?Box|PO\\.?\\s?B\\.?|PO\\.?\\s?Bx|Post\\s?Office\\s?Box|Box\\s?No\\.?|Box\\s?#|Box\\s?\\d+|Lockbox|P\\.?\\s?O\\.?\\s?B\\.?|P\\.?\\s?O\\.?\\s?Bx|P\\s?O\\s?Box\\s?No\\.?)\\b).{0,1000}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
errorMessage: 'City must be less than 100 characters',
id: 'accountHolderCity',
isRequired: true,
isRequiredInValueSet: true,
label: 'Account Holder City',
regEx: '^.{0,100}$',
validationRules: [
{
errorMessage: 'City must be less than 100 characters',
regEx: '^.{0,100}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
errorMessage: 'Swift must be less than 12 characters',
id: 'swiftBicCode',
isRequired: false,
isRequiredInValueSet: true,
label: 'Swift Code',
regEx: '^.{0,12}$',
validationRules: [
{
errorMessage: 'Swift must be less than 12 characters',
regEx: '^.{0,12}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
errorMessage: 'Beneficiary Bank Name must be less than 250 characters',
id: 'bankName',
isRequired: true,
isRequiredInValueSet: true,
label: 'Bank Name',
regEx: '^.{0,250}$',
validationRules: [
{
errorMessage: 'Beneficiary Bank Name must be less than 250 characters',
regEx: '^.{0,250}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
errorMessage: 'City must be less than 100 characters',
id: 'bankCity',
isRequired: true,
isRequiredInValueSet: true,
label: 'Bank City',
regEx: '^.{0,100}$',
validationRules: [
{
errorMessage: 'City must be less than 100 characters',
regEx: '^.{0,100}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
errorMessage: 'Bank Address Line 1 must be less than 1000 characters',
id: 'bankAddressLine1',
isRequired: true,
isRequiredInValueSet: true,
label: 'Bank Address',
regEx: '^.{0,1000}$',
validationRules: [
{
errorMessage: 'Bank Address Line 1 must be less than 1000 characters',
regEx: '^.{0,1000}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
detailedRule: [
{
isRequired: true,
value: [
{
errorMessage: 'Beneficiary Account Number is invalid. Value should be 1 to 50 characters long.',
regEx: '^.{1,50}$',
ruleDescription: '1 to 50 characters',
},
],
},
],
errorMessage: 'Beneficiary Account Number is invalid. Value should be 1 to 50 characters long.',
id: 'accountNumber',
isRequired: true,
isRequiredInValueSet: true,
label: 'Account Number (iACH)',
regEx: '^.{1,50}$',
validationRules: [
{
errorMessage: 'Beneficiary Account Number is invalid. Value should be 1 to 50 characters long.',
regEx: '^.{1,50}$',
ruleDescription: '1 to 50 characters',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
{
detailedRule: [
{
isRequired: true,
value: [
{
errorMessage: 'BSB Number is invalid. Value should be exactly 6 digits long.',
regEx: '^[0-9]{6}$',
ruleDescription: 'Exactly 6 digits',
},
],
},
],
errorMessage: 'BSB Number is invalid. Value should be exactly 6 digits long.',
id: 'routingCode',
isRequired: true,
isRequiredInValueSet: true,
label: 'BSB Number',
regEx: '^[0-9]{6}$',
validationRules: [
{
errorMessage: 'BSB Number is invalid. Value should be exactly 6 digits long.',
regEx: '^[0-9]{6}$',
ruleDescription: 'Exactly 6 digits',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
},
],
paymentMethods: ['E'],
preferredMethod: 'E',
};
}

function clearReimbursementAccount() {
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, null);
}
Expand Down Expand Up @@ -572,6 +800,7 @@ export {
updateAddPersonalBankAccountDraft,
clearPersonalBankAccountSetupType,
validatePlaidSelection,
getCorpayBankAccountFields,
};

export type {BusinessAddress, PersonalAddress};
Loading

0 comments on commit 543f72d

Please sign in to comment.