add api for fetching carpool

This commit is contained in:
Michael Fatemi 2021-07-08 00:41:55 -04:00
parent 362447689b
commit 08e0a0aed2
3 changed files with 25 additions and 19 deletions

View File

@ -1,3 +1,6 @@
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { getCarpool } from './api';
import { ICarpool } from './types'; import { ICarpool } from './types';
import UISecondaryBox from './UISecondaryBox'; import UISecondaryBox from './UISecondaryBox';
@ -13,13 +16,24 @@ function MemberList({ members }: { members: ICarpool['members'] }) {
); );
} }
export default function Carpool({ carpool }: { carpool: ICarpool }) { export default function Carpool() {
const id = +useParams<{ id: string }>().id;
const [carpool, setCarpool] = useState<ICarpool | null>(null);
useEffect(() => {
getCarpool(id).then(setCarpool);
}, [id]);
return ( return (
<UISecondaryBox style={{ width: '100%', alignItems: 'center' }}> <UISecondaryBox style={{ width: '100%', alignItems: 'center' }}>
{carpool && (
<>
<h2 style={{ textAlign: 'center' }}>{carpool.name}</h2> <h2 style={{ textAlign: 'center' }}>{carpool.name}</h2>
{carpool.description} {carpool.description}
<h3>Members</h3> <h3>Members</h3>
<MemberList members={carpool.members} /> <MemberList members={carpool.members} />
</>
)}
</UISecondaryBox> </UISecondaryBox>
); );
} }

View File

@ -1,5 +1,4 @@
import logout from './Authentication/logout'; import logout from './Authentication/logout';
import Carpool from './Carpool';
import Events from './Events'; import Events from './Events';
import Groups from './Groups'; import Groups from './Groups';
import { useMe } from './hooks'; import { useMe } from './hooks';
@ -7,24 +6,13 @@ import UIPressable from './UIPressable';
import UIPrimaryTitle from './UIPrimaryTitle'; import UIPrimaryTitle from './UIPrimaryTitle';
export default function WheelShare() { export default function WheelShare() {
const user = useMe()!; const { name } = useMe()!;
return ( return (
<> <>
<UIPrimaryTitle>WheelShare</UIPrimaryTitle> <UIPrimaryTitle>WheelShare</UIPrimaryTitle>
<Carpool {name}
carpool={{
name: 'Carpool',
id: 0,
description: 'Test carpool',
eventId: null,
members: [],
invitations: [],
}}
/>
{user.name}
<UIPressable onClick={logout}>Log out</UIPressable> <UIPressable onClick={logout}>Log out</UIPressable>
<Groups /> <Groups />

View File

@ -178,3 +178,7 @@ export async function getReceivedInvitationsAndRequests() {
'/users/@me/received_requests_and_invites' '/users/@me/received_requests_and_invites'
)) as IInvitation[]; )) as IInvitation[];
} }
export async function getCarpool(id: number) {
return await get('/carpools/' + id);
}