SurveyPage.js
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { useState, useEffect } from "react";
import Card from "../components/card/Card";
import ProgressBar from "../components/progressbar/ProgressBar";
import axios from 'axios';
import "./SurveyPage.scss";
function SurveyPage({history}) {
const [curIdx, setCurIdx] = useState(0);
const [question, setQuestion] = useState([]);
const [answer, setAnswer] = useState([]);
const [respond, setRespond] = useState([]);
useEffect(()=>{
const getApi = async() =>{
const {data} = await axios.get("getquestions");
setQuestion(data);
// console.log(question);
}
getApi();
},[]);
useEffect(()=>{
if(curIdx === 10){
const postApi = async ()=>{
const {data} = await axios.post("submit", answer);
console.log(data);
setRespond(data);
}
postApi();
history.push('/result');
}
},[curIdx]);
return (
<div className="container">
<div className="container__progress">
<ProgressBar percent={curIdx*10} />
</div>
<div className="slider">
{question && question.map((question,index) => (
<div className="slider__wrapper">
<Card
key={question.num}
question={question}
answer={answer}
setAnswer={setAnswer}
curIdx={curIdx}
setCurIdx={setCurIdx}
style={{
transform: `translateX(${(-30)*curIdx}rem)`,
transition: "0.5s",
}}
/>
</div>
))}
</div>
</div>
);
}
export default SurveyPage;