diff --git a/packages/berlin/src/components/tabs/TabsHeader.tsx b/packages/berlin/src/components/tabs/TabsHeader.tsx index 1c256e88..abee1a7d 100644 --- a/packages/berlin/src/components/tabs/TabsHeader.tsx +++ b/packages/berlin/src/components/tabs/TabsHeader.tsx @@ -1,19 +1,16 @@ -import { Fragment, useState } from 'react'; +import { Fragment } from 'react'; import { Body } from '../typography/Body.styled'; import { Tab } from './TabsHeader.styled'; type TabsHeaderProps = { tabNames: string[]; - initialTab?: string; + activeTab?: string; className?: string; onTabChange?: (tab: string) => void; }; -export function TabsHeader({ tabNames, initialTab, className, onTabChange }: TabsHeaderProps) { - const [activeTab, setActiveTab] = useState(initialTab || tabNames[0]); - +export function TabsHeader({ tabNames, activeTab, className, onTabChange }: TabsHeaderProps) { const handleTabClick = (tab: string) => { - setActiveTab(tab); if (onTabChange) { onTabChange(tab); } diff --git a/packages/berlin/src/pages/Event.tsx b/packages/berlin/src/pages/Event.tsx index 7846f9af..c8e079a3 100644 --- a/packages/berlin/src/pages/Event.tsx +++ b/packages/berlin/src/pages/Event.tsx @@ -4,7 +4,7 @@ import { useQuery } from '@tanstack/react-query'; import { useParams } from 'react-router-dom'; // API -import { fetchEvent, fetchEventCycles } from 'api'; +import { fetchEvent, fetchEventCycles, GetCycleResponse } from 'api'; // Components import { Body } from '../components/typography/Body.styled'; @@ -44,8 +44,66 @@ function Event() { [eventCycles], ); + const initialTab = useMemo( + () => (openCycles && openCycles.length > 0 ? 'upcoming' : 'past'), + [openCycles], + ); + + return ( + <> + +
+
+ + {event?.name} + {event?.description && ( +
+ {props.children}, + p: ({ node, ...props }) => {props.children}, + }} + > + {event.description} + +
+ )} +
+ {event?.imageUrl && ( +
+ {`${event.name} +
+ )} + +
+ + ); +} + +function Questions({ + initialTab, + openCycles, + closedCycles, + eventId, +}: { + initialTab: string; + openCycles: GetCycleResponse[] | undefined; + eventId?: string; + closedCycles: GetCycleResponse[] | undefined; +}) { + const [activeTab, setActiveTab] = useState(initialTab); + const tabNames = ['upcoming', 'past']; - const [activeTab, setActiveTab] = useState('upcoming'); const tabs = { upcoming: ( @@ -73,46 +131,15 @@ function Event() { }; return ( - <> - - -
-
- - {event?.name} - {event?.description && ( -
- {props.children}, - p: ({ node, ...props }) => {props.children}, - }} - > - {event.description} - -
- )} -
- {event?.imageUrl && ( -
- {`${event.name} -
- )} -
-
- Questions - -
- - - + +
+ Questions + +
+ + - +
); } - export default Event;