ModifySurveyView.tsx 1.77 KB
Newer Older
1
2
3
4
5
6
7
import React, { ChangeEvent, FormEvent, useState } from "react";
import { useNavigate } from "react-router-dom";
import { catchErrors } from "../helpers";
import { SpinnerIcon } from "../icons";
import { CreateQuestionData, ISurvey } from "../types";
import { QuestionsList } from "./QuestionsList";
import { SurveyTitle } from "./SurveyTitle";
8
import { SurveyTitleAndComment } from "./SurveyTitleAndComment";
9
10
11
12
13
14
15

type Props = {
  questions: CreateQuestionData[];
  survey: ISurvey;
  addQuestion: () => void;
  deleteQuestion: (id: string) => void;
  handleQuestion: (question: CreateQuestionData) => void;
16
  handleTitleComment: Function;
17
18
19
20
21
22
23
24
};

export const ModifySurveyView = ({
  questions,
  survey,
  addQuestion,
  deleteQuestion,
  handleQuestion,
25
  handleTitleComment,
26
}: Props) => {
27
28
29
30
31
32
33
34
35
36
  const [error, setError] = useState("");
  const [loading, setLoading] = useState(false);

  return (
    <>
      {loading && (
        <SpinnerIcon className="animate-spin h-5 w-5 mr-1 text-slate" />
      )}
      <form>
        <div className="flex flex-col place-items-center">
37
38
39
40
41
          <SurveyTitleAndComment
            title={survey.title}
            comment={survey.comment}
            handleTitleComment={handleTitleComment}
          />
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
          <QuestionsList
            questions={questions}
            handleQuestion={handleQuestion}
            deleteQuestion={deleteQuestion}
          />
          <button
            type="button"
            onClick={addQuestion}
            className="flex w-4/5 content-center justify-center border-2 border-black h-8 mt-3"
          >
            질문 추가
          </button>
          {error && (
            <div className="text-red-500 text-sm mt-3">
              <p>{error}</p>
            </div>
          )}
        </div>
      </form>
    </>
  );
};