import React, { useEffect, useState } from "react"; import { answerApi, surveyApi } from "../apis"; import { catchErrors } from "../helpers"; import { Accordion } from "./Accordion"; import { useParams } from "react-router-dom"; import { ISurvey } from "../types"; export const ResultSurvey = () => { let { surveyId } = useParams<{ surveyId: string }>(); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const [survey, setSurvey] = useState({ _id: surveyId || "", user: {}, title: "", comment: "", questions: [], }); useEffect(() => { getAnswers(); }, [surveyId]); async function getAnswers() { try { if (surveyId) { const survey = await answerApi.getAnswers(surveyId); // console.log(survey); setSurvey(survey); } else { setLoading(true); } } catch (error) { catchErrors(error, setError); } finally { setLoading(false); } } return (
{survey.title}
{survey.comment}
{survey.questions.map((question) => ( ))}
); }; export default ResultSurvey;