diff --git a/src/components/DummyProfiles/GetByIdForm.jsx b/src/components/DummyProfiles/GetByIdForm.jsx new file mode 100644 index 0000000..083d557 --- /dev/null +++ b/src/components/DummyProfiles/GetByIdForm.jsx @@ -0,0 +1,46 @@ +import { Flex, Input, Button, Text, VStack } from '@chakra-ui/react'; +import { getProfileById } from '../../../utils/profileUtils'; +import ProfileCard from './ProfileCard'; +import { useState } from 'react'; + +const GetByIdForm = () => { + const [id, setId] = useState(''); + const [profile, setProfile] = useState(); + + async function submitHandler(e) { + e.preventDefault(); + try { + const response = await getProfileById(id); + setProfile(response); + } catch (error) { + console.error('Error submitting form:', error); + } + } + + return ( + <> +
+ {profile &&Placeholder for the events page
; }; diff --git a/src/pages/DummyProfiles.jsx b/src/pages/DummyProfiles.jsx index f28b2b3..ec4ad56 100644 --- a/src/pages/DummyProfiles.jsx +++ b/src/pages/DummyProfiles.jsx @@ -1,6 +1,31 @@ +import { Button, VStack, StackDivider } from '@chakra-ui/react'; +import ProfileCard from '../components/DummyProfiles/ProfileCard'; +import ProfileForm from '../components/DummyProfiles/ProfileForm'; +import { getProfile } from '../../utils/profileUtils'; +import { useState } from 'react'; +import GetByIdForm from '../components/DummyProfiles/GetByIdForm'; const DummyProfiles = () => { - returnPlaceholder for the profiles page
; + const [profiles, setProfiles] = useState([]); + const [displayProfiles, setDisplayProfiles] = useState(false); + + const viewProfile = async () => { + await getProfile().then(data => setProfiles(data)); + setDisplayProfiles(prev => !prev); + }; + return ( +Placeholder for the volunteer data page
; + + const [volunteers, setVolunteers] = useState([]); + const [showCards, setShowCards] = useState(false); + const [volunteer_id, setVolunteerId] = useState([]); + const [number_in_party, setNumberInParty] = useState([]); + const [pounds, setPounds] = useState([]); + const [ounces, setOunces] = useState([]); + const [unusual_items, setUnusualItems] = useState([]); + const [event_id, setEventId] = useState([]); + + const getVolunteerData = async () => { + try { + const { data } = await Backend.get('/data'); + setVolunteers(data); + } catch (error) { + console.error('Error fetching volunteer data:', error.message); + } + }; + + const postVolunteerData = async (volunteer_id, number_in_party, pounds, + ounces, unusual_items, event_id) => { + try { + const postData = { + volunteer_id: volunteer_id, + number_in_party: number_in_party, + pounds: pounds, + ounces: ounces, + unusual_items: unusual_items, + event_id: event_id, + is_checked_in: false + }; + + const{ postStatus } = await Backend.post('/data', postData); + getVolunteerData(); + } catch (error) { + console.error('Error creating new volunteer:', error.message); + } + }; + + const deleteVolunteerData = async (id) => { + try { + await Backend.delete(`/data/${id}`); + // After deletion, refresh the volunteer data + getVolunteerData(); + } catch (error) { + console.error('Error deleting volunteer data:', error.message); + } + }; + + const renderVolunteerCards = () => { + return ( +Placeholder for the volunteer event page
; }; diff --git a/utils/profileUtils.js b/utils/profileUtils.js new file mode 100644 index 0000000..c9c1ddb --- /dev/null +++ b/utils/profileUtils.js @@ -0,0 +1,23 @@ +import Backend from './utils'; + +const getProfile = async () => { + const response = await Backend.get('/profiles'); + return response.data; +}; + +const postProfile = async profile => { + const response = await Backend.post('/profiles', profile); + return response.data; +}; + +const deleteProfile = async id => { + const response = await Backend.delete(`/profiles/${id}`); + return response.data; +}; + +const getProfileById = async id => { + const response = await Backend.get(`/profiles/${id}`); + return response.data; +}; + +export { getProfile, postProfile, deleteProfile, getProfileById }; diff --git a/utils/utils.js b/utils/utils.js index 4ac23dd..a464f17 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,8 +1,8 @@ -import axios from "axios"; +import axios from 'axios'; const Backend = axios.create({ - baseURL: "http://localhost:3001", + baseURL: 'http://localhost:3001', withCredentials: true, }); -export default Backend; \ No newline at end of file +export default Backend;