-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Internal QA] Missing personal details magic code modal uses navigation #73116
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
64a2299
d26cacd
b974274
cecb8d8
960480b
3d020e3
6b0a48f
677ac74
3e7e802
537fa20
4e84735
f906694
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,84 @@ | ||
| import React, {useCallback, useEffect, useMemo} from 'react'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import ValidateCodeActionContent from '@components/ValidateCodeActionModal/ValidateCodeActionContent'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import {clearDraftValues} from '@libs/actions/FormActions'; | ||
| import {clearPersonalDetailsErrors, updatePersonalDetailsAndShipExpensifyCards} from '@libs/actions/PersonalDetails'; | ||
| import {requestValidateCodeAction, resetValidateActionCodeSent} from '@libs/actions/User'; | ||
| import {normalizeCountryCode} from '@libs/CountryUtils'; | ||
| import {getLatestError} from '@libs/ErrorUtils'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {arePersonalDetailsMissing} from '@libs/PersonalDetailsUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import {primaryLoginSelector} from '@src/selectors/Account'; | ||
| import type {PersonalDetailsForm} from '@src/types/form'; | ||
| import type {CardList} from '@src/types/onyx'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import {getSubstepValues} from './utils'; | ||
|
|
||
| const areAllCardsShippedSelector = (cardList: OnyxEntry<CardList>) => Object.values(cardList ?? {})?.every((card) => card?.state !== CONST.EXPENSIFY_CARD.STATE.STATE_NOT_ISSUED); | ||
|
|
||
| function MissingPersonalDetailsMagicCodePage() { | ||
| const {translate} = useLocalize(); | ||
| const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS, {canBeMissing: false}); | ||
|
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.
What's this change for? Would be good to have some context.
Contributor
Author
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. Assumed this was misissue of Following This pages` logic relies on |
||
| const [draftValues] = useOnyx(ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM_DRAFT, {canBeMissing: false}); | ||
| const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false}); | ||
|
|
||
| const [areAllCardsShipped] = useOnyx(ONYXKEYS.CARD_LIST, {selector: areAllCardsShippedSelector, canBeMissing: true}); | ||
| const [primaryLogin] = useOnyx(ONYXKEYS.ACCOUNT, {selector: primaryLoginSelector, canBeMissing: true}); | ||
|
|
||
| const [validateCodeAction] = useOnyx(ONYXKEYS.VALIDATE_ACTION_CODE, {canBeMissing: true}); | ||
| const privateDetailsErrors = privatePersonalDetails?.errors ?? undefined; | ||
| const validateLoginError = getLatestError(privateDetailsErrors); | ||
|
|
||
| const missingDetails = arePersonalDetailsMissing(privatePersonalDetails); | ||
|
|
||
| useEffect(() => { | ||
| if (missingDetails || !!privateDetailsErrors || !areAllCardsShipped) { | ||
| return; | ||
| } | ||
|
|
||
| clearDraftValues(ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM); | ||
| Navigation.dismissModal(); | ||
| }, [missingDetails, privateDetailsErrors, areAllCardsShipped]); | ||
|
|
||
| const clearError = () => { | ||
| if (isEmptyObject(validateLoginError) && isEmptyObject(validateCodeAction?.errorFields)) { | ||
| return; | ||
| } | ||
| clearPersonalDetailsErrors(); | ||
| }; | ||
|
|
||
| const values = useMemo(() => normalizeCountryCode(getSubstepValues(privatePersonalDetails, draftValues)) as PersonalDetailsForm, [privatePersonalDetails, draftValues]); | ||
|
|
||
| const handleSubmitForm = useCallback( | ||
| (validateCode: string) => { | ||
| updatePersonalDetailsAndShipExpensifyCards(values, validateCode, countryCode); | ||
| }, | ||
| [countryCode, values], | ||
| ); | ||
|
|
||
| return ( | ||
| <ValidateCodeActionContent | ||
| title={translate('cardPage.validateCardTitle')} | ||
| descriptionPrimary={translate('cardPage.enterMagicCode', {contactMethod: primaryLogin ?? ''})} | ||
| sendValidateCode={() => requestValidateCodeAction()} | ||
| validateCodeActionErrorField="personalDetails" | ||
| handleSubmitForm={handleSubmitForm} | ||
| validateError={validateLoginError} | ||
| clearError={clearError} | ||
| onClose={() => { | ||
| resetValidateActionCodeSent(); | ||
| Navigation.goBack(ROUTES.MISSING_PERSONAL_DETAILS); | ||
| }} | ||
| isLoading={privatePersonalDetails?.isLoading} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| MissingPersonalDetailsMagicCodePage.displayName = 'MissingPersonalDetailsMagicCodePage'; | ||
|
|
||
| export default MissingPersonalDetailsMagicCodePage; | ||
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.
Lets also add a test for this method if there is none @jmusial feel free to do that in a follow up 🙇