SurveyCard.tsx 1.67 KB
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React from "react";
import { Link } from "react-router-dom";
import { ISurvey } from "../types";
import { DuplicateIcon } from "../icons";

type Props = {
  survey: ISurvey;
  handleDelete: (id: string) => Promise<void>;
};

export const SurveyCard = ({ survey, handleDelete }: Props) => {
  const copyLink = async () => {
    await navigator.clipboard.writeText(
      `http://localhost:8080/answers/${survey._id}`
    );
    alert("설문조사의 링크가 클립보드에 저장되었습니다.");
  };

  const onDelete = async () => {
    survey._id && (await handleDelete(survey._id));
  };

  return (
    <div className="w-40 h-48 md:w-52 md:h-60 rounded border-2 hover:border-2 hover:border-themeColor">
Yoon, Daeki's avatar
Yoon, Daeki committed
25
      <Link to={`${survey._id}`} state={survey} className="w-full pt-1">
Yoon, Daeki's avatar
Yoon, Daeki committed
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
        <p className="font-bold">
          {survey.title ? survey.title : "제목없는 설문조사"}
        </p>

        <div className="h-24 md:h-36 p-3 overflow-y-hidden hover:overflow-y-auto">
          <p className="text-gray-700 text-justify">
            {survey.comment ? survey.comment : "설명없는 설문조사"}
          </p>
        </div>
        <p className="text-gray-500 text-sm">
          {survey.updatedAt?.substring(0, 10)}
        </p>
      </Link>
      <div className="flex justify-end pt-1 pr-1">
        <button className="flex place-self-center" onClick={copyLink}>
          링크복사
          <DuplicateIcon className="w-7 h-7" />
        </button>
        <button
          type="button"
          className="bg-themeColor rounded text-white py-1 px-1.5 ml-1 mr-1.5"
          onClick={onDelete}
        >
          삭제
        </button>
      </div>
    </div>
  );
};