diff --git a/src/components/App.tsx b/src/components/App.tsx index 6d9e16e..f098788 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -5,7 +5,8 @@ import WheelShare from './WheelShare'; import WheelShareLoggedOut from './WheelShareLoggedOut'; const Authenticator = lazy(() => import('./Authentication/Authenticator')); -const Carpool = lazy(() => import('./Carpool/Carpool')); +const CarpoolPage = lazy(() => import('./Carpool/CarpoolPage')); +const EventPage = lazy(() => import('./Event/EventPage')); const Group = lazy(() => import('./Group')); const style: CSSProperties = { @@ -36,7 +37,8 @@ export default function App() { component={Authenticator} path="/auth/:provider/callback" /> - + + diff --git a/src/components/Carpool/Carpool.tsx b/src/components/Carpool/Carpool.tsx index 77e6307..6a94a91 100644 --- a/src/components/Carpool/Carpool.tsx +++ b/src/components/Carpool/Carpool.tsx @@ -1,10 +1,8 @@ import MailOutlineIcon from '@material-ui/icons/MailOutline'; import PersonAddIcon from '@material-ui/icons/PersonAdd'; import { createContext, useCallback, useEffect, useState } from 'react'; -import { useParams } from 'react-router-dom'; import { cancelCarpoolInvite, getCarpool, sendCarpoolInvite } from '../api'; import { lightgrey } from '../colors'; -import Header from '../Header/Header'; import { ICarpool } from '../types'; import UIButton from '../UI/UIButton'; import UISecondaryBox from '../UI/UISecondaryBox'; @@ -23,8 +21,7 @@ export const CarpoolContext = createContext({ }, }); -export default function Carpool() { - const id = +useParams<{ id: string }>().id; +export default function Carpool({ id }: { id: number }) { const [carpool, setCarpool] = useState(null); useEffect(() => { @@ -84,7 +81,6 @@ export default function Carpool() { return ( -
{carpool ? ( <> diff --git a/src/components/Carpool/CarpoolPage.tsx b/src/components/Carpool/CarpoolPage.tsx new file mode 100644 index 0000000..a7c381c --- /dev/null +++ b/src/components/Carpool/CarpoolPage.tsx @@ -0,0 +1,14 @@ +import { useParams } from 'react-router-dom'; +import Header from '../Header/Header'; +import Carpool from './Carpool'; + +export default function CarpoolPage() { + const id = +useParams<{ id: string }>().id; + + return ( + <> +
+ + + ); +} diff --git a/src/components/Event/EventPage.tsx b/src/components/Event/EventPage.tsx new file mode 100644 index 0000000..2cd8865 --- /dev/null +++ b/src/components/Event/EventPage.tsx @@ -0,0 +1,22 @@ +import { useEffect, useState } from 'react'; +import { useParams } from 'react-router-dom'; +import { getEvent } from '../api'; +import Header from '../Header/Header'; +import { IEvent } from '../types'; +import Event from './Event'; + +export default function EventPage() { + const id = +useParams<{ id: string }>().id; + const [event, setEvent] = useState(null); + + useEffect(() => { + getEvent(id).then(setEvent); + }, [id]); + + return ( + <> +
+ {event ? : Loading...} + + ); +} diff --git a/src/components/api.ts b/src/components/api.ts index 0b1b643..d2adbd3 100644 --- a/src/components/api.ts +++ b/src/components/api.ts @@ -1,5 +1,5 @@ import { GroupPreview } from './GroupJoinerLink'; -import { IInvitation, IEventSignup, ICarpool } from './types'; +import { IInvitation, IEventSignup, ICarpool, IEvent } from './types'; const base = process.env.REACT_APP_API_DOMAIN + 'api'; @@ -86,10 +86,14 @@ export async function createEvent({ }; } -export async function getEvents() { +export async function getEvents(): Promise { return await get('/events'); } +export async function getEvent(id: number): Promise { + return await get('/events/' + id); +} + export async function getGroup(id: number) { return await get('/groups/' + id); }