From c4787dae9e3f4d3b7396609c804455c4235c9dcb Mon Sep 17 00:00:00 2001 From: prachigarg19 <72646230+prachigarg19@users.noreply.github.com> Date: Thu, 22 Dec 2022 11:43:27 +0530 Subject: [PATCH 1/2] add condition for display of back button --- src/Donations/index.tsx | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index 67cc0ce6..32d2847b 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -103,6 +103,7 @@ function DonationInfo() { } = React.useContext(QueryParamContext); const [isMobile, setIsMobile] = React.useState(false); + const [showBackButton, setShowBackButton] = React.useState(null); React.useEffect(() => { if (typeof window !== "undefined") { if (window.innerWidth > 767) { @@ -140,6 +141,36 @@ function DonationInfo() { ); }; const router = useRouter(); + + function storePathValues() { + const storage = globalThis?.sessionStorage; + if (!storage) return; + // Set the previous path as the value of the current path. + const prevPath = storage.getItem("currentPath"); + storage.setItem("prevPath", prevPath); + // Set the current path value by looking at the window object. + storage.setItem("currentPath", window.origin); + } + + useEffect(storePathValues, [router]); + + useEffect(() => { + const storage = globalThis?.sessionStorage; + if ( + !storage || + router.query.step !== "donate" || + storage.getItem("showBackButton") === "false" + ) + return; + storage.setItem( + "showBackButton", + `${storage.getItem("prevPath") === window.origin}` + ); + const isShow = storage.getItem("showBackButton") === "true"; + + setShowBackButton(isShow); + }, [router.query.step]); + const goBack = () => { const callbackUrl = router.query.callback_url; router.push(`${callbackUrl ? callbackUrl : "/"}`); @@ -165,7 +196,7 @@ function DonationInfo() { alt="Background image with trees" /> */} - {isMobile && ( + {isMobile && (router.query["callback_url"] || showBackButton) && (