-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40357 from koko57/refactor/36648-wallet-enablemen…
…t-flow-personal-info Refactor/36648 wallet enablement flow personal info
- Loading branch information
Showing
32 changed files
with
960 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {useCallback} from 'react'; | ||
import type {FormOnyxKeys, FormOnyxValues} from '@components/Form/types'; | ||
import * as FormActions from '@userActions/FormActions'; | ||
import type {OnyxFormKey, OnyxFormValuesMapping} from '@src/ONYXKEYS'; | ||
import type {SubStepProps} from './useSubStep/types'; | ||
|
||
type UseStepFormSubmitParams<T extends keyof OnyxFormValuesMapping> = Pick<SubStepProps, 'onNext'> & { | ||
formId: OnyxFormKey; | ||
fieldIds: Array<FormOnyxKeys<T>>; | ||
shouldSaveDraft: boolean; | ||
}; | ||
|
||
/** | ||
* Hook for handling submit method in substeps. | ||
* When user is in editing mode, we should save values only when user confirms the change | ||
* @param formId - ID for particular form | ||
* @param onNext - callback | ||
* @param fieldIds - field IDs for particular step | ||
* @param shouldSaveDraft - if we should save draft values | ||
*/ | ||
export default function useStepFormSubmit<T extends keyof OnyxFormValuesMapping>({formId, onNext, fieldIds, shouldSaveDraft}: UseStepFormSubmitParams<T>) { | ||
return useCallback( | ||
(values: FormOnyxValues<T>) => { | ||
if (shouldSaveDraft) { | ||
const stepValues = fieldIds.reduce( | ||
(acc, key) => ({ | ||
...acc, | ||
[key]: values[key], | ||
}), | ||
{}, | ||
); | ||
|
||
FormActions.setDraftValues(formId, stepValues); | ||
} | ||
|
||
onNext(); | ||
}, | ||
[onNext, formId, fieldIds, shouldSaveDraft], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type {FormOnyxKeys} from '@components/Form/types'; | ||
import type {OnyxFormKey} from '@src/ONYXKEYS'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import useStepFormSubmit from './useStepFormSubmit'; | ||
import type {SubStepProps} from './useSubStep/types'; | ||
|
||
type UseWalletAdditionalDetailsStepFormSubmitParams = Pick<SubStepProps, 'onNext'> & { | ||
formId?: OnyxFormKey; | ||
fieldIds: Array<FormOnyxKeys<typeof ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS>>; | ||
shouldSaveDraft: boolean; | ||
}; | ||
|
||
/** | ||
* Hook for handling submit method in WalletAdditionalDetails substeps. | ||
* When user is in editing mode, we should save values only when user confirms the change | ||
* @param onNext - callback | ||
* @param fieldIds - field IDs for particular step | ||
* @param shouldSaveDraft - if we should save draft values | ||
*/ | ||
export default function useWalletAdditionalDetailsStepFormSubmit({onNext, fieldIds, shouldSaveDraft}: UseWalletAdditionalDetailsStepFormSubmitParams) { | ||
return useStepFormSubmit<typeof ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS>({ | ||
formId: ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS, | ||
onNext, | ||
fieldIds, | ||
shouldSaveDraft, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.