diff --git a/src/containers/my-cooperations/cooperation-details/CooperationDetails.tsx b/src/containers/my-cooperations/cooperation-details/CooperationDetails.tsx index c3d8e91f3..218eb6979 100644 --- a/src/containers/my-cooperations/cooperation-details/CooperationDetails.tsx +++ b/src/containers/my-cooperations/cooperation-details/CooperationDetails.tsx @@ -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' @@ -52,12 +52,25 @@ const CooperationDetails = () => { const { id } = useParams() const { isDesktop } = useBreakpoints() const { isActivityCreated } = useAppSelector(cooperationsSelector) - const [activeTab, setActiveTab] = useState( - CooperationTabsEnum.Activities - ) const [isNotesOpen, setIsNotesOpen] = useState(false) const [editMode, setEditMode] = useState(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] @@ -88,7 +101,7 @@ const CooperationDetails = () => { } const handleClick = (tab: CooperationTabsEnum) => { - setActiveTab(tab) + setSearchParams({ tab }) } const handleNotesClick = () => { diff --git a/src/containers/my-cooperations/cooperations-container/CooperationContainer.tsx b/src/containers/my-cooperations/cooperations-container/CooperationContainer.tsx index c2427cf54..dc3a38efa 100644 --- a/src/containers/my-cooperations/cooperations-container/CooperationContainer.tsx +++ b/src/containers/my-cooperations/cooperations-container/CooperationContainer.tsx @@ -50,7 +50,8 @@ const CooperationContainer: FC = ({ /> ) }) - : item.status === StatusEnum.Active && navigate(`./${item._id}`) + : item.status === StatusEnum.Active && + navigate(`./${item._id}?tab=activities`) } const cooperationGrid = (