From c10854523d6311f6c8382af18827d4484ce94e19 Mon Sep 17 00:00:00 2001 From: ShubhamPalriwala Date: Tue, 29 Aug 2023 19:16:42 +0530 Subject: [PATCH 01/26] fix: it is now not allowed to save/publish a survey with 0 responses --- .../surveys/[surveyId]/edit/SurveyMenuBar.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/SurveyMenuBar.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/SurveyMenuBar.tsx index ecdb222632..11ee0d8789 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/SurveyMenuBar.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/SurveyMenuBar.tsx @@ -94,6 +94,11 @@ export default function SurveyMenuBar({ }; const validateSurvey = (survey) => { + if (localSurvey.questions.length === 0) { + toast.error("Please add at least one question"); + return; + } + faultyQuestions = []; for (let index = 0; index < survey.questions.length; index++) { const question = survey.questions[index]; @@ -125,6 +130,11 @@ export default function SurveyMenuBar({ }; const saveSurveyAction = (shouldNavigateBack = false) => { + if (localSurvey.questions.length === 0) { + toast.error("Please add at least one question"); + return; + } + // variable named strippedSurvey that is a copy of localSurvey with isDraft removed from every question const strippedSurvey = { ...localSurvey, From 6dfc75a4ce0cb5d98723bff4d337be9176363ec9 Mon Sep 17 00:00:00 2001 From: ShubhamPalriwala Date: Tue, 29 Aug 2023 19:42:17 +0530 Subject: [PATCH 02/26] fix: consent question's checkbox should now have some text or default text mandatory --- .../[environmentId]/surveys/[surveyId]/edit/Validation.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/Validation.ts b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/Validation.ts index b11dc523e0..35261f0017 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/Validation.ts +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/Validation.ts @@ -1,6 +1,7 @@ // extend this object in order to add more validation rules import { + ConsentQuestion, MultipleChoiceMultiQuestion, MultipleChoiceSingleQuestion, Question, @@ -13,6 +14,9 @@ const validationRules = { multipleChoiceSingle: (question: MultipleChoiceSingleQuestion) => { return !question.choices.some((element) => element.label.trim() === ""); }, + consent: (question: ConsentQuestion) => { + return question.label.trim() !== ""; + }, defaultValidation: (question: Question) => { return question.headline.trim() !== ""; }, From 00494a709362caf3168822463bc3fba6252c8464 Mon Sep 17 00:00:00 2001 From: ShubhamPalriwala Date: Tue, 29 Aug 2023 23:08:09 +0530 Subject: [PATCH 03/26] fix: multi option single choose can now not have same options --- .../[surveyId]/edit/MultipleChoiceSingleForm.tsx | 10 +++++++++- .../surveys/[surveyId]/edit/Validation.ts | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceSingleForm.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceSingleForm.tsx index bf8b42ac61..e6d5cbc19d 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceSingleForm.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/MultipleChoiceSingleForm.tsx @@ -199,7 +199,15 @@ export default function MultipleChoiceSingleForm({ className={cn(choice.id === "other" && "border-dashed")} placeholder={choice.id === "other" ? "Other" : `Option ${choiceIdx + 1}`} onChange={(e) => updateChoice(choiceIdx, { label: e.target.value })} - isInvalid={isInValid && choice.label.trim() === ""} + isInvalid={ + isInValid && + (choice.label.trim() === "" || + question.choices.some((element, index) => + question.choices + .slice(index + 1) + .some((nextElement) => nextElement.label.trim() === element.label.trim()) + )) + } /> {question.choices && question.choices.length > 2 && ( element.label.trim() === ""); }, multipleChoiceSingle: (question: MultipleChoiceSingleQuestion) => { - return !question.choices.some((element) => element.label.trim() === ""); + return !( + question.choices.some((element) => element.label.trim() === "") || + question.choices.some((element, index) => + question.choices + .slice(index + 1) + .some((nextElement) => nextElement.label.trim() === element.label.trim()) + ) + ); }, consent: (question: ConsentQuestion) => { return question.label.trim() !== ""; From b7d4885e5171f8f87e88b011ba08ecdd713eb0f0 Mon Sep 17 00:00:00 2001 From: ShubhamPalriwala Date: Wed, 30 Aug 2023 13:11:24 +0530 Subject: [PATCH 04/26] fix: long single word was overflowing the thank you card --- apps/web/components/preview/Subheader.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/components/preview/Subheader.tsx b/apps/web/components/preview/Subheader.tsx index 030f911090..84bfe4640f 100644 --- a/apps/web/components/preview/Subheader.tsx +++ b/apps/web/components/preview/Subheader.tsx @@ -1,6 +1,6 @@ export default function Subheader({ subheader, questionId }: { subheader?: string; questionId: string }) { return ( -