Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libs/API/parameters/RequestNewValidateCodeParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type ResendValidateCodeParams from './ResendValidateCodeParams';

type RequestNewValidateCodeParams = {
email?: string;
deviceInfo: string;
};
} & ResendValidateCodeParams;

export default RequestNewValidateCodeParams;
21 changes: 21 additions & 0 deletions src/libs/API/parameters/ResendValidateCodeParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type {CONST} from 'expensify-common';
import type {ValueOf} from 'type-fest';

type ResendValidateCodeBaseParams = {
// Exclude reasons that require parameters - redefine them as separate types below to enforce their parameters are always passed
reasonCode: Exclude<ValueOf<typeof CONST.VALIDATE_CODE_REASONS>, typeof CONST.VALIDATE_CODE_REASONS.REVEAL_CARD_DETAILS>;
};

type ResendValidateCodeForRevealCardDetailsParams = {
reasonCode: typeof CONST.VALIDATE_CODE_REASONS.REVEAL_CARD_DETAILS;
reasonCardID: number;
};

// Will be removed eventually
type ResendValidateCodeNotYetImplementedParams = {
reasonCode: null;
};

type ResendValidateCodeParams = ResendValidateCodeBaseParams | ResendValidateCodeNotYetImplementedParams | ResendValidateCodeForRevealCardDetailsParams;

export default ResendValidateCodeParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ export type {default as UpdateAgentNameParams} from './UpdateAgentNameParams';
export type {default as UpdateAgentPromptParams} from './UpdateAgentPromptParams';
export type {default as UpdateAgentAvatarParams} from './UpdateAgentAvatarParams';
export type {default as DeleteAgentParams} from './DeleteAgentParams';
export type {default as ResendValidateCodeParams} from './ResendValidateCodeParams';
export type {default as SendExportFileFromConciergeParams} from './SendExportFileFromConciergeParams';
export type {default as ClearExportDownloadParams} from './ClearExportDownloadParams';
export type {default as UpgradeSubmitParams} from './UpgradeSubmitParams';
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.UPDATE_PERSONAL_BANK_ACCOUNT_INFO]: Parameters.UpdatePersonalBankAccountInfoParams;
[WRITE_COMMANDS.RESTART_BANK_ACCOUNT_SETUP]: Parameters.RestartBankAccountSetupParams;
[WRITE_COMMANDS.INITIATE_BANK_ACCOUNT_UNLOCK]: Parameters.InitiateBankAccountUnlockParams;
[WRITE_COMMANDS.RESEND_VALIDATE_CODE]: null;
[WRITE_COMMANDS.RESEND_VALIDATE_CODE]: Parameters.ResendValidateCodeParams | null;
[WRITE_COMMANDS.READ_NEWEST_ACTION]: Parameters.ReadNewestActionParams;
[WRITE_COMMANDS.MARK_ALL_MESSAGES_AS_READ]: Parameters.MarkAllMessagesAsReadParams;
[WRITE_COMMANDS.MARK_AS_UNREAD]: Parameters.MarkAsUnreadParams;
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
ReplaceTwoFactorDeviceParams,
RequestNewValidateCodeParams,
RequestUnlinkValidationLinkParams,
ResendValidateCodeParams,
ResetSMSDeliveryFailureStatusParams,
SignInUserWithLinkParams,
SignUpUserParams,
Expand Down Expand Up @@ -528,7 +529,7 @@ function callFunctionIfActionIsAllowed<TCallback extends ((...args: any[]) => an
/**
* Request a new validate / magic code for user to sign in via passwordless flow
*/
function resendValidateCode(login = credentials.login) {
function resendValidateCode(reasonParams: ResendValidateCodeParams, login = credentials.login) {
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.ACCOUNT>> = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -550,7 +551,7 @@ function resendValidateCode(login = credentials.login) {
];

Device.getDeviceInfoWithID().then((deviceInfo) => {
const params: RequestNewValidateCodeParams = {email: login, deviceInfo};
const params: RequestNewValidateCodeParams = {email: login, deviceInfo, ...reasonParams};
API.write(WRITE_COMMANDS.REQUEST_NEW_VALIDATE_CODE, params, {optimisticData, finallyData});
});
}
Expand Down
9 changes: 5 additions & 4 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
GetStatementPDFParams,
PusherPingParams,
RequestContactMethodValidateCodeParams,
ResendValidateCodeParams,
RevokeDeviceParams,
SetContactMethodAsDefaultParams,
SetNameValuePairParams,
Expand Down Expand Up @@ -204,8 +205,8 @@ function closeAccount(reason: string) {
/**
* Resend a validation link to a given login
*/
function resendValidateCode(login: string) {
sessionResendValidateCode(login);
function resendValidateCode(reasonParams: ResendValidateCodeParams, login: string) {
sessionResendValidateCode(reasonParams, login);
}

/**
Expand Down Expand Up @@ -514,7 +515,7 @@ function addNewContactMethod(contactMethod: string, validateCode = '') {
/**
* Requests a magic code to verify current user
*/
function requestValidateCodeAction() {
function requestValidateCodeAction(params?: ResendValidateCodeParams) {
const requestedAt = Date.now();
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.VALIDATE_ACTION_CODE>> = [
{
Expand Down Expand Up @@ -566,7 +567,7 @@ function requestValidateCodeAction() {
},
];

API.write(WRITE_COMMANDS.RESEND_VALIDATE_CODE, null, {optimisticData, successData, failureData});
API.write(WRITE_COMMANDS.RESEND_VALIDATE_CODE, params ?? null, {optimisticData, successData, failureData});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import SCREENS from '@src/SCREENS';

import {CONST as COMMON_CONST} from 'expensify-common';
import React, {useCallback, useEffect, useState} from 'react';
import {View} from 'react-native';

Expand Down Expand Up @@ -65,7 +66,7 @@ function BaseOnboardingPrivateDomain({shouldUseNativeStyles, route}: BaseOnboard
if (!email) {
return;
}
resendValidateCode(email);
resendValidateCode({reasonCode: COMMON_CONST.VALIDATE_CODE_REASONS.VALIDATE_ACCOUNT}, email);
}, [email]);

const handleBackButtonPress = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function BaseOnboardingWorkEmailValidation({shouldUseNativeStyles}: BaseOnboardi
if (!credentials?.login) {
return;
}
resendValidateCode(credentials.login);
resendValidateCode({reasonCode: null}, credentials.login);
};

const validateAccountAndMerge = (validateCode: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';

import {CONST as COMMON_CONST} from 'expensify-common';
import React, {useEffect} from 'react';

type NewContactMethodConfirmMagicCodePageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.PROFILE.NEW_CONTACT_METHOD_CONFIRM_MAGIC_CODE>;
Expand All @@ -37,7 +38,7 @@ function NewContactMethodConfirmMagicCodePage({route}: NewContactMethodConfirmMa
return (
<ValidateCodeActionContent
title={translate('delegate.makeSureItIsYou')}
sendValidateCode={() => requestValidateCodeAction()}
sendValidateCode={() => requestValidateCodeAction({reasonCode: COMMON_CONST.VALIDATE_CODE_REASONS.ADD_CONTACT_METHOD})}
descriptionPrimary={translate('contacts.enterMagicCode', contactMethod)}
validateCodeActionErrorField="addedLogin"
validateError={validateCodeError}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/settings/VerifyAccountPageBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

import {CONST as COMMON_CONST} from 'expensify-common';
import React, {useCallback, useEffect} from 'react';
import {View} from 'react-native';

Expand Down Expand Up @@ -48,6 +49,8 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo, handleClose,

useEffect(() => () => clearUnvalidatedNewContactMethodAction(), []);

const sendValidateCode = () => requestValidateCodeAction({reasonCode: COMMON_CONST.VALIDATE_CODE_REASONS.VALIDATE_ACCOUNT});

const handleSubmitForm = useCallback(
(validateCode: string) => {
validateSecondaryLogin(contactMethod, validateCode);
Expand Down Expand Up @@ -104,7 +107,7 @@ function VerifyAccountPageBase({navigateBackTo, navigateForwardTo, handleClose,
title={translate('contacts.validateAccount')}
descriptionPrimary={translate('contacts.featureRequiresValidate')}
descriptionSecondary={translate('contacts.enterMagicCode', contactMethod)}
sendValidateCode={requestValidateCodeAction}
sendValidateCode={sendValidateCode}
validateCodeActionErrorField="validateLogin"
validatePendingAction={loginData?.pendingFields?.validateCodeSent}
handleSubmitForm={handleSubmitForm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {Errors} from '@src/types/onyx/OnyxCommon';

import {CONST as COMMON_CONST} from 'expensify-common';
import React, {useState} from 'react';

type ExpensifyCardVerifyAccountPageProps =
Expand Down Expand Up @@ -68,7 +69,7 @@ function ExpensifyCardVerifyAccountPage({route}: ExpensifyCardVerifyAccountPageP
<ValidateCodeActionContent
title={translate('cardPage.validateCardTitle')}
descriptionPrimary={translate('cardPage.enterMagicCode', primaryLogin)}
sendValidateCode={() => requestValidateCodeAction()}
sendValidateCode={() => requestValidateCodeAction({reasonCode: COMMON_CONST.VALIDATE_CODE_REASONS.REVEAL_CARD_DETAILS, reasonCardID: Number.parseInt(cardID, 10)})}
validateCodeActionErrorField="revealExpensifyCardDetails"
handleSubmitForm={handleRevealCardDetails}
validateError={validateError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';

import {CONST} from 'expensify-common';
import React, {useCallback} from 'react';

import {useTravelCVVActions, useTravelCVVState} from './TravelCVVContextProvider';
Expand Down Expand Up @@ -56,11 +57,15 @@ function TravelCVVVerifyAccountPage() {
});
};

if (!travelCard) {
return null;
}

return (
<ValidateCodeActionContent
title={translate('cardPage.validateCardTitle')}
descriptionPrimary={translate('cardPage.enterMagicCode', primaryLogin ?? '')}
sendValidateCode={() => requestValidateCodeAction()}
sendValidateCode={() => requestValidateCodeAction({reasonCode: CONST.VALIDATE_CODE_REASONS.REVEAL_CARD_DETAILS, reasonCardID: travelCard.cardID})}
validateCodeActionErrorField="revealExpensifyCardDetails"
handleSubmitForm={handleRevealCardDetails}
validateError={validateError}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/signin/ChooseSSOOrMagicCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

import {CONST as COMMON_CONST} from 'expensify-common';
import React, {useEffect} from 'react';
import {Keyboard, View} from 'react-native';

Expand Down Expand Up @@ -77,7 +78,7 @@ function ChooseSSOOrMagicCode({setIsUsingMagicCode}: ChooseSSOOrMagicCodeProps)
text={translate('samlSignIn.useMagicCode')}
isLoading={account?.isLoading && account?.loadingForm === (account?.requiresTwoFactorAuth ? CONST.FORMS.VALIDATE_TFA_CODE_FORM : CONST.FORMS.VALIDATE_CODE_FORM)}
onPress={() => {
resendValidateCode(credentials?.login);
resendValidateCode({reasonCode: COMMON_CONST.VALIDATE_CODE_REASONS.SIGN_IN}, credentials?.login);
setIsUsingMagicCode(true);
}}
sentryLabel={CONST.SENTRY_LABEL.SIGN_IN.MAGIC_CODE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

import {useIsFocused} from '@react-navigation/native';
import {CONST as COMMON_CONST} from 'expensify-common';
import React, {useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
import {View} from 'react-native';

Expand Down Expand Up @@ -158,7 +159,7 @@ function BaseValidateCodeForm({autoComplete, isUsingRecoveryCode, setIsUsingReco
* Trigger the reset validate code flow and ensure the 2FA input field is reset to avoid it being permanently hidden
*/
const resendValidateCode = () => {
userActionsResendValidateCode(credentials?.login ?? '');
userActionsResendValidateCode({reasonCode: COMMON_CONST.VALIDATE_CODE_REASONS.SIGN_IN}, credentials?.login ?? '');
inputValidateCodeRef.current?.clear();
// Give feedback to the user to let them know the email was sent so that they don't spam the button.
countdownRef.current?.resetCountdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function WorkspaceVerifyWorkAccountPageContent({route}: WorkspaceVerifyWorkAccou
if (!workEmail) {
return;
}
resendValidateCode(workEmail);
resendValidateCode({reasonCode: null}, workEmail);
};

const validateAccountAndMerge = (validateCode: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function WorkspaceExpensifyCardVerifyWorkAccountPageContent({route}: WorkspaceEx
if (!workEmail) {
return;
}
resendValidateCode(workEmail);
resendValidateCode({reasonCode: null}, workEmail);
};

const validateAccountAndMerge = (validateCode: string) => {
Expand Down
Loading