From cd79fb5ee1e9320039e541ad60e8d7aae9525cbc Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Thu, 6 Jun 2024 14:52:55 +0200 Subject: [PATCH] add client support for handling disabled accounts --- .../AddInstanceInitForm.tsx | 2 +- .../components/DesktopSetup/DesktopSetup.tsx | 22 ++++++++++++++++++- src/shared/hooks/api/types.ts | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceInitForm/AddInstanceInitForm.tsx b/src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceInitForm/AddInstanceInitForm.tsx index 369582cb..4de6c833 100644 --- a/src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceInitForm/AddInstanceInitForm.tsx +++ b/src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceInitForm/AddInstanceInitForm.tsx @@ -157,7 +157,7 @@ export const AddInstanceInitForm = ({ nextStep }: Props) => { } // register new instance // is user in need of full enrollment ? - if (r.user.is_active) { + if (r.user.enrolled) { //no, only create new device for desktop client debug('User already active, adding device only.'); nextStep({ diff --git a/src/pages/enrollment/steps/DeviceStep/components/DesktopSetup/DesktopSetup.tsx b/src/pages/enrollment/steps/DeviceStep/components/DesktopSetup/DesktopSetup.tsx index c8f178e2..bc5f880e 100644 --- a/src/pages/enrollment/steps/DeviceStep/components/DesktopSetup/DesktopSetup.tsx +++ b/src/pages/enrollment/steps/DeviceStep/components/DesktopSetup/DesktopSetup.tsx @@ -88,11 +88,31 @@ export const DesktopSetup = () => { const deviceResponse = await createDeviceMutation({ name: values.name, pubkey: publicKey, + }).then((res) => { + if (!res.ok) { + toaster.error(LL.common.messages.error()); + error( + `Failed to create device during the enrollment. Error details: ${JSON.stringify( + res.data, + )} Error status code: ${JSON.stringify(res.status)}`, + ); + throw Error('Failed to create device'); + } + return res; }); mutateUserActivation({ password: userPassword, phone_number: userInfo.phone_number, - }).then(() => { + }).then((res) => { + if (!res.ok) { + toaster.error(LL.common.messages.error()); + error( + `Failed to activate user during the enrollment. Error details: ${JSON.stringify( + res.data, + )} Error status code: ${JSON.stringify(res.status)}`, + ); + throw Error('Failed to activate user'); + } info('User activated'); setIsLoading(true); debug('Invoking save_device_config'); diff --git a/src/shared/hooks/api/types.ts b/src/shared/hooks/api/types.ts index c6e478a1..be2140e0 100644 --- a/src/shared/hooks/api/types.ts +++ b/src/shared/hooks/api/types.ts @@ -18,6 +18,7 @@ export type UserInfo = { is_active: boolean; phone_number: string; device_names: string[]; + enrolled: boolean; }; export type EnrollmentStartRequest = { @@ -83,6 +84,7 @@ export type EnrollmentInitialUserInfo = { email: string; phone_number?: string; is_active: boolean; + enrolled: boolean; }; export type EnrollmentInstanceInfo = {