mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 11:20:17 -04:00
add api for fetching carpool
This commit is contained in:
parent
362447689b
commit
08e0a0aed2
|
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 />
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user