Skip to content

Commit

Permalink
Added active tab to URL params on the cooperation page
Browse files Browse the repository at this point in the history
  • Loading branch information
Made1ra committed Nov 23, 2024
1 parent 4cf481c commit ffb4ffe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useCallback, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useParams, useNavigate } from 'react-router-dom'
import { useParams, useNavigate, useSearchParams } from 'react-router-dom'
import { AxiosResponse } from 'axios'

import Box from '@mui/material/Box'
Expand Down Expand Up @@ -52,12 +52,25 @@ const CooperationDetails = () => {
const { id } = useParams()
const { isDesktop } = useBreakpoints()
const { isActivityCreated } = useAppSelector(cooperationsSelector)
const [activeTab, setActiveTab] = useState<CooperationTabsEnum>(
CooperationTabsEnum.Activities
)
const [isNotesOpen, setIsNotesOpen] = useState<boolean>(false)
const [editMode, setEditMode] = useState<boolean>(false)

const [searchParams, setSearchParams] = useSearchParams()

const hasTabInSearchParams = Object.values(CooperationTabsEnum).includes(
searchParams.get('tab') as CooperationTabsEnum
)

const activeTab = hasTabInSearchParams
? (searchParams.get('tab') as CooperationTabsEnum)
: CooperationTabsEnum.Activities

useEffect(() => {
if (!hasTabInSearchParams) {
setSearchParams({ tab: CooperationTabsEnum.Activities })
}
}, [hasTabInSearchParams, setSearchParams])

const responseError = useCallback(
() => navigate(errorRoutes.notFound.path),
[navigate]
Expand Down Expand Up @@ -88,7 +101,7 @@ const CooperationDetails = () => {
}

const handleClick = (tab: CooperationTabsEnum) => {
setActiveTab(tab)
setSearchParams({ tab })
}

const handleNotesClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const CooperationContainer: FC<CooperationContainerProps> = ({
/>
)
})
: item.status === StatusEnum.Active && navigate(`./${item._id}`)
: item.status === StatusEnum.Active &&
navigate(`./${item._id}?tab=activities`)
}

const cooperationGrid = (
Expand Down

0 comments on commit ffb4ffe

Please sign in to comment.