diff --git a/src/hooks/useReimbursementAccountStepFormSubmit.ts b/src/hooks/useReimbursementAccountStepFormSubmit.ts index f3a17447c7d7..98f079dd2447 100644 --- a/src/hooks/useReimbursementAccountStepFormSubmit.ts +++ b/src/hooks/useReimbursementAccountStepFormSubmit.ts @@ -5,28 +5,29 @@ import type {OnyxFormKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; import type {SubStepProps} from './useSubStep/types'; -type UseReimbursementAccountStepFormSubmitParams = Pick & { +type UseReimbursementAccountStepFormSubmitParams = Pick & { formId?: OnyxFormKey; fieldIds: Array>; + shouldSaveDraft: boolean; }; /** * Hook for handling submit method in ReimbursementAccount substeps. * When user is in editing mode we should save values only when user confirm that * @param formId - ID for particular form - * @param isEditing - if form is in editing mode * @param onNext - callback * @param fieldIds - field IDs for particular step + * @param shouldSaveDraft - if we should save draft values */ export default function useReimbursementAccountStepFormSubmit({ formId = ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM, - isEditing, onNext, fieldIds, + shouldSaveDraft, }: UseReimbursementAccountStepFormSubmitParams) { return useCallback( (values: FormOnyxValues) => { - if (isEditing) { + if (shouldSaveDraft) { const stepValues = fieldIds.reduce( (acc, key) => ({ ...acc, @@ -40,6 +41,6 @@ export default function useReimbursementAccountStepFormSubmit({ onNext(); }, - [isEditing, onNext, formId, fieldIds], + [onNext, formId, fieldIds, shouldSaveDraft], ); } diff --git a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/AddressUBO.tsx b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/AddressUBO.tsx index 999710310224..b68423115825 100644 --- a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/AddressUBO.tsx +++ b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/AddressUBO.tsx @@ -59,8 +59,8 @@ function AddressUBO({reimbursementAccountDraft, onNext, isEditing, beneficialOwn const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: stepFields, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/DateOfBirthUBO.tsx b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/DateOfBirthUBO.tsx index be1a0f170665..b60b19193dbc 100644 --- a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/DateOfBirthUBO.tsx +++ b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/DateOfBirthUBO.tsx @@ -51,8 +51,8 @@ function DateOfBirthUBO({reimbursementAccountDraft, onNext, isEditing, beneficia const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: [dobInputID], - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/LegalNameUBO.tsx b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/LegalNameUBO.tsx index ccd7104e2276..0fc7ab10d133 100644 --- a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/LegalNameUBO.tsx +++ b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/LegalNameUBO.tsx @@ -39,8 +39,8 @@ function LegalNameUBO({reimbursementAccountDraft, onNext, isEditing, beneficialO const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: stepFields, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/SocialSecurityNumberUBO.tsx b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/SocialSecurityNumberUBO.tsx index 3b5710134114..7c0c5ac0c057 100644 --- a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/SocialSecurityNumberUBO.tsx +++ b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/BeneficialOwnerDetailsFormSubsteps/SocialSecurityNumberUBO.tsx @@ -43,8 +43,8 @@ function SocialSecurityNumberUBO({reimbursementAccountDraft, onNext, isEditing, const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: stepFields, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/AddressBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/AddressBusiness.tsx index 354620f5e46a..bd6cf04adab2 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/AddressBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/AddressBusiness.tsx @@ -63,8 +63,8 @@ function AddressBusiness({reimbursementAccount, onNext, isEditing}: AddressBusin const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/IncorporationDateBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/IncorporationDateBusiness.tsx index 476d26f9589a..1f6b341cb261 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/IncorporationDateBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/IncorporationDateBusiness.tsx @@ -49,8 +49,8 @@ function IncorporationDateBusiness({reimbursementAccount, reimbursementAccountDr const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/IncorporationStateBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/IncorporationStateBusiness.tsx index b437e6ec05b5..02d932cf990e 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/IncorporationStateBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/IncorporationStateBusiness.tsx @@ -35,8 +35,8 @@ function IncorporationStateBusiness({reimbursementAccount, onNext, isEditing}: I const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/NameBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/NameBusiness.tsx index 8fc637fd24f2..377fbf9782ae 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/NameBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/NameBusiness.tsx @@ -47,8 +47,8 @@ function NameBusiness({reimbursementAccount, onNext, isEditing}: NameBusinessPro const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/PhoneNumberBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/PhoneNumberBusiness.tsx index e0d369e099d1..018922610080 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/PhoneNumberBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/PhoneNumberBusiness.tsx @@ -43,8 +43,9 @@ function PhoneNumberBusiness({reimbursementAccount, onNext, isEditing}: PhoneNum const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, - isEditing, onNext, + // During draft saving, the phone number is sanitized (i.e. leading and trailing whitespace is removed) + shouldSaveDraft: true, }); return ( diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/TaxIdBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/TaxIdBusiness.tsx index 46680276e76e..cabf0fc01576 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/TaxIdBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/TaxIdBusiness.tsx @@ -45,8 +45,8 @@ function TaxIdBusiness({reimbursementAccount, onNext, isEditing}: TaxIdBusinessP const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/TypeBusiness/TypeBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/TypeBusiness/TypeBusiness.tsx index f573923bd5c5..0ee629ae5e21 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/TypeBusiness/TypeBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/TypeBusiness/TypeBusiness.tsx @@ -35,8 +35,8 @@ function TypeBusiness({reimbursementAccount, onNext, isEditing}: TypeBusinessPro const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, - isEditing, onNext, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx b/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx index fedb9b29af71..0988b861e78f 100644 --- a/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx +++ b/src/pages/ReimbursementAccount/BusinessInfo/substeps/WebsiteBusiness.tsx @@ -56,8 +56,8 @@ function WebsiteBusiness({reimbursementAccount, user, session, onNext, isEditing const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, - isEditing, onNext, + shouldSaveDraft: isEditing, }); useEffect(() => { diff --git a/src/pages/ReimbursementAccount/PersonalInfo/substeps/Address.tsx b/src/pages/ReimbursementAccount/PersonalInfo/substeps/Address.tsx index 824ed950bd9f..712661510b7d 100644 --- a/src/pages/ReimbursementAccount/PersonalInfo/substeps/Address.tsx +++ b/src/pages/ReimbursementAccount/PersonalInfo/substeps/Address.tsx @@ -62,7 +62,7 @@ function Address({reimbursementAccount, onNext, isEditing}: AddressProps) { const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, onNext, - isEditing, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/PersonalInfo/substeps/DateOfBirth.tsx b/src/pages/ReimbursementAccount/PersonalInfo/substeps/DateOfBirth.tsx index 1aa7a083b20d..b02a56403641 100644 --- a/src/pages/ReimbursementAccount/PersonalInfo/substeps/DateOfBirth.tsx +++ b/src/pages/ReimbursementAccount/PersonalInfo/substeps/DateOfBirth.tsx @@ -58,7 +58,7 @@ function DateOfBirth({reimbursementAccount, reimbursementAccountDraft, onNext, i const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, onNext, - isEditing, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/PersonalInfo/substeps/FullName.tsx b/src/pages/ReimbursementAccount/PersonalInfo/substeps/FullName.tsx index 412227570365..1d225c1c32f2 100644 --- a/src/pages/ReimbursementAccount/PersonalInfo/substeps/FullName.tsx +++ b/src/pages/ReimbursementAccount/PersonalInfo/substeps/FullName.tsx @@ -52,7 +52,7 @@ function FullName({reimbursementAccount, onNext, isEditing}: FullNameProps) { const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, onNext, - isEditing, + shouldSaveDraft: isEditing, }); return ( diff --git a/src/pages/ReimbursementAccount/PersonalInfo/substeps/SocialSecurityNumber.tsx b/src/pages/ReimbursementAccount/PersonalInfo/substeps/SocialSecurityNumber.tsx index 02407dbce467..e647fd768fb1 100644 --- a/src/pages/ReimbursementAccount/PersonalInfo/substeps/SocialSecurityNumber.tsx +++ b/src/pages/ReimbursementAccount/PersonalInfo/substeps/SocialSecurityNumber.tsx @@ -46,7 +46,7 @@ function SocialSecurityNumber({reimbursementAccount, onNext, isEditing}: SocialS const handleSubmit = useReimbursementAccountStepFormSubmit({ fieldIds: STEP_FIELDS, onNext, - isEditing, + shouldSaveDraft: isEditing, }); return (