-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Migrate ExpensifyCard/ConfirmationPage to Navigation-Based Validation #76241
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
Changes from all commits
83ff582
cbf1688
7f1eaa2
7250568
fc7ca93
c5712e0
a40dca0
d44e37f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import React, {useCallback, useEffect} from 'react'; | ||
| import ValidateCodeActionContent from '@components/ValidateCodeActionModal/ValidateCodeActionContent'; | ||
| import useDefaultFundID from '@hooks/useDefaultFundID'; | ||
| import useInitial from '@hooks/useInitial'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import usePermissions from '@hooks/usePermissions'; | ||
| import {clearIssueNewCardError, clearIssueNewCardFlow, issueExpensifyCard} from '@libs/actions/Card'; | ||
| import {requestValidateCodeAction, resetValidateActionCodeSent} from '@libs/actions/User'; | ||
| import {getLatestErrorMessageField} from '@libs/ErrorUtils'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; | ||
| import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type SCREENS from '@src/SCREENS'; | ||
|
|
||
| type IssueNewCardConfirmMagicCodePageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.EXPENSIFY_CARD_ISSUE_NEW_CONFIRM_MAGIC_CODE>; | ||
|
|
||
| function IssueNewCardConfirmMagicCodePage({route}: IssueNewCardConfirmMagicCodePageProps) { | ||
| const {translate} = useLocalize(); | ||
| const policyID = route.params.policyID; | ||
| const backTo = route.params.backTo; | ||
| const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); | ||
| const primaryLogin = account?.primaryLogin ?? ''; | ||
| const [issueNewCard] = useOnyx(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, {canBeMissing: true}); | ||
| const validateError = getLatestErrorMessageField(issueNewCard); | ||
| const data = issueNewCard?.data; | ||
| const isSuccessful = issueNewCard?.isSuccessful; | ||
| const defaultFundID = useDefaultFundID(policyID); | ||
| const {isBetaEnabled} = usePermissions(); | ||
| const firstAssigneeEmail = useInitial(issueNewCard?.data?.assigneeEmail); | ||
| const shouldUseBackToParam = !firstAssigneeEmail || firstAssigneeEmail === issueNewCard?.data?.assigneeEmail; | ||
|
|
||
| useEffect(() => { | ||
| if (!isSuccessful) { | ||
| return; | ||
| } | ||
| if (backTo && shouldUseBackToParam) { | ||
| Navigation.goBack(backTo); | ||
| } else { | ||
| Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID), {forceReplace: true}); | ||
| } | ||
| clearIssueNewCardFlow(policyID); | ||
| }, [backTo, isSuccessful, policyID, shouldUseBackToParam]); | ||
|
|
||
| const handleSubmit = useCallback( | ||
| (validateCode: string) => { | ||
| // NOTE: For Expensify Card UK/EU, the backend will automatically detect the correct feedCountry to use | ||
| issueExpensifyCard(defaultFundID, policyID, isBetaEnabled(CONST.BETAS.EXPENSIFY_CARD_EU_UK) ? '' : CONST.COUNTRY.US, validateCode, data); | ||
| }, | ||
| [isBetaEnabled, data, defaultFundID, policyID], | ||
| ); | ||
|
|
||
| const handleClose = useCallback(() => { | ||
| resetValidateActionCodeSent(); | ||
| Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW.getRoute(policyID, backTo)); | ||
| }, [policyID, backTo]); | ||
|
|
||
| return ( | ||
| <ValidateCodeActionContent | ||
| isLoading={issueNewCard?.isLoading} | ||
| title={translate('cardPage.validateCardTitle')} | ||
| descriptionPrimary={translate('cardPage.enterMagicCode', {contactMethod: primaryLogin})} | ||
| sendValidateCode={() => requestValidateCodeAction()} | ||
| validateCodeActionErrorField={data?.cardType === CONST.EXPENSIFY_CARD.CARD_TYPE.PHYSICAL ? 'createExpensifyCard' : 'createAdminIssuedVirtualCard'} | ||
| handleSubmitForm={handleSubmit} | ||
| validateError={validateError} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-4 (docs)The inline function Wrap this function with const clearError = useCallback(() => setValidateError({}), []);Then pass it directly: clearError={clearError} |
||
| clearError={() => clearIssueNewCardError(policyID)} | ||
| onClose={handleClose} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| IssueNewCardConfirmMagicCodePage.displayName = 'ExpensifyCardVerifyAccountPage'; | ||
|
|
||
| export default IssueNewCardConfirmMagicCodePage; | ||
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.
Came from this issue
We have a bit specific case when app reopens Expensify Card page after issuing card and swiping right on ios
More context here