Skip to content

Commit

Permalink
fix: fix minor bugs (#323)
Browse files Browse the repository at this point in the history
* fix saving a new tunnel

* fix font

* allow number input

* add messages to error toasts

* rephrase
  • Loading branch information
t-aleksander authored Oct 9, 2024
1 parent 21f2c9c commit 0f95b32
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ const en = {
},
messages: {
error: 'Unexpected error occurred!',
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.',
},
Expand Down
13 changes: 11 additions & 2 deletions src/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,17 @@ 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​:​ ​{​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
*/
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
/**
Expand Down Expand Up @@ -1626,12 +1631,16 @@ export type TranslationFunctions = {
* Unexpected error occurred!
*/
error: () => LocalizedString
/**
* An error occurred: {message}
*/
errorWithMessage: (arg: { message: unknown }) => LocalizedString
/**
* Token has expired, please contact your administrator to issue a new enrollment token
*/
tokenExpired: () => LocalizedString
/**
* There was a network error. Can't reach server."
* There was a network error. Can't reach proxy.
*/
networkError: () => LocalizedString
/**
Expand Down
4 changes: 3 additions & 1 deletion src/pages/client/pages/CarouselPage/cards/CarouselCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ const MoreSection = () => {

return (
<>
<Markdown>{localLL.isMore()}</Markdown>
<div className="more">
<Markdown>{localLL.isMore()}</Markdown>
</div>
<GithubButton />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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);
});
});
Expand All @@ -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,
}),
);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
);
}
}
}
Expand Down Expand Up @@ -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),
}),
);
});
});
}
Expand Down Expand Up @@ -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,
}),
);
}
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,6 +54,7 @@ type FormFields = {
post_down?: string;
};
const defaultValues: FormFields = {
id: null,
name: '',
pubkey: '',
prvkey: '',
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -136,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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
Expand Down Expand Up @@ -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),
}),
);
}
});
});
Expand Down

0 comments on commit 0f95b32

Please sign in to comment.