-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
back button + popups #2707
back button + popups #2707
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useEffect } from "react"; | ||
|
||
import { usePopup } from "../admin/connectors/Popup"; | ||
import { PopupSpec } from "../admin/connectors/Popup"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
interface PopupMessages { | ||
[key: string]: PopupSpec; | ||
} | ||
|
||
export const usePopupFromQuery = (messages: PopupMessages) => { | ||
const router = useRouter(); | ||
const { popup, setPopup } = usePopup(); | ||
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. style: Consider destructuring |
||
|
||
useEffect(() => { | ||
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. logic: The effect has missing dependencies. Add |
||
const searchParams = new URLSearchParams(window.location.search); | ||
// Get the value for search param with key "message" | ||
const messageValue = searchParams.get("message"); | ||
// Check if any key from messages object is present in search params | ||
if (messageValue && messageValue in messages) { | ||
const popupMessage = messages[messageValue]; | ||
router.replace(window.location.pathname); | ||
setPopup(popupMessage); | ||
} | ||
}, []); | ||
|
||
return { popup }; | ||
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. style: The |
||
}; |
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.
logic: This logic may cause unexpected behavior if the URL contains other query parameters