mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-29 19:10:50 -06:00
Fix summary showing NaN values when adding new Consent or CTA question (#518)
This commit is contained in:
@@ -16,10 +16,11 @@ interface ChoiceResult {
|
||||
export default function CTASummary({ questionSummary }: CTASummaryProps) {
|
||||
const ctr: ChoiceResult = useMemo(() => {
|
||||
const clickedAbs = questionSummary.responses.filter((response) => response.value === "clicked").length;
|
||||
|
||||
const count = questionSummary.responses.length;
|
||||
if (count === 0) return { count: 0, percentage: 0 };
|
||||
return {
|
||||
count: questionSummary.responses.length,
|
||||
percentage: clickedAbs / questionSummary.responses.length,
|
||||
count: count,
|
||||
percentage: clickedAbs / count,
|
||||
};
|
||||
}, [questionSummary]);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ConsentQuestion } from "@formbricks/types/questions";
|
||||
import type { QuestionSummary } from "@formbricks/types/responses";
|
||||
import { ProgressBar } from "@formbricks/ui";
|
||||
import { InboxStackIcon } from "@heroicons/react/24/solid";
|
||||
import { useMemo } from "react";
|
||||
|
||||
interface ConsentSummaryProps {
|
||||
questionSummary: QuestionSummary<ConsentQuestion>;
|
||||
@@ -16,15 +17,20 @@ interface ChoiceResult {
|
||||
}
|
||||
|
||||
export default function ConsentSummary({ questionSummary }: ConsentSummaryProps) {
|
||||
const total = questionSummary.responses.length;
|
||||
const clickedAbs = questionSummary.responses.filter((response) => response.value !== "dismissed").length;
|
||||
const ctr: ChoiceResult = {
|
||||
count: total,
|
||||
acceptedCount: clickedAbs,
|
||||
acceptedPercentage: clickedAbs / total,
|
||||
dismissedCount: total - clickedAbs,
|
||||
dismissedPercentage: 1 - clickedAbs / total,
|
||||
};
|
||||
const ctr: ChoiceResult = useMemo(() => {
|
||||
const total = questionSummary.responses.length;
|
||||
const clickedAbs = questionSummary.responses.filter((response) => response.value !== "dismissed").length;
|
||||
if (total === 0) {
|
||||
return { count: 0, acceptedCount: 0, acceptedPercentage: 0, dismissedCount: 0, dismissedPercentage: 0 };
|
||||
}
|
||||
return {
|
||||
count: total,
|
||||
acceptedCount: clickedAbs,
|
||||
acceptedPercentage: clickedAbs / total,
|
||||
dismissedCount: total - clickedAbs,
|
||||
dismissedPercentage: 1 - clickedAbs / total,
|
||||
};
|
||||
}, [questionSummary]);
|
||||
|
||||
return (
|
||||
<div className=" rounded-lg border border-slate-200 bg-slate-50 shadow-sm">
|
||||
|
||||
Reference in New Issue
Block a user