Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim the value when going back on connect bank account #28305

Merged
merged 33 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
183e3fe
Trim the value when going back on connect bank account
dukenv0307 Sep 27, 2023
99477df
use draft if the default value is empty
dukenv0307 Sep 27, 2023
04e7887
fix typo
dukenv0307 Sep 27, 2023
161abe5
save value to draft after updating data successfully
dukenv0307 Sep 27, 2023
15ef37f
fix merge main
dukenv0307 Sep 27, 2023
883db65
fix jest
dukenv0307 Sep 27, 2023
10f72f8
fix lint
dukenv0307 Sep 27, 2023
0fa5251
Merge branch 'main' into fix/25996
dukenv0307 Sep 27, 2023
4532a36
add comment
dukenv0307 Sep 27, 2023
3c4be81
create a const for fields of the step
dukenv0307 Sep 27, 2023
936289c
fix lint
dukenv0307 Sep 27, 2023
88fc114
Merge branch 'fix/25996' of https://github.com/dukenv0307/App into fi…
dukenv0307 Sep 27, 2023
25c2366
reuse the const
dukenv0307 Sep 27, 2023
6caa796
revert const
dukenv0307 Sep 28, 2023
270eddf
fix jest
dukenv0307 Sep 28, 2023
12f5f05
fix lint
dukenv0307 Sep 28, 2023
a58a10e
fix no update when clicking on go back
dukenv0307 Sep 29, 2023
f2b02f1
don't call update when unnecessary
dukenv0307 Sep 29, 2023
6139ff2
Merge branch 'main' into fix/25996
dukenv0307 Oct 3, 2023
96bf07d
Merge branch 'fix/25996' of https://github.com/dukenv0307/App into fi…
dukenv0307 Oct 3, 2023
0de5e86
add default value for param
dukenv0307 Oct 3, 2023
b4bfd76
add check for shouldUpdateDataToDraft
dukenv0307 Oct 3, 2023
1c1dd14
rename variable
dukenv0307 Oct 3, 2023
401e05d
fix lint
dukenv0307 Oct 3, 2023
cc35473
remove unuse field
dukenv0307 Oct 3, 2023
0314480
Update src/pages/ReimbursementAccount/ReimbursementAccountPage.js
dukenv0307 Oct 3, 2023
abb6b20
add description
dukenv0307 Oct 4, 2023
bec41b8
add more detail description
dukenv0307 Oct 4, 2023
4e75345
fix typo
dukenv0307 Oct 4, 2023
c0e74b9
Update src/libs/actions/BankAccounts.js
dukenv0307 Oct 6, 2023
0f48962
rename the variable
dukenv0307 Oct 6, 2023
8d692b0
Update src/pages/ReimbursementAccount/ReimbursementAccountPage.js
dukenv0307 Oct 9, 2023
26e9552
fix lint
dukenv0307 Oct 9, 2023
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
8 changes: 8 additions & 0 deletions src/components/AddressSearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ function AddressSearch(props) {
props.onInputChange(values);
}

if (_.isFunction(props.onValueChange)) {
props.onValueChange(values);
}

props.onPress(values);
};

Expand Down Expand Up @@ -337,6 +341,10 @@ function AddressSearch(props) {
props.onInputChange({street: text});
}

if (_.isFunction(props.onValueChange)) {
props.onValueChange({street: text});
}

// If the text is empty, we set displayListViewBorder to false to prevent UI flickering
if (_.isEmpty(text)) {
setDisplayListViewBorder(false);
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ReimbursementAccount/AddressForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function AddressForm(props) {
value={props.values.street}
defaultValue={props.defaultValues.street}
onInputChange={props.onFieldChange}
onValueChange={props.onFieldChange}
errorText={props.errors.street ? props.translate('bankAccount.error.addressStreet') : ''}
hint={props.translate('common.noPO')}
renamedInputKeys={props.inputKeys}
Expand All @@ -129,6 +130,7 @@ function AddressForm(props) {
value={props.values.state}
defaultValue={props.defaultValues.state || ''}
onInputChange={(value) => props.onFieldChange({state: value})}
onValueChange={(value) => props.onFieldChange({state: value})}
errorText={props.errors.state ? props.translate('bankAccount.error.addressState') : ''}
/>
</View>
Expand Down
38 changes: 28 additions & 10 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'underscore';
import lodashGet from 'lodash/get';
import React, {useMemo} from 'react';
import React, {useMemo, useState} from 'react';
import {View} from 'react-native';
import Str from 'expensify-common/lib/str';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -54,6 +54,23 @@ const defaultProps = {
};

function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaultStateForField, onBackButtonPress, translate, session, user, policyID}) {
const defaultWebsite = useMemo(() => (lodashGet(user, 'isFromPublicDomain', false) ? 'https://' : `https://www.${Str.extractEmailDomain(session.email, '')}`), [user, session]);
const [companyInfomation, setCompanyInfomation] = useState({
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: should be ...Information

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

street: getDefaultStateForField('addressStreet') || reimbursementAccountDraft.addressStreet,
city: getDefaultStateForField('addressCity') || reimbursementAccountDraft.addressCity,
state: getDefaultStateForField('addressState') || reimbursementAccountDraft.addressState,
zipCode: getDefaultStateForField('addressZipCode') || reimbursementAccountDraft.addressZipCode,
companyPhone: getDefaultStateForField('companyPhone') || reimbursementAccountDraft.companyPhone,
website: getDefaultStateForField('website', defaultWebsite) || reimbursementAccountDraft.website,
});

const onFieldChange = (field) => {
setCompanyInfomation((prevCompanyInformation) => ({
...prevCompanyInformation,
...field,
}));
};

/**
* @param {Array} fieldNames
*
Expand All @@ -64,8 +81,6 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
..._.pick(reimbursementAccountDraft, ...fieldNames),
});

const defaultWebsite = useMemo(() => (lodashGet(user, 'isFromPublicDomain', false) ? 'https://' : `https://www.${Str.extractEmailDomain(session.email, '')}`), [user, session]);

/**
* @param {Object} values - form input values passed by the Form component
* @returns {Object} - Object containing the errors for each inputID, e.g. {inputID1: error1, inputID2: error2}
Expand Down Expand Up @@ -173,18 +188,19 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
/>
<AddressForm
translate={translate}
defaultValues={{
street: getDefaultStateForField('addressStreet'),
city: getDefaultStateForField('addressCity'),
state: getDefaultStateForField('addressState'),
zipCode: getDefaultStateForField('addressZipCode'),
values={{
street: companyInfomation.street,
city: companyInfomation.city,
state: companyInfomation.state,
zipCode: companyInfomation.zipCode,
}}
inputKeys={{
street: 'addressStreet',
city: 'addressCity',
state: 'addressState',
zipCode: 'addressZipCode',
}}
onFieldChange={onFieldChange}
shouldSaveDraft
streetTranslationKey="common.companyAddress"
/>
Expand All @@ -196,7 +212,8 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
containerStyles={[styles.mt4]}
keyboardType={CONST.KEYBOARD_TYPE.PHONE_PAD}
placeholder={translate('common.phoneNumberPlaceholder')}
defaultValue={getDefaultStateForField('companyPhone')}
value={companyInfomation.companyPhone}
onValueChange={(value) => onFieldChange({companyPhone: value})}
shouldSaveDraft
/>
<TextInput
Expand All @@ -205,7 +222,8 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul
accessibilityLabel={translate('companyStep.companyWebsite')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
containerStyles={[styles.mt4]}
defaultValue={getDefaultStateForField('website', defaultWebsite)}
value={companyInfomation.website}
onValueChange={(value) => onFieldChange({website: value})}
shouldSaveDraft
hint={translate('common.websiteExample')}
keyboardType={CONST.KEYBOARD_TYPE.URL}
Expand Down