Skip to content

Commit

Permalink
Feature/Hide progress bar
Browse files Browse the repository at this point in the history
Co-authored-by: Ryczko <[email protected]>
  • Loading branch information
DevDaniloFerrari and Ryczko authored Jan 28, 2024
1 parent b9c147f commit 9a888cc
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 16 deletions.
3 changes: 2 additions & 1 deletion locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"surveyOptionsModal": {
"title": "Display options",
"OneQuestionPerStep": "One question per step",
"DisplayTitle": "Display title"
"DisplayTitle": "Display title",
"HideProgressBar": "Hide progress bar"
},
"questionType": {
"question": "Question",
Expand Down
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ model Survey {
answers Answer[]
oneQuestionPerStep Boolean
displayTitle Boolean
hideProgressBar Boolean?
accentColor String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ export default function SurveyOptionsModalModal({
title={t('surveyOptionsModal.title')}
content={
<div className="mb-2 mt-4">
<Toggle
isEnabled={surveyOptions.displayTitle}
classNames="gap-2 mb-4"
testId="display-title-toggle"
onToggle={() => {
updateOptions('displayTitle', !surveyOptions.displayTitle);
}}
label={t('surveyOptionsModal.DisplayTitle')}
/>

<hr className="my-4" />

<Toggle
isEnabled={surveyOptions.oneQuestionPerStep}
classNames="gap-2"
Expand All @@ -35,18 +47,28 @@ export default function SurveyOptionsModalModal({
'oneQuestionPerStep',
!surveyOptions.oneQuestionPerStep
);

updateOptions('hideProgressBar', false);
}}
label={t('surveyOptionsModal.OneQuestionPerStep')}
/>
<Toggle
isEnabled={surveyOptions.displayTitle}
classNames="gap-2 mt-4"
testId="display-title-toggle"
onToggle={() => {
updateOptions('displayTitle', !surveyOptions.displayTitle);
}}
label={t('surveyOptionsModal.DisplayTitle')}
/>

{surveyOptions.oneQuestionPerStep ? (
<Toggle
isEnabled={surveyOptions.hideProgressBar}
classNames="gap-2 mt-4"
testId="display-title-toggle"
onToggle={() => {
updateOptions(
'hideProgressBar',
!surveyOptions.hideProgressBar
);
}}
label={t('surveyOptionsModal.HideProgressBar')}
/>
) : (
<></>
)}

<hr className="my-4" />
<div className="flex items-center gap-3 text-sm">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function PreviewPanel() {
id: '',
displayTitle: surveyOptions.displayTitle,
oneQuestionPerStep: surveyOptions.oneQuestionPerStep,
hideProgressBar: surveyOptions.hideProgressBar,
userId: '',
title,
accentColor: surveyOptions.accentColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Question {
export interface SurveyOptions {
oneQuestionPerStep: boolean;
displayTitle: boolean;
hideProgressBar: boolean;
accentColor: string;
}

Expand All @@ -44,6 +45,7 @@ export const useCreateSurveyManager = (initialData?: SurveyWithQuestions) => {
const [surveyOptions, setSurveyOptions] = useState<SurveyOptions>({
oneQuestionPerStep: initialData?.oneQuestionPerStep ?? true,
displayTitle: initialData?.displayTitle ?? true,
hideProgressBar: initialData?.hideProgressBar ?? false,
accentColor: initialData?.accentColor ?? '#C7D2FE',
});

Expand Down Expand Up @@ -245,6 +247,7 @@ export const useCreateSurveyManager = (initialData?: SurveyWithQuestions) => {
title,
oneQuestionPerStep: surveyOptions.oneQuestionPerStep,
displayTitle: surveyOptions.displayTitle,
hideProgressBar: surveyOptions.hideProgressBar,
accentColor: surveyOptions.accentColor,
questions: questions.map((question) => ({
title: question.title,
Expand Down Expand Up @@ -281,6 +284,7 @@ export const useCreateSurveyManager = (initialData?: SurveyWithQuestions) => {
title,
oneQuestionPerStep: surveyOptions.oneQuestionPerStep,
displayTitle: surveyOptions.displayTitle,
hideProgressBar: surveyOptions.hideProgressBar,
accentColor: surveyOptions.accentColor,
questions: questions.map((question) => ({
id: question.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ export default function OneQuestionView() {
{formData.questions.length > 0 && (
<>
<AnswersComponentFactory questionIndex={activeQuestionIndex} />
<Progressbar
currentStep={activeQuestionIndex + 1}
totalSteps={formData?.questions.length}
isSubmitted={isAnswering}
accentColor={formData?.accentColor}
/>
{!formData.hideProgressBar ? (
<Progressbar
currentStep={activeQuestionIndex + 1}
totalSteps={formData?.questions.length}
isSubmitted={isAnswering}
accentColor={formData?.accentColor}
/>
) : (
<></>
)}
</>
)}
</>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/api/survey/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export default async function handler(
oneQuestionPerStep,
displayTitle,
accentColor,
hideProgressBar,
} = req.body as SurveyData;
if (!isSurveyValid(req.body)) {
return res.status(400).end();
Expand Down Expand Up @@ -191,6 +192,7 @@ export default async function handler(
oneQuestionPerStep,
displayTitle,
accentColor,
hideProgressBar,
},
});

Expand Down
3 changes: 3 additions & 0 deletions src/pages/api/survey/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface SurveyData {
questions: Question[];
oneQuestionPerStep: boolean;
displayTitle: boolean;
hideProgressBar: boolean;
accentColor: string;
}

Expand Down Expand Up @@ -77,6 +78,7 @@ export default async function handler(
questions,
oneQuestionPerStep,
displayTitle,
hideProgressBar,
accentColor,
} = req.body as SurveyData;

Expand All @@ -93,6 +95,7 @@ export default async function handler(
isActive: true,
oneQuestionPerStep,
displayTitle,
hideProgressBar,
questions: {
create: questions.map((question, index) => ({
type: question.type,
Expand Down

1 comment on commit 9a888cc

@vercel
Copy link

@vercel vercel bot commented on 9a888cc Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

formslab – ./

formslab-ryczko.vercel.app
formslab.vercel.app
formslab-git-main-ryczko.vercel.app

Please sign in to comment.