0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-01-29 01:28:59 -05:00

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

View file

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

View file

@ -37,6 +37,7 @@ const Share = ({ shareId }: { shareId: string }) => {
modals, modals,
t("share.error.visitor-limit-exceeded.title"), t("share.error.visitor-limit-exceeded.title"),
t("share.error.visitor-limit-exceeded.description"), t("share.error.visitor-limit-exceeded.description"),
"go-home",
); );
} else { } else {
toast.axiosError(e); toast.axiosError(e);
@ -58,12 +59,14 @@ const Share = ({ shareId }: { shareId: string }) => {
modals, modals,
t("share.error.removed.title"), t("share.error.removed.title"),
e.response.data.message, e.response.data.message,
"go-home",
); );
} else { } else {
showErrorModal( showErrorModal(
modals, modals,
t("share.error.not-found.title"), t("share.error.not-found.title"),
t("share.error.not-found.description"), t("share.error.not-found.description"),
"go-home",
); );
} }
} else if (error == "share_password_required") { } else if (error == "share_password_required") {
@ -71,7 +74,12 @@ const Share = ({ shareId }: { shareId: string }) => {
} else if (error == "share_token_required") { } else if (error == "share_token_required") {
getShareToken(); getShareToken();
} else { } 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, modals,
"Invalid Link", "Invalid Link",
"This link is invalid. Please check your link.", "This link is invalid. Please check your link.",
"go-home",
); );
setIsLoading(false); setIsLoading(false);
}); });