forked from Ryczko/FormsLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
149 additions
and
204 deletions.
There are no files selected for viewing
51 changes: 6 additions & 45 deletions
51
src/features/surveys/features/SurveyDisplay/SurveyDisplay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,19 @@ | ||
import React from 'react'; | ||
import { SurveyWithQuestions } from 'types/SurveyWithQuestions'; | ||
import { useSurveyAnswerManager } from 'features/surveys/features/SurveyDisplay/managers/surveyAnswerManager'; | ||
import useTranslation from 'next-translate/useTranslation'; | ||
import AllQuestionsView from 'features/surveys/features/SurveyDisplay/components/AllQuestionsView/AllQuestionsView'; | ||
import OneQuestionView from 'features/surveys/features/SurveyDisplay/components/OneQuestionView/OneQuestionView'; | ||
import { SurveyDisplayContext } from 'features/surveys/features/SurveyDisplay/context'; | ||
import SurveyDisplayContent from 'features/surveys/features/SurveyDisplay/SurveyDisplayContent'; | ||
|
||
interface SurveyDisplayProps { | ||
initialData: SurveyWithQuestions; | ||
} | ||
|
||
export default function SurveyDisplay({ initialData }: SurveyDisplayProps) { | ||
const { t } = useTranslation('survey'); | ||
|
||
const { | ||
handleAnswerChange, | ||
handleSave, | ||
isAnswering, | ||
formData, | ||
isSubmitted, | ||
activeQuestionIndex, | ||
handleNextQuestion, | ||
handlePreviousQuestion, | ||
} = useSurveyAnswerManager(initialData); | ||
const manager = useSurveyAnswerManager(initialData); | ||
|
||
return ( | ||
<> | ||
<div className="w-full"> | ||
{formData?.isActive ? ( | ||
formData.oneQuestionPerStep ? ( | ||
<OneQuestionView | ||
activeQuestionIndex={activeQuestionIndex} | ||
formData={formData} | ||
handleNextQuestion={handleNextQuestion} | ||
handlePreviousQuestion={handlePreviousQuestion} | ||
isSubmitted={isSubmitted} | ||
handleAnswerChange={handleAnswerChange} | ||
isAnswering={isAnswering} | ||
/> | ||
) : ( | ||
<AllQuestionsView | ||
formData={formData} | ||
handleSave={handleSave} | ||
handleAnswerChange={handleAnswerChange} | ||
isAnswering={isAnswering} | ||
isSubmitted={isSubmitted} | ||
/> | ||
) | ||
) : ( | ||
<> | ||
<div className="text-5xl">🙁</div> | ||
<div className="my-5 text-xl">{t('surveyNoLongerActive')}</div> | ||
</> | ||
)} | ||
</div> | ||
</> | ||
<SurveyDisplayContext.Provider value={manager}> | ||
<SurveyDisplayContent /> | ||
</SurveyDisplayContext.Provider> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/features/surveys/features/SurveyDisplay/SurveyDisplayContent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { useSurveyDisplayContext } from 'features/surveys/features/SurveyDisplay/context'; | ||
import OneQuestionView from 'features/surveys/features/SurveyDisplay/components/OneQuestionView/OneQuestionView'; | ||
import AllQuestionsView from 'features/surveys/features/SurveyDisplay/components/AllQuestionsView/AllQuestionsView'; | ||
import SurveyNoActive from 'features/surveys/features/SurveyDisplay/components/SurveyNoActive/SurveyNoActive'; | ||
|
||
export default function SurveyDisplayContent() { | ||
const { formData } = useSurveyDisplayContext(); | ||
|
||
return ( | ||
<div className="w-full"> | ||
{formData?.isActive ? ( | ||
formData.oneQuestionPerStep ? ( | ||
<OneQuestionView /> | ||
) : ( | ||
<AllQuestionsView /> | ||
) | ||
) : ( | ||
<SurveyNoActive /> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 10 additions & 16 deletions
26
...ys/features/SurveyDisplay/components/AnswersComponent/ChoiceComponent/ChoiceComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 11 additions & 17 deletions
28
...tures/surveys/features/SurveyDisplay/components/AnswersComponent/ListAnswersComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.