Skip to content

Commit

Permalink
Merge pull request #36961 from GandalfGwaihir/issue-36072
Browse files Browse the repository at this point in the history
[fix]: Able to save a phone number with some spaces before and After the number
  • Loading branch information
nkuoch authored Mar 14, 2024
2 parents 0a512c9 + 7c2e74d commit 206d293
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 21 deletions.
11 changes: 6 additions & 5 deletions src/hooks/useReimbursementAccountStepFormSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ import type {OnyxFormKey} from '@src/ONYXKEYS';
import ONYXKEYS from '@src/ONYXKEYS';
import type {SubStepProps} from './useSubStep/types';

type UseReimbursementAccountStepFormSubmitParams = Pick<SubStepProps, 'isEditing' | 'onNext'> & {
type UseReimbursementAccountStepFormSubmitParams = Pick<SubStepProps, 'onNext'> & {
formId?: OnyxFormKey;
fieldIds: Array<FormOnyxKeys<typeof ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM>>;
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<typeof ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM>) => {
if (isEditing) {
if (shouldSaveDraft) {
const stepValues = fieldIds.reduce(
(acc, key) => ({
...acc,
Expand All @@ -40,6 +41,6 @@ export default function useReimbursementAccountStepFormSubmit({

onNext();
},
[isEditing, onNext, formId, fieldIds],
[onNext, formId, fieldIds, shouldSaveDraft],
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function AddressUBO({reimbursementAccountDraft, onNext, isEditing, beneficialOwn

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: stepFields,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function DateOfBirthUBO({reimbursementAccountDraft, onNext, isEditing, beneficia

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: [dobInputID],
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function LegalNameUBO({reimbursementAccountDraft, onNext, isEditing, beneficialO

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: stepFields,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function SocialSecurityNumberUBO({reimbursementAccountDraft, onNext, isEditing,

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: stepFields,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ function AddressBusiness({reimbursementAccount, onNext, isEditing}: AddressBusin

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function IncorporationDateBusiness({reimbursementAccount, reimbursementAccountDr

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function IncorporationStateBusiness({reimbursementAccount, onNext, isEditing}: I

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function NameBusiness({reimbursementAccount, onNext, isEditing}: NameBusinessPro

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function TaxIdBusiness({reimbursementAccount, onNext, isEditing}: TaxIdBusinessP

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function TypeBusiness({reimbursementAccount, onNext, isEditing}: TypeBusinessPro

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ function WebsiteBusiness({reimbursementAccount, user, session, onNext, isEditing

const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
isEditing,
onNext,
shouldSaveDraft: isEditing,
});

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Address({reimbursementAccount, onNext, isEditing}: AddressProps) {
const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
onNext,
isEditing,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function DateOfBirth({reimbursementAccount, reimbursementAccountDraft, onNext, i
const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
onNext,
isEditing,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function FullName({reimbursementAccount, onNext, isEditing}: FullNameProps) {
const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
onNext,
isEditing,
shouldSaveDraft: isEditing,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function SocialSecurityNumber({reimbursementAccount, onNext, isEditing}: SocialS
const handleSubmit = useReimbursementAccountStepFormSubmit({
fieldIds: STEP_FIELDS,
onNext,
isEditing,
shouldSaveDraft: isEditing,
});

return (
Expand Down

0 comments on commit 206d293

Please sign in to comment.