From 33f2b5ef62aeffbb8a66a507f49a6876be4ce923 Mon Sep 17 00:00:00 2001 From: Tatiana Nikolaeva Date: Mon, 26 May 2025 10:11:53 +0500 Subject: [PATCH] fix surveyInfo --- SurveyFrontend/src/api/SurveyApi.ts | 1 + .../components/MySurveyList/MySurveyList.tsx | 13 ++++- .../src/components/Results/Results.tsx | 18 ++++--- .../SettingSurvey/SettingSurvey.module.css | 1 + .../SettingSurvey/SettingSurvey.tsx | 48 +++++-------------- .../src/components/SurveyInfo/SurveyInfo.tsx | 4 +- .../src/components/SurveyPage/SurveyPage.tsx | 33 ++++++++----- .../SurveyCreateAndEditingPage.tsx | 35 +++++++++++++- 8 files changed, 91 insertions(+), 62 deletions(-) diff --git a/SurveyFrontend/src/api/SurveyApi.ts b/SurveyFrontend/src/api/SurveyApi.ts index d182347..4c20c73 100644 --- a/SurveyFrontend/src/api/SurveyApi.ts +++ b/SurveyFrontend/src/api/SurveyApi.ts @@ -5,6 +5,7 @@ export interface ISurvey { title: string; description: string; createdBy: number; + createdAt: string; } export interface INewSurvey{ diff --git a/SurveyFrontend/src/components/MySurveyList/MySurveyList.tsx b/SurveyFrontend/src/components/MySurveyList/MySurveyList.tsx index 6fa3d1a..8083640 100644 --- a/SurveyFrontend/src/components/MySurveyList/MySurveyList.tsx +++ b/SurveyFrontend/src/components/MySurveyList/MySurveyList.tsx @@ -13,6 +13,17 @@ export const MySurveyList = () => { const navigate = useNavigate(); const [surveys, setSurveys] = useState([]); + const formatDate = (dateString: string) => { + const date = new Date(dateString); + const day = String(date.getDate()).padStart(2, '0'); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const year = date.getFullYear(); + const hours = String(date.getHours()).padStart(2, '0'); + const minutes = String(date.getMinutes()).padStart(2, '0'); + + return `${day}/${month}/${year} ${hours}:${minutes}`; + }; + useEffect(() => { const fetchSurvey = async () => { try { @@ -63,7 +74,7 @@ export const MySurveyList = () => {

{survey.title}

{survey.description}

- Дата создания: {survey.createdBy} + Дата создания: {formatDate(survey.createdAt)}
{ - const [descriptionSurvey, setDescriptionSurvey] = useState(''); - const [titleSurvey, setTitleSurvey] = useState('Название опроса'); + + const { survey, setSurvey } = useOutletContext<{ + survey: ISurvey; + setSurvey: (survey: ISurvey) => void; + }>(); return(
setSurvey({ ...survey, description: value })} + setTitleSurvey={(value) => setSurvey({ ...survey, title: value })} />
) diff --git a/SurveyFrontend/src/components/SettingSurvey/SettingSurvey.module.css b/SurveyFrontend/src/components/SettingSurvey/SettingSurvey.module.css index 055808d..fd5b485 100644 --- a/SurveyFrontend/src/components/SettingSurvey/SettingSurvey.module.css +++ b/SurveyFrontend/src/components/SettingSurvey/SettingSurvey.module.css @@ -2,6 +2,7 @@ .settingSurvey{ width: 85%; + height: 100vh; } .startEndTime{ diff --git a/SurveyFrontend/src/components/SettingSurvey/SettingSurvey.tsx b/SurveyFrontend/src/components/SettingSurvey/SettingSurvey.tsx index a01c61c..bec8a4c 100644 --- a/SurveyFrontend/src/components/SettingSurvey/SettingSurvey.tsx +++ b/SurveyFrontend/src/components/SettingSurvey/SettingSurvey.tsx @@ -1,51 +1,25 @@ -import React, {useState} from 'react'; +import React from 'react'; import SurveyInfo from "../SurveyInfo/SurveyInfo.tsx"; import styles from "./SettingSurvey.module.css"; import TimeEvent from "../TimeEvent/TimeEvent.tsx"; import SaveButton from "../SaveButton/SaveButton.tsx"; -// import {useParams} from "react-router-dom"; -// import {getSurveyById, ISurvey} from "../../api/SurveyApi.ts"; +import {ISurvey} from "../../api/SurveyApi.ts"; +import {useOutletContext} from "react-router-dom"; const SettingSurvey: React.FC = () => { - const [descriptionSurvey, setDescriptionSurvey] = useState(''); - // const [survey, setSurvey] = useState(null); - const [titleSurvey, setTitleSurvey] = useState(''); - // const { surveyId } = useParams<{ surveyId: string }>(); - - // useEffect(() => { - // if (!surveyId) { - // console.error('Survey ID is missing'); - // return; - // } - // const id = parseInt(surveyId); - // if (isNaN(id)) { - // console.error('Invalid survey ID'); - // return; - // } - // - // const fetchData = async () => { - // try { - // const surveyData = await getSurveyById(id); - // setSurvey(surveyData); - // setTitleSurvey(surveyData.title); - // setDescriptionSurvey(surveyData.description); - // } catch (error) { - // console.error('Ошибка:', error); - // } - // }; - // - // fetchData(); - // - // }, [surveyId]); + const { survey, setSurvey } = useOutletContext<{ + survey: ISurvey; + setSurvey: (survey: ISurvey) => void; + }>(); return (
setSurvey({ ...survey, description: value })} + setTitleSurvey={(value) => setSurvey({ ...survey, title: value })} />
diff --git a/SurveyFrontend/src/components/SurveyInfo/SurveyInfo.tsx b/SurveyFrontend/src/components/SurveyInfo/SurveyInfo.tsx index 57e04c1..3ce15ff 100644 --- a/SurveyFrontend/src/components/SurveyInfo/SurveyInfo.tsx +++ b/SurveyFrontend/src/components/SurveyInfo/SurveyInfo.tsx @@ -88,7 +88,7 @@ const SurveyInfo: React.FC = ({titleSurvey, setDescriptionSurve } const renderTitle = () => { - if (isSurveyViewPage || isCompleteSurveyActive) { + if (isCompleteSurveyActive) { return (