import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; import { surveyApi } from "../apis"; import { SurveyType } from "../types"; import { catchErrors } from "../helpers"; 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/edit/${data._id}`, { replace: true, }); }; async function deleteSurvey() { try { if (data._id) { const survey = await surveyApi.deleteSurvey(data._id); setSuccess(true); setError(""); location.reload(); } else { setLoading(true); } } catch (error) { console.log("에러발생"); catchErrors(error, setError); } finally { setLoading(false); } } return (
{data.comment ? data.comment : "설명없는 설문조사"}
{data.title ? data.title : "제목없는 설문조사"}
{data.updatedAt?.substring(0, 10)}