improve Group page API

This commit is contained in:
Michael Fatemi 2021-04-10 20:52:38 -04:00
parent 2eb0871d14
commit 28274b3fc7

View File

@ -38,12 +38,17 @@ const SAMPLE_POOLS: Carpool.Pool[] = [
export default function Group() {
// eslint-disable-next-line
const { id } = useParams<{ id: string }>();
const [error, setError] = useState(false);
const [group, setGroup] = useState<Carpool.Group>();
const [pools, setPools] = useState<Carpool.Pool[]>(SAMPLE_POOLS);
useEffect(() => {
makeAPIGetCall('/group', { groupID: id }).then((res) => {
setGroup(res.data.data);
if ('error' in res.data) {
setError(true);
} else {
setGroup(res.data.data);
}
});
makeAPIGetCall('/group_pools', { groupID: id }).then((res) => {
@ -51,6 +56,10 @@ export default function Group() {
});
}, [id]);
if (error) {
return <h1 style={{ textAlign: 'center' }}>Group Not Found</h1>;
}
if (!group) {
return <h1 style={{ textAlign: 'center' }}>Loading</h1>;
}