mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-15 01:14:27 -05:00
fix: back links on error modals
This commit is contained in:
parent
e572506d4f
commit
f52dffdaac
4 changed files with 26 additions and 5 deletions
|
@ -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>
|
||||
</>
|
||||
|
|
|
@ -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",
|
||||
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@ const Share = ({ reverseShareToken }: { reverseShareToken: string }) => {
|
|||
modals,
|
||||
"Invalid Link",
|
||||
"This link is invalid. Please check your link.",
|
||||
"go-home",
|
||||
);
|
||||
setIsLoading(false);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue