mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 10:19:51 -06:00
fix: getSyncSurveys (#2062)
This commit is contained in:
@@ -7,6 +7,7 @@ import Link from "next/link";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { toast } from "react-hot-toast";
|
||||
|
||||
import { cn } from "@formbricks/lib/cn";
|
||||
import { isAdvancedSegment } from "@formbricks/lib/segment/utils";
|
||||
import { TAttributeClass } from "@formbricks/types/attributeClasses";
|
||||
import { TBaseFilter, TSegment, TSegmentCreateInput, TSegmentUpdateInput } from "@formbricks/types/segment";
|
||||
@@ -209,7 +210,11 @@ export default function TargetingCard({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-3 flex items-center gap-2">
|
||||
<div
|
||||
className={cn(
|
||||
"mt-3 flex items-center gap-2",
|
||||
segment?.isPrivate && !segment?.filters?.length && "mt-0"
|
||||
)}>
|
||||
<Button variant="secondary" size="sm" onClick={() => setAddFilterModalOpen(true)}>
|
||||
Add filter
|
||||
</Button>
|
||||
|
||||
@@ -7,6 +7,7 @@ import Link from "next/link";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
import { cn } from "@formbricks/lib/cn";
|
||||
import { TActionClass } from "@formbricks/types/actionClasses";
|
||||
import { TAttributeClass } from "@formbricks/types/attributeClasses";
|
||||
import { TBaseFilter, TSegment, TSegmentCreateInput, TSegmentUpdateInput } from "@formbricks/types/segment";
|
||||
@@ -223,7 +224,11 @@ export function AdvancedTargetingCard({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-3 flex items-center gap-3">
|
||||
<div
|
||||
className={cn(
|
||||
"mt-3 flex items-center gap-2",
|
||||
segment?.isPrivate && !segment?.filters?.length && "mt-0"
|
||||
)}>
|
||||
<Button variant="secondary" size="sm" onClick={() => setAddFilterModalOpen(true)}>
|
||||
Add filter
|
||||
</Button>
|
||||
|
||||
@@ -8,6 +8,7 @@ import { TActionClass } from "@formbricks/types/actionClasses";
|
||||
import { ZOptionalNumber } from "@formbricks/types/common";
|
||||
import { ZId } from "@formbricks/types/environment";
|
||||
import { DatabaseError, InvalidInputError, ResourceNotFoundError } from "@formbricks/types/errors";
|
||||
import { TPerson } from "@formbricks/types/people";
|
||||
import { TSegment, ZSegment, ZSegmentFilters } from "@formbricks/types/segment";
|
||||
import { TSurvey, TSurveyInput, ZSurvey } from "@formbricks/types/surveys";
|
||||
|
||||
@@ -564,7 +565,7 @@ export const getSyncSurveys = async (
|
||||
const surveys = await unstable_cache(
|
||||
async () => {
|
||||
const product = await getProductByEnvironmentId(environmentId);
|
||||
const person = await getPerson(personId);
|
||||
const person = personId === "legacy" ? ({ id: "legacy" } as TPerson) : await getPerson(personId);
|
||||
|
||||
if (!product) {
|
||||
throw new Error("Product not found");
|
||||
@@ -625,7 +626,7 @@ export const getSyncSurveys = async (
|
||||
const personActionClassIds = Array.from(
|
||||
new Set(personActions?.map((action) => action.actionClass?.id ?? ""))
|
||||
);
|
||||
const personUserId = person.userId ?? person.attributes.userId ?? "";
|
||||
const personUserId = person.userId ?? person.attributes?.userId ?? "";
|
||||
|
||||
// the surveys now have segment filters, so we need to evaluate them
|
||||
const surveyPromises = surveys.map(async (survey) => {
|
||||
@@ -652,7 +653,11 @@ export const getSyncSurveys = async (
|
||||
|
||||
// we check if the person meets the attribute filters for all the attribute filters
|
||||
const isEligible = attributeFilters.every((attributeFilter) => {
|
||||
const personAttributeValue = person.attributes[attributeFilter.attributeClassName];
|
||||
const personAttributeValue = person?.attributes?.[attributeFilter.attributeClassName];
|
||||
if (!personAttributeValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attributeFilter.operator === "equals") {
|
||||
return personAttributeValue === attributeFilter.value;
|
||||
} else if (attributeFilter.operator === "notEquals") {
|
||||
@@ -669,7 +674,7 @@ export const getSyncSurveys = async (
|
||||
// Evaluate the segment filters
|
||||
const result = await evaluateSegment(
|
||||
{
|
||||
attributes: person.attributes,
|
||||
attributes: person.attributes ?? {},
|
||||
actionIds: personActionClassIds,
|
||||
deviceType,
|
||||
environmentId,
|
||||
|
||||
Reference in New Issue
Block a user