From eddef971099a7e5f8d168be43006b3715c2799b4 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:10:19 +0200 Subject: [PATCH 1/5] fix saving a new tunnel --- .../components/AddTunnelFormCard/AddTunnelFormCard.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/client/pages/ClientAddTunnelPage/components/AddTunnelFormCard/AddTunnelFormCard.tsx b/src/pages/client/pages/ClientAddTunnelPage/components/AddTunnelFormCard/AddTunnelFormCard.tsx index 7f7c742d..42e03a4e 100644 --- a/src/pages/client/pages/ClientAddTunnelPage/components/AddTunnelFormCard/AddTunnelFormCard.tsx +++ b/src/pages/client/pages/ClientAddTunnelPage/components/AddTunnelFormCard/AddTunnelFormCard.tsx @@ -36,6 +36,7 @@ import { validateIpOrDomainList } from '../../../../../../shared/validators/tunn import { clientApi } from '../../../../clientAPI/clientApi'; type FormFields = { + id: null; name: string; pubkey: string; prvkey: string; @@ -53,6 +54,7 @@ type FormFields = { post_down?: string; }; const defaultValues: FormFields = { + id: null, name: '', pubkey: '', prvkey: '', @@ -81,6 +83,7 @@ export const AddTunnelFormCard = () => { const schema = useMemo( () => z.object({ + id: z.null(), name: z.string().trim().min(1, LL.form.errors.required()), pubkey: z .string() From 4e5f29fee9d24426b1c6e66ed1db5852b1add836 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:21:03 +0200 Subject: [PATCH 2/5] fix font --- src/pages/client/pages/CarouselPage/cards/CarouselCards.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/client/pages/CarouselPage/cards/CarouselCards.tsx b/src/pages/client/pages/CarouselPage/cards/CarouselCards.tsx index 5a899736..6f0968d2 100644 --- a/src/pages/client/pages/CarouselPage/cards/CarouselCards.tsx +++ b/src/pages/client/pages/CarouselPage/cards/CarouselCards.tsx @@ -100,7 +100,9 @@ const MoreSection = () => { return ( <> - {localLL.isMore()} +
+ {localLL.isMore()} +
); From 778c84dd8b4d959eb3b3280b5426ffdcec67576b Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:23:15 +0200 Subject: [PATCH 3/5] allow number input --- .../components/AddTunnelFormCard/AddTunnelFormCard.tsx | 2 +- .../ClientEditTunnelPage/components/EditTunnelFormCard.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/client/pages/ClientAddTunnelPage/components/AddTunnelFormCard/AddTunnelFormCard.tsx b/src/pages/client/pages/ClientAddTunnelPage/components/AddTunnelFormCard/AddTunnelFormCard.tsx index 42e03a4e..9ebc0db7 100644 --- a/src/pages/client/pages/ClientAddTunnelPage/components/AddTunnelFormCard/AddTunnelFormCard.tsx +++ b/src/pages/client/pages/ClientAddTunnelPage/components/AddTunnelFormCard/AddTunnelFormCard.tsx @@ -139,7 +139,7 @@ export const AddTunnelFormCard = () => { } return true; }, LL.form.errors.invalid()), - persistent_keep_alive: z.number(), + persistent_keep_alive: z.coerce.number(), route_all_traffic: z.boolean(), pre_up: z.string().nullable(), post_up: z.string().nullable(), diff --git a/src/pages/client/pages/ClientEditTunnelPage/components/EditTunnelFormCard.tsx b/src/pages/client/pages/ClientEditTunnelPage/components/EditTunnelFormCard.tsx index 036bbd00..8b53fa0c 100644 --- a/src/pages/client/pages/ClientEditTunnelPage/components/EditTunnelFormCard.tsx +++ b/src/pages/client/pages/ClientEditTunnelPage/components/EditTunnelFormCard.tsx @@ -175,7 +175,7 @@ export const EditTunnelFormCard = ({ tunnel, submitRef }: Props) => { } return true; }, LL.form.errors.invalid()), - persistent_keep_alive: z.number(), + persistent_keep_alive: z.coerce.number(), route_all_traffic: z.boolean(), pre_up: z.string().nullable(), post_up: z.string().nullable(), From 052e5c1d86311b31de2f6c59c5aff4fb0ff88816 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:09:53 +0200 Subject: [PATCH 4/5] add messages to error toasts --- src/i18n/en/index.ts | 1 + src/i18n/i18n-types.ts | 9 +++++++ .../AddInstanceDeviceForm.tsx | 22 +++++++++++---- .../AddInstanceInitForm.tsx | 27 +++++++++++++++---- .../DeleteTunnelModal/DeleteTunnelModal.tsx | 6 ++++- .../LocationCardConnectButton.tsx | 6 ++++- .../DeleteInstanceModal.tsx | 6 ++++- .../components/UpdateInstanceModalForm.tsx | 6 ++++- .../components/DesktopSetup/DesktopSetup.tsx | 14 +++++++--- 9 files changed, 80 insertions(+), 17 deletions(-) diff --git a/src/i18n/en/index.ts b/src/i18n/en/index.ts index 05aca774..e8db53f8 100644 --- a/src/i18n/en/index.ts +++ b/src/i18n/en/index.ts @@ -42,6 +42,7 @@ const en = { }, messages: { error: 'Unexpected error occurred!', + errorWithMessage: 'An error occurred, details: {message}', tokenExpired: 'Token has expired, please contact your administrator to issue a new enrollment token', networkError: 'There was a network error. Can\'t reach server."', diff --git a/src/i18n/i18n-types.ts b/src/i18n/i18n-types.ts index c84c882a..3b1c19bb 100644 --- a/src/i18n/i18n-types.ts +++ b/src/i18n/i18n-types.ts @@ -123,6 +123,11 @@ type RootTranslation = { * U​n​e​x​p​e​c​t​e​d​ ​e​r​r​o​r​ ​o​c​c​u​r​r​e​d​! */ error: string + /** + * A​n​ ​e​r​r​o​r​ ​o​c​c​u​r​r​e​d​,​ ​d​e​t​a​i​l​s​:​ ​{​m​e​s​s​a​g​e​} + * @param {unknown} message + */ + errorWithMessage: RequiredParams<'message'> /** * T​o​k​e​n​ ​h​a​s​ ​e​x​p​i​r​e​d​,​ ​p​l​e​a​s​e​ ​c​o​n​t​a​c​t​ ​y​o​u​r​ ​a​d​m​i​n​i​s​t​r​a​t​o​r​ ​t​o​ ​i​s​s​u​e​ ​a​ ​n​e​w​ ​e​n​r​o​l​l​m​e​n​t​ ​t​o​k​e​n */ @@ -1626,6 +1631,10 @@ export type TranslationFunctions = { * Unexpected error occurred! */ error: () => LocalizedString + /** + * An error occurred, details: {message} + */ + errorWithMessage: (arg: { message: unknown }) => LocalizedString /** * Token has expired, please contact your administrator to issue a new enrollment token */ diff --git a/src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceDeviceForm/AddInstanceDeviceForm.tsx b/src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceDeviceForm/AddInstanceDeviceForm.tsx index 9e854dd7..950f49f1 100644 --- a/src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceDeviceForm/AddInstanceDeviceForm.tsx +++ b/src/pages/client/pages/ClientAddInstancePage/components/AddInstanceFormCard/components/AddInstanceDeviceForm/AddInstanceDeviceForm.tsx @@ -101,7 +101,7 @@ export const AddInstanceDeviceForm = ({ response }: Props) => { (r.data as ErrorData)?.error ? (r.data as ErrorData).error + ', ' : '' }`; error( - `Failed to create device check enrollment and defguard logs, details: ${details}Error status code: ${r.status}`, + `Failed to create device check enrollment and defguard logs, details: ${details} Error status code: ${r.status}`, ); throw Error(`Failed to create device, details: ${details}`); } @@ -128,8 +128,12 @@ export const AddInstanceDeviceForm = ({ response }: Props) => { }); navigate(routes.client.instancePage, { replace: true }); }) - .catch(() => { - toaster.error(LL.common.messages.error()); + .catch((e) => { + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); setIsLoading(false); }); }); @@ -142,9 +146,17 @@ export const AddInstanceDeviceForm = ({ response }: Props) => { toaster.error(LL.common.messages.networkError()); return; } - toaster.error(LL.common.messages.error()); + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); } else { - toaster.error((e as Error).message); + toaster.error( + LL.common.messages.errorWithMessage({ + message: (e as Error).message, + }), + ); } } }; 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 ba5a4c08..e54dc2e6 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 @@ -109,13 +109,18 @@ export const AddInstanceInitForm = ({ nextStep }: Props) => { setIsLoading(false); error(JSON.stringify(res.data)); error(JSON.stringify(res.status)); + const errorMessage = (res.data as EnrollmentError).error; - switch ((res.data as EnrollmentError).error) { + switch (errorMessage) { case 'token expired': { throw Error(LL.common.messages.tokenExpired()); } default: { - throw Error(LL.common.messages.error()); + throw Error( + LL.common.messages.errorWithMessage({ + message: errorMessage, + }), + ); } } } @@ -166,7 +171,11 @@ export const AddInstanceInitForm = ({ nextStep }: Props) => { }) .catch((e) => { error(e); - toaster.error(LL.common.messages.error()); + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); }); }); } @@ -204,9 +213,17 @@ export const AddInstanceInitForm = ({ nextStep }: Props) => { toaster.error(LL.common.messages.networkError()); return; } - toaster.error(LL.common.messages.error()); + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); } else { - toaster.error((e as Error).message); + toaster.error( + LL.common.messages.errorWithMessage({ + message: (e as Error).message, + }), + ); } }); }; diff --git a/src/pages/client/pages/ClientEditTunnelPage/modals/DeleteTunnelModal/DeleteTunnelModal.tsx b/src/pages/client/pages/ClientEditTunnelPage/modals/DeleteTunnelModal/DeleteTunnelModal.tsx index dda20902..228e521d 100644 --- a/src/pages/client/pages/ClientEditTunnelPage/modals/DeleteTunnelModal/DeleteTunnelModal.tsx +++ b/src/pages/client/pages/ClientEditTunnelPage/modals/DeleteTunnelModal/DeleteTunnelModal.tsx @@ -54,7 +54,11 @@ export const DeleteTunnelModal = () => { navigate(routes.client.base, { replace: true }); }, onError: (e) => { - toaster.error(localLL.messages.error()); + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); console.error(e); }, }); diff --git a/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardConnectButton/LocationCardConnectButton.tsx b/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardConnectButton/LocationCardConnectButton.tsx index 3c9e214f..cd0a8b91 100644 --- a/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardConnectButton/LocationCardConnectButton.tsx +++ b/src/pages/client/pages/ClientInstancePage/components/LocationsList/components/LocationCardConnectButton/LocationCardConnectButton.tsx @@ -61,7 +61,11 @@ export const LocationCardConnectButton = ({ location }: Props) => { } } catch (e) { setIsLoading(false); - toaster.error(LL.common.messages.error()); + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); error(`Error handling interface: ${e}`); console.error(e); } diff --git a/src/pages/client/pages/ClientInstancePage/modals/DeleteInstanceModal/DeleteInstanceModal.tsx b/src/pages/client/pages/ClientInstancePage/modals/DeleteInstanceModal/DeleteInstanceModal.tsx index 522bd101..dbedf1fa 100644 --- a/src/pages/client/pages/ClientInstancePage/modals/DeleteInstanceModal/DeleteInstanceModal.tsx +++ b/src/pages/client/pages/ClientInstancePage/modals/DeleteInstanceModal/DeleteInstanceModal.tsx @@ -51,7 +51,11 @@ export const DeleteInstanceModal = () => { }); }, onError: (e) => { - toaster.error(localLL.messages.error()); + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); console.error(e); }, }); diff --git a/src/pages/client/pages/ClientInstancePage/modals/UpdateInstanceModal/components/UpdateInstanceModalForm.tsx b/src/pages/client/pages/ClientInstancePage/modals/UpdateInstanceModal/components/UpdateInstanceModalForm.tsx index b3388475..e0e143ae 100644 --- a/src/pages/client/pages/ClientInstancePage/modals/UpdateInstanceModal/components/UpdateInstanceModalForm.tsx +++ b/src/pages/client/pages/ClientInstancePage/modals/UpdateInstanceModal/components/UpdateInstanceModalForm.tsx @@ -157,7 +157,11 @@ export const UpdateInstanceModalForm = () => { } } else { // Token or URL is invalid. - toaster.error(localLL.messages.error()); + toaster.error( + LL.common.messages.errorWithMessage({ + message: 'Token or URL is invalid', + }), + ); setError( 'token', { diff --git a/src/pages/enrollment/steps/DeviceStep/components/DesktopSetup/DesktopSetup.tsx b/src/pages/enrollment/steps/DeviceStep/components/DesktopSetup/DesktopSetup.tsx index 3cf9a31c..7d80154a 100644 --- a/src/pages/enrollment/steps/DeviceStep/components/DesktopSetup/DesktopSetup.tsx +++ b/src/pages/enrollment/steps/DeviceStep/components/DesktopSetup/DesktopSetup.tsx @@ -51,7 +51,11 @@ export const DesktopSetup = () => { { mutationFn: activateUser, onError: (e) => { - toaster.error(LL.common.messages.error()); + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); console.error(e); error(String(e)); }, @@ -138,9 +142,13 @@ export const DesktopSetup = () => { toaster.error(LL.common.messages.networkError()); return; } - toaster.error(LL.common.messages.error()); + toaster.error(LL.common.messages.errorWithMessage({ message: String(e) })); } else { - toaster.error((e as Error).message); + toaster.error( + LL.common.messages.errorWithMessage({ + message: String(e), + }), + ); } }); }); From 1d4b56900e9862dd7e4a7b07ae360aba8cf95420 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:56:40 +0200 Subject: [PATCH 5/5] rephrase --- src/i18n/en/index.ts | 4 ++-- src/i18n/i18n-types.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/i18n/en/index.ts b/src/i18n/en/index.ts index e8db53f8..b5f305e0 100644 --- a/src/i18n/en/index.ts +++ b/src/i18n/en/index.ts @@ -42,10 +42,10 @@ const en = { }, messages: { error: 'Unexpected error occurred!', - errorWithMessage: 'An error occurred, details: {message}', + errorWithMessage: 'An error occurred: {message}', tokenExpired: 'Token has expired, please contact your administrator to issue a new enrollment token', - networkError: 'There was a network error. Can\'t reach server."', + networkError: "There was a network error. Can't reach proxy.", configChanged: 'Confguration for instance {instance: string} has changed. Disconnect from all locations to apply changes.', }, diff --git a/src/i18n/i18n-types.ts b/src/i18n/i18n-types.ts index 3b1c19bb..67248acd 100644 --- a/src/i18n/i18n-types.ts +++ b/src/i18n/i18n-types.ts @@ -124,7 +124,7 @@ type RootTranslation = { */ error: string /** - * A​n​ ​e​r​r​o​r​ ​o​c​c​u​r​r​e​d​,​ ​d​e​t​a​i​l​s​:​ ​{​m​e​s​s​a​g​e​} + * A​n​ ​e​r​r​o​r​ ​o​c​c​u​r​r​e​d​:​ ​{​m​e​s​s​a​g​e​} * @param {unknown} message */ errorWithMessage: RequiredParams<'message'> @@ -133,7 +133,7 @@ type RootTranslation = { */ tokenExpired: string /** - * T​h​e​r​e​ ​w​a​s​ ​a​ ​n​e​t​w​o​r​k​ ​e​r​r​o​r​.​ ​C​a​n​'​t​ ​r​e​a​c​h​ ​s​e​r​v​e​r​.​" + * T​h​e​r​e​ ​w​a​s​ ​a​ ​n​e​t​w​o​r​k​ ​e​r​r​o​r​.​ ​C​a​n​'​t​ ​r​e​a​c​h​ ​p​r​o​x​y​. */ networkError: string /** @@ -1632,7 +1632,7 @@ export type TranslationFunctions = { */ error: () => LocalizedString /** - * An error occurred, details: {message} + * An error occurred: {message} */ errorWithMessage: (arg: { message: unknown }) => LocalizedString /** @@ -1640,7 +1640,7 @@ export type TranslationFunctions = { */ tokenExpired: () => LocalizedString /** - * There was a network error. Can't reach server." + * There was a network error. Can't reach proxy. */ networkError: () => LocalizedString /**