fix: web-app surveys not triggered with modified api endpoint (#1097)

This commit is contained in:
Matti Nannt
2023-10-11 18:48:54 +02:00
committed by GitHub
parent 2f8aa9b2ae
commit 61aaf301c1
3 changed files with 12 additions and 6 deletions
@@ -1,7 +1,7 @@
import { prisma } from "@formbricks/database";
import { selectSurvey } from "@formbricks/lib/survey/service";
import { TSurveysWithTriggers } from "@formbricks/types/v1/js";
import { TPerson } from "@formbricks/types/v1/people";
import { TSurvey } from "@formbricks/types/v1/surveys";
import { unstable_cache } from "next/cache";
const getSurveysCacheTags = (environmentId: string, personId: string): string[] => [
@@ -26,7 +26,7 @@ export const getSurveysCached = (environmentId: string, person: TPerson) =>
}
)();
export const getSurveys = async (environmentId: string, person: TPerson): Promise<TSurvey[]> => {
export const getSurveys = async (environmentId: string, person: TPerson): Promise<TSurveysWithTriggers[]> => {
// get recontactDays from product
const product = await prisma.product.findFirst({
where: {
@@ -133,7 +133,7 @@ export const getSurveys = async (environmentId: string, person: TPerson): Promis
});
// filter surveys that meet the recontactDays criteria
const surveys: TSurvey[] = potentialSurveysWithAttributes
const surveys: TSurveysWithTriggers[] = potentialSurveysWithAttributes
.filter((survey) => {
if (!lastDisplayPerson) {
// no display yet - always display
@@ -165,7 +165,7 @@ export const getSurveys = async (environmentId: string, person: TPerson): Promis
.map((survey) => ({
...survey,
singleUse: survey.singleUse ? JSON.parse(JSON.stringify(survey.singleUse)) : null,
triggers: survey.triggers.map((trigger) => trigger.eventClass.name),
triggers: survey.triggers.map((trigger) => trigger.eventClass),
attributeFilters: survey.attributeFilters.map((af) => ({
...af,
attributeClassId: af.attributeClass.id,
+1 -1
View File
@@ -1,4 +1,4 @@
import { getSurveysCached } from "@/app/api/v1/js/surveys";
import { getSurveysCached } from "@/app/api/v1/js/sync/lib/surveys";
import { MAU_LIMIT } from "@formbricks/lib/constants";
import { getActionClasses } from "@formbricks/lib/actionClass/service";
import { getEnvironment } from "@formbricks/lib/environment/service";
+7 -1
View File
@@ -5,10 +5,16 @@ import { ZSurvey } from "./surveys";
import { ZActionClass } from "./actionClasses";
import { ZProduct } from "./product";
const ZSurveysWithTriggers = ZSurvey.augment({
triggers: z.array(ZActionClass),
});
export type TSurveysWithTriggers = z.infer<typeof ZSurveysWithTriggers>;
export const ZJsState = z.object({
person: ZPerson,
session: ZSession,
surveys: z.array(ZSurvey),
surveys: z.array(ZSurveysWithTriggers),
noCodeActionClasses: z.array(ZActionClass),
product: ZProduct,
});