From cd40e655fb1f1b7bcfcc4178249ddd7aed04dbc2 Mon Sep 17 00:00:00 2001 From: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com> Date: Wed, 19 Jun 2024 13:34:11 +0530 Subject: [PATCH] fix: progress bar issue (#2771) Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com> --- apps/web/playwright/js.spec.ts | 1 - .../src/components/general/ProgressBar.tsx | 33 +++++++------------ 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/apps/web/playwright/js.spec.ts b/apps/web/playwright/js.spec.ts index aebb34853b..1e624670cf 100644 --- a/apps/web/playwright/js.spec.ts +++ b/apps/web/playwright/js.spec.ts @@ -29,7 +29,6 @@ test.describe("JS Package Test", async () => { await expect(page.locator("#howToSendCardOption-website")).toBeVisible(); await page.locator("#howToSendCardOption-website").click(); await page.locator("#howToSendCardOption-website").click(); - await page.locator("#whenToSendCardTrigger").click(); await page.getByRole("button", { name: "Add action" }).click(); await page.getByText("New SessionGets fired when a").click(); diff --git a/packages/surveys/src/components/general/ProgressBar.tsx b/packages/surveys/src/components/general/ProgressBar.tsx index c6fae01c48..a65c5776bc 100644 --- a/packages/surveys/src/components/general/ProgressBar.tsx +++ b/packages/surveys/src/components/general/ProgressBar.tsx @@ -10,34 +10,23 @@ interface ProgressBarProps { export const ProgressBar = ({ survey, questionId }: ProgressBarProps) => { const currentQuestionIdx = useMemo( - () => survey.questions.findIndex((e) => e.id === questionId), + () => survey.questions.findIndex((q) => q.id === questionId), [survey, questionId] ); - const calculateProgress = useCallback((questionId: string, survey: TSurvey, progress: number) => { - if (survey.questions.length === 0) return 0; - let currentQustionIdx = survey.questions.findIndex((e) => e.id === questionId); - if (currentQustionIdx === -1) currentQustionIdx = 0; - const elementIdx = calculateElementIdx(survey, currentQustionIdx); + const calculateProgress = useCallback( + (index: number, questionsLength: number) => { + if (questionsLength === 0) return 0; + if (index === -1) index = 0; - const newProgress = elementIdx / survey.questions.length; - let updatedProgress = progress; - if (newProgress > progress) { - updatedProgress = newProgress; - } else if (newProgress <= progress && progress + 0.1 <= 1) { - updatedProgress = progress + 0.1; - } - return updatedProgress; - }, []); + const elementIdx = calculateElementIdx(survey, index); + return elementIdx / questionsLength; + }, + [survey] + ); const progressArray = useMemo(() => { - let progress = 0; - let progressArrayTemp: number[] = []; - survey.questions.forEach((question) => { - progress = calculateProgress(question.id, survey, progress); - progressArrayTemp.push(progress); - }); - return progressArrayTemp; + return survey.questions.map((_, index) => calculateProgress(index, survey.questions.length)); }, [calculateProgress, survey]); return ;