Skip to content

Commit

Permalink
Fix draft saving mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Jan 4, 2025
1 parent dbd5145 commit d88fe50
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function AccountHolderInformation({isEditing, onNext, formValues, fieldsMap}: Cu
const handleSubmit = useInternationalBankAccountFormSubmit({
fieldIds: Object.keys(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]),
onNext,
shouldSaveDraft: true,
shouldSaveDraft: isEditing,
});

const validate = useCallback(
Expand Down Expand Up @@ -107,6 +107,7 @@ function AccountHolderInformation({isEditing, onNext, formValues, fieldsMap}: Cu
items={getItems(field)}
disabled={field.id === ACCOUNT_HOLDER_COUNTRY}
interactive={field.id === ACCOUNT_HOLDER_COUNTRY ? false : undefined}
shouldSaveDraft={!isEditing}
renamedInputKeys={{
street: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]?.accountHolderAddress1) ? '' : 'accountHolderAddress1',
street2: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.ACCOUNT_HOLDER_INFORMATION]?.accountHolderAddress2) ? '' : 'accountHolderAddress2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ function AccountType({isEditing, onNext, formValues, fieldsMap}: CustomSubStepPr
onNext();
}, [currentAccountType, fieldData.isRequired, formValues, isEditing, onNext]);

const onSelectionChange = useCallback((country: Option) => {
setCurrentAccountType(country.value);
}, []);
const onSelectionChange = useCallback(
(country: Option) => {
if (!isEditing) {
FormActions.setDraftValues(ONYXKEYS.FORMS.INTERNATIONAL_BANK_ACCOUNT_FORM, {[CONST.CORPAY_FIELDS.ACCOUNT_TYPE_KEY]: currentAccountType});
}
setCurrentAccountType(country.value);
},
[currentAccountType, isEditing],
);

const options = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function BankAccountDetails({isEditing, onNext, resetScreenIndex, formValues, fi
const handleSubmit = useInternationalBankAccountFormSubmit({
fieldIds: Object.keys(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_ACCOUNT_DETAILS] ?? {}),
onNext,
shouldSaveDraft: true,
shouldSaveDraft: isEditing,
});

const onCurrencySelected = useCallback(
Expand Down Expand Up @@ -86,6 +86,7 @@ function BankAccountDetails({isEditing, onNext, resetScreenIndex, formValues, fi
defaultValue={formValues[field.id]}
label={field.label + (field.isRequired ? '' : ` (${translate('common.optional')})`)}
items={(field.valueSet ?? []).map(({id, text}) => ({value: id, label: text}))}
shouldSaveDraft={!isEditing}
/>
</View>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function BankInformation({isEditing, onNext, formValues, fieldsMap}: CustomSubSt
const handleSubmit = useInternationalBankAccountFormSubmit({
fieldIds: Object.keys(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_INFORMATION]),
onNext,
shouldSaveDraft: true,
shouldSaveDraft: isEditing,
});

const validate = useCallback(
Expand Down Expand Up @@ -95,6 +95,7 @@ function BankInformation({isEditing, onNext, formValues, fieldsMap}: CustomSubSt
defaultValue={formValues[field.id]}
label={field.label + (field.isRequired ? '' : ` (${translate('common.optional')})`)}
items={getItems(field)}
shouldSaveDraft={!isEditing}
renamedInputKeys={{
street: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_INFORMATION]?.bankAddressLine1) ? '' : 'bankAddressLine1',
street2: isEmptyObject(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_INFORMATION]?.bankAddressLine2) ? '' : 'bankAddressLine2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubStepProp
inputID="acceptTerms"
LabelComponent={TermsAndConditionsLabel}
style={[styles.mt3]}
shouldSaveDraft
/>
<FormHelpMessage
style={[styles.mt3, styles.mbn1]}
Expand Down

0 comments on commit d88fe50

Please sign in to comment.