diff --git a/react-whenMeet/package-lock.json b/react-whenMeet/package-lock.json index 11a4fcd559a5231a7b6d84898f330fde40a832fe..e6355a5ab1a363cd185f0606a1eb4809256764ca 100644 --- a/react-whenMeet/package-lock.json +++ b/react-whenMeet/package-lock.json @@ -11,6 +11,7 @@ "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", + "axios": "^1.6.2", "gh-pages": "^6.0.0", "prop-types": "^15.8.1", "react": "^18.2.0", @@ -5362,6 +5363,29 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -14606,6 +14630,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", diff --git a/react-whenMeet/package.json b/react-whenMeet/package.json index 7ed24817b6d074363217ba8ecb07218d8395623b..1341b784006fdf2b9382d46ffc7e70f3902d998e 100644 --- a/react-whenMeet/package.json +++ b/react-whenMeet/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", + "axios": "^1.6.2", "gh-pages": "^6.0.0", "prop-types": "^15.8.1", "react": "^18.2.0", diff --git a/react-whenMeet/src/App.js b/react-whenMeet/src/App.js index 6468946fe78f5ae88926172aac10b2c2dd98d8ea..15b0c4d93e8d528dc9b56bbc6ae25a95462dba84 100644 --- a/react-whenMeet/src/App.js +++ b/react-whenMeet/src/App.js @@ -12,8 +12,8 @@ function App() { <Router> <Routes> <Route path="/meetinginfo/linkpage" element={<LinkPage />}></Route> - <Route path="/homeparticipate/usertimeinfo" element={<UserTimeInfo />}></Route> - <Route path="/homeparticipate" element={<HomeParticipate />}></Route> + <Route path="/homeparticipate/:id/usertimeinfo" element={<UserTimeInfo />}></Route> + <Route path="/homeparticipate/:id" element={<HomeParticipate />}></Route> <Route path="/meetinginfo" element={<MeetingInfo />}></Route> <Route path="/result" element={<ResultMake />}></Route>//寃곌낵�뺤씤�섏씠吏� <Route path="/resultend" element={<ResultEnd />}></Route>// �ы몴 醫낅즺 diff --git a/react-whenMeet/src/components/HomeMakeForm.js b/react-whenMeet/src/components/HomeMakeForm.js index 7e7c8f4daf71d22d9fad5bc83ee854bc64a96d0f..315b9fd7c21cb9026b0d2fa4283d2fbe8fdd8cdc 100644 --- a/react-whenMeet/src/components/HomeMakeForm.js +++ b/react-whenMeet/src/components/HomeMakeForm.js @@ -23,7 +23,7 @@ function HomeMakeForm() { } else if (password === "") { return alert("Password瑜� �낅젰�섏꽭��"); } else { - navigate("/MeetingInfo"); + navigate("/MeetingInfo", {state : {title, password}}); } }; diff --git a/react-whenMeet/src/components/HomeParticipateForm.js b/react-whenMeet/src/components/HomeParticipateForm.js index 860dd7c7e134ca7cea5af32db7cae45409bb727f..8353487abb06cbdfea5b88df66b82ff2e63ebba3 100644 --- a/react-whenMeet/src/components/HomeParticipateForm.js +++ b/react-whenMeet/src/components/HomeParticipateForm.js @@ -1,55 +1,124 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import Input from "./Input"; import Button from "./Button"; -import { useNavigate } from "react-router-dom"; +import { useNavigate, useLocation } from "react-router-dom"; +import axios from "axios"; function HomeParticipateForm() { - const [name,setName] = useState(""); - const [password,setPassword] = useState(""); - const [email,setEmail] = useState(""); + const [name, setName] = useState(""); + const [password, setPassword] = useState(""); + const [email, setEmail] = useState(""); const navigate = useNavigate(); + const location = useLocation(); + const { id } = location.state; - const handleName = (event)=>{ + const handleName = (event) => { setName(event.target.value); } - const handlePassword = (event)=>{ + const handlePassword = (event) => { setPassword(event.target.value); } - const handleEmail = (event)=>{ + const handleEmail = (event) => { setEmail(event.target.value); } + const checkParticipantExistence = async()=>{ + const response = await axios.get(`http://43.200.79.42:3000/meetings/${id}/participants/?name=${name}`); + if(response.data){ + alert('�대� 議댁옱�섎뒗 �대쫫�낅땲��.') + } + return response.data.name; + } - const handleSubmit = (event) => { + const newHandleSubmit = async (event) => { + event.preventDefault(); + if (name === "") { + alert('�대쫫�� �낅젰�섏꽭��') + } + else { + try { + const response = await axios.post(`http://43.200.79.42:3000/meetings/${id}/participants`, { + name: name, + password: password, + email: email + }); + navigate('UserTimeInfo', { state: { id } }); + } + catch (error) { + console.error(error); + } + } + }; + const oldHandleSubmit = async (event) => { event.preventDefault(); - name === "" ? alert('�대쫫�� �낅젰�섏꽭��') : navigate('UserTimeInfo'); + if (name === "") { + alert('�대쫫�� �낅젰�섏꽭��') + } + else { + try { + const response = await axios.post(`http://43.200.79.42:3000/meetings/${id}/entry`,{ + name : name, + password : password + }); + if(response.status === 401 ){ + alert('�대쫫 �먮뒗 Password瑜� �섎せ �낅젰�섏��듬땲��'); + return; + } + else if(response.status === 404){ + alert('�쇱튂�섎뒗 李멸��먭� 議댁옱�섏� �딆뒿�덈떎'); + return; + } + //navigate('UserTimeInfo', { state: { id } }); + } + catch (error) { + if (error.response) { + if (error.response.status === 401) { + alert('�대쫫 �먮뒗 Password瑜� �섎せ �낅젰�섏��듬땲��'); + } else if (error.response.status === 404) { + alert('�쇱튂�섎뒗 李멸��먭� 議댁옱�섏� �딆뒿�덈떎'); + } else { + alert(`Unexpected status code: ${error.response.status}`); + } + } else { + // Handle other types of errors + console.error(error); + } + + } + } }; return ( <form> <div> - <h1>�쎌냽 Title</h1> - <Input - type="text" - value={name} - onChange={handleName} - placeholder="�대쫫" + <h1>�ы몴�� 李몄뿬�섍린</h1> + {console.log({id})} + <Input + type="text" + value={name} + onChange={handleName} + placeholder="�대쫫" /> - <Input - type="password" - value={password} - onChange={handlePassword} - placeholder="Password(�좏깮)" + <Input + type="password" + value={password} + onChange={handlePassword} + placeholder="Password" /> - <Input - type="text" - value={email} - onChange={handleEmail} - placeholder="�대찓��(�좏깮)" + <Input + type="text" + value={email} + onChange={handleEmail} + placeholder="�대찓��(�좏깮)" + /> + <Button + type='submit' + text='�좉퇋李몄뿬' + onClick={newHandleSubmit} /> <Button - type='submit' - text='�ㅼ쓬' - onClick={handleSubmit} + type='submit' + text='�ъ갭��' + onClick={oldHandleSubmit} /> </div> </form> diff --git a/react-whenMeet/src/components/LinkPageForm.js b/react-whenMeet/src/components/LinkPageForm.js index 45edc9acae93e484abe45d5ea75eb67ce3a8394a..c676b0cf6a97cf72c70d7e4531cc265876fa81b1 100644 --- a/react-whenMeet/src/components/LinkPageForm.js +++ b/react-whenMeet/src/components/LinkPageForm.js @@ -1,15 +1,19 @@ import { useState } from "react"; import Input from "../components/Input"; import Button from "../components/Button"; -import { useNavigate } from "react-router-dom"; +import { useNavigate,useLocation } from "react-router-dom"; +import axios from "axios"; function LinkPageForm() { const [link, setLink] = useState(""); + const location = useLocation(); const navigate = useNavigate(); + const {id} = location.state; + const copyToClipboard = async (link) => { try { - const textToCopy = `localhost:3000/HomeParticipate`; + const textToCopy = `localhost:3000/HomeParticipate/${id}`; await navigator.clipboard.writeText(textToCopy); alert('�대┰蹂대뱶�� 蹂듭궗�섏뿀�듬땲��'); } catch (err) { @@ -17,17 +21,17 @@ function LinkPageForm() { } }; - const handleSubmit = (event) => { + const handleSubmit = async(event) => { event.preventDefault(); - setLink(`/HomeParticipate`) - navigate(link); + console.log({id}); + navigate(`/HomeParticipate/${id}`,{state : {id}}); } return ( <form onSubmit={handleSubmit}> <div> <Input - value={`localhost:3000/HomeParticipate/`} + value={`localhost:3000/HomeParticipate/${id}`} /> <Button type="button" diff --git a/react-whenMeet/src/components/MeetingInfoForm.js b/react-whenMeet/src/components/MeetingInfoForm.js index 38fcec877bb49cbdfde4826ed786ac7fef1b8663..a9cee2401dafe374e03f228eef87fc59efb855e3 100644 --- a/react-whenMeet/src/components/MeetingInfoForm.js +++ b/react-whenMeet/src/components/MeetingInfoForm.js @@ -2,7 +2,8 @@ import { useState } from "react"; import Input from "../components/Input"; import Button from "../components/Button"; import Calendar from "../components/Calendar"; -import { useNavigate } from "react-router-dom"; +import { useNavigate, useLocation } from "react-router-dom"; +import axios from "axios"; function MeetingInfoForm() { const [meetingPurpose, setMeetingPurpose] = useState(""); @@ -18,6 +19,8 @@ function MeetingInfoForm() { '湲고�' ]; const navigate = useNavigate(); + const location = useLocation(); + const { title, password } = location.state; const [usingDate, setUsingDate] = useState([]); @@ -45,11 +48,29 @@ function MeetingInfoForm() { setEnd(event.target.value); } - const handleSubmit = (event) => { + const handleSubmit = async (event) => { event.preventDefault(); - console.log(usingDate); - (meetingPurpose === "" || meetingPurpose === "�좏깮") ? alert("紐⑹쟻�� �좏깮�섏꽭��") : navigate("LinkPage"); - } + + if (meetingPurpose === "" || meetingPurpose === "�좏깮") { + alert("紐⑹쟻�� �좏깮�섏꽭��"); + } else { + try { + const response = await axios.post("http://43.200.79.42:3000/meetings", { + title: title, + adminPassword: password, + purpose: meetingPurpose, + startDate: start, + endDate: end, + maxParticipants: number, + voteExpiresAt: endVote + }); + const id = response.data.id; + navigate("LinkPage",{state : {id}}); + } catch (error) { + console.error("Error sending data to the backEnd", error); + } + } + }; return ( <form onSubmit={handleSubmit}> @@ -66,18 +87,18 @@ function MeetingInfoForm() { </label> </div> - <Calendar onChange={handleCalendar} usingDate={usingDate} setUsingDate={setUsingDate}/> + <Calendar onChange={handleCalendar} usingDate={usingDate} setUsingDate={setUsingDate} /> <div className="timeStartEnd"> �쒖옉: <Input - type="time" + type="date" value={start} onChange={handleStart} placeholder="�쒖옉" /> 醫낅즺: <Input - type="time" + type="date" value={end} onChange={handleEnd} placeholder="醫낅즺" diff --git a/react-whenMeet/src/routes/UserTimeInfo.js b/react-whenMeet/src/routes/UserTimeInfo.js index 4acb39d9961802fe469657dcaa9cc8b0b987a301..3b09b48ca2212336556b7e49dd9c5138f52f2348 100644 --- a/react-whenMeet/src/routes/UserTimeInfo.js +++ b/react-whenMeet/src/routes/UserTimeInfo.js @@ -1,19 +1,37 @@ -import { useState } from "react"; +import { useState,useEffect } from "react"; import Button from "../components/Button"; import CalendarWeek2 from "../components/CalendarWeek2" import "../styles/HomeMake.css" +import axios from "axios"; +import { useNavigate, useLocation } from "react-router-dom"; function UserTimeInfo() { const [state, setState] = useState(true); const [availableSchedules, setAvailableSchedules] = useState([]); const [availableTimes, setAvailableTimes] = useState([]); + + const location = useLocation(); + const {id} = location.state; + const handleState = () => { setState((state) => !state); } const handleCalendar = (value) => { console.log('Selected Date:', value); }; + + useEffect(() => { + const fetchData = async () => { + try { + const response = await axios.get(`http://43.200.79.42:3000/meetings/${id}/`); + console.log(response.data.title); + } catch (error) { + console.error(error); + } + }; + fetchData(); + }, [id]); const handleAlert = () => { let sat = [...availableTimes].sort(); @@ -55,8 +73,6 @@ function UserTimeInfo() { return availableTimes.includes(value); } - - return ( <div className="center-container"> <Button