-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30bb918
commit d58acd3
Showing
4 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useRouter } from "next/router" | ||
import { useEffect, useState } from "react" | ||
import { ProfileMenu } from "../../models/profile" | ||
|
||
export function useProfileTab(initialTab: ProfileMenu) { | ||
const router = useRouter() | ||
const [activeTab, setActiveTab] = useState<ProfileMenu>(initialTab) | ||
|
||
useEffect(() => { | ||
const initialTab = router.query.tab as ProfileMenu | ||
if (Object.values(ProfileMenu).includes(initialTab)) { | ||
setActiveTab(initialTab) | ||
} | ||
|
||
const handleRouteChange = () => { | ||
const newTab = router.query.tab as ProfileMenu | ||
if (Object.values(ProfileMenu).includes(newTab)) { | ||
setActiveTab(newTab) | ||
} | ||
} | ||
|
||
router.events.on("routeChangeComplete", handleRouteChange) | ||
|
||
return () => { | ||
router.events.off("routeChangeComplete", handleRouteChange) | ||
} | ||
}, [router]) | ||
|
||
const handleTabChange = (newTab: ProfileMenu) => { | ||
router.push(`?tab=${newTab}`) | ||
} | ||
|
||
return [activeTab, handleTabChange] as [ProfileMenu, (newTab: ProfileMenu) => void] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { ProfileMenu } from "../../models/profile" | ||
import Profile from "../../pages/profile" | ||
import { render, setAuthForTest } from "../test-utils" | ||
|
||
beforeAll(() => setAuthForTest()) | ||
|
||
it("renders Profile Page correctly", () => { | ||
const { container } = render(<Profile />) | ||
const { container } = render(<Profile initialTab={ProfileMenu.USER_INFO} />) | ||
expect(container).toMatchSnapshot() | ||
}) |