-
Notifications
You must be signed in to change notification settings - Fork 4
86b82fa34 - feat: add url fragment linking to tabs on edit sponsor page #751
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
base: master
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 |
|---|---|---|
|
|
@@ -43,6 +43,26 @@ import SponsorUsersListPerSponsorPage from "./sponsor-users-list-per-sponsor"; | |
| import SponsorFormsTab from "./sponsor-forms-tab"; | ||
| import SponsorBadgeScans from "./sponsor-badge-scans"; | ||
|
|
||
| const tabsToFragmentMap = [ | ||
| "general", | ||
| "users", | ||
| "pages", | ||
| "media_uploads", | ||
| "forms", | ||
| "cart", | ||
| "purchases", | ||
| "badge_scans" | ||
| ]; | ||
|
|
||
| const getFragmentFromValue = (index) => tabsToFragmentMap[index]; | ||
|
|
||
| const getTabFromUrlFragment = () => { | ||
| const result = tabsToFragmentMap.indexOf( | ||
| window.location.hash.replace("#", "") | ||
| ); | ||
| return result > -1 ? result : 0; | ||
| }; | ||
|
|
||
| const CustomTabPanel = (props) => { | ||
| const { children, value, index, ...other } = props; | ||
|
|
||
|
|
@@ -91,10 +111,15 @@ const EditSponsorPage = (props) => { | |
| getExtraQuestionMeta | ||
| } = props; | ||
|
|
||
| const [selectedTab, setSelectedTab] = useState(0); | ||
| const [selectedTab, setSelectedTab] = useState(getTabFromUrlFragment()); | ||
|
|
||
| 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. @niko-exo To support SPA-style hash navigation (manual hash edits, back/forward), please replace that effect with a hashchange listener |
||
| setSelectedTab(getTabFromUrlFragment()); | ||
| }, [window.location.hash]); | ||
|
|
||
| const handleTabChange = (event, newValue) => { | ||
| setSelectedTab(newValue); | ||
| window.location.hash = getFragmentFromValue(newValue); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
|
|
@@ -127,7 +152,7 @@ const EditSponsorPage = (props) => { | |
|
|
||
| return ( | ||
| <Box> | ||
| <Container maxWidth="lg" sx={{position: "relative"}}> | ||
| <Container maxWidth="lg" sx={{ position: "relative" }}> | ||
| <Typography fontSize="3.4rem" variant="h4"> | ||
| {entity.company?.name} | ||
| </Typography> | ||
|
|
||
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.
on the initial load
general tab should be selected hence #general should be show by default