Skip to content
Snippets Groups Projects
Commit 1449c0a8 authored by Min Dong Hyeun's avatar Min Dong Hyeun
Browse files

[ADD] API

parent 311547f6
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"@testing-library/jest-dom": "^5.17.0", "@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"axios": "^1.6.2",
"gh-pages": "^6.0.0", "gh-pages": "^6.0.0",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
"react": "^18.2.0", "react": "^18.2.0",
...@@ -5362,6 +5363,29 @@ ...@@ -5362,6 +5363,29 @@
"node": ">=4" "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": { "node_modules/axobject-query": {
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz",
...@@ -14606,6 +14630,11 @@ ...@@ -14606,6 +14630,11 @@
"node": ">= 0.10" "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": { "node_modules/psl": {
"version": "1.9.0", "version": "1.9.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.17.0", "@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"axios": "^1.6.2",
"gh-pages": "^6.0.0", "gh-pages": "^6.0.0",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
"react": "^18.2.0", "react": "^18.2.0",
......
...@@ -12,8 +12,8 @@ function App() { ...@@ -12,8 +12,8 @@ function App() {
<Router> <Router>
<Routes> <Routes>
<Route path="/meetinginfo/linkpage" element={<LinkPage />}></Route> <Route path="/meetinginfo/linkpage" element={<LinkPage />}></Route>
<Route path="/homeparticipate/usertimeinfo" element={<UserTimeInfo />}></Route> <Route path="/homeparticipate/:id/usertimeinfo" element={<UserTimeInfo />}></Route>
<Route path="/homeparticipate" element={<HomeParticipate />}></Route> <Route path="/homeparticipate/:id" element={<HomeParticipate />}></Route>
<Route path="/meetinginfo" element={<MeetingInfo />}></Route> <Route path="/meetinginfo" element={<MeetingInfo />}></Route>
<Route path="/result" element={<ResultMake />}></Route>//결과확인페이지 <Route path="/result" element={<ResultMake />}></Route>//결과확인페이지
<Route path="/resultend" element={<ResultEnd />}></Route>// 투표 종료 <Route path="/resultend" element={<ResultEnd />}></Route>// 투표 종료
......
...@@ -23,7 +23,7 @@ function HomeMakeForm() { ...@@ -23,7 +23,7 @@ function HomeMakeForm() {
} else if (password === "") { } else if (password === "") {
return alert("Password를 입력하세요"); return alert("Password를 입력하세요");
} else { } else {
navigate("/MeetingInfo"); navigate("/MeetingInfo", {state : {title, password}});
} }
}; };
......
import { useState } from "react"; import { useState, useEffect } from "react";
import Input from "./Input"; import Input from "./Input";
import Button from "./Button"; import Button from "./Button";
import { useNavigate } from "react-router-dom"; import { useNavigate, useLocation } from "react-router-dom";
import axios from "axios";
function HomeParticipateForm() { function HomeParticipateForm() {
const [name, setName] = useState(""); const [name, setName] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [email, setEmail] = useState(""); const [email, setEmail] = useState("");
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation();
const { id } = location.state;
const handleName = (event) => { const handleName = (event) => {
setName(event.target.value); setName(event.target.value);
...@@ -18,16 +21,77 @@ function HomeParticipateForm() { ...@@ -18,16 +21,77 @@ function HomeParticipateForm() {
const handleEmail = (event) => { const handleEmail = (event) => {
setEmail(event.target.value); 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(); 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 ( return (
<form> <form>
<div> <div>
<h1>약속 Title</h1> <h1>투표에 참여하기</h1>
{console.log({id})}
<Input <Input
type="text" type="text"
value={name} value={name}
...@@ -38,7 +102,7 @@ function HomeParticipateForm() { ...@@ -38,7 +102,7 @@ function HomeParticipateForm() {
type="password" type="password"
value={password} value={password}
onChange={handlePassword} onChange={handlePassword}
placeholder="Password(선택)" placeholder="Password"
/> />
<Input <Input
type="text" type="text"
...@@ -48,8 +112,13 @@ function HomeParticipateForm() { ...@@ -48,8 +112,13 @@ function HomeParticipateForm() {
/> />
<Button <Button
type='submit' type='submit'
text='다음' text='신규참여'
onClick={handleSubmit} onClick={newHandleSubmit}
/>
<Button
type='submit'
text='재참여'
onClick={oldHandleSubmit}
/> />
</div> </div>
</form> </form>
......
import { useState } from "react"; import { useState } from "react";
import Input from "../components/Input"; import Input from "../components/Input";
import Button from "../components/Button"; import Button from "../components/Button";
import { useNavigate } from "react-router-dom"; import { useNavigate,useLocation } from "react-router-dom";
import axios from "axios";
function LinkPageForm() { function LinkPageForm() {
const [link, setLink] = useState(""); const [link, setLink] = useState("");
const location = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
const {id} = location.state;
const copyToClipboard = async (link) => { const copyToClipboard = async (link) => {
try { try {
const textToCopy = `localhost:3000/HomeParticipate`; const textToCopy = `localhost:3000/HomeParticipate/${id}`;
await navigator.clipboard.writeText(textToCopy); await navigator.clipboard.writeText(textToCopy);
alert('클립보드에 복사되었습니다'); alert('클립보드에 복사되었습니다');
} catch (err) { } catch (err) {
...@@ -17,17 +21,17 @@ function LinkPageForm() { ...@@ -17,17 +21,17 @@ function LinkPageForm() {
} }
}; };
const handleSubmit = (event) => { const handleSubmit = async(event) => {
event.preventDefault(); event.preventDefault();
setLink(`/HomeParticipate`) console.log({id});
navigate(link); navigate(`/HomeParticipate/${id}`,{state : {id}});
} }
return ( return (
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<div> <div>
<Input <Input
value={`localhost:3000/HomeParticipate/`} value={`localhost:3000/HomeParticipate/${id}`}
/> />
<Button <Button
type="button" type="button"
......
...@@ -2,7 +2,8 @@ import { useState } from "react"; ...@@ -2,7 +2,8 @@ import { useState } from "react";
import Input from "../components/Input"; import Input from "../components/Input";
import Button from "../components/Button"; import Button from "../components/Button";
import Calendar from "../components/Calendar"; import Calendar from "../components/Calendar";
import { useNavigate } from "react-router-dom"; import { useNavigate, useLocation } from "react-router-dom";
import axios from "axios";
function MeetingInfoForm() { function MeetingInfoForm() {
const [meetingPurpose, setMeetingPurpose] = useState(""); const [meetingPurpose, setMeetingPurpose] = useState("");
...@@ -18,6 +19,8 @@ function MeetingInfoForm() { ...@@ -18,6 +19,8 @@ function MeetingInfoForm() {
'기타' '기타'
]; ];
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation();
const { title, password } = location.state;
const [usingDate, setUsingDate] = useState([]); const [usingDate, setUsingDate] = useState([]);
...@@ -45,11 +48,29 @@ function MeetingInfoForm() { ...@@ -45,11 +48,29 @@ function MeetingInfoForm() {
setEnd(event.target.value); setEnd(event.target.value);
} }
const handleSubmit = (event) => { const handleSubmit = async (event) => {
event.preventDefault(); 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 ( return (
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
...@@ -70,14 +91,14 @@ function MeetingInfoForm() { ...@@ -70,14 +91,14 @@ function MeetingInfoForm() {
<div className="timeStartEnd"> <div className="timeStartEnd">
시작: 시작:
<Input <Input
type="time" type="date"
value={start} value={start}
onChange={handleStart} onChange={handleStart}
placeholder="시작" placeholder="시작"
/> />
종료: 종료:
<Input <Input
type="time" type="date"
value={end} value={end}
onChange={handleEnd} onChange={handleEnd}
placeholder="종료" placeholder="종료"
......
import { useState } from "react"; import { useState,useEffect } from "react";
import Button from "../components/Button"; import Button from "../components/Button";
import Calendar from "../components/Calendar" import Calendar from "../components/Calendar"
import "../styles/HomeMake.css" import "../styles/HomeMake.css"
import axios from "axios";
import { useNavigate, useLocation } from "react-router-dom";
function UserTimeInfo() { function UserTimeInfo() {
const [state, setState] = useState(true); const [state, setState] = useState(true);
const location = useLocation();
const {id} = location.state;
const handleState = () => { const handleState = () => {
setState((state) => !state); setState((state) => !state);
} }
const handleCalendar = (value) => { const handleCalendar = (value) => {
console.log('Selected Date:', 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]);
return ( return (
<div className="center-container"> <div className="center-container">
<Button <Button
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment