import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; import { surveyApi } from "../apis"; import { SurveyType } from "../types"; import { catchErrors } from "../helpers"; import { DuplicateIcon } from "../icons"; type Props = { data: SurveyType; }; export const MySurveyCard = ({ data }: Props) => { const navigate = useNavigate(); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const editSurvey = () => { navigate(`/surveys/${data._id}/edit`, { replace: true, state: { save: true }, }); }; const copyLink = () => { navigator.clipboard.writeText(`http://localhost:8080/survey/${data._id}`); alert("설문조사의 링크가 클립보드에 저장되었습니다."); }; async function deleteSurvey() { if (window.confirm("해당 설문조사를 삭제하시겠습니까?")) { try { if (data._id) { const survey = await surveyApi.deleteSurvey(data._id); setSuccess(true); setError(""); alert("삭제되었습니다."); location.reload(); } else { setLoading(true); } } catch (error) { console.log("에러발생"); catchErrors(error, setError); } finally { setLoading(false); } } else { alert("삭제를 취소합니다."); } } return (