mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-18 18:10:16 -04:00
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { getActiveCarpools } from '../api';
|
|
import { ICarpool } from '../types';
|
|
import UILink from '../UI/UILink';
|
|
import UISecondaryBox from '../UI/UISecondaryBox';
|
|
|
|
function ActiveCarpoolListItem({ carpool }: { carpool: ICarpool }) {
|
|
return (
|
|
<div>
|
|
<h4>{carpool.name}</h4>
|
|
<UILink href={`/carpools/${carpool.id}`}>View carpool</UILink>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function ActiveCarpools() {
|
|
const [activeCarpools, setActiveCarpools] = useState<ICarpool[]>([]);
|
|
|
|
useEffect(() => {
|
|
getActiveCarpools().then(setActiveCarpools);
|
|
}, []);
|
|
|
|
return (
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
width: '19rem',
|
|
}}
|
|
>
|
|
<h1 style={{ textAlign: 'center' }}>Carpools</h1>
|
|
<UISecondaryBox style={{ width: '100%', boxSizing: 'border-box' }}>
|
|
{activeCarpools.length > 0 ? activeCarpools.map((carpool) => (
|
|
<ActiveCarpoolListItem carpool={carpool} key={carpool.id} />
|
|
)) : "No Carpools"}
|
|
</UISecondaryBox>
|
|
</div>
|
|
);
|
|
}
|