Skip to content

Commit eb8fb22

Browse files
committed
show specific error for closed work account in AddWorkEmail
1 parent 394868a commit eb8fb22

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/libs/actions/Session/index.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ const canAnonymousUserAccessRoute = (route: string) => {
14601460
};
14611461

14621462
function AddWorkEmail(workEmail: string) {
1463-
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM>> = [
1463+
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM | typeof ONYXKEYS.ONBOARDING_ERROR_MESSAGE_TRANSLATION_KEY>> = [
14641464
{
14651465
onyxMethod: Onyx.METHOD.MERGE,
14661466
key: ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM,
@@ -1469,6 +1469,11 @@ function AddWorkEmail(workEmail: string) {
14691469
isLoading: true,
14701470
},
14711471
},
1472+
{
1473+
onyxMethod: Onyx.METHOD.MERGE,
1474+
key: ONYXKEYS.ONBOARDING_ERROR_MESSAGE_TRANSLATION_KEY,
1475+
value: null,
1476+
},
14721477
];
14731478

14741479
const successData: Array<OnyxUpdate<typeof ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM>> = [
@@ -1498,15 +1503,24 @@ function AddWorkEmail(workEmail: string) {
14981503
},
14991504
];
15001505

1501-
API.write(
1502-
WRITE_COMMANDS.ADD_WORK_EMAIL,
1506+
// We need to inspect the response to detect the closed-account error and surface a specific translation key, which API.write cannot do.
1507+
// eslint-disable-next-line rulesdir/no-api-side-effects-method
1508+
API.makeRequestWithSideEffects(
1509+
SIDE_EFFECT_REQUEST_COMMANDS.ADD_WORK_EMAIL,
15031510
{workEmail},
15041511
{
15051512
optimisticData,
15061513
successData,
15071514
failureData,
15081515
},
1509-
);
1516+
).then((response) => {
1517+
if (response?.jsonCode !== CONST.JSON_CODE.EXP_ERROR) {
1518+
return;
1519+
}
1520+
if (response?.message === CONST.WORK_ACCOUNT_CLOSED_ERROR || response?.title === CONST.WORK_ACCOUNT_CLOSED_ERROR) {
1521+
Onyx.merge(ONYXKEYS.ONBOARDING_ERROR_MESSAGE_TRANSLATION_KEY, 'onboarding.mergeBlockScreen.workAccountClosedSubtitle');
1522+
}
1523+
});
15101524
}
15111525

15121526
function MergeIntoAccountAndLogin(workEmail: string | undefined, validateCode: string, accountID: number | undefined) {

0 commit comments

Comments
 (0)