fix response questions in wrong order FOR-558

This commit is contained in:
Matthias Nannt
2023-04-17 09:49:10 +02:00
parent 324a150a90
commit 8ef8c93f3d
2 changed files with 24 additions and 10 deletions

View File

@@ -24,14 +24,17 @@ export default function ResponseTimeline({ environmentId, surveyId }) {
// Replace question IDs with question headlines in response data
const updatedResponses = responses.map((response) => {
const updatedData: Array<{ question: string; answer: string }> = []; // Specify the type of updatedData
for (const [questionId, answer] of Object.entries(response.data)) {
const questionHeadline = questionIdToHeadline[questionId];
if (questionHeadline) {
updatedData.push({ question: questionHeadline, answer: answer as string });
const updatedResponse: Array<{ question: string; answer: string }> = []; // Specify the type of updatedData
// iterate over survey questions and build the updated response
for (const question of survey.questions) {
const questionId = question.id;
const questionHeadline = question.headline;
const answer = response.data[questionId];
if (answer) {
updatedResponse.push({ question: questionHeadline, answer: answer as string });
}
}
return { ...response, data: updatedData };
return { ...response, responses: updatedResponse };
});
return updatedResponses;

View File

@@ -1,10 +1,21 @@
import { PersonAvatar } from "@formbricks/ui";
import { timeSince } from "@formbricks/lib/time";
import Link from "next/link";
import { PersonAvatar } from "@formbricks/ui";
import { CheckCircleIcon } from "@heroicons/react/24/solid";
import Link from "next/link";
interface OpenTextSummaryProps {
data: any;
data: {
id: string;
personId: string;
value: string;
updatedAt: string;
finished: boolean;
responses: {
id: string;
question: string;
answer: string;
}[];
};
environmentId: string;
}
@@ -42,7 +53,7 @@ export default function SingleResponse({ data, environmentId }: OpenTextSummaryP
</div>
</div>
<div className="space-y-6 rounded-b-lg bg-white p-6">
{data.data.map((response) => {
{data.responses.map((response) => {
return (
<div key={response.id}>
<p className="text-sm text-slate-500">{response.question}</p>