Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/pages/sponsors/edit-sponsor-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link

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

 if (result > -1) return result;

  if (window.location.hash) window.location.hash = "general";
  return 0
```;

};

const CustomTabPanel = (props) => {
const { children, value, index, ...other } = props;

Expand Down Expand Up @@ -91,10 +111,15 @@ const EditSponsorPage = (props) => {
getExtraQuestionMeta
} = props;

const [selectedTab, setSelectedTab] = useState(0);
const [selectedTab, setSelectedTab] = useState(getTabFromUrlFragment());

useEffect(() => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niko-exo
rite now the tab selection only updates from the URL hash on initial page load. The effect useEffect(..., [window.location.hash]) won’t reliably fire on hash updates because changing window.location.hash doesn’t trigger a React re-render.

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(() => {
Expand Down Expand Up @@ -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>
Expand Down