-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add condition to display back button #356
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,39 @@ 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This raises a warning about a type error for |
||
// Set the current path value by looking at the window object. | ||
storage.setItem("currentPath", window.origin); | ||
} | ||
|
||
useEffect(storePathValues, [router]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not put the code of the function directly into the |
||
|
||
useEffect(() => { | ||
const storage = globalThis?.sessionStorage; | ||
if ( | ||
!storage || | ||
router.query.step !== "donate" || | ||
storage.getItem("showBackButton") === "false" | ||
) | ||
return; | ||
storage.setItem( | ||
"showBackButton", | ||
`${ | ||
storage.getItem("prevPath") === window.origin && | ||
router.query["callback_url"] | ||
}` | ||
); | ||
const isShow = storage.getItem("showBackButton") === "true"; | ||
|
||
setShowBackButton(isShow); | ||
Comment on lines
+172
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be just one line of code. |
||
}, [router.query.step]); | ||
|
||
const goBack = () => { | ||
const callbackUrl = router.query.callback_url; | ||
router.push(`${callbackUrl ? callbackUrl : "/"}`); | ||
|
@@ -165,7 +199,7 @@ function DonationInfo() { | |
alt="Background image with trees" | ||
/> */} | ||
|
||
{isMobile && ( | ||
{isMobile && (router.query["callback_url"] || showBackButton) && ( | ||
<button | ||
id={"backButtonSingleP"} | ||
className={"callbackButton"} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use boolean state as for
isMobile
above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because I if the value if set to false at any point of time, it means that the user came from an external link and so I don't want to display the back button. Setting false initially would prevent me from updating the value and setting true would display the back button. Hence, I've set null as the initial value.