fix: autoclose and autoComplete issue (#1426)

This commit is contained in:
Dhruwang Jariwala
2023-12-13 14:54:03 +05:30
committed by GitHub
parent 7c3c6652d4
commit e2aba0cd4a
3 changed files with 11 additions and 25 deletions

View File

@@ -1,7 +1,6 @@
import { responses } from "@/app/lib/api/response";
import { transformErrorToDetails } from "@/app/lib/api/validator";
import { sendResponseFinishedEmail } from "@/app/lib/email";
import { prisma } from "@formbricks/database";
import { INTERNAL_SECRET } from "@formbricks/lib/constants";
import { convertDatesInObject } from "@formbricks/lib/time";
import { TSurveyQuestion } from "@formbricks/types/surveys";
@@ -10,6 +9,9 @@ import { ZPipelineInput } from "@formbricks/types/pipelines";
import { headers } from "next/headers";
import { NextResponse } from "next/server";
import { handleIntegrations } from "./lib/handleIntegrations";
import { getIntegrations } from "@formbricks/lib/integration/service";
import { prisma } from "@formbricks/database";
import { getSurvey, updateSurvey } from "@formbricks/lib/survey/service";
export async function POST(request: Request) {
// check authentication with x-api-key header and CRON_SECRET env variable
@@ -95,11 +97,7 @@ export async function POST(request: Request) {
},
});
const integrations = await prisma.integration.findMany({
where: {
environmentId,
},
});
const integrations = await getIntegrations(environmentId);
if (integrations.length > 0) {
handleIntegrations(integrations, inputValidation.data);
}
@@ -143,17 +141,9 @@ export async function POST(request: Request) {
})
);
}
const updateSurveyStatus = async (surveyId: string) => {
// Get the survey instance by surveyId
const survey = await prisma.survey.findUnique({
where: {
id: surveyId,
},
select: {
autoComplete: true,
},
});
const survey = await getSurvey(surveyId);
if (survey?.autoComplete) {
// Get the number of responses to a survey
@@ -163,17 +153,13 @@ export async function POST(request: Request) {
},
});
if (responseCount === survey.autoComplete) {
await prisma.survey.update({
where: {
id: surveyId,
},
data: {
status: "completed",
},
});
const updatedSurvey = { ...survey };
updatedSurvey.status = "completed";
await updateSurvey(updatedSurvey);
}
}
};
await updateSurveyStatus(surveyId);
}

View File

@@ -1,6 +1,6 @@
export default function Progress({ progress }: { progress: number }) {
return (
<div className="bg-accent-bg h-2 w-full rounded-full">
<div className="bg-accent-bg h-2 w-full overflow-hidden rounded-full">
<div
className="transition-width bg-brand z-20 h-2 rounded-full duration-500"
style={{ width: `${Math.floor(progress * 100)}%` }}></div>

View File

@@ -45,7 +45,7 @@ export function SurveyModal({
onDisplay={onDisplay}
onActiveQuestionChange={onActiveQuestionChange}
onResponse={onResponse}
onClose={onClose}
onClose={close}
onFinished={() => {
onFinished();
setTimeout(() => {