1
0
Fork 0

fix: back links on error modals

This commit is contained in:
Elias Schneider 2024-02-05 16:13:54 +01:00
parent e572506d4f
commit f52dffdaac
No known key found for this signature in database
GPG Key ID: 07E623B294202B6C
4 changed files with 26 additions and 5 deletions

View File

@ -8,6 +8,7 @@ const showErrorModal = (
modals: ModalsContextProps,
title: string,
text: string,
action: "go-back" | "go-home" = "go-back",
) => {
return modals.openModal({
closeOnClickOutside: false,
@ -15,11 +16,17 @@ const showErrorModal = (
closeOnEscape: false,
title: title,
children: <Body text={text} />,
children: <Body text={text} action={action} />,
});
};
const Body = ({ text }: { text: string }) => {
const Body = ({
text,
action,
}: {
text: string;
action: "go-back" | "go-home";
}) => {
const modals = useModals();
const router = useRouter();
return (
@ -29,10 +36,14 @@ const Body = ({ text }: { text: string }) => {
<Button
onClick={() => {
modals.closeAll();
router.back();
if (action === "go-back") {
router.back();
} else if (action === "go-home") {
router.push("/");
}
}}
>
<FormattedMessage id="common.button.go-back" />
<FormattedMessage id={`common.button.${action}`} />
</Button>
</Stack>
</>

View File

@ -529,6 +529,7 @@ export default {
"common.text.navigate-to-link": "Go to the link",
"common.text.or": "or",
"common.button.go-back": "Go back",
"common.button.go-home": "Go home",
"common.notify.copied": "Your link was copied to the clipboard",
"common.success": "Success",

View File

@ -37,6 +37,7 @@ const Share = ({ shareId }: { shareId: string }) => {
modals,
t("share.error.visitor-limit-exceeded.title"),
t("share.error.visitor-limit-exceeded.description"),
"go-home",
);
} else {
toast.axiosError(e);
@ -58,12 +59,14 @@ const Share = ({ shareId }: { shareId: string }) => {
modals,
t("share.error.removed.title"),
e.response.data.message,
"go-home",
);
} else {
showErrorModal(
modals,
t("share.error.not-found.title"),
t("share.error.not-found.description"),
"go-home",
);
}
} else if (error == "share_password_required") {
@ -71,7 +74,12 @@ const Share = ({ shareId }: { shareId: string }) => {
} else if (error == "share_token_required") {
getShareToken();
} else {
showErrorModal(modals, t("common.error"), t("common.error.unknown"));
showErrorModal(
modals,
t("common.error"),
t("common.error.unknown"),
"go-home",
);
}
});
};

View File

@ -30,6 +30,7 @@ const Share = ({ reverseShareToken }: { reverseShareToken: string }) => {
modals,
"Invalid Link",
"This link is invalid. Please check your link.",
"go-home",
);
setIsLoading(false);
});