From f52dffdaac5a893804525913943f3f4f99b7c55a Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Mon, 5 Feb 2024 16:13:54 +0100 Subject: [PATCH] fix: back links on error modals --- .../src/components/share/showErrorModal.tsx | 19 +++++++++++++++---- frontend/src/i18n/translations/en-US.ts | 1 + frontend/src/pages/share/[shareId]/index.tsx | 10 +++++++++- .../src/pages/upload/[reverseShareToken].tsx | 1 + 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/share/showErrorModal.tsx b/frontend/src/components/share/showErrorModal.tsx index 066f71d9..61869184 100644 --- a/frontend/src/components/share/showErrorModal.tsx +++ b/frontend/src/components/share/showErrorModal.tsx @@ -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: , + children: , }); }; -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 }) => { diff --git a/frontend/src/i18n/translations/en-US.ts b/frontend/src/i18n/translations/en-US.ts index 7870fb68..49e915df 100644 --- a/frontend/src/i18n/translations/en-US.ts +++ b/frontend/src/i18n/translations/en-US.ts @@ -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", diff --git a/frontend/src/pages/share/[shareId]/index.tsx b/frontend/src/pages/share/[shareId]/index.tsx index aa335d40..cefe85d7 100644 --- a/frontend/src/pages/share/[shareId]/index.tsx +++ b/frontend/src/pages/share/[shareId]/index.tsx @@ -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", + ); } }); }; diff --git a/frontend/src/pages/upload/[reverseShareToken].tsx b/frontend/src/pages/upload/[reverseShareToken].tsx index 67b301c6..8fe1b897 100644 --- a/frontend/src/pages/upload/[reverseShareToken].tsx +++ b/frontend/src/pages/upload/[reverseShareToken].tsx @@ -30,6 +30,7 @@ const Share = ({ reverseShareToken }: { reverseShareToken: string }) => { modals, "Invalid Link", "This link is invalid. Please check your link.", + "go-home", ); setIsLoading(false); });