Skip to content

Commit

Permalink
fix: add comment and fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Chakravarthy7102 committed Sep 1, 2023
1 parent 0b1e818 commit e7f2637
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/ui/components/userDetail/userDetailForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,29 +290,27 @@ export const UserDetailChangeEmailForm: FC<UserDetailChangeEmailFormProps> = (
return;
}

let response;

try {
response = await updateUserInformation({
const response = await updateUserInformation({
userId,
email,
recipeId,
tenantId,
});

if (response.status === "INVALID_EMAIL_ERROR") {
setApiError(response.error);
} else if (response.status === "EMAIL_ALREADY_EXISTS_ERROR") {
setApiError("A user with this email already exists");
} else if (response.status === "OK") {
showToast(getUpdateEmailToast(true));
await onEmailChange(true);
}
} catch (error) {
if (ForbiddenError.isThisError(error)) {
void onCancel();
}
}

if (response?.status === "INVALID_EMAIL_ERROR") {
setApiError(response.error);
} else if (response?.status === "EMAIL_ALREADY_EXISTS_ERROR") {
setApiError("A user with this email already exists");
} else if (response?.status === "OK") {
showToast(getUpdateEmailToast(true));
await onEmailChange(true);
}
};

const onCancel = async () => {
Expand Down Expand Up @@ -392,26 +390,24 @@ export const UserDetailChangePasswordForm: FC<UserDetailChangePasswordFormProps>
return;
}

let response;

try {
response = await updatePassword(
const response = await updatePassword(
userId,
password,
matchingTenantIds.length > 0 ? matchingTenantIds[0].tenantId : undefined
);

if (response?.status === "INVALID_PASSWORD_ERROR") {
setApiError(response.error);
} else if (response?.status === "OK") {
showToast(getUpdatePasswordToast(true));
await onPasswordChange();
}
} catch (error) {
if (ForbiddenError.isThisError(error)) {
void onCancel();
}
}

if (response?.status === "INVALID_PASSWORD_ERROR") {
setApiError(response.error);
} else if (response?.status === "OK") {
showToast(getUpdatePasswordToast(true));
await onPasswordChange();
}
};

const onCancel = async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export const useFetchData = () => {
}
window.dispatchEvent(getAccessDeniedEvent(message));

/* throwing this error just to make sure that this case is handled in some places in the application.
global search for ForbiddenError.isThisError to see those places
*/

throw new ForbiddenError(message);
}

Expand Down

0 comments on commit e7f2637

Please sign in to comment.