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/${data._id}/edit`, { replace: true, }); }; const goSurvey = () => { navigate(`/surveys/${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 (
{/**/}
); };