Profile.tsx 1.69 KB
Newer Older
1
import React, { useEffect, useState } from "react";
2
import { useNavigate } from "react-router-dom";
Jiwon Yoon's avatar
Jiwon Yoon committed
3
4
import { surveyApi } from "../apis";
import { SurveyType } from "../types";
5
import { MySurveyCard } from "./MySurvey";
Yoon, Daeki's avatar
Yoon, Daeki committed
6

7
8
9
10
11
const testData = [
  { id: 0, name: "이름1", description: "설명1" },
  { id: 1, name: "이름2", description: "설명2" },
  { id: 2, name: "이름3", description: "설명3" },
];
Yoon, Daeki's avatar
Yoon, Daeki committed
12
export const Profile = () => {
13
  const navigate = useNavigate();
Jiwon Yoon's avatar
Jiwon Yoon committed
14
15
16
17
18
19
  const [survey, setSurvey] = useState<SurveyType>({
    user: {},
    title: "",
    comment: "",
    questions: [],
  });
20
21
22
23
24
  const [cardDatas, setCardDatas] = useState<SurveyType[]>([]);

  useEffect(() => {
    getSurveys();
  }, [cardDatas]);
Jiwon Yoon's avatar
Jiwon Yoon committed
25
26
27
28
29
30
  async function createSurvey() {
    const newSurvey: SurveyType = await surveyApi.createSurvey(survey);
    navigate(`/surveys/edit/${newSurvey._id}`, {
      replace: true,
    });
  }
31

32
33
34
35
36
37
  async function getSurveys() {
    const surveys: SurveyType[] = await surveyApi.getSurveys();
    setCardDatas(surveys);
  }
  // let surveys = getSurvey(_id);

Lee SeoYeon's avatar
Lee SeoYeon committed
38
  return (
Lee SeoYeon's avatar
0708    
Lee SeoYeon committed
39
40
    <div className="flex flex-col items-center">
      <div className="m-5">나의 설문조사</div>
jang dong hyeok's avatar
.    
jang dong hyeok committed
41
      <div className="flex space-x-4 mt-5">
42
43
        <button
          onClick={createSurvey}
Lee SeoYeon's avatar
Lee SeoYeon committed
44
45
46
47
48
          className="flex h-60 w-48 items-center border-2 border-themeColor font-bold bg-gray-200 hover:bg-themeColor rounded-lg "
        >
          <div className="text-center px-6 py-6 font-bold text-gray-500 place-items-center hover:text-white">
            CREATE NEW SURVEY!
          </div>
49
        </button>
50
51
52
        {cardDatas.map((data, i) => {
          return <MySurveyCard data={data} key={i} />;
        })}
Lee SeoYeon's avatar
Lee SeoYeon committed
53
54
55
      </div>
    </div>
  );
Yoon, Daeki's avatar
Yoon, Daeki committed
56
};