diff --git a/src/features/surveys/features/SurveyDisplay/components/AnswersComponent/EmojiListItem/EmojiListItem.tsx b/src/features/surveys/features/SurveyDisplay/components/AnswersComponent/EmojiListItem/EmojiListItem.tsx index 11385839..daf2628e 100644 --- a/src/features/surveys/features/SurveyDisplay/components/AnswersComponent/EmojiListItem/EmojiListItem.tsx +++ b/src/features/surveys/features/SurveyDisplay/components/AnswersComponent/EmojiListItem/EmojiListItem.tsx @@ -5,12 +5,12 @@ interface EmojiListItemProps { icon: string; selected?: boolean; isAnySelected?: boolean; - onClick: (icon: string) => void; + onClick?: (icon: string) => void; } function EmojiListItem({ icon, - onClick, + onClick = () => undefined, isAnySelected, selected = false, }: EmojiListItemProps) { diff --git a/src/features/surveys/features/SurveyDisplay/components/AnswersComponent/RateComponent/StarComponent/StarComponent.tsx b/src/features/surveys/features/SurveyDisplay/components/AnswersComponent/RateComponent/StarComponent/StarComponent.tsx index 15eaaf9f..2a08e5e2 100644 --- a/src/features/surveys/features/SurveyDisplay/components/AnswersComponent/RateComponent/StarComponent/StarComponent.tsx +++ b/src/features/surveys/features/SurveyDisplay/components/AnswersComponent/RateComponent/StarComponent/StarComponent.tsx @@ -3,9 +3,9 @@ import React from 'react'; interface StarComponentProps { classNames?: string; - onMouseEnter: () => void; - onMouseLeave: () => void; - onClick: () => void; + onMouseEnter?: () => void; + onMouseLeave?: () => void; + onClick?: () => void; } export default function StarComponent({ diff --git a/src/features/surveys/features/SurveyResults/components/IndividualResults/IndividualResults.tsx b/src/features/surveys/features/SurveyResults/components/IndividualResults/IndividualResults.tsx index 57c4b841..7595b765 100644 --- a/src/features/surveys/features/SurveyResults/components/IndividualResults/IndividualResults.tsx +++ b/src/features/surveys/features/SurveyResults/components/IndividualResults/IndividualResults.tsx @@ -1,5 +1,137 @@ -import React from 'react'; +import React, { useState } from 'react'; +import { useSurveyResultsContext } from 'features/surveys/features/SurveyResults/managers/context'; +import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/outline'; +import Button, { ButtonVariant } from 'shared/components/Button/Button'; +import Input, { InputSize } from 'shared/components/Input/Input'; +import { QuestionType } from '@prisma/client'; +import EmojiListItem from 'features/surveys/features/SurveyDisplay/components/AnswersComponent/EmojiListItem/EmojiListItem'; +import StarComponent from 'features/surveys/features/SurveyDisplay/components/AnswersComponent/RateComponent/StarComponent/StarComponent'; +import clsx from 'clsx'; export default function IndividualResults() { - return
To be implemented
; + const { mappedAnswersData, surveyData } = useSurveyResultsContext(); + const [currentIndex, setCurrentIndex] = useState(0); + const totalAnswers = surveyData?.answers.length || 0; + + const handlePrevious = () => { + setCurrentIndex((prevIndex) => Math.max(prevIndex - 1, 0)); + }; + + const handleNext = () => { + setCurrentIndex((prevIndex) => Math.min(prevIndex + 1, totalAnswers - 1)); + }; + + const handleInputChange = (e: React.ChangeEvent) => { + const newValue = parseInt(e.target.value) - 1; + if (newValue >= 0 && newValue < totalAnswers) { + setCurrentIndex(newValue); + } + }; + + if (totalAnswers <= 0) { + return <>; + } + + return ( +
+
+
+ + {Object.keys(mappedAnswersData).map((key, index) => { + const questionData = surveyData?.questions[index]; + const question = mappedAnswersData[key].question; + const questionType = mappedAnswersData[key].questionType; + const answer = mappedAnswersData[key].answers[currentIndex].answer; + + return ( +
+

{question}

+ {questionType === QuestionType.INPUT &&

{answer}

} + +
+ {questionType === QuestionType.RATE && + [...Array(5)].map((_, index) => ( + + ))} +
+ + {questionType === QuestionType.CHOICE && + questionData?.options.map((option, idx) => ( + + ))} + +
+ {questionType === QuestionType.EMOJI && + questionData?.options.map((icon, idx) => ( + + ))} +
+
+ ); + })} +
+ ); }