Skip to content

Commit

Permalink
add functionality for active-tab statistical route
Browse files Browse the repository at this point in the history
  • Loading branch information
zuies committed Feb 12, 2024
1 parent e521dcf commit 09a0b4d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Binary file added src/components/global/.CustomTab.tsx.swp
Binary file not shown.
40 changes: 38 additions & 2 deletions src/pages/statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@ import { useToken } from '../context/TokenContext';
import EmptyState from '../components/global/EmptyState';
import emptyState from '../assets/svg/empty-state.svg';
import Image from 'next/image';
import { useRouter } from 'next/router';

const Statistics = () => {
const { community } = useToken();
const router = useRouter();

const platformId = community?.platforms.find(
(platform) => platform.disconnectedAt === null
)?.id;

const tabMap: { [key: string]: string } = {
activeMembers: '1',
disengagedMembers: '2',
};

const reverseTabMap: { [key: string]: string } = {
'1': 'activeMembers',
'2': 'disengagedMembers',
};

const [loading, setLoading] = useState<boolean>(true);
const [activeMemberDate, setActiveMemberDate] = useState(1);
const [onBoardingMemberDate, setOnBoardingMemberDate] = useState(1);
Expand All @@ -40,13 +53,36 @@ const Statistics = () => {
fetchOnboardingMembers,
} = useAppStore();

const [activeTab, setActiveTab] = useState('1');
const [activeTab, setActiveTab] = useState<string>(
tabMap[router.query.tab as string] || '1'
);

useEffect(() => {
if (!router.isReady) return;

const handleRouteChange = () => {
setActiveTab(tabMap[router.query.tab as string] || '1');
};

handleRouteChange();

router.events.on('routeChangeComplete', handleRouteChange);

return () => {
router.events.off('routeChangeComplete', handleRouteChange);
};
}, [router.isReady, router.query.tab]);

const handleTabChange = (
event: React.SyntheticEvent,
newValue: string
): void => {
setActiveTab(newValue);
if (newValue in reverseTabMap) {
const urlTabIdentifier = reverseTabMap[newValue];
router.push(`/statistics?tab=${urlTabIdentifier}`, undefined, {
shallow: true,
});
}
};

useEffect(() => {
Expand Down

0 comments on commit 09a0b4d

Please sign in to comment.