Profile.tsx 1.73 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 "./MySurveyCard";
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
  const [cardDatas, setCardDatas] = useState<SurveyType[]>([]);

  useEffect(() => {
    getSurveys();
24
25
  }, []);

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

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

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