diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index 18fa9b2bc343f..727e810e59849 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -49,7 +49,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {ExpenseRuleForm, MerchantRuleForm} from '@src/types/form'; -import type {AppReview, BlockedFromConcierge, CustomStatusDraft, ExpenseRule, LoginList, Policy} from '@src/types/onyx'; +import type {AppReview, BlockedFromConcierge, CustomStatusDraft, ExpenseRule, Policy} from '@src/types/onyx'; import type Login from '@src/types/onyx/Login'; import type {Errors} from '@src/types/onyx/OnyxCommon'; import type {AnyOnyxServerUpdate, OnyxServerUpdate, OnyxUpdateEvent} from '@src/types/onyx/OnyxUpdatesFromServer'; @@ -511,14 +511,7 @@ function requestValidateCodeAction() { /** * Validates a secondary login / contact method */ -function validateSecondaryLogin( - currentUserPersonalDetails: OnyxEntry, - loginList: OnyxEntry, - contactMethod: string, - validateCode: string, - formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], - shouldResetActionCode?: boolean, -) { +function validateSecondaryLogin(contactMethod: string, validateCode: string, formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], shouldResetActionCode?: boolean) { const optimisticData: Array> = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -544,16 +537,7 @@ function validateSecondaryLogin( }, }, ]; - const successData: Array< - OnyxUpdate< - | typeof ONYXKEYS.LOGIN_LIST - | typeof ONYXKEYS.ACCOUNT - | typeof ONYXKEYS.SESSION - | typeof ONYXKEYS.PERSONAL_DETAILS_LIST - | typeof ONYXKEYS.COLLECTION.POLICY - | typeof ONYXKEYS.VALIDATE_ACTION_CODE - > - > = [ + const successData: Array> = [ { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.LOGIN_LIST, @@ -578,70 +562,6 @@ function validateSecondaryLogin( }, }, ]; - // If the primary login isn't validated yet, set the secondary login as the primary login - if (!loginList?.[currentEmail].validatedDate) { - successData.push( - ...[ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.ACCOUNT, - value: { - primaryLogin: contactMethod, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.SESSION, - value: { - email: contactMethod, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: { - [currentUserAccountID]: { - login: contactMethod, - displayName: PersonalDetailsUtils.createDisplayName(contactMethod, currentUserPersonalDetails, formatPhoneNumber), - }, - }, - }, - ], - ); - - for (const policy of Object.values(allPolicies ?? {})) { - if (!policy) { - continue; - } - - let optimisticPolicyDataValue; - - if (policy.employeeList) { - const currentEmployee = policy.employeeList[currentEmail]; - optimisticPolicyDataValue = { - employeeList: { - [currentEmail]: null, - [contactMethod]: currentEmployee, - }, - }; - } - - if (policy.ownerAccountID === currentUserAccountID) { - optimisticPolicyDataValue = { - ...optimisticPolicyDataValue, - owner: contactMethod, - }; - } - - if (optimisticPolicyDataValue) { - successData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`, - value: optimisticPolicyDataValue, - }); - } - } - } const failureData: Array> = [ { diff --git a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx index bb294a61f8cf4..7003f17384062 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx @@ -349,7 +349,7 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) { {isValidateCodeFormVisible && !!loginData && !loginData.validatedDate && ( validateSecondaryLogin(currentUserPersonalDetails, loginList, contactMethod, validateCode, formatPhoneNumber)} + handleSubmitForm={(validateCode) => validateSecondaryLogin(contactMethod, validateCode, formatPhoneNumber)} validateError={!isEmptyObject(validateLoginError) ? validateLoginError : getLatestErrorField(loginData, 'validateCodeSent')} clearError={() => { // When removing unverified contact methods, the ValidateCodeActionForm unmounts and triggers clearError. diff --git a/src/pages/settings/VerifyAccountPageBase.tsx b/src/pages/settings/VerifyAccountPageBase.tsx index f733a5b13ea43..806ef42266700 100644 --- a/src/pages/settings/VerifyAccountPageBase.tsx +++ b/src/pages/settings/VerifyAccountPageBase.tsx @@ -42,9 +42,9 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo, handleClose, const handleSubmitForm = useCallback( (validateCode: string) => { - validateSecondaryLogin(currentUserPersonalDetails, loginList, contactMethod, validateCode, formatPhoneNumber, true); + validateSecondaryLogin(contactMethod, validateCode, formatPhoneNumber, true); }, - [currentUserPersonalDetails, loginList, contactMethod, formatPhoneNumber], + [contactMethod, formatPhoneNumber], ); const handleCloseWithFallback = useCallback(() => {