mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-05 02:58:36 -06:00
fix: feedback
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZI18nString = z.record(z.string()).refine((obj) => "default" in obj, {
|
||||
message: "Object must have a 'default' key",
|
||||
message: "I18n string must have a 'default' key",
|
||||
});
|
||||
|
||||
export type TI18nString = z.infer<typeof ZI18nString>;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { TActionJumpToBlock, TSurveyBlock, TSurveyBlockId, TSurveyBlockLogicAction } from "./blocks";
|
||||
import type { TActionJumpToBlock, TSurveyBlock, TSurveyBlockLogicAction } from "./blocks";
|
||||
|
||||
export const findBlocksWithCyclicLogic = (blocks: TSurveyBlock[]): TSurveyBlockId[] => {
|
||||
export const findBlocksWithCyclicLogic = (blocks: TSurveyBlock[]): string[] => {
|
||||
const visited: Record<string, boolean> = {};
|
||||
const recStack: Record<string, boolean> = {};
|
||||
const cyclicBlocks = new Set<TSurveyBlockId>();
|
||||
const cyclicBlocks = new Set<string>();
|
||||
|
||||
const checkForCyclicLogic = (blockId: TSurveyBlockId): boolean => {
|
||||
const checkForCyclicLogic = (blockId: string): boolean => {
|
||||
if (!visited[blockId]) {
|
||||
visited[blockId] = true;
|
||||
recStack[blockId] = true;
|
||||
|
||||
@@ -6,36 +6,10 @@ import {
|
||||
ZActionNumberVariableCalculateOperator,
|
||||
ZActionTextVariableCalculateOperator,
|
||||
ZConditionGroup,
|
||||
ZDynamicLogicFieldValue,
|
||||
} from "./logic";
|
||||
|
||||
// Block ID - CUID (system-generated, NOT user-editable)
|
||||
export const ZSurveyBlockId = z.string().cuid2();
|
||||
|
||||
export type TSurveyBlockId = z.infer<typeof ZSurveyBlockId>;
|
||||
|
||||
// Copy condition types from types.ts for block logic
|
||||
const ZDynamicQuestion = z.object({
|
||||
type: z.literal("question"),
|
||||
value: z.string().min(1, "Conditional Logic: Question id cannot be empty"),
|
||||
meta: z.record(z.string()).optional(),
|
||||
});
|
||||
|
||||
const ZDynamicVariable = z.object({
|
||||
type: z.literal("variable"),
|
||||
value: z
|
||||
.string()
|
||||
.cuid2({ message: "Conditional Logic: Variable id must be a valid cuid" })
|
||||
.min(1, "Conditional Logic: Variable id cannot be empty"),
|
||||
});
|
||||
|
||||
const ZDynamicHiddenField = z.object({
|
||||
type: z.literal("hiddenField"),
|
||||
value: z.string().min(1, "Conditional Logic: Hidden field id cannot be empty"),
|
||||
});
|
||||
|
||||
const ZDynamicLogicFieldValue = z.union([ZDynamicQuestion, ZDynamicVariable, ZDynamicHiddenField], {
|
||||
message: "Conditional Logic: Invalid dynamic field value",
|
||||
});
|
||||
export const ZSurveyBlockId = ZId;
|
||||
|
||||
// Block Logic - Actions
|
||||
const ZActionCalculateBase = z.object({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { ZUrl } from "../common";
|
||||
import { ZI18nString } from "../i18n";
|
||||
import { ZAllowedFileExtension } from "../storage";
|
||||
import { FORBIDDEN_IDS } from "./validation";
|
||||
@@ -51,11 +52,11 @@ export type TSurveyElementId = z.infer<typeof ZSurveyElementId>;
|
||||
// Base element (like ZSurveyQuestionBase but WITHOUT logic, buttonLabel, backButtonLabel)
|
||||
export const ZSurveyElementBase = z.object({
|
||||
id: ZSurveyElementId,
|
||||
type: z.string(),
|
||||
type: z.nativeEnum(TSurveyElementTypeEnum),
|
||||
headline: ZI18nString,
|
||||
subheader: ZI18nString.optional(),
|
||||
imageUrl: z.string().optional(),
|
||||
videoUrl: z.string().optional(),
|
||||
imageUrl: ZUrl.optional(),
|
||||
videoUrl: ZUrl.optional(),
|
||||
required: z.boolean(),
|
||||
scale: z.enum(["number", "smiley", "star"]).optional(),
|
||||
range: z.union([z.literal(5), z.literal(3), z.literal(4), z.literal(7), z.literal(10)]).optional(),
|
||||
|
||||
Reference in New Issue
Block a user