import React, { useState, useEffect } from 'react'; import Layout from "../../../components/layout"; import { GetServerSideProps } from 'next'; import { Location, UserRole } from "@prisma/client"; import axiosServer from '../../../src/axiosServer'; const common = require('../../../src/helpers/common'); // import * as common from '../../../src/helpers/common'; import SurveyForm from '../../../components/survey/SurveyForm'; import _ from 'lodash'; const SurveyPage = ({ serverSurveys }) => { const [selectedSurvey, setSelectedSurvey] = useState(null); return (

Анкети

Списък

    {serverSurveys.map((survey) => (
  • {survey.id}: {survey.content}

    {/*

    {survey.publicFrom} - {survey.publicUntil}

    */}

    [{survey.answers}]

    {Object.entries(_.groupBy(survey.messages, message => message.answer || "Без отговор")).map(([key, items]) => (
    {key}: {items.length}
    ))}
  • ))}

Детайли

{/*

Selected Survey

{selectedSurvey ? (

{selectedSurvey.title}

{selectedSurvey.description}

) : (

No survey selected.

)}
*/}
); }; export default SurveyPage; export const getServerSideProps: GetServerSideProps = async (context) => { const prisma = common.getPrismaClient(); let serverSurveys = await prisma.survey.findMany({ where: { }, include: { messages: true, }, }); serverSurveys = common.convertDatesToISOStrings(serverSurveys); context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate"); return { props: { serverSurveys: serverSurveys }, }; };