-
Notifications
You must be signed in to change notification settings - Fork 4
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
Feature/ Consoles - Extract console tabs into components #2189
base: master
Are you sure you want to change the base?
Changes from 4 commits
02eed45
d40abe1
101686b
71f178a
666eb68
9e799b5
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,61 @@ | ||
import { useEffect, useState } from 'react' | ||
import { useRouter } from 'next/router' | ||
import { Tab, TabList, TabPanel, TabPanels, Tabs } from '../Tabs' | ||
|
||
const ConsoleTabs = ({ defaultActiveTabId, tabs = [], updateActiveTabId }) => { | ||
const validTabIds = tabs.flatMap((tab) => (tab.visible ? tab.id : [])) | ||
const [activeTabId, setActiveTabId] = useState( | ||
decodeURIComponent(window.location.hash.substring(1)) || | ||
defaultActiveTabId || | ||
validTabIds[0] | ||
) | ||
const router = useRouter() | ||
|
||
useEffect(() => { | ||
if (!validTabIds.includes(activeTabId)) { | ||
setActiveTabId(defaultActiveTabId) | ||
updateActiveTabId?.(`#${defaultActiveTabId}`) | ||
return | ||
} | ||
updateActiveTabId?.(`#${activeTabId}`) | ||
router.replace(`#${activeTabId}`).catch((e) => { | ||
if (!e.cancelled) { | ||
throw e | ||
} | ||
}) | ||
}, [activeTabId]) | ||
|
||
return ( | ||
<Tabs> | ||
<TabList> | ||
{tabs.map((tab) => { | ||
const { id, label, visible } = tab | ||
if (!visible) return null | ||
return ( | ||
<Tab | ||
key={id} | ||
id={id} | ||
active={activeTabId === id ? true : undefined} | ||
onClick={() => setActiveTabId(id)} | ||
> | ||
{label} | ||
</Tab> | ||
) | ||
})} | ||
</TabList> | ||
<TabPanels> | ||
{tabs.map((tab) => { | ||
const { id, content, visible } = tab | ||
if (!visible || activeTabId !== `${id}`) return null | ||
return ( | ||
<TabPanel key={id} id={id}> | ||
{content} | ||
</TabPanel> | ||
) | ||
})} | ||
</TabPanels> | ||
</Tabs> | ||
) | ||
} | ||
|
||
export default ConsoleTabs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
/* globals promptError: false */ | ||
import { useContext, useEffect, useState } from 'react' | ||
import { useContext, useEffect } from 'react' | ||
import { useRouter } from 'next/router' | ||
import useUser from '../../hooks/useUser' | ||
import useQuery from '../../hooks/useQuery' | ||
import { Tab, TabList, TabPanel, TabPanels, Tabs } from '../Tabs' | ||
import { referrerLink, venueHomepageLink } from '../../lib/banner-links' | ||
import WebFieldContext from '../WebFieldContext' | ||
import BasicHeader from './BasicHeader' | ||
|
@@ -12,6 +11,7 @@ import EthicsChairOverview from './EthicsChairConsole/EthicsChairOverview' | |
import PaperStatus from './EthicsChairConsole/EthicsChairPaperStatus' | ||
import EthicsChairTasks from './EthicsChairConsole/EthicsChairTasks' | ||
import { getRoleHashFragment } from '../../lib/utils' | ||
import ConsoleTabs from './ConsoleTabs' | ||
|
||
const EthicsChairConsole = ({ appContext }) => { | ||
const { | ||
|
@@ -31,17 +31,9 @@ const EthicsChairConsole = ({ appContext }) => { | |
const { setBannerContent } = appContext | ||
const router = useRouter() | ||
const query = useQuery() | ||
const [activeTabId, setActiveTabId] = useState( | ||
decodeURIComponent(window.location.hash) || '#overview' | ||
) | ||
const { user, userLoading } = useUser() | ||
|
||
const ethicsChairsUrlFormat = getRoleHashFragment(ethicsChairsName) | ||
const validTabIds = [ | ||
'#overview', | ||
`#${submissionName.toLowerCase()}-status`, | ||
`#${ethicsChairsUrlFormat}-tasks`, | ||
] | ||
|
||
useEffect(() => { | ||
if (!query) return | ||
|
@@ -53,14 +45,6 @@ const EthicsChairConsole = ({ appContext }) => { | |
} | ||
}, [query, venueId]) | ||
|
||
useEffect(() => { | ||
if (!validTabIds.includes(activeTabId)) { | ||
setActiveTabId(validTabIds[0]) | ||
return | ||
} | ||
router.replace(activeTabId) | ||
}, [activeTabId]) | ||
|
||
const missingConfig = Object.entries({ | ||
header, | ||
entity: group, | ||
|
@@ -85,45 +69,29 @@ const EthicsChairConsole = ({ appContext }) => { | |
return ( | ||
<> | ||
<BasicHeader title={header?.title} instructions={header.instructions} /> | ||
<Tabs> | ||
<TabList> | ||
<Tab | ||
id="overview" | ||
active={activeTabId === '#overview' ? true : undefined} | ||
onClick={() => setActiveTabId('#overview')} | ||
> | ||
Overview | ||
</Tab> | ||
<Tab | ||
id={`${submissionName.toLowerCase()}-status`} | ||
active={ | ||
activeTabId === `#${submissionName.toLowerCase()}-status` ? true : undefined | ||
} | ||
onClick={() => setActiveTabId(`#${submissionName.toLowerCase()}-status`)} | ||
> | ||
{submissionName} Status | ||
</Tab> | ||
<Tab | ||
id={`${ethicsChairsUrlFormat}-tasks`} | ||
active={activeTabId === `#${ethicsChairsUrlFormat}-tasks` ? true : undefined} | ||
onClick={() => setActiveTabId(`#${ethicsChairsUrlFormat}-tasks`)} | ||
> | ||
Ethics Chair Tasks | ||
</Tab> | ||
</TabList> | ||
|
||
<TabPanels> | ||
<TabPanel id="overview"> | ||
<EthicsChairOverview /> | ||
</TabPanel> | ||
<TabPanel id={`${submissionName.toLowerCase()}-status`}> | ||
{activeTabId === `#${submissionName.toLowerCase()}-status` && <PaperStatus />} | ||
</TabPanel> | ||
<TabPanel id={`${ethicsChairsUrlFormat}-tasks`}> | ||
{activeTabId === `#${ethicsChairsUrlFormat}-tasks` && <EthicsChairTasks />} | ||
</TabPanel> | ||
</TabPanels> | ||
</Tabs> | ||
<ConsoleTabs | ||
defaultActiveTabId="overview" | ||
tabs={[ | ||
Comment on lines
+72
to
+74
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. The AC and Reviewer console have 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. for AC and reviewer console the activaTabId is required to construct the referrer link so that user can go back to the same tab for ethics chair console it's fixed to be paper status tab [Ethics Chair Console](/group?id=${venueId}/${ethicsChairsName}#${submissionName.toLowerCase()}-status) so i think it's not required |
||
{ | ||
id: 'overview', | ||
label: 'Overview', | ||
content: <EthicsChairOverview />, | ||
visible: true, | ||
}, | ||
{ | ||
id: `${submissionName.toLowerCase()}-status`, | ||
label: `${submissionName} Status`, | ||
content: <PaperStatus />, | ||
visible: true, | ||
}, | ||
{ | ||
id: `${ethicsChairsUrlFormat}-tasks`, | ||
label: 'Ethics Chair Tasks', | ||
content: <EthicsChairTasks />, | ||
visible: true, | ||
}, | ||
]} | ||
/> | ||
</> | ||
) | ||
} | ||
|
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.
Do we need to call
updateActiveTabId
here? I think whensetActiveTabId
is called it will trigger useEffect again with a valid (default) tab, so the parent's state would already get updated in line 20 with the default. What do you think?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.
i think you are right