-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Refactor/36648 wallet enablement flow personal info #40357
Merged
mountiny
merged 39 commits into
Expensify:main
from
koko57:refactor/36648-wallet-enablement-flow-personal-info
Apr 29, 2024
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
7c16aa4
refactor: personal info wip
koko57 6331ddd
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 2fb2ce4
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 8876374
fix: wrap the page for displaying offline indicator correctly, do not…
koko57 07559bd
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 e8c9058
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 fc2e134
refactor: rename AddressForm to AddressFormFields
koko57 03111d4
refactor: remove unused file
koko57 85e77ec
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 f19d447
refactor: wip
koko57 647f538
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 3e7f27d
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 1e0e3af
feat: add phone number page
koko57 ffc26f9
feat: add validation for the field, editing phone number
koko57 9b665e8
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 b8e9d43
feat: add proper copies
koko57 c135183
refactor: make useStepSubmit generic
koko57 4718b80
refactor: finishing touches
koko57 c888b6f
fix: change step order
koko57 744c276
fix: rename components
koko57 042138b
fix: linter
koko57 5303251
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 10bb996
fix: minor fix
koko57 4a050bd
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 bffc4b6
fix: add issue link
koko57 ec9ed98
fix: minor fix
koko57 d6f65ef
fix: minor fix
koko57 16b2067
refactor: replace withOnyx with useOnyx
koko57 c001154
fix: minor fix
koko57 3866998
fix: minor fix
koko57 0711f4c
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 d88c4e7
fix: jumping inputs
koko57 5ea49d2
fix: remove wrappers, change the labels
koko57 57f1a7b
fix: address step title
koko57 04c20eb
fix: apply requested changes
koko57 879287c
fix: minor fix
koko57 67a43b1
fix: remove unnecessary style
koko57 e98ef14
Merge branch 'main' into refactor/36648-wallet-enablement-flow-person…
koko57 cb13e9c
fix: comment change
koko57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering why this extra new hook is required, bcoz to me it seems only adding a nested level from
useReimbursementAccountStepFormSubmit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's used also for useWalletAdditionalDetailsStepFormSubmit. I could just have renamed useReimbursementAccountStepFormSubmit to useStepFromSubmit, but everytime for every form I would need to remember to pass the formId and instantiate it with a proper type. Here each form can have it's own hook properly typed and with proper formId passed and I just import the proper hook and I don't need to remember of types or Id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got your point, here I would suggest to remove
useReimbursementAccountStepFormSubmit
anduseWalletAdditionalDetailsStepFormSubmit
by using the generic hookuseStepFormSubmit
which you have created. I think passingformId
from the substep components should be fine.For eg. I have tried this in
FullNameStep
and it works fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pujan92 I also didn't want to touch the ReimbursementAccount files in this PR. There are also some other changes in both flows that could be refactored and reused but I've planned to do that after this flow is complete and working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I understand your concerns. Maybe at the time of refactoring, we can bring this point over there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pujan92 yeah, of course, I will keep that in mind! thanks!