Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/i18n.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,7 @@ checksums:
environments/workspace/look/show_powered_by_formbricks: a0e96edadec8ef326423feccc9d06be7
environments/workspace/look/styling_updated_successfully: b8b74b50dde95abcd498633e9d0c891f
environments/workspace/look/suggest_colors: ddc4543b416ab774007b10a3434343cd
environments/workspace/look/suggested_colors_applied_please_save: 226fa70af5efc8ffa0a3755909c8163e
environments/workspace/look/theme: 21fe00b7a518089576fb83c08631107a
environments/workspace/look/theme_settings_description: 9fc45322818c3774ab4a44ea14d7836e
environments/workspace/tags/add: 87c4a663507f2bcbbf79934af8164e13
Expand Down
9 changes: 8 additions & 1 deletion apps/web/lib/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ export function validateInputs<T extends ValidationPair<any>[]>(
for (const [value, schema] of pairs) {
const inputValidation = schema.safeParse(value);
if (!inputValidation.success) {
const zodDetails = inputValidation.error.issues
.map((issue) => {
const path = issue?.path?.join(".") ?? "";
return `${path}${issue.message}`;
})
.join("; ");

logger.error(
inputValidation.error,
`Validation failed for ${JSON.stringify(value).substring(0, 100)} and ${JSON.stringify(schema)}`
);
throw new ValidationError("Validation failed");
throw new ValidationError(`Validation failed: ${zodDetails}`);
}
parsedData.push(inputValidation.data);
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "\"Powered by Formbricks\"-Signatur anzeigen",
"styling_updated_successfully": "Styling erfolgreich aktualisiert",
"suggest_colors": "Farben vorschlagen",
"suggested_colors_applied_please_save": "Vorgeschlagene Farben erfolgreich generiert. Drücke \"Speichern\", um die Änderungen zu übernehmen.",
"theme": "Theme",
"theme_settings_description": "Erstelle ein Style-Theme für alle Umfragen. Du kannst für jede Umfrage individuelles Styling aktivieren."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Show “Powered by Formbricks” Signature",
"styling_updated_successfully": "Styling updated successfully",
"suggest_colors": "Suggest colors",
"suggested_colors_applied_please_save": "Suggested colors generated successfully. Press \"Save\" to persist the changes.",
"theme": "Theme",
"theme_settings_description": "Create a style theme for all surveys. You can enable custom styling for each survey."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Mostrar firma 'Powered by Formbricks'",
"styling_updated_successfully": "Estilo actualizado correctamente",
"suggest_colors": "Sugerir colores",
"suggested_colors_applied_please_save": "Colores sugeridos generados correctamente. Pulsa \"Guardar\" para conservar los cambios.",
"theme": "Tema",
"theme_settings_description": "Crea un tema de estilo para todas las encuestas. Puedes activar el estilo personalizado para cada encuesta."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Afficher la signature « Propulsé par Formbricks »",
"styling_updated_successfully": "Style mis à jour avec succès",
"suggest_colors": "Suggérer des couleurs",
"suggested_colors_applied_please_save": "Couleurs suggérées générées avec succès. Appuyez sur « Enregistrer » pour conserver les modifications.",
"theme": "Thème",
"theme_settings_description": "Créez un thème de style pour toutes les enquêtes. Vous pouvez activer un style personnalisé pour chaque enquête."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/hu-HU.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Az „A gépházban: Formbricks” aláírás megjelenítése",
"styling_updated_successfully": "A stílus sikeresen frissítve",
"suggest_colors": "Színek ajánlása",
"suggested_colors_applied_please_save": "A javasolt színek sikeresen generálva. Nyomd meg a \"Mentés\" gombot a változtatások véglegesítéséhez.",
"theme": "Téma",
"theme_settings_description": "Stílustéma létrehozása az összes kérdőívhez. Egyéni stílust engedélyezhet minden egyes kérdőívhez."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "「Powered by Formbricks」署名を表示",
"styling_updated_successfully": "スタイルを正常に更新しました",
"suggest_colors": "カラーを提案",
"suggested_colors_applied_please_save": "推奨カラーが正常に生成されました。変更を保存するには「保存」を押してください。",
"theme": "テーマ",
"theme_settings_description": "すべてのアンケート用のスタイルテーマを作成します。各アンケートでカスタムスタイルを有効にできます。"
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Toon 'Powered by Formbricks' handtekening",
"styling_updated_successfully": "Styling succesvol bijgewerkt",
"suggest_colors": "Kleuren voorstellen",
"suggested_colors_applied_please_save": "Voorgestelde kleuren succesvol gegenereerd. Druk op \"Opslaan\" om de wijzigingen te behouden.",
"theme": "Thema",
"theme_settings_description": "Maak een stijlthema voor alle enquêtes. Je kunt aangepaste styling inschakelen voor elke enquête."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Mostrar assinatura 'Powered by Formbricks'",
"styling_updated_successfully": "Estilo atualizado com sucesso",
"suggest_colors": "Sugerir cores",
"suggested_colors_applied_please_save": "Cores sugeridas geradas com sucesso. Pressione \"Salvar\" para manter as alterações.",
"theme": "Tema",
"theme_settings_description": "Crie um tema de estilo para todas as pesquisas. Você pode ativar estilo personalizado para cada pesquisa."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Mostrar assinatura 'Powered by Formbricks'",
"styling_updated_successfully": "Estilo atualizado com sucesso",
"suggest_colors": "Sugerir cores",
"suggested_colors_applied_please_save": "Cores sugeridas geradas com sucesso. Pressiona \"Guardar\" para manter as alterações.",
"theme": "Tema",
"theme_settings_description": "Crie um tema de estilo para todos os inquéritos. Pode ativar estilos personalizados para cada inquérito."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/ro-RO.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Afișează semnătura „Powered by Formbricks”",
"styling_updated_successfully": "Stilizarea a fost actualizată cu succes",
"suggest_colors": "Sugerează culori",
"suggested_colors_applied_please_save": "Culorile sugerate au fost generate cu succes. Apasă pe „Salvează” pentru a păstra modificările.",
"theme": "Temă",
"theme_settings_description": "Creează o temă de stil pentru toate sondajele. Poți activa stilizare personalizată pentru fiecare sondaj."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Показывать подпись «Работает на Formbricks»",
"styling_updated_successfully": "Стили успешно обновлены",
"suggest_colors": "Предложить цвета",
"suggested_colors_applied_please_save": "Рекомендованные цвета успешно сгенерированы. Нажми «Сохранить», чтобы применить изменения.",
"theme": "Тема",
"theme_settings_description": "Создайте стиль для всех опросов. Вы можете включить индивидуальное оформление для каждого опроса."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/sv-SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "Visa 'Powered by Formbricks'-signatur",
"styling_updated_successfully": "Stiluppdatering lyckades",
"suggest_colors": "Föreslå färger",
"suggested_colors_applied_please_save": "Föreslagna färger har skapats. Tryck på \"Spara\" för att spara ändringarna.",
"theme": "Tema",
"theme_settings_description": "Skapa ett stilmall för alla undersökningar. Du kan aktivera anpassad stil för varje undersökning."
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/zh-Hans-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "显示“Powered by Formbricks”标识",
"styling_updated_successfully": "样式更新成功",
"suggest_colors": "推荐颜色",
"suggested_colors_applied_please_save": "已成功生成推荐配色。请点击“保存”以保留更改。",
"theme": "主题",
"theme_settings_description": "为所有问卷创建一个样式主题。你可以为每个问卷启用自定义样式。"
},
Expand Down
1 change: 1 addition & 0 deletions apps/web/locales/zh-Hant-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@
"show_powered_by_formbricks": "顯示「Powered by Formbricks」標記",
"styling_updated_successfully": "樣式已成功更新",
"suggest_colors": "建議顏色",
"suggested_colors_applied_please_save": "已成功產生建議色彩。請按「儲存」以保存變更。",
"theme": "主題",
"theme_settings_description": "為所有調查建立樣式主題。您可以為每個調查啟用自訂樣式。"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ import { NextRequest, userAgent } from "next/server";
import { logger } from "@formbricks/logger";
import { TContactAttributesInput } from "@formbricks/types/contact-attribute";
import { ZEnvironmentId } from "@formbricks/types/environment";
import { ResourceNotFoundError } from "@formbricks/types/errors";
import { ResourceNotFoundError, ValidationError } from "@formbricks/types/errors";
import { TJsPersonState } from "@formbricks/types/js";
import { responses } from "@/app/lib/api/response";
import { withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
import { getIsContactsEnabled } from "@/modules/ee/license-check/lib/utils";
import { updateUser } from "./lib/update-user";

const handleError = (err: unknown, url: string): { response: Response } => {
if (err instanceof ResourceNotFoundError) {
return { response: responses.notFoundResponse(err.resourceType, err.resourceId) };
}

if (err instanceof ValidationError) {
return { response: responses.badRequestResponse(err.message, undefined, true) };
}

logger.error({ error: err, url }, "Error in POST /api/v1/client/[environmentId]/user");
return { response: responses.internalServerErrorResponse("Unable to fetch user state", true) };
};

export const OPTIONS = async (): Promise<Response> => {
return responses.successResponse(
{},
Expand Down Expand Up @@ -123,16 +136,7 @@ export const POST = withV1ApiWrapper({
response: responses.successResponse(responseJson, true),
};
} catch (err) {
if (err instanceof ResourceNotFoundError) {
return {
response: responses.notFoundResponse(err.resourceType, err.resourceId),
};
}

logger.error({ error: err, url: req.url }, "Error in POST /api/v1/client/[environmentId]/user");
return {
response: responses.internalServerErrorResponse(err.message ?? "Unable to fetch person state", true),
};
return handleError(err, req.url);
}
},
});
22 changes: 7 additions & 15 deletions apps/web/modules/ee/contacts/lib/validate-attribute-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,14 @@ describe("validateAndParseAttributeValue", () => {
}
});

test("converts numbers to string", () => {
test("rejects number values (SDK must pass actual strings)", () => {
const result = validateAndParseAttributeValue(42, "string", "testKey");
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.parsedValue.value).toBe("42");
expect(result.parsedValue.valueNumber).toBeNull();
}
});

test("converts Date to ISO string", () => {
const date = new Date("2024-01-15T10:30:00.000Z");
const result = validateAndParseAttributeValue(date, "string", "testKey");
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.parsedValue.value).toBe("2024-01-15T10:30:00.000Z");
expect(result.parsedValue.valueDate).toBeNull();
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error.code).toBe("string_type_mismatch");
expect(result.error.params.key).toBe("testKey");
expect(result.error.params.type).toBe("number");
expect(formatValidationError(result.error)).toContain("received a number");
}
});
});
Expand Down
45 changes: 25 additions & 20 deletions apps/web/modules/ee/contacts/lib/validate-attribute-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ export type TAttributeValidationResult =
error: TAttributeValidationError;
};

/**
* Converts any value to a string representation
*/
const convertToString = (value: TRawValue): string => {
if (value instanceof Date) return value.toISOString();
if (typeof value === "number") return String(value);
return value;
};

/**
* Gets a human-readable type name for error messages
*/
Expand All @@ -45,16 +36,28 @@ const getTypeName = (value: TRawValue): string => {
};

/**
* Validates and parses a string type attribute
* Validates and parses a string type attribute.
*/
const validateStringType = (value: TRawValue): TAttributeValidationResult => ({
valid: true,
parsedValue: {
value: convertToString(value),
valueNumber: null,
valueDate: null,
},
});
const validateStringType = (value: TRawValue, attributeKey: string): TAttributeValidationResult => {
if (typeof value === "string") {
return {
valid: true,
parsedValue: {
value,
valueNumber: null,
valueDate: null,
},
};
}

return {
valid: false,
error: {
code: "string_type_mismatch",
params: { key: attributeKey, type: getTypeName(value) },
},
};
};

/**
* Validates and parses a number type attribute.
Expand Down Expand Up @@ -170,13 +173,13 @@ export const validateAndParseAttributeValue = (
): TAttributeValidationResult => {
switch (expectedDataType) {
case "string":
return validateStringType(value);
return validateStringType(value, attributeKey);
case "number":
return validateNumberType(value, attributeKey);
case "date":
return validateDateType(value, attributeKey);
default:
return validateStringType(value);
return validateStringType(value, attributeKey);
}
};

Expand All @@ -185,6 +188,8 @@ export const validateAndParseAttributeValue = (
* Used for API/SDK responses.
*/
const VALIDATION_ERROR_TEMPLATES: Record<string, string> = {
string_type_mismatch:
"Attribute '{key}' expects a string but received a {type}. Pass an actual string value.",
number_type_mismatch:
"Attribute '{key}' expects a number but received a string. Pass an actual number value (e.g., 123 instead of \"123\").",
date_invalid: "Attribute '{key}' expects a valid date. Received: Invalid Date",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const ThemeStyling = ({
form.setValue(key as keyof TProjectStyling, value, { shouldDirty: true });
}

toast.success(t("environments.workspace.look.styling_updated_successfully"));
toast.success(t("environments.workspace.look.suggested_colors_applied_please_save"));
setConfirmSuggestColorsOpen(false);
};

Expand Down
2 changes: 1 addition & 1 deletion apps/web/modules/survey/editor/components/styling-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const StylingView = ({
form.setValue(key as keyof TSurveyStyling, value, { shouldDirty: true });
}

toast.success(t("environments.workspace.look.styling_updated_successfully"));
toast.success(t("environments.workspace.look.suggested_colors_applied_please_save"));
setConfirmSuggestColorsOpen(false);
};

Expand Down
2 changes: 1 addition & 1 deletion apps/web/modules/ui/components/input-combo-box/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export const InputCombobox: React.FC<InputComboboxProps> = ({
tabIndex={0}
aria-controls="options"
aria-expanded={open}
className={cn("flex h-full w-full cursor-pointer items-center justify-end bg-white pr-2", {
className={cn("flex w-full cursor-pointer items-center justify-end bg-white pr-2 h-10", {
"w-10 justify-center pr-0": withInput && inputType !== "dropdown",
"pointer-events-none": isClearing,
})}>
Expand Down
10 changes: 5 additions & 5 deletions apps/web/modules/ui/components/preview-survey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ export const PreviewSurvey = ({
)}>
{previewMode === "mobile" && (
<>
<p className="absolute top-0 left-0 m-2 rounded bg-slate-100 px-2 py-1 text-xs text-slate-400">
<p className="absolute left-0 top-0 m-2 rounded bg-slate-100 px-2 py-1 text-xs text-slate-400">
Preview
</p>
<div className="absolute top-0 right-0 m-2">
<div className="absolute right-0 top-0 m-2">
<ResetProgressButton onClick={resetProgress} />
</div>
<MediaBackground
Expand Down Expand Up @@ -265,7 +265,7 @@ export const PreviewSurvey = ({
</Modal>
) : (
<div className="flex h-full w-full flex-col justify-center px-1">
<div className="absolute top-5 left-5">
<div className="absolute left-5 top-5">
{!styling.isLogoHidden && (
<ClientLogo
environmentId={environment.id}
Expand Down Expand Up @@ -296,7 +296,7 @@ export const PreviewSurvey = ({
</>
)}
{previewMode === "desktop" && (
<div className="flex h-full flex-1 flex-col">
<div className="flex h-full w-full flex-1 flex-col">
<div className="flex h-8 w-full items-center rounded-t-lg bg-slate-100">
<div className="ml-6 flex space-x-2">
<div className="h-3 w-3 rounded-full bg-red-500"></div>
Expand Down Expand Up @@ -373,7 +373,7 @@ export const PreviewSurvey = ({
styling={styling}
ContentRef={ContentRef as React.RefObject<HTMLDivElement>}
isEditorView>
<div className="absolute top-5 left-5">
<div className="absolute left-5 top-5">
{!styling.isLogoHidden && (
<ClientLogo
environmentId={environment.id}
Expand Down
9 changes: 0 additions & 9 deletions docs/xm-and-surveys/xm/best-practices/cancel-subscription.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ The Churn Survey is among the most effective ways to identify weaknesses in your

* Follow-up to prevent bad reviews

* Coming soon: Make survey mandatory

## Overview

To run the Churn Survey in your app you want to proceed as follows:
Expand Down Expand Up @@ -80,13 +78,6 @@ Whenever a user visits this page, matches the filter conditions above and the re

Here is our complete [Actions manual](/xm-and-surveys/surveys/website-app-surveys/actions/) covering [No-Code](/xm-and-surveys/surveys/website-app-surveys/actions#setting-up-no-code-actions) and [Code](/xm-and-surveys/surveys/website-app-surveys/actions#setting-up-code-actions) Actions.

<Note>
Pre-churn flow coming soon We’re currently building full-screen survey
pop-ups. You’ll be able to prevent users from closing the survey unless they
respond to it. It’s certainly debatable if you want that but you could force
them to click through the survey before letting them cancel 🤷
</Note>

### 5. Select Action in the “When to ask” card

![Select feedback button action](/images/xm-and-surveys/xm/best-practices/cancel-subscription/select-action.webp)
Expand Down
Loading
Loading