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 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 (
<UISecondaryBox style={{ width: '100%', alignItems: 'center' }}>
<h2 style={{ textAlign: 'center' }}>{carpool.name}</h2>
{carpool.description}
<h3>Members</h3>
<MemberList members={carpool.members} />
{carpool && (
<>
<h2 style={{ textAlign: 'center' }}>{carpool.name}</h2>
{carpool.description}
<h3>Members</h3>
<MemberList members={carpool.members} />
</>
)}
</UISecondaryBox>
);
}

View File

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

View File

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