From c5b9447a5389295b4a03fba8b7e56f08c8e86fbc Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Sun, 11 Apr 2021 04:02:39 -0400 Subject: [PATCH] feat: didn't go to sleep --- package.json | 3 +++ src/components/CreateGroup.tsx | 16 +++++++++++- src/components/CreatePool.tsx | 41 +++++++++++++++++++++++------ src/components/Groups.tsx | 36 +++++++++++++++++-------- src/components/MyGroups.tsx | 48 +++++++++------------------------- src/components/Nav.tsx | 5 ++-- src/components/PoolMap.tsx | 32 ++++++++--------------- yarn.lock | 36 ++++++++++++++++++++++++- 8 files changed, 136 insertions(+), 81 deletions(-) diff --git a/package.json b/package.json index 8d1d440..79b1b43 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", "@types/bootstrap": "^5.0.12", + "@types/google-map-react": "^2.1.0", "@types/leaflet": "^1.7.0", "@types/node": "^14.14.37", "@types/react": "^17.0.3", @@ -17,7 +18,9 @@ "axios": "^0.21.1", "bootstrap": "^4.6.0", "dotenv": "^8.2.0", + "google-map-react": "^2.1.9", "jquery": "^3.6.0", + "leaflet": "^1.7.1", "popper.js": "^1.16.1", "react": "^17.0.2", "react-bootstrap": "^1.5.2", diff --git a/src/components/CreateGroup.tsx b/src/components/CreateGroup.tsx index c51feec..47582fe 100644 --- a/src/components/CreateGroup.tsx +++ b/src/components/CreateGroup.tsx @@ -6,6 +6,7 @@ import Typography from '@material-ui/core/Typography'; import CloudUploadIcon from '@material-ui/icons/CloudUpload'; import { useState } from 'react'; import { makeAPIPostCall } from '../api/utils'; +import { useHistory } from 'react-router-dom'; const useStyles = makeStyles((theme) => ({ root: { @@ -19,11 +20,24 @@ const useStyles = makeStyles((theme) => ({ }, })); const CreateGroup = () => { + const history = useHistory(); const [title, setTitle] = useState('No Title'); const classes = useStyles(); const onClick = () => { - makeAPIPostCall('/groups/', { title }); + makeAPIPostCall('/groups/', { + name: title, + }).then((res) => { + handleCallback(res.data); + }); + }; + + const handleCallback = (res: any) => { + if (res.status === 'error') { + alert('There was a problem with your form!'); + } else { + history.push('/profile'); + } }; return ( diff --git a/src/components/CreatePool.tsx b/src/components/CreatePool.tsx index 11b3902..a7da11c 100644 --- a/src/components/CreatePool.tsx +++ b/src/components/CreatePool.tsx @@ -5,7 +5,8 @@ import { makeStyles } from '@material-ui/core/styles'; import CloudUploadIcon from '@material-ui/icons/CloudUpload'; import { useEffect, useState } from 'react'; import { searchForPlaces } from '../api/google'; -import { makeAPIPostCall } from '../api/utils'; +import { makeAPIPostCall, makeAPIGetCall } from '../api/utils'; +import { useHistory } from 'react-router-dom'; const useStyles = makeStyles((theme) => ({ root: { @@ -20,6 +21,7 @@ const useStyles = makeStyles((theme) => ({ })); const CreatePool = () => { + const history = useHistory(); const [title, setTitle] = useState('No Title'); const [capacity, setCapacity] = useState(0); const [start, setStart] = useState(''); @@ -29,6 +31,7 @@ const CreatePool = () => { const [description, setDescription] = useState(''); const classes = useStyles(); const [group, setGroup] = useState(''); + const [groups, setGroups] = useState([]); const onClick = () => { makeAPIPostCall('/pools/', { @@ -40,9 +43,25 @@ const CreatePool = () => { direction, type, group_id: group, + }).then((res) => { + handleCallback(res.data); }); }; - useEffect(() => {}, []); + + const handleCallback = (res: any) => { + if (res.status === 'error') { + alert('There was a problem with your form!'); + } else { + history.push('/profile'); + } + }; + + useEffect(() => { + makeAPIGetCall('/users/@me/groups').then((res) => { + if (res.data.data) setGroups(res.data.data); + }); + }, []); + return (
{ />
-