@@ -13,7 +13,7 @@ import { AdministrationDataType, HttpStatus, SummaryDataType, ActionType } from
1313import { ApiUtils } from '@/utils'
1414import { signOut , useSession } from 'next-auth/react'
1515import { useTranslations } from 'next-intl'
16- import { notFound , useRouter } from 'next/navigation'
16+ import { notFound , useRouter , useSearchParams } from 'next/navigation'
1717import { useEffect , useState } from 'react'
1818import { Button , Col , Dropdown , ListGroup , Row , Spinner , Tab } from 'react-bootstrap'
1919import LinkProjects from '../../../components/LinkProjects'
@@ -36,6 +36,19 @@ export default function ViewProjects({ projectId }: { projectId: string }) {
3636 const [ administrationData , setAdministrationData ] = useState < AdministrationDataType | undefined > ( undefined )
3737 const [ show , setShow ] = useState ( false )
3838 const router = useRouter ( )
39+ const searchParams = useSearchParams ( )
40+ const DEFAULT_ACTIVE_TAB = 'summary'
41+ const [ activeKey , setActiveKey ] = useState ( DEFAULT_ACTIVE_TAB )
42+
43+ useEffect ( ( ) => {
44+ const fragment = searchParams . get ( 'tab' ) || DEFAULT_ACTIVE_TAB
45+ setActiveKey ( fragment )
46+ } , [ searchParams ] )
47+
48+ const handleSelect = ( key : string | null ) => {
49+ setActiveKey ( key ?? DEFAULT_ACTIVE_TAB )
50+ router . push ( `?tab=${ key } ` )
51+ }
3952
4053 useEffect ( ( ) => {
4154 if ( status !== 'authenticated' ) return
@@ -71,19 +84,19 @@ export default function ViewProjects({ projectId }: { projectId: string }) {
7184 const handleEditProject = ( projectId : string ) => {
7285 if ( session . user . email === summaryData [ '_embedded' ] [ 'createdBy' ] [ 'email' ] ) {
7386 MessageService . success ( t ( 'You are editing the original document' ) )
74- router . push ( `/projects/edit/${ projectId } ` )
87+ router . push ( `/projects/edit/${ projectId } ?tab= ${ activeKey } ` )
7588 }
7689 else {
7790 MessageService . success ( t ( 'You will create a moderation request if you update' ) )
78- router . push ( `/projects/edit/${ projectId } ` )
91+ router . push ( `/projects/edit/${ projectId } ?tab= ${ activeKey } ` )
7992 }
8093 }
8194
8295 return (
8396 < >
8497 < LinkProjects show = { show } setShow = { setShow } projectId = { projectId } />
8598 < div className = 'container page-content' >
86- < Tab . Container defaultActiveKey = 'summary' mountOnEnter = { true } unmountOnExit = { true } >
99+ < Tab . Container activeKey = { activeKey } onSelect = { ( k ) => handleSelect ( k ) } mountOnEnter = { true } unmountOnExit = { true } >
87100 < Row >
88101 < Col sm = 'auto' className = 'me-3' >
89102 < ListGroup >
0 commit comments