mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-28 09:20:49 -06:00
Compare commits
28 Commits
v3.8.6
...
fix-Vietna
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2915f878e | ||
|
|
710a813e9b | ||
|
|
8bdb818995 | ||
|
|
20466c3800 | ||
|
|
faf6c2d062 | ||
|
|
a760a3c341 | ||
|
|
94e6d2f215 | ||
|
|
a6f1c0f63d | ||
|
|
c653996cbb | ||
|
|
da44fef89d | ||
|
|
4dc2c5e3df | ||
|
|
1797c2ae20 | ||
|
|
3b5da01c0a | ||
|
|
0f1bdce002 | ||
|
|
7c8f3e826f | ||
|
|
f21d63bb55 | ||
|
|
f223bb3d3f | ||
|
|
51001d07b6 | ||
|
|
a9eedd3c7a | ||
|
|
b0aa08fe4e | ||
|
|
8d45d24d55 | ||
|
|
8c1b9f81b9 | ||
|
|
71fad1c22b | ||
|
|
292266c597 | ||
|
|
54e589a6a0 | ||
|
|
fb3f425c27 | ||
|
|
1aaa30c6e9 | ||
|
|
8611410b21 |
@@ -206,12 +206,6 @@ UNKEY_ROOT_KEY=
|
||||
# Disable custom cache handler if necessary (e.g. if deployed on Vercel)
|
||||
# CUSTOM_CACHE_DISABLED=1
|
||||
|
||||
# Azure AI settings
|
||||
# AI_AZURE_RESSOURCE_NAME=
|
||||
# AI_AZURE_API_KEY=
|
||||
# AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID=
|
||||
# AI_AZURE_LLM_DEPLOYMENT_ID=
|
||||
|
||||
# INTERCOM_APP_ID=
|
||||
# INTERCOM_SECRET_KEY=
|
||||
|
||||
@@ -224,3 +218,6 @@ UNKEY_ROOT_KEY=
|
||||
# The SENTRY_AUTH_TOKEN variable is picked up by the Sentry Build Plugin.
|
||||
# It's used automatically by Sentry during the build for authentication when uploading source maps.
|
||||
# SENTRY_AUTH_TOKEN=
|
||||
|
||||
# Disable the user management from UI
|
||||
# DISABLE_USER_MANAGEMENT
|
||||
3
.github/copilot-instructions.md
vendored
3
.github/copilot-instructions.md
vendored
@@ -10,8 +10,9 @@ When generating test files inside the "/app/web" path, follow these rules:
|
||||
- Follow the same test pattern used for other files in the package where the file is located
|
||||
- All imports should be at the top of the file, not inside individual tests
|
||||
- For mocking inside "test" blocks use "vi.mocked"
|
||||
- Add the original file path to the "test.coverage.include"array in the "apps/web/vite.config.mts" file
|
||||
- Add the original file path to the "test.coverage.include"array in the "apps/web/vite.config.mts" file. Do this only when the test file is created.
|
||||
- Don't mock functions that are already mocked in the "apps/web/vitestSetup.ts" file
|
||||
- When using "screen.getByText" check for the tolgee string if it is being used in the file.
|
||||
|
||||
If it's a test for a ".tsx" file, follow these extra instructions:
|
||||
|
||||
|
||||
38
.github/workflows/deploy-formbricks-cloud.yml
vendored
38
.github/workflows/deploy-formbricks-cloud.yml
vendored
@@ -12,6 +12,13 @@ on:
|
||||
required: false
|
||||
type: string
|
||||
default: 'ghcr.io/formbricks/formbricks'
|
||||
ENVIRONMENT:
|
||||
description: 'The environment to deploy to'
|
||||
required: true
|
||||
type: choice
|
||||
options:
|
||||
- stage
|
||||
- prod
|
||||
workflow_call:
|
||||
inputs:
|
||||
VERSION:
|
||||
@@ -23,6 +30,10 @@ on:
|
||||
required: false
|
||||
type: string
|
||||
default: 'ghcr.io/formbricks/formbricks'
|
||||
ENVIRONMENT:
|
||||
description: 'The environment to deploy to'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
@@ -35,6 +46,13 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Tailscale
|
||||
uses: tailscale/github-action@v3
|
||||
with:
|
||||
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
|
||||
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
|
||||
tags: tag:github
|
||||
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
|
||||
with:
|
||||
@@ -48,6 +66,8 @@ jobs:
|
||||
AWS_REGION: eu-central-1
|
||||
|
||||
- uses: helmfile/helmfile-action@v2
|
||||
name: Deploy Formbricks Cloud Prod
|
||||
if: (github.event_name == 'workflow_call' || github.event_name == 'workflow_dispatch') && github.event.inputs.ENVIRONMENT == 'prod'
|
||||
env:
|
||||
VERSION: ${{ inputs.VERSION }}
|
||||
REPOSITORY: ${{ inputs.REPOSITORY }}
|
||||
@@ -58,7 +78,23 @@ jobs:
|
||||
helm-plugins: >
|
||||
https://github.com/databus23/helm-diff,
|
||||
https://github.com/jkroepke/helm-secrets
|
||||
helmfile-args: apply
|
||||
helmfile-args: apply -l environment=prod
|
||||
helmfile-auto-init: "false"
|
||||
helmfile-workdirectory: infra/formbricks-cloud-helm
|
||||
|
||||
- uses: helmfile/helmfile-action@v2
|
||||
name: Deploy Formbricks Cloud Stage
|
||||
if: github.event_name == 'workflow_dispatch' && github.event.inputs.ENVIRONMENT == 'stage'
|
||||
env:
|
||||
VERSION: ${{ inputs.VERSION }}
|
||||
REPOSITORY: ${{ inputs.REPOSITORY }}
|
||||
FORMBRICKS_INGRESS_CERT_ARN: ${{ secrets.STAGE_FORMBRICKS_INGRESS_CERT_ARN }}
|
||||
FORMBRICKS_ROLE_ARN: ${{ secrets.STAGE_FORMBRICKS_ROLE_ARN }}
|
||||
with:
|
||||
helm-plugins: >
|
||||
https://github.com/databus23/helm-diff,
|
||||
https://github.com/jkroepke/helm-secrets
|
||||
helmfile-args: apply -l environment=stage
|
||||
helmfile-auto-init: "false"
|
||||
helmfile-workdirectory: infra/formbricks-cloud-helm
|
||||
|
||||
|
||||
1
.github/workflows/formbricks-release.yml
vendored
1
.github/workflows/formbricks-release.yml
vendored
@@ -31,3 +31,4 @@ jobs:
|
||||
- helm-chart-release
|
||||
with:
|
||||
VERSION: ${{ needs.docker-build.outputs.VERSION }}
|
||||
ENVIRONMENT: "prod"
|
||||
|
||||
56
.github/workflows/release-changesets.yml
vendored
56
.github/workflows/release-changesets.yml
vendored
@@ -1,56 +0,0 @@
|
||||
name: Release Changesets
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
#push:
|
||||
# branches:
|
||||
# - main
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
packages: write
|
||||
|
||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
|
||||
|
||||
- name: Setup Node.js 18.x
|
||||
uses: actions/setup-node@7c12f8017d5436eb855f1ed4399f037a36fbd9e8 # v2.5.2
|
||||
with:
|
||||
node-version: 18.x
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@c3b53f6a16e57305370b4ae5a540c2077a1d50dd # v2.2.4
|
||||
|
||||
- name: Install Dependencies
|
||||
run: pnpm install --config.platform=linux --config.architecture=x64
|
||||
|
||||
- name: Create Release Pull Request or Publish to npm
|
||||
id: changesets
|
||||
uses: changesets/action@c8bada60c408975afd1a20b3db81d6eee6789308 # v1.4.9
|
||||
with:
|
||||
# This expects you to have a script called release which does a build for your packages and calls changeset publish
|
||||
publish: pnpm release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
@@ -51,7 +51,7 @@ jobs:
|
||||
# https://github.com/docker/login-action
|
||||
- name: Log into registry ${{ env.REGISTRY }}
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
|
||||
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
|
||||
2
.github/workflows/release-docker-github.yml
vendored
2
.github/workflows/release-docker-github.yml
vendored
@@ -71,7 +71,7 @@ jobs:
|
||||
# https://github.com/docker/login-action
|
||||
- name: Log into registry ${{ env.REGISTRY }}
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
|
||||
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
|
||||
@@ -33,6 +33,13 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
|
||||
- name: Tailscale
|
||||
uses: tailscale/github-action@v3
|
||||
with:
|
||||
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
|
||||
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
|
||||
tags: tag:github
|
||||
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
|
||||
with:
|
||||
@@ -16,6 +16,6 @@ if [ -f branch.json ]; then
|
||||
echo "Skipping tolgee-pull: NEXT_PUBLIC_TOLGEE_API_KEY is not set"
|
||||
else
|
||||
pnpm run tolgee-pull
|
||||
git add packages/lib/messages
|
||||
git add apps/web/locales
|
||||
fi
|
||||
fi
|
||||
@@ -4,33 +4,33 @@
|
||||
"patterns": ["./apps/web/**/*.ts?(x)"],
|
||||
"projectId": 10304,
|
||||
"pull": {
|
||||
"path": "./packages/lib/messages"
|
||||
"path": "./apps/web/locales"
|
||||
},
|
||||
"push": {
|
||||
"files": [
|
||||
{
|
||||
"language": "en-US",
|
||||
"path": "./packages/lib/messages/en-US.json"
|
||||
"path": "./apps/web/locales/en-US.json"
|
||||
},
|
||||
{
|
||||
"language": "de-DE",
|
||||
"path": "./packages/lib/messages/de-DE.json"
|
||||
"path": "./apps/web/locales/de-DE.json"
|
||||
},
|
||||
{
|
||||
"language": "fr-FR",
|
||||
"path": "./packages/lib/messages/fr-FR.json"
|
||||
"path": "./apps/web/locales/fr-FR.json"
|
||||
},
|
||||
{
|
||||
"language": "pt-BR",
|
||||
"path": "./packages/lib/messages/pt-BR.json"
|
||||
"path": "./apps/web/locales/pt-BR.json"
|
||||
},
|
||||
{
|
||||
"language": "zh-Hant-TW",
|
||||
"path": "./packages/lib/messages/zh-Hant-TW.json"
|
||||
"path": "./apps/web/locales/zh-Hant-TW.json"
|
||||
},
|
||||
{
|
||||
"language": "pt-PT",
|
||||
"path": "./packages/lib/messages/pt-PT.json"
|
||||
"path": "./apps/web/locales/pt-PT.json"
|
||||
}
|
||||
],
|
||||
"forceMode": "OVERRIDE"
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -3,7 +3,7 @@ Copyright (c) 2024 Formbricks GmbH
|
||||
Portions of this software are licensed as follows:
|
||||
|
||||
- All content that resides under the "apps/web/modules/ee" directory of this repository, if these directories exist, is licensed under the license defined in "apps/web/modules/ee/LICENSE".
|
||||
- All content that resides under the "packages/js/", "packages/react-native/", "packages/android/", "packages/ios/" and "packages/api/" directories of this repository, if that directories exist, is licensed under the "MIT" license as defined in the "LICENSE" files of these packages.
|
||||
- All content that resides under the "packages/js/", "packages/android/", "packages/ios/" and "packages/api/" directories of this repository, if that directories exist, is licensed under the "MIT" license as defined in the "LICENSE" files of these packages.
|
||||
- All third party components incorporated into the Formbricks Software are licensed under the original license provided by the owner of the applicable component.
|
||||
- Content outside of the above mentioned directories or restrictions above is available under the "AGPLv3" license as defined below.
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
EXPO_PUBLIC_APP_URL=http://192.168.0.197:3000
|
||||
EXPO_PUBLIC_FORMBRICKS_ENVIRONMENT_ID=cm5p0cs7r000819182b32j0a1
|
||||
@@ -1,7 +0,0 @@
|
||||
module.exports = {
|
||||
extends: ["@formbricks/eslint-config/react.js"],
|
||||
parserOptions: {
|
||||
project: "tsconfig.json",
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
};
|
||||
35
apps/demo-react-native/.gitignore
vendored
35
apps/demo-react-native/.gitignore
vendored
@@ -1,35 +0,0 @@
|
||||
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
|
||||
|
||||
# dependencies
|
||||
node_modules/
|
||||
|
||||
# Expo
|
||||
.expo/
|
||||
dist/
|
||||
web-build/
|
||||
|
||||
# Native
|
||||
*.orig.*
|
||||
*.jks
|
||||
*.p8
|
||||
*.p12
|
||||
*.key
|
||||
*.mobileprovision
|
||||
|
||||
# Metro
|
||||
.metro-health-check*
|
||||
|
||||
# debug
|
||||
npm-debug.*
|
||||
yarn-debug.*
|
||||
yarn-error.*
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# local env files
|
||||
.env*.local
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
@@ -1,35 +0,0 @@
|
||||
{
|
||||
"expo": {
|
||||
"android": {
|
||||
"adaptiveIcon": {
|
||||
"backgroundColor": "#ffffff",
|
||||
"foregroundImage": "./assets/adaptive-icon.png"
|
||||
}
|
||||
},
|
||||
"assetBundlePatterns": ["**/*"],
|
||||
"icon": "./assets/icon.png",
|
||||
"ios": {
|
||||
"infoPlist": {
|
||||
"NSCameraUsageDescription": "Take pictures for certain activities.",
|
||||
"NSMicrophoneUsageDescription": "Need microphone access for recording videos.",
|
||||
"NSPhotoLibraryUsageDescription": "Select pictures for certain activities."
|
||||
},
|
||||
"supportsTablet": true
|
||||
},
|
||||
"jsEngine": "hermes",
|
||||
"name": "react-native-demo",
|
||||
"newArchEnabled": true,
|
||||
"orientation": "portrait",
|
||||
"slug": "react-native-demo",
|
||||
"splash": {
|
||||
"backgroundColor": "#ffffff",
|
||||
"image": "./assets/splash.png",
|
||||
"resizeMode": "contain"
|
||||
},
|
||||
"userInterfaceStyle": "light",
|
||||
"version": "1.0.0",
|
||||
"web": {
|
||||
"favicon": "./assets/favicon.png"
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 46 KiB |
@@ -1,6 +0,0 @@
|
||||
module.exports = function babel(api) {
|
||||
api.cache(true);
|
||||
return {
|
||||
presets: ["babel-preset-expo"],
|
||||
};
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { registerRootComponent } from "expo";
|
||||
import { LogBox } from "react-native";
|
||||
import App from "./src/app";
|
||||
|
||||
registerRootComponent(App);
|
||||
|
||||
LogBox.ignoreAllLogs();
|
||||
@@ -1,21 +0,0 @@
|
||||
// Learn more https://docs.expo.io/guides/customizing-metro
|
||||
const path = require("node:path");
|
||||
const { getDefaultConfig } = require("expo/metro-config");
|
||||
|
||||
// Find the workspace root, this can be replaced with `find-yarn-workspace-root`
|
||||
const workspaceRoot = path.resolve(__dirname, "../..");
|
||||
const projectRoot = __dirname;
|
||||
|
||||
const config = getDefaultConfig(projectRoot);
|
||||
|
||||
// 1. Watch all files within the monorepo
|
||||
config.watchFolders = [workspaceRoot];
|
||||
// 2. Let Metro know where to resolve packages, and in what order
|
||||
config.resolver.nodeModulesPaths = [
|
||||
path.resolve(projectRoot, "node_modules"),
|
||||
path.resolve(workspaceRoot, "node_modules"),
|
||||
];
|
||||
// 3. Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
|
||||
config.resolver.disableHierarchicalLookup = true;
|
||||
|
||||
module.exports = config;
|
||||
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"name": "@formbricks/demo-react-native",
|
||||
"version": "1.0.0",
|
||||
"main": "./index.js",
|
||||
"scripts": {
|
||||
"dev": "expo start",
|
||||
"android": "expo start --android",
|
||||
"ios": "expo start --ios",
|
||||
"web": "expo start --web",
|
||||
"eject": "expo eject",
|
||||
"clean": "rimraf .turbo node_modules .expo"
|
||||
},
|
||||
"dependencies": {
|
||||
"@formbricks/js": "workspace:*",
|
||||
"@formbricks/react-native": "workspace:*",
|
||||
"@react-native-async-storage/async-storage": "2.1.0",
|
||||
"expo": "52.0.28",
|
||||
"expo-status-bar": "2.0.1",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"react-native": "0.76.6",
|
||||
"react-native-webview": "13.12.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.26.0",
|
||||
"@types/react": "18.3.18",
|
||||
"typescript": "5.7.2"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
import { StatusBar } from "expo-status-bar";
|
||||
import React, { type JSX } from "react";
|
||||
import { Button, LogBox, StyleSheet, Text, View } from "react-native";
|
||||
import Formbricks, {
|
||||
logout,
|
||||
setAttribute,
|
||||
setAttributes,
|
||||
setLanguage,
|
||||
setUserId,
|
||||
track,
|
||||
} from "@formbricks/react-native";
|
||||
|
||||
LogBox.ignoreAllLogs();
|
||||
|
||||
export default function App(): JSX.Element {
|
||||
if (!process.env.EXPO_PUBLIC_FORMBRICKS_ENVIRONMENT_ID) {
|
||||
throw new Error("EXPO_PUBLIC_FORMBRICKS_ENVIRONMENT_ID is required");
|
||||
}
|
||||
|
||||
if (!process.env.EXPO_PUBLIC_APP_URL) {
|
||||
throw new Error("EXPO_PUBLIC_APP_URL is required");
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text>Formbricks React Native SDK Demo</Text>
|
||||
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 10,
|
||||
}}>
|
||||
<Button
|
||||
title="Trigger Code Action"
|
||||
onPress={() => {
|
||||
track("code").catch((error: unknown) => {
|
||||
// eslint-disable-next-line no-console -- logging is allowed in demo apps
|
||||
console.error("Error tracking event:", error);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
title="Set User Id"
|
||||
onPress={() => {
|
||||
setUserId("random-user-id").catch((error: unknown) => {
|
||||
// eslint-disable-next-line no-console -- logging is allowed in demo apps
|
||||
console.error("Error setting user id:", error);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
title="Set User Attributess (multiple)"
|
||||
onPress={() => {
|
||||
setAttributes({
|
||||
testAttr: "attr-test",
|
||||
testAttr2: "attr-test-2",
|
||||
testAttr3: "attr-test-3",
|
||||
testAttr4: "attr-test-4",
|
||||
}).catch((error: unknown) => {
|
||||
// eslint-disable-next-line no-console -- logging is allowed in demo apps
|
||||
console.error("Error setting user attributes:", error);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
title="Set User Attributes (single)"
|
||||
onPress={() => {
|
||||
setAttribute("testSingleAttr", "testSingleAttr").catch((error: unknown) => {
|
||||
// eslint-disable-next-line no-console -- logging is allowed in demo apps
|
||||
console.error("Error setting user attributes:", error);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
title="Logout"
|
||||
onPress={() => {
|
||||
logout().catch((error: unknown) => {
|
||||
// eslint-disable-next-line no-console -- logging is allowed in demo apps
|
||||
console.error("Error logging out:", error);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
title="Set Language (de)"
|
||||
onPress={() => {
|
||||
setLanguage("de").catch((error: unknown) => {
|
||||
// eslint-disable-next-line no-console -- logging is allowed in demo apps
|
||||
console.error("Error setting language:", error);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<StatusBar style="auto" />
|
||||
|
||||
<Formbricks
|
||||
appUrl={process.env.EXPO_PUBLIC_APP_URL as string}
|
||||
environmentId={process.env.EXPO_PUBLIC_FORMBRICKS_ENVIRONMENT_ID as string}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: "#fff",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true
|
||||
},
|
||||
"extends": "expo/tsconfig.base"
|
||||
}
|
||||
@@ -3,13 +3,13 @@ module.exports = {
|
||||
ignorePatterns: ["**/package.json", "**/tsconfig.json"],
|
||||
overrides: [
|
||||
{
|
||||
files: ["lib/messages/**/*.json"],
|
||||
files: ["locales/*.json"],
|
||||
plugins: ["i18n-json"],
|
||||
rules: {
|
||||
"i18n-json/identical-keys": [
|
||||
"error",
|
||||
{
|
||||
filePath: require("path").join(__dirname, "messages", "en-US.json"),
|
||||
filePath: require("path").join(__dirname, "locales", "en-US.json"),
|
||||
checkExtraKeys: false,
|
||||
checkMissingKeys: true,
|
||||
},
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { getDefaultEndingCard } from "@/app/lib/templates";
|
||||
import {
|
||||
buildCTAQuestion,
|
||||
buildNPSQuestion,
|
||||
buildOpenTextQuestion,
|
||||
buildRatingQuestion,
|
||||
getDefaultEndingCard,
|
||||
} from "@/app/lib/survey-builder";
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
import { TFnType } from "@tolgee/react";
|
||||
import { logger } from "@formbricks/logger";
|
||||
import { TSurveyQuestionTypeEnum } from "@formbricks/types/surveys/types";
|
||||
import { TXMTemplate } from "@formbricks/types/templates";
|
||||
|
||||
export const getXMSurveyDefault = (t: TFnType): TXMTemplate => {
|
||||
@@ -26,35 +31,26 @@ const npsSurvey = (t: TFnType): TXMTemplate => {
|
||||
...getXMSurveyDefault(t),
|
||||
name: t("templates.nps_survey_name"),
|
||||
questions: [
|
||||
{
|
||||
id: createId(),
|
||||
type: TSurveyQuestionTypeEnum.NPS,
|
||||
headline: { default: t("templates.nps_survey_question_1_headline") },
|
||||
buildNPSQuestion({
|
||||
headline: t("templates.nps_survey_question_1_headline"),
|
||||
required: true,
|
||||
lowerLabel: { default: t("templates.nps_survey_question_1_lower_label") },
|
||||
upperLabel: { default: t("templates.nps_survey_question_1_upper_label") },
|
||||
lowerLabel: t("templates.nps_survey_question_1_lower_label"),
|
||||
upperLabel: t("templates.nps_survey_question_1_upper_label"),
|
||||
isColorCodingEnabled: true,
|
||||
},
|
||||
{
|
||||
id: createId(),
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: t("templates.nps_survey_question_2_headline") },
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
headline: t("templates.nps_survey_question_2_headline"),
|
||||
required: false,
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: createId(),
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: t("templates.nps_survey_question_3_headline") },
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
headline: t("templates.nps_survey_question_3_headline"),
|
||||
required: false,
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
t,
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -67,9 +63,8 @@ const starRatingSurvey = (t: TFnType): TXMTemplate => {
|
||||
...defaultSurvey,
|
||||
name: t("templates.star_rating_survey_name"),
|
||||
questions: [
|
||||
{
|
||||
buildRatingQuestion({
|
||||
id: reusableQuestionIds[0],
|
||||
type: TSurveyQuestionTypeEnum.Rating,
|
||||
logic: [
|
||||
{
|
||||
id: createId(),
|
||||
@@ -102,16 +97,15 @@ const starRatingSurvey = (t: TFnType): TXMTemplate => {
|
||||
],
|
||||
range: 5,
|
||||
scale: "number",
|
||||
headline: { default: t("templates.star_rating_survey_question_1_headline") },
|
||||
headline: t("templates.star_rating_survey_question_1_headline"),
|
||||
required: true,
|
||||
lowerLabel: { default: t("templates.star_rating_survey_question_1_lower_label") },
|
||||
upperLabel: { default: t("templates.star_rating_survey_question_1_upper_label") },
|
||||
isColorCodingEnabled: false,
|
||||
},
|
||||
{
|
||||
lowerLabel: t("templates.star_rating_survey_question_1_lower_label"),
|
||||
upperLabel: t("templates.star_rating_survey_question_1_upper_label"),
|
||||
t,
|
||||
}),
|
||||
buildCTAQuestion({
|
||||
id: reusableQuestionIds[1],
|
||||
html: { default: t("templates.star_rating_survey_question_2_html") },
|
||||
type: TSurveyQuestionTypeEnum.CTA,
|
||||
html: t("templates.star_rating_survey_question_2_html"),
|
||||
logic: [
|
||||
{
|
||||
id: createId(),
|
||||
@@ -138,25 +132,23 @@ const starRatingSurvey = (t: TFnType): TXMTemplate => {
|
||||
],
|
||||
},
|
||||
],
|
||||
headline: { default: t("templates.star_rating_survey_question_2_headline") },
|
||||
headline: t("templates.star_rating_survey_question_2_headline"),
|
||||
required: true,
|
||||
buttonUrl: "https://formbricks.com/github",
|
||||
buttonLabel: { default: t("templates.star_rating_survey_question_2_button_label") },
|
||||
buttonLabel: t("templates.star_rating_survey_question_2_button_label"),
|
||||
buttonExternal: true,
|
||||
},
|
||||
{
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
id: reusableQuestionIds[2],
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: t("templates.star_rating_survey_question_3_headline") },
|
||||
headline: t("templates.star_rating_survey_question_3_headline"),
|
||||
required: true,
|
||||
subheader: { default: t("templates.star_rating_survey_question_3_subheader") },
|
||||
buttonLabel: { default: t("templates.star_rating_survey_question_3_button_label") },
|
||||
placeholder: { default: t("templates.star_rating_survey_question_3_placeholder") },
|
||||
subheader: t("templates.star_rating_survey_question_3_subheader"),
|
||||
buttonLabel: t("templates.star_rating_survey_question_3_button_label"),
|
||||
placeholder: t("templates.star_rating_survey_question_3_placeholder"),
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
t,
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -169,9 +161,8 @@ const csatSurvey = (t: TFnType): TXMTemplate => {
|
||||
...defaultSurvey,
|
||||
name: t("templates.csat_survey_name"),
|
||||
questions: [
|
||||
{
|
||||
buildRatingQuestion({
|
||||
id: reusableQuestionIds[0],
|
||||
type: TSurveyQuestionTypeEnum.Rating,
|
||||
logic: [
|
||||
{
|
||||
id: createId(),
|
||||
@@ -204,15 +195,14 @@ const csatSurvey = (t: TFnType): TXMTemplate => {
|
||||
],
|
||||
range: 5,
|
||||
scale: "smiley",
|
||||
headline: { default: t("templates.csat_survey_question_1_headline") },
|
||||
headline: t("templates.csat_survey_question_1_headline"),
|
||||
required: true,
|
||||
lowerLabel: { default: t("templates.csat_survey_question_1_lower_label") },
|
||||
upperLabel: { default: t("templates.csat_survey_question_1_upper_label") },
|
||||
isColorCodingEnabled: false,
|
||||
},
|
||||
{
|
||||
lowerLabel: t("templates.csat_survey_question_1_lower_label"),
|
||||
upperLabel: t("templates.csat_survey_question_1_upper_label"),
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
id: reusableQuestionIds[1],
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
logic: [
|
||||
{
|
||||
id: createId(),
|
||||
@@ -239,25 +229,20 @@ const csatSurvey = (t: TFnType): TXMTemplate => {
|
||||
],
|
||||
},
|
||||
],
|
||||
headline: { default: t("templates.csat_survey_question_2_headline") },
|
||||
headline: t("templates.csat_survey_question_2_headline"),
|
||||
required: false,
|
||||
placeholder: { default: t("templates.csat_survey_question_2_placeholder") },
|
||||
placeholder: t("templates.csat_survey_question_2_placeholder"),
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
id: reusableQuestionIds[2],
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: t("templates.csat_survey_question_3_headline") },
|
||||
headline: t("templates.csat_survey_question_3_headline"),
|
||||
required: false,
|
||||
placeholder: { default: t("templates.csat_survey_question_3_placeholder") },
|
||||
placeholder: t("templates.csat_survey_question_3_placeholder"),
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
t,
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -267,28 +252,22 @@ const cessSurvey = (t: TFnType): TXMTemplate => {
|
||||
...getXMSurveyDefault(t),
|
||||
name: t("templates.cess_survey_name"),
|
||||
questions: [
|
||||
{
|
||||
id: createId(),
|
||||
type: TSurveyQuestionTypeEnum.Rating,
|
||||
buildRatingQuestion({
|
||||
range: 5,
|
||||
scale: "number",
|
||||
headline: { default: t("templates.cess_survey_question_1_headline") },
|
||||
headline: t("templates.cess_survey_question_1_headline"),
|
||||
required: true,
|
||||
lowerLabel: { default: t("templates.cess_survey_question_1_lower_label") },
|
||||
upperLabel: { default: t("templates.cess_survey_question_1_upper_label") },
|
||||
isColorCodingEnabled: false,
|
||||
},
|
||||
{
|
||||
id: createId(),
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: t("templates.cess_survey_question_2_headline") },
|
||||
lowerLabel: t("templates.cess_survey_question_1_lower_label"),
|
||||
upperLabel: t("templates.cess_survey_question_1_upper_label"),
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
headline: t("templates.cess_survey_question_2_headline"),
|
||||
required: true,
|
||||
placeholder: { default: t("templates.cess_survey_question_2_placeholder") },
|
||||
placeholder: t("templates.cess_survey_question_2_placeholder"),
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
t,
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -301,9 +280,8 @@ const smileysRatingSurvey = (t: TFnType): TXMTemplate => {
|
||||
...defaultSurvey,
|
||||
name: t("templates.smileys_survey_name"),
|
||||
questions: [
|
||||
{
|
||||
buildRatingQuestion({
|
||||
id: reusableQuestionIds[0],
|
||||
type: TSurveyQuestionTypeEnum.Rating,
|
||||
logic: [
|
||||
{
|
||||
id: createId(),
|
||||
@@ -336,16 +314,15 @@ const smileysRatingSurvey = (t: TFnType): TXMTemplate => {
|
||||
],
|
||||
range: 5,
|
||||
scale: "smiley",
|
||||
headline: { default: t("templates.smileys_survey_question_1_headline") },
|
||||
headline: t("templates.smileys_survey_question_1_headline"),
|
||||
required: true,
|
||||
lowerLabel: { default: t("templates.smileys_survey_question_1_lower_label") },
|
||||
upperLabel: { default: t("templates.smileys_survey_question_1_upper_label") },
|
||||
isColorCodingEnabled: false,
|
||||
},
|
||||
{
|
||||
lowerLabel: t("templates.smileys_survey_question_1_lower_label"),
|
||||
upperLabel: t("templates.smileys_survey_question_1_upper_label"),
|
||||
t,
|
||||
}),
|
||||
buildCTAQuestion({
|
||||
id: reusableQuestionIds[1],
|
||||
html: { default: t("templates.smileys_survey_question_2_html") },
|
||||
type: TSurveyQuestionTypeEnum.CTA,
|
||||
html: t("templates.smileys_survey_question_2_html"),
|
||||
logic: [
|
||||
{
|
||||
id: createId(),
|
||||
@@ -372,25 +349,23 @@ const smileysRatingSurvey = (t: TFnType): TXMTemplate => {
|
||||
],
|
||||
},
|
||||
],
|
||||
headline: { default: t("templates.smileys_survey_question_2_headline") },
|
||||
headline: t("templates.smileys_survey_question_2_headline"),
|
||||
required: true,
|
||||
buttonUrl: "https://formbricks.com/github",
|
||||
buttonLabel: { default: t("templates.smileys_survey_question_2_button_label") },
|
||||
buttonLabel: t("templates.smileys_survey_question_2_button_label"),
|
||||
buttonExternal: true,
|
||||
},
|
||||
{
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
id: reusableQuestionIds[2],
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: t("templates.smileys_survey_question_3_headline") },
|
||||
headline: t("templates.smileys_survey_question_3_headline"),
|
||||
required: true,
|
||||
subheader: { default: t("templates.smileys_survey_question_3_subheader") },
|
||||
buttonLabel: { default: t("templates.smileys_survey_question_3_button_label") },
|
||||
placeholder: { default: t("templates.smileys_survey_question_3_placeholder") },
|
||||
subheader: t("templates.smileys_survey_question_3_subheader"),
|
||||
buttonLabel: t("templates.smileys_survey_question_3_button_label"),
|
||||
placeholder: t("templates.smileys_survey_question_3_placeholder"),
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
t,
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -400,37 +375,26 @@ const enpsSurvey = (t: TFnType): TXMTemplate => {
|
||||
...getXMSurveyDefault(t),
|
||||
name: t("templates.enps_survey_name"),
|
||||
questions: [
|
||||
{
|
||||
id: createId(),
|
||||
type: TSurveyQuestionTypeEnum.NPS,
|
||||
headline: {
|
||||
default: t("templates.enps_survey_question_1_headline"),
|
||||
},
|
||||
buildNPSQuestion({
|
||||
headline: t("templates.enps_survey_question_1_headline"),
|
||||
required: false,
|
||||
lowerLabel: { default: t("templates.enps_survey_question_1_lower_label") },
|
||||
upperLabel: { default: t("templates.enps_survey_question_1_upper_label") },
|
||||
lowerLabel: t("templates.enps_survey_question_1_lower_label"),
|
||||
upperLabel: t("templates.enps_survey_question_1_upper_label"),
|
||||
isColorCodingEnabled: true,
|
||||
},
|
||||
{
|
||||
id: createId(),
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: t("templates.enps_survey_question_2_headline") },
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
headline: t("templates.enps_survey_question_2_headline"),
|
||||
required: false,
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: createId(),
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: t("templates.enps_survey_question_3_headline") },
|
||||
t,
|
||||
}),
|
||||
buildOpenTextQuestion({
|
||||
headline: t("templates.enps_survey_question_3_headline"),
|
||||
required: false,
|
||||
inputType: "text",
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
t,
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
@@ -58,11 +58,6 @@ const Page = async (props) => {
|
||||
comingSoon: false,
|
||||
onRequest: false,
|
||||
},
|
||||
{
|
||||
title: t("environments.settings.enterprise.ai"),
|
||||
comingSoon: false,
|
||||
onRequest: true,
|
||||
},
|
||||
{
|
||||
title: t("environments.settings.enterprise.audit_logs"),
|
||||
comingSoon: false,
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { getFormattedErrorMessage } from "@/lib/utils/helper";
|
||||
import { updateOrganizationAIEnabledAction } from "@/modules/ee/insights/actions";
|
||||
import { Alert, AlertDescription } from "@/modules/ui/components/alert";
|
||||
import { Label } from "@/modules/ui/components/label";
|
||||
import { Switch } from "@/modules/ui/components/switch";
|
||||
import { useTranslate } from "@tolgee/react";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { TOrganization } from "@formbricks/types/organizations";
|
||||
|
||||
interface AIToggleProps {
|
||||
environmentId: string;
|
||||
organization: TOrganization;
|
||||
isOwnerOrManager: boolean;
|
||||
}
|
||||
|
||||
export const AIToggle = ({ organization, isOwnerOrManager }: AIToggleProps) => {
|
||||
const { t } = useTranslate();
|
||||
const [isAIEnabled, setIsAIEnabled] = useState(organization.isAIEnabled);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const handleUpdateOrganization = async (data) => {
|
||||
try {
|
||||
setIsAIEnabled(data.enabled);
|
||||
setIsSubmitting(true);
|
||||
const updatedOrganizationResponse = await updateOrganizationAIEnabledAction({
|
||||
organizationId: organization.id,
|
||||
data: {
|
||||
isAIEnabled: data.enabled,
|
||||
},
|
||||
});
|
||||
|
||||
if (updatedOrganizationResponse?.data) {
|
||||
if (data.enabled) {
|
||||
toast.success(t("environments.settings.general.formbricks_ai_enable_success_message"));
|
||||
} else {
|
||||
toast.success(t("environments.settings.general.formbricks_ai_disable_success_message"));
|
||||
}
|
||||
} else {
|
||||
const errorMessage = getFormattedErrorMessage(updatedOrganizationResponse);
|
||||
toast.error(errorMessage);
|
||||
}
|
||||
} catch (err) {
|
||||
toast.error(`Error: ${err.message}`);
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
if (typeof window !== "undefined") {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor="formbricks-ai-toggle" className="cursor-pointer">
|
||||
{t("environments.settings.general.enable_formbricks_ai")}
|
||||
</Label>
|
||||
<Switch
|
||||
id="formbricks-ai-toggle"
|
||||
disabled={!isOwnerOrManager || isSubmitting}
|
||||
checked={isAIEnabled}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleUpdateOrganization({ enabled: !organization.isAIEnabled });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-3 text-xs text-slate-600">
|
||||
{t("environments.settings.general.formbricks_ai_privacy_policy_text")}{" "}
|
||||
<Link
|
||||
className="underline"
|
||||
href={"https://formbricks.com/privacy-policy"}
|
||||
rel="noreferrer"
|
||||
target="_blank">
|
||||
{t("common.privacy_policy")}
|
||||
</Link>
|
||||
.
|
||||
</div>
|
||||
</div>
|
||||
{!isOwnerOrManager && (
|
||||
<Alert variant="warning" className="mt-4">
|
||||
<AlertDescription>
|
||||
{t("environments.settings.general.only_org_owner_can_perform_action")}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -1,9 +1,5 @@
|
||||
import { getUser } from "@/lib/user/service";
|
||||
import {
|
||||
getIsMultiOrgEnabled,
|
||||
getIsOrganizationAIReady,
|
||||
getWhiteLabelPermission,
|
||||
} from "@/modules/ee/license-check/lib/utils";
|
||||
import { getIsMultiOrgEnabled, getWhiteLabelPermission } from "@/modules/ee/license-check/lib/utils";
|
||||
import { getEnvironmentAuth } from "@/modules/environments/lib/utils";
|
||||
import { TEnvironmentAuth } from "@/modules/environments/types/environment-auth";
|
||||
import { getTranslate } from "@/tolgee/server";
|
||||
@@ -33,12 +29,6 @@ vi.mock("@/lib/constants", () => ({
|
||||
WEBAPP_URL: "mock-webapp-url",
|
||||
SMTP_HOST: "mock-smtp-host",
|
||||
SMTP_PORT: "mock-smtp-port",
|
||||
AI_AZURE_LLM_RESSOURCE_NAME: "mock-ai-azure-llm-ressource-name",
|
||||
AI_AZURE_LLM_API_KEY: "mock-ai",
|
||||
AI_AZURE_LLM_DEPLOYMENT_ID: "mock-ai-azure-llm-deployment-id",
|
||||
AI_AZURE_EMBEDDINGS_RESSOURCE_NAME: "mock-ai-azure-embeddings-ressource-name",
|
||||
AI_AZURE_EMBEDDINGS_API_KEY: "mock-ai-azure-embeddings-api-key",
|
||||
AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID: "mock-ai-azure-embeddings-deployment-id",
|
||||
}));
|
||||
|
||||
vi.mock("next-auth", () => ({
|
||||
@@ -59,7 +49,6 @@ vi.mock("@/modules/environments/lib/utils", () => ({
|
||||
|
||||
vi.mock("@/modules/ee/license-check/lib/utils", () => ({
|
||||
getIsMultiOrgEnabled: vi.fn(),
|
||||
getIsOrganizationAIReady: vi.fn(),
|
||||
getWhiteLabelPermission: vi.fn(),
|
||||
}));
|
||||
|
||||
@@ -80,7 +69,6 @@ describe("Page", () => {
|
||||
vi.mocked(getUser).mockResolvedValue(mockUser);
|
||||
vi.mocked(getEnvironmentAuth).mockResolvedValue(mockEnvironmentAuth);
|
||||
vi.mocked(getIsMultiOrgEnabled).mockResolvedValue(true);
|
||||
vi.mocked(getIsOrganizationAIReady).mockResolvedValue(true);
|
||||
vi.mocked(getWhiteLabelPermission).mockResolvedValue(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { OrganizationSettingsNavbar } from "@/app/(app)/environments/[environmentId]/settings/(organization)/components/OrganizationSettingsNavbar";
|
||||
import { AIToggle } from "@/app/(app)/environments/[environmentId]/settings/(organization)/general/components/AIToggle";
|
||||
import { FB_LOGO_URL, IS_FORMBRICKS_CLOUD } from "@/lib/constants";
|
||||
import { getUser } from "@/lib/user/service";
|
||||
import {
|
||||
getIsMultiOrgEnabled,
|
||||
getIsOrganizationAIReady,
|
||||
getWhiteLabelPermission,
|
||||
} from "@/modules/ee/license-check/lib/utils";
|
||||
import { getIsMultiOrgEnabled, getWhiteLabelPermission } from "@/modules/ee/license-check/lib/utils";
|
||||
import { EmailCustomizationSettings } from "@/modules/ee/whitelabel/email-customization/components/email-customization-settings";
|
||||
import { getEnvironmentAuth } from "@/modules/environments/lib/utils";
|
||||
import { PageContentWrapper } from "@/modules/ui/components/page-content-wrapper";
|
||||
@@ -35,8 +30,6 @@ const Page = async (props: { params: Promise<{ environmentId: string }> }) => {
|
||||
|
||||
const isOwnerOrManager = isManager || isOwner;
|
||||
|
||||
const isOrganizationAIReady = await getIsOrganizationAIReady(organization.billing.plan);
|
||||
|
||||
return (
|
||||
<PageContentWrapper>
|
||||
<PageHeader pageTitle={t("environments.settings.general.organization_settings")}>
|
||||
@@ -56,17 +49,6 @@ const Page = async (props: { params: Promise<{ environmentId: string }> }) => {
|
||||
membershipRole={currentUserMembership?.role}
|
||||
/>
|
||||
</SettingsCard>
|
||||
{isOrganizationAIReady && (
|
||||
<SettingsCard
|
||||
title={t("environments.settings.general.formbricks_ai")}
|
||||
description={t("environments.settings.general.formbricks_ai_description")}>
|
||||
<AIToggle
|
||||
environmentId={params.environmentId}
|
||||
organization={organization}
|
||||
isOwnerOrManager={isOwnerOrManager}
|
||||
/>
|
||||
</SettingsCard>
|
||||
)}
|
||||
<EmailCustomizationSettings
|
||||
organization={organization}
|
||||
hasWhiteLabelPermission={hasWhiteLabelPermission}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"use server";
|
||||
|
||||
import { generateInsightsForSurvey } from "@/app/api/(internal)/insights/lib/utils";
|
||||
import { getResponseCountBySurveyId, getResponses } from "@/lib/response/service";
|
||||
import { authenticatedActionClient } from "@/lib/utils/action-client";
|
||||
import { checkAuthorizationUpdated } from "@/lib/utils/action-client-middleware";
|
||||
@@ -108,31 +107,3 @@ export const getResponseCountAction = authenticatedActionClient
|
||||
|
||||
return getResponseCountBySurveyId(parsedInput.surveyId, parsedInput.filterCriteria);
|
||||
});
|
||||
|
||||
const ZGenerateInsightsForSurveyAction = z.object({
|
||||
surveyId: ZId,
|
||||
});
|
||||
|
||||
export const generateInsightsForSurveyAction = authenticatedActionClient
|
||||
.schema(ZGenerateInsightsForSurveyAction)
|
||||
.action(async ({ ctx, parsedInput }) => {
|
||||
await checkAuthorizationUpdated({
|
||||
userId: ctx.user.id,
|
||||
organizationId: await getOrganizationIdFromSurveyId(parsedInput.surveyId),
|
||||
access: [
|
||||
{
|
||||
type: "organization",
|
||||
schema: ZGenerateInsightsForSurveyAction,
|
||||
data: parsedInput,
|
||||
roles: ["owner", "manager"],
|
||||
},
|
||||
{
|
||||
type: "projectTeam",
|
||||
projectId: await getProjectIdFromSurveyId(parsedInput.surveyId),
|
||||
minPermission: "readWrite",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
generateInsightsForSurvey(parsedInput.surveyId);
|
||||
});
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import { SurveyAnalysisNavigation } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/components/SurveyAnalysisNavigation";
|
||||
import { ResponsePage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponsePage";
|
||||
import { EnableInsightsBanner } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/EnableInsightsBanner";
|
||||
import { SurveyAnalysisCTA } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA";
|
||||
import { needsInsightsGeneration } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/utils";
|
||||
import { MAX_RESPONSES_FOR_INSIGHT_GENERATION, RESPONSES_PER_PAGE, WEBAPP_URL } from "@/lib/constants";
|
||||
import { RESPONSES_PER_PAGE, WEBAPP_URL } from "@/lib/constants";
|
||||
import { getSurveyDomain } from "@/lib/getSurveyUrl";
|
||||
import { getResponseCountBySurveyId } from "@/lib/response/service";
|
||||
import { getSurvey } from "@/lib/survey/service";
|
||||
import { getTagsByEnvironmentId } from "@/lib/tag/service";
|
||||
import { getUser } from "@/lib/user/service";
|
||||
import { findMatchingLocale } from "@/lib/utils/locale";
|
||||
import { getIsAIEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
import { getEnvironmentAuth } from "@/modules/environments/lib/utils";
|
||||
import { PageContentWrapper } from "@/modules/ui/components/page-content-wrapper";
|
||||
import { PageHeader } from "@/modules/ui/components/page-header";
|
||||
@@ -20,7 +17,7 @@ const Page = async (props) => {
|
||||
const params = await props.params;
|
||||
const t = await getTranslate();
|
||||
|
||||
const { session, environment, organization, isReadOnly } = await getEnvironmentAuth(params.environmentId);
|
||||
const { session, environment, isReadOnly } = await getEnvironmentAuth(params.environmentId);
|
||||
|
||||
const survey = await getSurvey(params.surveyId);
|
||||
|
||||
@@ -38,11 +35,6 @@ const Page = async (props) => {
|
||||
|
||||
const totalResponseCount = await getResponseCountBySurveyId(params.surveyId);
|
||||
|
||||
const isAIEnabled = await getIsAIEnabled({
|
||||
isAIEnabled: organization.isAIEnabled,
|
||||
billing: organization.billing,
|
||||
});
|
||||
const shouldGenerateInsights = needsInsightsGeneration(survey);
|
||||
const locale = await findMatchingLocale();
|
||||
const surveyDomain = getSurveyDomain();
|
||||
|
||||
@@ -57,16 +49,9 @@ const Page = async (props) => {
|
||||
isReadOnly={isReadOnly}
|
||||
user={user}
|
||||
surveyDomain={surveyDomain}
|
||||
responseCount={totalResponseCount}
|
||||
/>
|
||||
}>
|
||||
{isAIEnabled && shouldGenerateInsights && (
|
||||
<EnableInsightsBanner
|
||||
surveyId={survey.id}
|
||||
surveyResponseCount={totalResponseCount}
|
||||
maxResponseCount={MAX_RESPONSES_FOR_INSIGHT_GENERATION}
|
||||
/>
|
||||
)}
|
||||
|
||||
<SurveyAnalysisNavigation
|
||||
environmentId={environment.id}
|
||||
survey={survey}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionSummaryAddress } from "@formbricks/types/surveys/types";
|
||||
import { AddressSummary } from "./AddressSummary";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("@/lib/time", () => ({
|
||||
timeSince: () => "2 hours ago",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/contact", () => ({
|
||||
getContactIdentifier: () => "contact@example.com",
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/avatars", () => ({
|
||||
PersonAvatar: ({ personId }: { personId: string }) => <div data-testid="person-avatar">{personId}</div>,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/array-response", () => ({
|
||||
ArrayResponse: ({ value }: { value: string[] }) => (
|
||||
<div data-testid="array-response">{value.join(", ")}</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("./QuestionSummaryHeader", () => ({
|
||||
QuestionSummaryHeader: () => <div data-testid="question-summary-header" />,
|
||||
}));
|
||||
|
||||
describe("AddressSummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const environmentId = "env-123";
|
||||
const survey = {} as TSurvey;
|
||||
const locale = "en-US";
|
||||
|
||||
test("renders table headers correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Address Question" },
|
||||
samples: [],
|
||||
} as unknown as TSurveyQuestionSummaryAddress;
|
||||
|
||||
render(
|
||||
<AddressSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("question-summary-header")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.user")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.response")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.time")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders contact information correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Address Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: ["123 Main St", "Apt 4", "New York", "NY", "10001"],
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: { email: "user@example.com" },
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryAddress;
|
||||
|
||||
render(
|
||||
<AddressSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("person-avatar")).toHaveTextContent("contact1");
|
||||
expect(screen.getByText("contact@example.com")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("array-response")).toHaveTextContent("123 Main St, Apt 4, New York, NY, 10001");
|
||||
expect(screen.getByText("2 hours ago")).toBeInTheDocument();
|
||||
|
||||
// Check link to contact
|
||||
const contactLink = screen.getByText("contact@example.com").closest("a");
|
||||
expect(contactLink).toHaveAttribute("href", `/environments/${environmentId}/contacts/contact1`);
|
||||
});
|
||||
|
||||
test("renders anonymous user when no contact is provided", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Address Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response2",
|
||||
value: ["456 Oak St", "London", "UK"],
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: null,
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryAddress;
|
||||
|
||||
render(
|
||||
<AddressSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("person-avatar")).toHaveTextContent("anonymous");
|
||||
expect(screen.getByText("common.anonymous")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("array-response")).toHaveTextContent("456 Oak St, London, UK");
|
||||
});
|
||||
|
||||
test("renders multiple responses correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Address Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: ["123 Main St", "New York"],
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
{
|
||||
id: "response2",
|
||||
value: ["456 Oak St", "London"],
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact2" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryAddress;
|
||||
|
||||
render(
|
||||
<AddressSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getAllByTestId("person-avatar")).toHaveLength(2);
|
||||
expect(screen.getAllByTestId("array-response")).toHaveLength(2);
|
||||
expect(screen.getAllByText("2 hours ago")).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionSummaryCta } from "@formbricks/types/surveys/types";
|
||||
import { CTASummary } from "./CTASummary";
|
||||
|
||||
vi.mock("@/modules/ui/components/progress-bar", () => ({
|
||||
ProgressBar: ({ progress, barColor }: { progress: number; barColor: string }) => (
|
||||
<div data-testid="progress-bar">{`${progress}-${barColor}`}</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("./QuestionSummaryHeader", () => ({
|
||||
QuestionSummaryHeader: ({
|
||||
additionalInfo,
|
||||
}: {
|
||||
showResponses: boolean;
|
||||
additionalInfo: React.ReactNode;
|
||||
}) => <div data-testid="question-summary-header">{additionalInfo}</div>,
|
||||
}));
|
||||
|
||||
vi.mock("lucide-react", () => ({
|
||||
InboxIcon: () => <div data-testid="inbox-icon" />,
|
||||
}));
|
||||
|
||||
vi.mock("../lib/utils", () => ({
|
||||
convertFloatToNDecimal: (value: number) => value.toFixed(2),
|
||||
}));
|
||||
|
||||
describe("CTASummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const survey = {} as TSurvey;
|
||||
|
||||
test("renders with all metrics and required question", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "CTA Question", required: true },
|
||||
impressionCount: 100,
|
||||
clickCount: 25,
|
||||
skipCount: 10,
|
||||
ctr: { count: 25, percentage: 25 },
|
||||
} as unknown as TSurveyQuestionSummaryCta;
|
||||
|
||||
render(<CTASummary questionSummary={questionSummary} survey={survey} />);
|
||||
|
||||
expect(screen.getByTestId("question-summary-header")).toBeInTheDocument();
|
||||
expect(screen.getByText("100 common.impressions")).toBeInTheDocument();
|
||||
// Use getAllByText instead of getByText for multiple matching elements
|
||||
expect(screen.getAllByText("25 common.clicks")).toHaveLength(2);
|
||||
expect(screen.queryByText("10 common.skips")).not.toBeInTheDocument(); // Should not show skips for required questions
|
||||
|
||||
// Check CTR section
|
||||
expect(screen.getByText("CTR")).toBeInTheDocument();
|
||||
expect(screen.getByText("25.00%")).toBeInTheDocument();
|
||||
|
||||
// Check progress bar
|
||||
expect(screen.getByTestId("progress-bar")).toHaveTextContent("0.25-bg-brand-dark");
|
||||
});
|
||||
|
||||
test("renders skip count for non-required questions", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "CTA Question", required: false },
|
||||
impressionCount: 100,
|
||||
clickCount: 20,
|
||||
skipCount: 30,
|
||||
ctr: { count: 20, percentage: 20 },
|
||||
} as unknown as TSurveyQuestionSummaryCta;
|
||||
|
||||
render(<CTASummary questionSummary={questionSummary} survey={survey} />);
|
||||
|
||||
expect(screen.getByText("30 common.skips")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders singular form for count = 1", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "CTA Question", required: true },
|
||||
impressionCount: 10,
|
||||
clickCount: 1,
|
||||
skipCount: 0,
|
||||
ctr: { count: 1, percentage: 10 },
|
||||
} as unknown as TSurveyQuestionSummaryCta;
|
||||
|
||||
render(<CTASummary questionSummary={questionSummary} survey={survey} />);
|
||||
|
||||
// Use getAllByText instead of getByText for multiple matching elements
|
||||
expect(screen.getAllByText("1 common.click")).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,69 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionSummaryCal } from "@formbricks/types/surveys/types";
|
||||
import { CalSummary } from "./CalSummary";
|
||||
|
||||
vi.mock("@/modules/ui/components/progress-bar", () => ({
|
||||
ProgressBar: ({ progress, barColor }: { progress: number; barColor: string }) => (
|
||||
<div data-testid="progress-bar">{`${progress}-${barColor}`}</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("./QuestionSummaryHeader", () => ({
|
||||
QuestionSummaryHeader: () => <div data-testid="question-summary-header" />,
|
||||
}));
|
||||
|
||||
vi.mock("../lib/utils", () => ({
|
||||
convertFloatToNDecimal: (value: number) => value.toFixed(2),
|
||||
}));
|
||||
|
||||
describe("CalSummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const environmentId = "env-123";
|
||||
const survey = {} as TSurvey;
|
||||
|
||||
test("renders the correct components and data", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Calendar Question" },
|
||||
booked: { count: 5, percentage: 75 },
|
||||
skipped: { count: 1, percentage: 25 },
|
||||
} as unknown as TSurveyQuestionSummaryCal;
|
||||
|
||||
render(<CalSummary questionSummary={questionSummary} environmentId={environmentId} survey={survey} />);
|
||||
|
||||
expect(screen.getByTestId("question-summary-header")).toBeInTheDocument();
|
||||
|
||||
// Check if booked section is displayed
|
||||
expect(screen.getByText("common.booked")).toBeInTheDocument();
|
||||
expect(screen.getByText("75.00%")).toBeInTheDocument();
|
||||
expect(screen.getByText("5 common.responses")).toBeInTheDocument();
|
||||
|
||||
// Check if skipped section is displayed
|
||||
expect(screen.getByText("common.dismissed")).toBeInTheDocument();
|
||||
expect(screen.getByText("25.00%")).toBeInTheDocument();
|
||||
expect(screen.getByText("1 common.response")).toBeInTheDocument();
|
||||
|
||||
// Check progress bars
|
||||
const progressBars = screen.getAllByTestId("progress-bar");
|
||||
expect(progressBars).toHaveLength(2);
|
||||
expect(progressBars[0]).toHaveTextContent("0.75-bg-brand-dark");
|
||||
expect(progressBars[1]).toHaveTextContent("0.25-bg-brand-dark");
|
||||
});
|
||||
|
||||
test("renders singular and plural response counts correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Calendar Question" },
|
||||
booked: { count: 1, percentage: 50 },
|
||||
skipped: { count: 1, percentage: 50 },
|
||||
} as unknown as TSurveyQuestionSummaryCal;
|
||||
|
||||
render(<CalSummary questionSummary={questionSummary} environmentId={environmentId} survey={survey} />);
|
||||
|
||||
// Use getAllByText directly since we know there are multiple matching elements
|
||||
const responseElements = screen.getAllByText("1 common.response");
|
||||
expect(responseElements).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,153 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionSummaryContactInfo } from "@formbricks/types/surveys/types";
|
||||
import { ContactInfoSummary } from "./ContactInfoSummary";
|
||||
|
||||
vi.mock("@/lib/time", () => ({
|
||||
timeSince: () => "2 hours ago",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/contact", () => ({
|
||||
getContactIdentifier: () => "contact@example.com",
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/avatars", () => ({
|
||||
PersonAvatar: ({ personId }: { personId: string }) => <div data-testid="person-avatar">{personId}</div>,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/array-response", () => ({
|
||||
ArrayResponse: ({ value }: { value: string[] }) => (
|
||||
<div data-testid="array-response">{value.join(", ")}</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("./QuestionSummaryHeader", () => ({
|
||||
QuestionSummaryHeader: () => <div data-testid="question-summary-header" />,
|
||||
}));
|
||||
|
||||
describe("ContactInfoSummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const environmentId = "env-123";
|
||||
const survey = {} as TSurvey;
|
||||
const locale = "en-US";
|
||||
|
||||
test("renders table headers correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Contact Info Question" },
|
||||
samples: [],
|
||||
} as unknown as TSurveyQuestionSummaryContactInfo;
|
||||
|
||||
render(
|
||||
<ContactInfoSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("question-summary-header")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.user")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.response")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.time")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders contact information correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Contact Info Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: ["John Doe", "john@example.com", "+1234567890"],
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: { email: "user@example.com" },
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryContactInfo;
|
||||
|
||||
render(
|
||||
<ContactInfoSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("person-avatar")).toHaveTextContent("contact1");
|
||||
expect(screen.getByText("contact@example.com")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("array-response")).toHaveTextContent("John Doe, john@example.com, +1234567890");
|
||||
expect(screen.getByText("2 hours ago")).toBeInTheDocument();
|
||||
|
||||
// Check link to contact
|
||||
const contactLink = screen.getByText("contact@example.com").closest("a");
|
||||
expect(contactLink).toHaveAttribute("href", `/environments/${environmentId}/contacts/contact1`);
|
||||
});
|
||||
|
||||
test("renders anonymous user when no contact is provided", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Contact Info Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response2",
|
||||
value: ["Anonymous User", "anonymous@example.com"],
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: null,
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryContactInfo;
|
||||
|
||||
render(
|
||||
<ContactInfoSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("person-avatar")).toHaveTextContent("anonymous");
|
||||
expect(screen.getByText("common.anonymous")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("array-response")).toHaveTextContent("Anonymous User, anonymous@example.com");
|
||||
});
|
||||
|
||||
test("renders multiple responses correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Contact Info Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: ["John Doe", "john@example.com"],
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
{
|
||||
id: "response2",
|
||||
value: ["Jane Smith", "jane@example.com"],
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact2" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryContactInfo;
|
||||
|
||||
render(
|
||||
<ContactInfoSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getAllByTestId("person-avatar")).toHaveLength(2);
|
||||
expect(screen.getAllByTestId("array-response")).toHaveLength(2);
|
||||
expect(screen.getAllByText("2 hours ago")).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,192 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionSummaryDate } from "@formbricks/types/surveys/types";
|
||||
import { DateQuestionSummary } from "./DateQuestionSummary";
|
||||
|
||||
vi.mock("@/lib/time", () => ({
|
||||
timeSince: () => "2 hours ago",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/contact", () => ({
|
||||
getContactIdentifier: () => "contact@example.com",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/datetime", () => ({
|
||||
formatDateWithOrdinal: (_: Date) => "January 1st, 2023",
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/avatars", () => ({
|
||||
PersonAvatar: ({ personId }: { personId: string }) => <div data-testid="person-avatar">{personId}</div>,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/button", () => ({
|
||||
Button: ({ children, onClick }: { children: React.ReactNode; onClick: () => void }) => (
|
||||
<button onClick={onClick} data-testid="load-more-button">
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("next/link", () => ({
|
||||
default: ({ children, href }: { children: React.ReactNode; href: string }) => (
|
||||
<a href={href} data-testid="next-link">
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("./QuestionSummaryHeader", () => ({
|
||||
QuestionSummaryHeader: () => <div data-testid="question-summary-header" />,
|
||||
}));
|
||||
|
||||
describe("DateQuestionSummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const environmentId = "env-123";
|
||||
const survey = {} as TSurvey;
|
||||
const locale = "en-US";
|
||||
|
||||
test("renders table headers correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Date Question" },
|
||||
samples: [],
|
||||
} as unknown as TSurveyQuestionSummaryDate;
|
||||
|
||||
render(
|
||||
<DateQuestionSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("question-summary-header")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.user")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.response")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.time")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders date responses correctly", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Date Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: "2023-01-01",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryDate;
|
||||
|
||||
render(
|
||||
<DateQuestionSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("January 1st, 2023")).toBeInTheDocument();
|
||||
expect(screen.getByText("contact@example.com")).toBeInTheDocument();
|
||||
expect(screen.getByText("2 hours ago")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders invalid dates with special message", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Date Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: "invalid-date",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryDate;
|
||||
|
||||
render(
|
||||
<DateQuestionSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("common.invalid_date(invalid-date)")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders anonymous user when no contact is provided", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Date Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: "2023-01-01",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: null,
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryDate;
|
||||
|
||||
render(
|
||||
<DateQuestionSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("common.anonymous")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("shows load more button when there are more responses and loads more on click", async () => {
|
||||
const samples = Array.from({ length: 15 }, (_, i) => ({
|
||||
id: `response${i}`,
|
||||
value: "2023-01-01",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: null,
|
||||
contactAttributes: {},
|
||||
}));
|
||||
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Date Question" },
|
||||
samples,
|
||||
} as unknown as TSurveyQuestionSummaryDate;
|
||||
|
||||
render(
|
||||
<DateQuestionSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
// Initially 10 responses should be visible
|
||||
expect(screen.getAllByText("January 1st, 2023")).toHaveLength(10);
|
||||
|
||||
// "Load More" button should be visible
|
||||
const loadMoreButton = screen.getByTestId("load-more-button");
|
||||
expect(loadMoreButton).toBeInTheDocument();
|
||||
|
||||
// Click "Load More"
|
||||
await userEvent.click(loadMoreButton);
|
||||
|
||||
// Now all 15 responses should be visible
|
||||
expect(screen.getAllByText("January 1st, 2023")).toHaveLength(15);
|
||||
|
||||
// "Load More" button should disappear
|
||||
expect(screen.queryByTestId("load-more-button")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,71 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { generateInsightsForSurveyAction } from "@/modules/ee/insights/actions";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/modules/ui/components/alert";
|
||||
import { Badge } from "@/modules/ui/components/badge";
|
||||
import { Button } from "@/modules/ui/components/button";
|
||||
import { TooltipRenderer } from "@/modules/ui/components/tooltip";
|
||||
import { useTranslate } from "@tolgee/react";
|
||||
import { SparklesIcon } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
interface EnableInsightsBannerProps {
|
||||
surveyId: string;
|
||||
maxResponseCount: number;
|
||||
surveyResponseCount: number;
|
||||
}
|
||||
|
||||
export const EnableInsightsBanner = ({
|
||||
surveyId,
|
||||
surveyResponseCount,
|
||||
maxResponseCount,
|
||||
}: EnableInsightsBannerProps) => {
|
||||
const { t } = useTranslate();
|
||||
const [isGeneratingInsights, setIsGeneratingInsights] = useState(false);
|
||||
|
||||
const handleInsightGeneration = async () => {
|
||||
toast.success("Generating insights for this survey. Please check back in a few minutes.", {
|
||||
duration: 3000,
|
||||
});
|
||||
setIsGeneratingInsights(true);
|
||||
toast.success(t("environments.surveys.summary.enable_ai_insights_banner_success"));
|
||||
generateInsightsForSurveyAction({ surveyId });
|
||||
};
|
||||
|
||||
if (isGeneratingInsights) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Alert className="mb-6 mt-4 flex items-center gap-4 border-slate-400 bg-white">
|
||||
<div>
|
||||
<SparklesIcon strokeWidth={1.5} className="size-7 text-slate-700" />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<AlertTitle>
|
||||
<span className="mr-2">{t("environments.surveys.summary.enable_ai_insights_banner_title")}</span>
|
||||
<Badge type="gray" size="normal" text="Beta" />
|
||||
</AlertTitle>
|
||||
<AlertDescription className="flex items-start justify-between gap-4">
|
||||
{t("environments.surveys.summary.enable_ai_insights_banner_description")}
|
||||
</AlertDescription>
|
||||
</div>
|
||||
<TooltipRenderer
|
||||
tooltipContent={
|
||||
surveyResponseCount > maxResponseCount
|
||||
? t("environments.surveys.summary.enable_ai_insights_banner_tooltip")
|
||||
: undefined
|
||||
}>
|
||||
<Button
|
||||
size="sm"
|
||||
className="shrink-0"
|
||||
onClick={handleInsightGeneration}
|
||||
loading={isGeneratingInsights}
|
||||
disabled={surveyResponseCount > maxResponseCount}>
|
||||
{t("environments.surveys.summary.enable_ai_insights_banner_button")}
|
||||
</Button>
|
||||
</TooltipRenderer>
|
||||
</Alert>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,231 @@
|
||||
import { FileUploadSummary } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/FileUploadSummary";
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import {
|
||||
TSurvey,
|
||||
TSurveyFileUploadQuestion,
|
||||
TSurveyQuestionSummaryFileUpload,
|
||||
TSurveyQuestionTypeEnum,
|
||||
} from "@formbricks/types/surveys/types";
|
||||
|
||||
// Mock child components and hooks
|
||||
vi.mock("@/modules/ui/components/avatars", () => ({
|
||||
PersonAvatar: vi.fn(() => <div>PersonAvatarMock</div>),
|
||||
}));
|
||||
|
||||
vi.mock("./QuestionSummaryHeader", () => ({
|
||||
QuestionSummaryHeader: vi.fn(() => <div>QuestionSummaryHeaderMock</div>),
|
||||
}));
|
||||
|
||||
// Mock utility functions
|
||||
vi.mock("@/lib/storage/utils", () => ({
|
||||
getOriginalFileNameFromUrl: (url: string) => `original-${url.split("/").pop()}`,
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/time", () => ({
|
||||
timeSince: () => "some time ago",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/contact", () => ({
|
||||
getContactIdentifier: () => "contact@example.com",
|
||||
}));
|
||||
|
||||
const environmentId = "test-env-id";
|
||||
const survey = { id: "survey-1" } as TSurvey;
|
||||
const locale = "en-US";
|
||||
|
||||
const createMockResponse = (id: string, value: string[], contactId: string | null = null) => ({
|
||||
id: `response-${id}`,
|
||||
value,
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: contactId ? { id: contactId, name: `Contact ${contactId}` } : null,
|
||||
contactAttributes: contactId ? { email: `contact${contactId}@example.com` } : {},
|
||||
});
|
||||
|
||||
const questionSummaryBase = {
|
||||
question: {
|
||||
id: "q1",
|
||||
headline: { default: "Upload your file" },
|
||||
type: TSurveyQuestionTypeEnum.FileUpload,
|
||||
} as unknown as TSurveyFileUploadQuestion,
|
||||
responseCount: 0,
|
||||
files: [],
|
||||
} as unknown as TSurveyQuestionSummaryFileUpload;
|
||||
|
||||
describe("FileUploadSummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("renders the component with initial responses", () => {
|
||||
const files = Array.from({ length: 5 }, (_, i) =>
|
||||
createMockResponse(i.toString(), [`https://example.com/file${i}.pdf`], `contact-${i}`)
|
||||
);
|
||||
const questionSummary = {
|
||||
...questionSummaryBase,
|
||||
files,
|
||||
responseCount: files.length,
|
||||
} as unknown as TSurveyQuestionSummaryFileUpload;
|
||||
|
||||
render(
|
||||
<FileUploadSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("QuestionSummaryHeaderMock")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.user")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.response")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.time")).toBeInTheDocument();
|
||||
expect(screen.getAllByText("PersonAvatarMock")).toHaveLength(5);
|
||||
expect(screen.getAllByText("contact@example.com")).toHaveLength(5);
|
||||
expect(screen.getByText("original-file0.pdf")).toBeInTheDocument();
|
||||
expect(screen.getByText("original-file4.pdf")).toBeInTheDocument();
|
||||
expect(screen.queryByText("common.load_more")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders 'Skipped' when value is an empty array", () => {
|
||||
const files = [createMockResponse("skipped", [], "contact-skipped")];
|
||||
const questionSummary = {
|
||||
...questionSummaryBase,
|
||||
files,
|
||||
responseCount: files.length,
|
||||
} as unknown as TSurveyQuestionSummaryFileUpload;
|
||||
|
||||
render(
|
||||
<FileUploadSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("common.skipped")).toBeInTheDocument();
|
||||
expect(screen.queryByText(/original-/)).not.toBeInTheDocument(); // No file name should be rendered
|
||||
});
|
||||
|
||||
test("renders 'Anonymous' when contact is null", () => {
|
||||
const files = [createMockResponse("anon", ["https://example.com/anonfile.jpg"], null)];
|
||||
const questionSummary = {
|
||||
...questionSummaryBase,
|
||||
files,
|
||||
responseCount: files.length,
|
||||
} as unknown as TSurveyQuestionSummaryFileUpload;
|
||||
|
||||
render(
|
||||
<FileUploadSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("common.anonymous")).toBeInTheDocument();
|
||||
expect(screen.getByText("original-anonfile.jpg")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("shows 'Load More' button when there are more than 10 responses and loads more on click", async () => {
|
||||
const files = Array.from({ length: 15 }, (_, i) =>
|
||||
createMockResponse(i.toString(), [`https://example.com/file${i}.txt`], `contact-${i}`)
|
||||
);
|
||||
const questionSummary = {
|
||||
...questionSummaryBase,
|
||||
files,
|
||||
responseCount: files.length,
|
||||
} as unknown as TSurveyQuestionSummaryFileUpload;
|
||||
|
||||
render(
|
||||
<FileUploadSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
// Initially 10 responses should be visible
|
||||
expect(screen.getAllByText("PersonAvatarMock")).toHaveLength(10);
|
||||
expect(screen.getByText("original-file9.txt")).toBeInTheDocument();
|
||||
expect(screen.queryByText("original-file10.txt")).not.toBeInTheDocument();
|
||||
|
||||
// "Load More" button should be visible
|
||||
const loadMoreButton = screen.getByText("common.load_more");
|
||||
expect(loadMoreButton).toBeInTheDocument();
|
||||
|
||||
// Click "Load More"
|
||||
await userEvent.click(loadMoreButton);
|
||||
|
||||
// Now all 15 responses should be visible
|
||||
expect(screen.getAllByText("PersonAvatarMock")).toHaveLength(15);
|
||||
expect(screen.getByText("original-file14.txt")).toBeInTheDocument();
|
||||
|
||||
// "Load More" button should disappear
|
||||
expect(screen.queryByText("common.load_more")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders multiple files for a single response", () => {
|
||||
const files = [
|
||||
createMockResponse(
|
||||
"multi",
|
||||
["https://example.com/fileA.png", "https://example.com/fileB.docx"],
|
||||
"contact-multi"
|
||||
),
|
||||
];
|
||||
const questionSummary = {
|
||||
...questionSummaryBase,
|
||||
files,
|
||||
responseCount: files.length,
|
||||
} as unknown as TSurveyQuestionSummaryFileUpload;
|
||||
|
||||
render(
|
||||
<FileUploadSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("original-fileA.png")).toBeInTheDocument();
|
||||
expect(screen.getByText("original-fileB.docx")).toBeInTheDocument();
|
||||
// Check that download links exist
|
||||
const links = screen.getAllByRole("link");
|
||||
// 1 contact link + 2 file links
|
||||
expect(links.filter((link) => link.getAttribute("target") === "_blank")).toHaveLength(2);
|
||||
expect(
|
||||
links.find((link) => link.getAttribute("href") === "https://example.com/fileA.png")
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
links.find((link) => link.getAttribute("href") === "https://example.com/fileB.docx")
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders contact link correctly", () => {
|
||||
const contactId = "contact-link-test";
|
||||
const files = [createMockResponse("link", ["https://example.com/link.pdf"], contactId)];
|
||||
const questionSummary = {
|
||||
...questionSummaryBase,
|
||||
files,
|
||||
responseCount: files.length,
|
||||
} as unknown as TSurveyQuestionSummaryFileUpload;
|
||||
|
||||
render(
|
||||
<FileUploadSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
const contactLink = screen.getByText("contact@example.com").closest("a");
|
||||
expect(contactLink).toBeInTheDocument();
|
||||
expect(contactLink).toHaveAttribute("href", `/environments/${environmentId}/contacts/${contactId}`);
|
||||
});
|
||||
});
|
||||
@@ -74,12 +74,12 @@ export const FileUploadSummary = ({
|
||||
<div className="col-span-2 grid">
|
||||
{Array.isArray(response.value) &&
|
||||
(response.value.length > 0 ? (
|
||||
response.value.map((fileUrl, index) => {
|
||||
response.value.map((fileUrl) => {
|
||||
const fileName = getOriginalFileNameFromUrl(fileUrl);
|
||||
|
||||
return (
|
||||
<div className="relative m-2 rounded-lg bg-slate-200" key={fileUrl}>
|
||||
<a href={fileUrl} key={index} target="_blank" rel="noopener noreferrer">
|
||||
<a href={fileUrl} key={fileUrl} target="_blank" rel="noopener noreferrer">
|
||||
<div className="absolute top-0 right-0 m-2">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-slate-50 hover:bg-white">
|
||||
<DownloadIcon className="h-6 text-slate-500" />
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TEnvironment } from "@formbricks/types/environment";
|
||||
import { TSurveyQuestionSummaryHiddenFields } from "@formbricks/types/surveys/types";
|
||||
import { HiddenFieldsSummary } from "./HiddenFieldsSummary";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("@/lib/time", () => ({
|
||||
timeSince: () => "2 hours ago",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/contact", () => ({
|
||||
getContactIdentifier: () => "contact@example.com",
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/avatars", () => ({
|
||||
PersonAvatar: ({ personId }: { personId: string }) => <div data-testid="person-avatar">{personId}</div>,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/button", () => ({
|
||||
Button: ({ children, onClick }: { children: React.ReactNode; onClick: () => void }) => (
|
||||
<button onClick={onClick} data-testid="load-more-button">
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
// Mock lucide-react components
|
||||
vi.mock("lucide-react", () => ({
|
||||
InboxIcon: () => <div data-testid="inbox-icon" />,
|
||||
MessageSquareTextIcon: () => <div data-testid="message-icon" />,
|
||||
Link: ({ children, href, className }: { children: React.ReactNode; href: string; className: string }) => (
|
||||
<a href={href} className={className} data-testid="lucide-link">
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
}));
|
||||
|
||||
// Mock Next.js Link
|
||||
vi.mock("next/link", () => ({
|
||||
default: ({ children, href }: { children: React.ReactNode; href: string }) => (
|
||||
<a href={href} data-testid="next-link">
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
}));
|
||||
|
||||
describe("HiddenFieldsSummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const environment = { id: "env-123" } as TEnvironment;
|
||||
const locale = "en-US";
|
||||
|
||||
test("renders component with correct header and single response", () => {
|
||||
const questionSummary = {
|
||||
id: "hidden-field-1",
|
||||
responseCount: 1,
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: "Hidden value",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryHiddenFields;
|
||||
|
||||
render(
|
||||
<HiddenFieldsSummary environment={environment} questionSummary={questionSummary} locale={locale} />
|
||||
);
|
||||
|
||||
expect(screen.getByText("hidden-field-1")).toBeInTheDocument();
|
||||
expect(screen.getByText("Hidden Field")).toBeInTheDocument();
|
||||
expect(screen.getByText("1 common.response")).toBeInTheDocument();
|
||||
|
||||
// Headers
|
||||
expect(screen.getByText("common.user")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.response")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.time")).toBeInTheDocument();
|
||||
|
||||
// We can skip checking for PersonAvatar as it's inside hidden md:flex
|
||||
expect(screen.getByText("contact@example.com")).toBeInTheDocument();
|
||||
expect(screen.getByText("Hidden value")).toBeInTheDocument();
|
||||
expect(screen.getByText("2 hours ago")).toBeInTheDocument();
|
||||
|
||||
// Check for link without checking for specific href
|
||||
expect(screen.getByText("contact@example.com")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders anonymous user when no contact is provided", () => {
|
||||
const questionSummary = {
|
||||
id: "hidden-field-1",
|
||||
responseCount: 1,
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: "Anonymous hidden value",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: null,
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryHiddenFields;
|
||||
|
||||
render(
|
||||
<HiddenFieldsSummary environment={environment} questionSummary={questionSummary} locale={locale} />
|
||||
);
|
||||
|
||||
// Instead of checking for avatar, just check for anonymous text
|
||||
expect(screen.getByText("common.anonymous")).toBeInTheDocument();
|
||||
expect(screen.getByText("Anonymous hidden value")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders plural response label when multiple responses", () => {
|
||||
const questionSummary = {
|
||||
id: "hidden-field-1",
|
||||
responseCount: 2,
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: "Hidden value 1",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
{
|
||||
id: "response2",
|
||||
value: "Hidden value 2",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact2" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryHiddenFields;
|
||||
|
||||
render(
|
||||
<HiddenFieldsSummary environment={environment} questionSummary={questionSummary} locale={locale} />
|
||||
);
|
||||
|
||||
expect(screen.getByText("2 common.responses")).toBeInTheDocument();
|
||||
expect(screen.getAllByText("contact@example.com")).toHaveLength(2);
|
||||
});
|
||||
|
||||
test("shows load more button when there are more responses and loads more on click", async () => {
|
||||
const samples = Array.from({ length: 15 }, (_, i) => ({
|
||||
id: `response${i}`,
|
||||
value: `Hidden value ${i}`,
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: null,
|
||||
contactAttributes: {},
|
||||
}));
|
||||
|
||||
const questionSummary = {
|
||||
id: "hidden-field-1",
|
||||
responseCount: samples.length,
|
||||
samples,
|
||||
} as unknown as TSurveyQuestionSummaryHiddenFields;
|
||||
|
||||
render(
|
||||
<HiddenFieldsSummary environment={environment} questionSummary={questionSummary} locale={locale} />
|
||||
);
|
||||
|
||||
// Initially 10 responses should be visible
|
||||
expect(screen.getAllByText(/Hidden value \d+/)).toHaveLength(10);
|
||||
|
||||
// "Load More" button should be visible
|
||||
const loadMoreButton = screen.getByTestId("load-more-button");
|
||||
expect(loadMoreButton).toBeInTheDocument();
|
||||
|
||||
// Click "Load More"
|
||||
await userEvent.click(loadMoreButton);
|
||||
|
||||
// Now all 15 responses should be visible
|
||||
expect(screen.getAllByText(/Hidden value \d+/)).toHaveLength(15);
|
||||
|
||||
// "Load More" button should disappear
|
||||
expect(screen.queryByTestId("load-more-button")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,174 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionSummaryOpenText } from "@formbricks/types/surveys/types";
|
||||
import { OpenTextSummary } from "./OpenTextSummary";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("@/lib/time", () => ({
|
||||
timeSince: () => "2 hours ago",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/contact", () => ({
|
||||
getContactIdentifier: () => "contact@example.com",
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/analysis/utils", () => ({
|
||||
renderHyperlinkedContent: (text: string) => <div data-testid="hyperlinked-content">{text}</div>,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/avatars", () => ({
|
||||
PersonAvatar: ({ personId }: { personId: string }) => <div data-testid="person-avatar">{personId}</div>,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/button", () => ({
|
||||
Button: ({ children, onClick }: { children: React.ReactNode; onClick: () => void }) => (
|
||||
<button onClick={onClick} data-testid="load-more-button">
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/secondary-navigation", () => ({
|
||||
SecondaryNavigation: ({ activeId, navigation }: any) => (
|
||||
<div data-testid="secondary-navigation">
|
||||
{navigation.map((item: any) => (
|
||||
<button key={item.id} onClick={item.onClick} data-active={activeId === item.id}>
|
||||
{item.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/table", () => ({
|
||||
Table: ({ children }: { children: React.ReactNode }) => <table data-testid="table">{children}</table>,
|
||||
TableHeader: ({ children }: { children: React.ReactNode }) => <thead>{children}</thead>,
|
||||
TableBody: ({ children }: { children: React.ReactNode }) => <tbody>{children}</tbody>,
|
||||
TableRow: ({ children }: { children: React.ReactNode }) => <tr>{children}</tr>,
|
||||
TableHead: ({ children }: { children: React.ReactNode }) => <th>{children}</th>,
|
||||
TableCell: ({ children, width }: { children: React.ReactNode; width?: number }) => (
|
||||
<td style={width ? { width } : {}}>{children}</td>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ee/insights/components/insights-view", () => ({
|
||||
InsightView: () => <div data-testid="insight-view"></div>,
|
||||
}));
|
||||
|
||||
vi.mock("./QuestionSummaryHeader", () => ({
|
||||
QuestionSummaryHeader: ({ additionalInfo }: { additionalInfo?: React.ReactNode }) => (
|
||||
<div data-testid="question-summary-header">{additionalInfo}</div>
|
||||
),
|
||||
}));
|
||||
|
||||
describe("OpenTextSummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const environmentId = "env-123";
|
||||
const survey = { id: "survey-1" } as TSurvey;
|
||||
const locale = "en-US";
|
||||
|
||||
test("renders response mode by default when insights not enabled", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Open Text Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: "Sample response text",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: { id: "contact1" },
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryOpenText;
|
||||
|
||||
render(
|
||||
<OpenTextSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("question-summary-header")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("table")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("person-avatar")).toHaveTextContent("contact1");
|
||||
expect(screen.getByText("contact@example.com")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("hyperlinked-content")).toHaveTextContent("Sample response text");
|
||||
expect(screen.getByText("2 hours ago")).toBeInTheDocument();
|
||||
|
||||
// No secondary navigation when insights not enabled
|
||||
expect(screen.queryByTestId("secondary-navigation")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders anonymous user when no contact is provided", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Open Text Question" },
|
||||
samples: [
|
||||
{
|
||||
id: "response1",
|
||||
value: "Anonymous response",
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: null,
|
||||
contactAttributes: {},
|
||||
},
|
||||
],
|
||||
} as unknown as TSurveyQuestionSummaryOpenText;
|
||||
|
||||
render(
|
||||
<OpenTextSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("person-avatar")).toHaveTextContent("anonymous");
|
||||
expect(screen.getByText("common.anonymous")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("shows load more button when there are more responses and loads more on click", async () => {
|
||||
const samples = Array.from({ length: 15 }, (_, i) => ({
|
||||
id: `response${i}`,
|
||||
value: `Response ${i}`,
|
||||
updatedAt: new Date().toISOString(),
|
||||
contact: null,
|
||||
contactAttributes: {},
|
||||
}));
|
||||
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Open Text Question" },
|
||||
samples,
|
||||
} as unknown as TSurveyQuestionSummaryOpenText;
|
||||
|
||||
render(
|
||||
<OpenTextSummary
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environmentId}
|
||||
survey={survey}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
// Initially 10 responses should be visible
|
||||
expect(screen.getAllByTestId("hyperlinked-content")).toHaveLength(10);
|
||||
|
||||
// "Load More" button should be visible
|
||||
const loadMoreButton = screen.getByTestId("load-more-button");
|
||||
expect(loadMoreButton).toBeInTheDocument();
|
||||
|
||||
// Click "Load More"
|
||||
await userEvent.click(loadMoreButton);
|
||||
|
||||
// Now all 15 responses should be visible
|
||||
expect(screen.getAllByTestId("hyperlinked-content")).toHaveLength(15);
|
||||
|
||||
// "Load More" button should disappear
|
||||
expect(screen.queryByTestId("load-more-button")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -3,10 +3,8 @@
|
||||
import { timeSince } from "@/lib/time";
|
||||
import { getContactIdentifier } from "@/lib/utils/contact";
|
||||
import { renderHyperlinkedContent } from "@/modules/analysis/utils";
|
||||
import { InsightView } from "@/modules/ee/insights/components/insights-view";
|
||||
import { PersonAvatar } from "@/modules/ui/components/avatars";
|
||||
import { Button } from "@/modules/ui/components/button";
|
||||
import { SecondaryNavigation } from "@/modules/ui/components/secondary-navigation";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/modules/ui/components/table";
|
||||
import { useTranslate } from "@tolgee/react";
|
||||
import Link from "next/link";
|
||||
@@ -19,25 +17,12 @@ interface OpenTextSummaryProps {
|
||||
questionSummary: TSurveyQuestionSummaryOpenText;
|
||||
environmentId: string;
|
||||
survey: TSurvey;
|
||||
isAIEnabled: boolean;
|
||||
documentsPerPage?: number;
|
||||
locale: TUserLocale;
|
||||
}
|
||||
|
||||
export const OpenTextSummary = ({
|
||||
questionSummary,
|
||||
environmentId,
|
||||
survey,
|
||||
isAIEnabled,
|
||||
documentsPerPage,
|
||||
locale,
|
||||
}: OpenTextSummaryProps) => {
|
||||
export const OpenTextSummary = ({ questionSummary, environmentId, survey, locale }: OpenTextSummaryProps) => {
|
||||
const { t } = useTranslate();
|
||||
const isInsightsEnabled = isAIEnabled && questionSummary.insightsEnabled;
|
||||
const [visibleResponses, setVisibleResponses] = useState(10);
|
||||
const [activeTab, setActiveTab] = useState<"insights" | "responses">(
|
||||
isInsightsEnabled && questionSummary.insights.length ? "insights" : "responses"
|
||||
);
|
||||
|
||||
const handleLoadMore = () => {
|
||||
// Increase the number of visible responses by 10, not exceeding the total number of responses
|
||||
@@ -46,104 +31,62 @@ export const OpenTextSummary = ({
|
||||
);
|
||||
};
|
||||
|
||||
const tabNavigation = [
|
||||
{
|
||||
id: "insights",
|
||||
label: t("common.insights"),
|
||||
onClick: () => setActiveTab("insights"),
|
||||
},
|
||||
{
|
||||
id: "responses",
|
||||
label: t("common.responses"),
|
||||
onClick: () => setActiveTab("responses"),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm">
|
||||
<QuestionSummaryHeader
|
||||
questionSummary={questionSummary}
|
||||
survey={survey}
|
||||
additionalInfo={
|
||||
isAIEnabled && questionSummary.insightsEnabled === false ? (
|
||||
<div className="flex items-center space-x-2">
|
||||
<div className="flex items-center rounded-lg bg-slate-100 p-2">
|
||||
{t("environments.surveys.summary.insights_disabled")}
|
||||
</div>
|
||||
</div>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
{isInsightsEnabled && (
|
||||
<div className="ml-4">
|
||||
<SecondaryNavigation activeId={activeTab} navigation={tabNavigation} />
|
||||
</div>
|
||||
)}
|
||||
<QuestionSummaryHeader questionSummary={questionSummary} survey={survey} />
|
||||
<div className="border-t border-slate-200"></div>
|
||||
<div className="max-h-[40vh] overflow-y-auto">
|
||||
{activeTab === "insights" ? (
|
||||
<InsightView
|
||||
insights={questionSummary.insights}
|
||||
questionId={questionSummary.question.id}
|
||||
surveyId={survey.id}
|
||||
documentsPerPage={documentsPerPage}
|
||||
locale={locale}
|
||||
/>
|
||||
) : activeTab === "responses" ? (
|
||||
<>
|
||||
<Table>
|
||||
<TableHeader className="bg-slate-100">
|
||||
<TableRow>
|
||||
<TableHead>{t("common.user")}</TableHead>
|
||||
<TableHead>{t("common.response")}</TableHead>
|
||||
<TableHead>{t("common.time")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{questionSummary.samples.slice(0, visibleResponses).map((response) => (
|
||||
<TableRow key={response.id}>
|
||||
<TableCell>
|
||||
{response.contact ? (
|
||||
<Link
|
||||
className="ph-no-capture group flex items-center"
|
||||
href={`/environments/${environmentId}/contacts/${response.contact.id}`}>
|
||||
<div className="hidden md:flex">
|
||||
<PersonAvatar personId={response.contact.id} />
|
||||
</div>
|
||||
<p className="ph-no-capture break-all text-slate-600 group-hover:underline md:ml-2">
|
||||
{getContactIdentifier(response.contact, response.contactAttributes)}
|
||||
</p>
|
||||
</Link>
|
||||
) : (
|
||||
<div className="group flex items-center">
|
||||
<div className="hidden md:flex">
|
||||
<PersonAvatar personId="anonymous" />
|
||||
</div>
|
||||
<p className="break-normal text-slate-600 md:ml-2">{t("common.anonymous")}</p>
|
||||
</div>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
{typeof response.value === "string"
|
||||
? renderHyperlinkedContent(response.value)
|
||||
: response.value}
|
||||
</TableCell>
|
||||
<TableCell width={120}>
|
||||
{timeSince(new Date(response.updatedAt).toISOString(), locale)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{visibleResponses < questionSummary.samples.length && (
|
||||
<div className="flex justify-center py-4">
|
||||
<Button onClick={handleLoadMore} variant="secondary" size="sm">
|
||||
{t("common.load_more")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : null}
|
||||
<Table>
|
||||
<TableHeader className="bg-slate-100">
|
||||
<TableRow>
|
||||
<TableHead>{t("common.user")}</TableHead>
|
||||
<TableHead>{t("common.response")}</TableHead>
|
||||
<TableHead>{t("common.time")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{questionSummary.samples.slice(0, visibleResponses).map((response) => (
|
||||
<TableRow key={response.id}>
|
||||
<TableCell>
|
||||
{response.contact ? (
|
||||
<Link
|
||||
className="ph-no-capture group flex items-center"
|
||||
href={`/environments/${environmentId}/contacts/${response.contact.id}`}>
|
||||
<div className="hidden md:flex">
|
||||
<PersonAvatar personId={response.contact.id} />
|
||||
</div>
|
||||
<p className="ph-no-capture break-all text-slate-600 group-hover:underline md:ml-2">
|
||||
{getContactIdentifier(response.contact, response.contactAttributes)}
|
||||
</p>
|
||||
</Link>
|
||||
) : (
|
||||
<div className="group flex items-center">
|
||||
<div className="hidden md:flex">
|
||||
<PersonAvatar personId="anonymous" />
|
||||
</div>
|
||||
<p className="break-normal text-slate-600 md:ml-2">{t("common.anonymous")}</p>
|
||||
</div>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
{typeof response.value === "string"
|
||||
? renderHyperlinkedContent(response.value)
|
||||
: response.value}
|
||||
</TableCell>
|
||||
<TableCell width={120}>
|
||||
{timeSince(new Date(response.updatedAt).toISOString(), locale)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{visibleResponses < questionSummary.samples.length && (
|
||||
<div className="flex justify-center py-4">
|
||||
<Button onClick={handleLoadMore} variant="secondary" size="sm">
|
||||
{t("common.load_more")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionSummary, TSurveyQuestionTypeEnum } from "@formbricks/types/surveys/types";
|
||||
import { QuestionSummaryHeader } from "./QuestionSummaryHeader";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("@/lib/utils/recall", () => ({
|
||||
recallToHeadline: () => ({ default: "Recalled Headline" }),
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/survey/editor/lib/utils", () => ({
|
||||
formatTextWithSlashes: (text: string) => <span data-testid="formatted-headline">{text}</span>,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/survey/lib/questions", () => ({
|
||||
getQuestionTypes: () => [
|
||||
{
|
||||
id: "openText",
|
||||
label: "Open Text",
|
||||
icon: () => <div data-testid="question-icon">Icon</div>,
|
||||
},
|
||||
{
|
||||
id: "multipleChoice",
|
||||
label: "Multiple Choice",
|
||||
icon: () => <div data-testid="question-icon">Icon</div>,
|
||||
},
|
||||
],
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/settings-id", () => ({
|
||||
SettingsId: ({ title, id }: { title: string; id: string }) => (
|
||||
<div data-testid="settings-id">
|
||||
{title}: {id}
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
// Mock InboxIcon
|
||||
vi.mock("lucide-react", () => ({
|
||||
InboxIcon: () => <div data-testid="inbox-icon"></div>,
|
||||
}));
|
||||
|
||||
describe("QuestionSummaryHeader", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const survey = {} as TSurvey;
|
||||
|
||||
test("renders header with question headline and type", () => {
|
||||
const questionSummary = {
|
||||
question: {
|
||||
id: "q1",
|
||||
headline: { default: "Test Question" },
|
||||
type: "openText" as TSurveyQuestionTypeEnum,
|
||||
required: true,
|
||||
},
|
||||
responseCount: 42,
|
||||
} as unknown as TSurveyQuestionSummary;
|
||||
|
||||
render(<QuestionSummaryHeader questionSummary={questionSummary} survey={survey} />);
|
||||
|
||||
expect(screen.getByTestId("formatted-headline")).toHaveTextContent("Recalled Headline");
|
||||
|
||||
// Look for text content with a more specific approach
|
||||
const questionTypeElement = screen.getByText((content) => {
|
||||
return content.includes("Open Text") && !content.includes("common.question_id");
|
||||
});
|
||||
expect(questionTypeElement).toBeInTheDocument();
|
||||
|
||||
// Check for responses text specifically
|
||||
expect(
|
||||
screen.getByText((content) => {
|
||||
return content.includes("42") && content.includes("common.responses");
|
||||
})
|
||||
).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByTestId("question-icon")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("settings-id")).toHaveTextContent("common.question_id: q1");
|
||||
expect(screen.queryByText("environments.surveys.edit.optional")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("shows 'optional' tag when question is not required", () => {
|
||||
const questionSummary = {
|
||||
question: {
|
||||
id: "q2",
|
||||
headline: { default: "Optional Question" },
|
||||
type: "multipleChoice" as TSurveyQuestionTypeEnum,
|
||||
required: false,
|
||||
},
|
||||
responseCount: 10,
|
||||
} as unknown as TSurveyQuestionSummary;
|
||||
|
||||
render(<QuestionSummaryHeader questionSummary={questionSummary} survey={survey} />);
|
||||
|
||||
expect(screen.getByText("environments.surveys.edit.optional")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("hides response count when showResponses is false", () => {
|
||||
const questionSummary = {
|
||||
question: {
|
||||
id: "q3",
|
||||
headline: { default: "No Response Count Question" },
|
||||
type: "openText" as TSurveyQuestionTypeEnum,
|
||||
required: true,
|
||||
},
|
||||
responseCount: 15,
|
||||
} as unknown as TSurveyQuestionSummary;
|
||||
|
||||
render(<QuestionSummaryHeader questionSummary={questionSummary} survey={survey} showResponses={false} />);
|
||||
|
||||
expect(
|
||||
screen.queryByText((content) => content.includes("15") && content.includes("common.responses"))
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("shows unknown question type for unrecognized type", () => {
|
||||
const questionSummary = {
|
||||
question: {
|
||||
id: "q4",
|
||||
headline: { default: "Unknown Type Question" },
|
||||
type: "unknownType" as TSurveyQuestionTypeEnum,
|
||||
required: true,
|
||||
},
|
||||
responseCount: 5,
|
||||
} as unknown as TSurveyQuestionSummary;
|
||||
|
||||
render(<QuestionSummaryHeader questionSummary={questionSummary} survey={survey} />);
|
||||
|
||||
// Look for text in the question type element specifically
|
||||
const unknownTypeElement = screen.getByText((content) => {
|
||||
return (
|
||||
content.includes("environments.surveys.summary.unknown_question_type") &&
|
||||
!content.includes("common.question_id")
|
||||
);
|
||||
});
|
||||
expect(unknownTypeElement).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders additional info when provided", () => {
|
||||
const questionSummary = {
|
||||
question: {
|
||||
id: "q5",
|
||||
headline: { default: "With Additional Info" },
|
||||
type: "openText" as TSurveyQuestionTypeEnum,
|
||||
required: true,
|
||||
},
|
||||
responseCount: 20,
|
||||
} as unknown as TSurveyQuestionSummary;
|
||||
|
||||
const additionalInfo = <div data-testid="additional-info">Extra Information</div>;
|
||||
|
||||
render(
|
||||
<QuestionSummaryHeader
|
||||
questionSummary={questionSummary}
|
||||
survey={survey}
|
||||
additionalInfo={additionalInfo}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("additional-info")).toBeInTheDocument();
|
||||
expect(screen.getByText("Extra Information")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,104 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionSummaryRanking, TSurveyType } from "@formbricks/types/surveys/types";
|
||||
import { RankingSummary } from "./RankingSummary";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("./QuestionSummaryHeader", () => ({
|
||||
QuestionSummaryHeader: () => <div data-testid="question-summary-header" />,
|
||||
}));
|
||||
|
||||
vi.mock("../lib/utils", () => ({
|
||||
convertFloatToNDecimal: (value: number) => value.toFixed(2),
|
||||
}));
|
||||
|
||||
describe("RankingSummary", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const survey = {} as TSurvey;
|
||||
const surveyType: TSurveyType = "app";
|
||||
|
||||
test("renders ranking results in correct order", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Rank the following" },
|
||||
choices: {
|
||||
option1: { value: "Option A", avgRanking: 1.5, others: [] },
|
||||
option2: { value: "Option B", avgRanking: 2.3, others: [] },
|
||||
option3: { value: "Option C", avgRanking: 1.2, others: [] },
|
||||
},
|
||||
} as unknown as TSurveyQuestionSummaryRanking;
|
||||
|
||||
render(<RankingSummary questionSummary={questionSummary} survey={survey} surveyType={surveyType} />);
|
||||
|
||||
expect(screen.getByTestId("question-summary-header")).toBeInTheDocument();
|
||||
|
||||
// Check order: should be sorted by avgRanking (ascending)
|
||||
const options = screen.getAllByText(/Option [A-C]/);
|
||||
expect(options[0]).toHaveTextContent("Option C"); // 1.2 (lowest avgRanking first)
|
||||
expect(options[1]).toHaveTextContent("Option A"); // 1.5
|
||||
expect(options[2]).toHaveTextContent("Option B"); // 2.3
|
||||
|
||||
// Check rankings are displayed
|
||||
expect(screen.getByText("#1")).toBeInTheDocument();
|
||||
expect(screen.getByText("#2")).toBeInTheDocument();
|
||||
expect(screen.getByText("#3")).toBeInTheDocument();
|
||||
|
||||
// Check average values are displayed
|
||||
expect(screen.getByText("#1.20")).toBeInTheDocument();
|
||||
expect(screen.getByText("#1.50")).toBeInTheDocument();
|
||||
expect(screen.getByText("#2.30")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders 'other values found' section when others exist", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Rank the following" },
|
||||
choices: {
|
||||
option1: {
|
||||
value: "Option A",
|
||||
avgRanking: 1.0,
|
||||
others: [{ value: "Other value", count: 2 }],
|
||||
},
|
||||
},
|
||||
} as unknown as TSurveyQuestionSummaryRanking;
|
||||
|
||||
render(<RankingSummary questionSummary={questionSummary} survey={survey} surveyType={surveyType} />);
|
||||
|
||||
expect(screen.getByText("environments.surveys.summary.other_values_found")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("shows 'User' column in other values section for app survey type", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Rank the following" },
|
||||
choices: {
|
||||
option1: {
|
||||
value: "Option A",
|
||||
avgRanking: 1.0,
|
||||
others: [{ value: "Other value", count: 1 }],
|
||||
},
|
||||
},
|
||||
} as unknown as TSurveyQuestionSummaryRanking;
|
||||
|
||||
render(<RankingSummary questionSummary={questionSummary} survey={survey} surveyType="app" />);
|
||||
|
||||
expect(screen.getByText("common.user")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("doesn't show 'User' column for link survey type", () => {
|
||||
const questionSummary = {
|
||||
question: { id: "q1", headline: "Rank the following" },
|
||||
choices: {
|
||||
option1: {
|
||||
value: "Option A",
|
||||
avgRanking: 1.0,
|
||||
others: [{ value: "Other value", count: 1 }],
|
||||
},
|
||||
},
|
||||
} as unknown as TSurveyQuestionSummaryRanking;
|
||||
|
||||
render(<RankingSummary questionSummary={questionSummary} survey={survey} surveyType="link" />);
|
||||
|
||||
expect(screen.queryByText("common.user")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,125 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TSurvey, TSurveyQuestionTypeEnum, TSurveySummary } from "@formbricks/types/surveys/types";
|
||||
import { SummaryDropOffs } from "./SummaryDropOffs";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("@/lib/utils/recall", () => ({
|
||||
recallToHeadline: () => ({ default: "Recalled Question" }),
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/survey/editor/lib/utils", () => ({
|
||||
formatTextWithSlashes: (text) => <span data-testid="formatted-text">{text}</span>,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/survey/lib/questions", () => ({
|
||||
getQuestionIcon: () => () => <div data-testid="question-icon" />,
|
||||
}));
|
||||
|
||||
vi.mock("@/modules/ui/components/tooltip", () => ({
|
||||
TooltipProvider: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
Tooltip: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
TooltipTrigger: ({ children }: { children: React.ReactNode }) => (
|
||||
<div data-testid="tooltip-trigger">{children}</div>
|
||||
),
|
||||
TooltipContent: ({ children }: { children: React.ReactNode }) => (
|
||||
<div data-testid="tooltip-content">{children}</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("lucide-react", () => ({
|
||||
TimerIcon: () => <div data-testid="timer-icon" />,
|
||||
}));
|
||||
|
||||
describe("SummaryDropOffs", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const mockSurvey = {} as TSurvey;
|
||||
const mockDropOff: TSurveySummary["dropOff"] = [
|
||||
{
|
||||
questionId: "q1",
|
||||
headline: "First Question",
|
||||
questionType: TSurveyQuestionTypeEnum.OpenText,
|
||||
ttc: 15000, // 15 seconds
|
||||
impressions: 100,
|
||||
dropOffCount: 20,
|
||||
dropOffPercentage: 20,
|
||||
},
|
||||
{
|
||||
questionId: "q2",
|
||||
headline: "Second Question",
|
||||
questionType: TSurveyQuestionTypeEnum.MultipleChoiceMulti,
|
||||
ttc: 30000, // 30 seconds
|
||||
impressions: 80,
|
||||
dropOffCount: 15,
|
||||
dropOffPercentage: 18.75,
|
||||
},
|
||||
{
|
||||
questionId: "q3",
|
||||
headline: "Third Question",
|
||||
questionType: TSurveyQuestionTypeEnum.Rating,
|
||||
ttc: 0, // No time data
|
||||
impressions: 65,
|
||||
dropOffCount: 10,
|
||||
dropOffPercentage: 15.38,
|
||||
},
|
||||
];
|
||||
|
||||
test("renders header row with correct columns", () => {
|
||||
render(<SummaryDropOffs dropOff={mockDropOff} survey={mockSurvey} />);
|
||||
|
||||
// Check header
|
||||
expect(screen.getByText("common.questions")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("tooltip-trigger")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("timer-icon")).toBeInTheDocument();
|
||||
expect(screen.getByText("environments.surveys.summary.impressions")).toBeInTheDocument();
|
||||
expect(screen.getByText("environments.surveys.summary.drop_offs")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders tooltip with correct content", () => {
|
||||
render(<SummaryDropOffs dropOff={mockDropOff} survey={mockSurvey} />);
|
||||
|
||||
expect(screen.getByTestId("tooltip-content")).toBeInTheDocument();
|
||||
expect(screen.getByText("environments.surveys.summary.ttc_tooltip")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders all drop-off items with correct data", () => {
|
||||
render(<SummaryDropOffs dropOff={mockDropOff} survey={mockSurvey} />);
|
||||
|
||||
// There should be 3 rows of data (one for each question)
|
||||
expect(screen.getAllByTestId("question-icon")).toHaveLength(3);
|
||||
expect(screen.getAllByTestId("formatted-text")).toHaveLength(3);
|
||||
|
||||
// Check time to complete values
|
||||
expect(screen.getByText("15.00s")).toBeInTheDocument(); // 15000ms converted to seconds
|
||||
expect(screen.getByText("30.00s")).toBeInTheDocument(); // 30000ms converted to seconds
|
||||
expect(screen.getByText("N/A")).toBeInTheDocument(); // 0ms shown as N/A
|
||||
|
||||
// Check impressions values
|
||||
expect(screen.getByText("100")).toBeInTheDocument();
|
||||
expect(screen.getByText("80")).toBeInTheDocument();
|
||||
expect(screen.getByText("65")).toBeInTheDocument();
|
||||
|
||||
// Check drop-off counts and percentages
|
||||
expect(screen.getByText("20")).toBeInTheDocument();
|
||||
expect(screen.getByText("(20%)")).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText("15")).toBeInTheDocument();
|
||||
expect(screen.getByText("(19%)")).toBeInTheDocument(); // 18.75% rounded to 19%
|
||||
|
||||
expect(screen.getByText("10")).toBeInTheDocument();
|
||||
expect(screen.getByText("(15%)")).toBeInTheDocument(); // 15.38% rounded to 15%
|
||||
});
|
||||
|
||||
test("renders empty state when dropOff array is empty", () => {
|
||||
render(<SummaryDropOffs dropOff={[]} survey={mockSurvey} />);
|
||||
|
||||
// Header should still be visible
|
||||
expect(screen.getByText("common.questions")).toBeInTheDocument();
|
||||
|
||||
// But no question icons
|
||||
expect(screen.queryByTestId("question-icon")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -39,8 +39,6 @@ interface SummaryListProps {
|
||||
environment: TEnvironment;
|
||||
survey: TSurvey;
|
||||
totalResponseCount: number;
|
||||
isAIEnabled: boolean;
|
||||
documentsPerPage?: number;
|
||||
locale: TUserLocale;
|
||||
}
|
||||
|
||||
@@ -50,8 +48,6 @@ export const SummaryList = ({
|
||||
responseCount,
|
||||
survey,
|
||||
totalResponseCount,
|
||||
isAIEnabled,
|
||||
documentsPerPage,
|
||||
locale,
|
||||
}: SummaryListProps) => {
|
||||
const { setSelectedFilter, selectedFilter } = useResponseFilter();
|
||||
@@ -134,8 +130,6 @@ export const SummaryList = ({
|
||||
questionSummary={questionSummary}
|
||||
environmentId={environment.id}
|
||||
survey={survey}
|
||||
isAIEnabled={isAIEnabled}
|
||||
documentsPerPage={documentsPerPage}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
import { cleanup, render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { TEnvironment } from "@formbricks/types/environment";
|
||||
import { TSurvey } from "@formbricks/types/surveys/types";
|
||||
import { TUserLocale } from "@formbricks/types/user";
|
||||
import { SummaryPage } from "./SummaryPage";
|
||||
|
||||
// Mock actions
|
||||
vi.mock("@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/actions", () => ({
|
||||
getResponseCountAction: vi.fn().mockResolvedValue({ data: 42 }),
|
||||
getSurveySummaryAction: vi.fn().mockResolvedValue({
|
||||
data: {
|
||||
meta: {
|
||||
completedPercentage: 80,
|
||||
completedResponses: 40,
|
||||
displayCount: 50,
|
||||
dropOffPercentage: 20,
|
||||
dropOffCount: 10,
|
||||
startsPercentage: 100,
|
||||
totalResponses: 50,
|
||||
ttcAverage: 120,
|
||||
},
|
||||
dropOff: [
|
||||
{
|
||||
questionId: "q1",
|
||||
headline: "Question 1",
|
||||
questionType: "openText",
|
||||
ttc: 20000,
|
||||
impressions: 50,
|
||||
dropOffCount: 5,
|
||||
dropOffPercentage: 10,
|
||||
},
|
||||
],
|
||||
summary: [
|
||||
{
|
||||
question: { id: "q1", headline: "Question 1", type: "openText", required: true },
|
||||
responseCount: 45,
|
||||
type: "openText",
|
||||
samples: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/app/share/[sharingKey]/actions", () => ({
|
||||
getResponseCountBySurveySharingKeyAction: vi.fn().mockResolvedValue({ data: 42 }),
|
||||
getSummaryBySurveySharingKeyAction: vi.fn().mockResolvedValue({
|
||||
data: {
|
||||
meta: {
|
||||
completedPercentage: 80,
|
||||
completedResponses: 40,
|
||||
displayCount: 50,
|
||||
dropOffPercentage: 20,
|
||||
dropOffCount: 10,
|
||||
startsPercentage: 100,
|
||||
totalResponses: 50,
|
||||
ttcAverage: 120,
|
||||
},
|
||||
dropOff: [
|
||||
{
|
||||
questionId: "q1",
|
||||
headline: "Question 1",
|
||||
questionType: "openText",
|
||||
ttc: 20000,
|
||||
impressions: 50,
|
||||
dropOffCount: 5,
|
||||
dropOffPercentage: 10,
|
||||
},
|
||||
],
|
||||
summary: [
|
||||
{
|
||||
question: { id: "q1", headline: "Question 1", type: "openText", required: true },
|
||||
responseCount: 45,
|
||||
type: "openText",
|
||||
samples: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock components
|
||||
vi.mock(
|
||||
"@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryDropOffs",
|
||||
() => ({
|
||||
SummaryDropOffs: () => <div data-testid="summary-drop-offs">DropOffs Component</div>,
|
||||
})
|
||||
);
|
||||
|
||||
vi.mock(
|
||||
"@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryList",
|
||||
() => ({
|
||||
SummaryList: ({ summary, responseCount }: any) => (
|
||||
<div data-testid="summary-list">
|
||||
<span>Response Count: {responseCount}</span>
|
||||
<span>Summary Items: {summary.length}</span>
|
||||
</div>
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
vi.mock(
|
||||
"@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryMetadata",
|
||||
() => ({
|
||||
SummaryMetadata: ({ showDropOffs, setShowDropOffs, isLoading }: any) => (
|
||||
<div data-testid="summary-metadata">
|
||||
<span>Is Loading: {isLoading ? "true" : "false"}</span>
|
||||
<button onClick={() => setShowDropOffs(!showDropOffs)}>Toggle Dropoffs</button>
|
||||
</div>
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
vi.mock(
|
||||
"@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ScrollToTop",
|
||||
() => ({
|
||||
__esModule: true,
|
||||
default: () => <div data-testid="scroll-to-top">Scroll To Top</div>,
|
||||
})
|
||||
);
|
||||
|
||||
vi.mock("@/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/CustomFilter", () => ({
|
||||
CustomFilter: () => <div data-testid="custom-filter">Custom Filter</div>,
|
||||
}));
|
||||
|
||||
vi.mock("@/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/ResultsShareButton", () => ({
|
||||
ResultsShareButton: () => <div data-testid="results-share-button">Share Results</div>,
|
||||
}));
|
||||
|
||||
// Mock context
|
||||
vi.mock("@/app/(app)/environments/[environmentId]/components/ResponseFilterContext", () => ({
|
||||
useResponseFilter: () => ({
|
||||
selectedFilter: { filter: [], onlyComplete: false },
|
||||
dateRange: { from: null, to: null },
|
||||
resetState: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock hooks
|
||||
vi.mock("@/lib/utils/hooks/useIntervalWhenFocused", () => ({
|
||||
useIntervalWhenFocused: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/recall", () => ({
|
||||
replaceHeadlineRecall: (survey: any) => survey,
|
||||
}));
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useParams: () => ({}),
|
||||
useSearchParams: () => ({ get: () => null }),
|
||||
}));
|
||||
|
||||
describe("SummaryPage", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
const mockEnvironment = { id: "env-123" } as TEnvironment;
|
||||
const mockSurvey = {
|
||||
id: "survey-123",
|
||||
environmentId: "env-123",
|
||||
} as TSurvey;
|
||||
const locale = "en-US" as TUserLocale;
|
||||
|
||||
const defaultProps = {
|
||||
environment: mockEnvironment,
|
||||
survey: mockSurvey,
|
||||
surveyId: "survey-123",
|
||||
webAppUrl: "https://app.example.com",
|
||||
totalResponseCount: 50,
|
||||
locale,
|
||||
isReadOnly: false,
|
||||
};
|
||||
|
||||
test("renders loading state initially", () => {
|
||||
render(<SummaryPage {...defaultProps} />);
|
||||
|
||||
expect(screen.getByTestId("summary-metadata")).toBeInTheDocument();
|
||||
expect(screen.getByText("Is Loading: true")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders summary components after loading", async () => {
|
||||
render(<SummaryPage {...defaultProps} />);
|
||||
|
||||
// Wait for loading to complete
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Is Loading: false")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(screen.getByTestId("custom-filter")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("results-share-button")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("scroll-to-top")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("summary-list")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("shows drop-offs component when toggled", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<SummaryPage {...defaultProps} />);
|
||||
|
||||
// Wait for loading to complete
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Is Loading: false")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Drop-offs should initially be hidden
|
||||
expect(screen.queryByTestId("summary-drop-offs")).not.toBeInTheDocument();
|
||||
|
||||
// Toggle drop-offs
|
||||
await user.click(screen.getByText("Toggle Dropoffs"));
|
||||
|
||||
// Drop-offs should now be visible
|
||||
expect(screen.getByTestId("summary-drop-offs")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("doesn't show share button in read-only mode", async () => {
|
||||
render(<SummaryPage {...defaultProps} isReadOnly={true} />);
|
||||
|
||||
// Wait for loading to complete
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Is Loading: false")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(screen.queryByTestId("results-share-button")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -46,7 +46,6 @@ interface SummaryPageProps {
|
||||
webAppUrl: string;
|
||||
user?: TUser;
|
||||
totalResponseCount: number;
|
||||
isAIEnabled: boolean;
|
||||
documentsPerPage?: number;
|
||||
locale: TUserLocale;
|
||||
isReadOnly: boolean;
|
||||
@@ -58,8 +57,6 @@ export const SummaryPage = ({
|
||||
surveyId,
|
||||
webAppUrl,
|
||||
totalResponseCount,
|
||||
isAIEnabled,
|
||||
documentsPerPage,
|
||||
locale,
|
||||
isReadOnly,
|
||||
}: SummaryPageProps) => {
|
||||
@@ -184,8 +181,6 @@ export const SummaryPage = ({
|
||||
survey={surveyMemoized}
|
||||
environment={environment}
|
||||
totalResponseCount={totalResponseCount}
|
||||
isAIEnabled={isAIEnabled}
|
||||
documentsPerPage={documentsPerPage}
|
||||
locale={locale}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
import { ShareEmbedSurvey } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey";
|
||||
import { SuccessMessage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SuccessMessage";
|
||||
import { SurveyStatusDropdown } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/SurveyStatusDropdown";
|
||||
import { getFormattedErrorMessage } from "@/lib/utils/helper";
|
||||
import { EditPublicSurveyAlertDialog } from "@/modules/survey/components/edit-public-survey-alert-dialog";
|
||||
import { useSingleUseId } from "@/modules/survey/hooks/useSingleUseId";
|
||||
import { copySurveyLink } from "@/modules/survey/lib/client-utils";
|
||||
import { copySurveyToOtherEnvironmentAction } from "@/modules/survey/list/actions";
|
||||
import { Badge } from "@/modules/ui/components/badge";
|
||||
import { IconBar } from "@/modules/ui/components/iconbar";
|
||||
import { useTranslate } from "@tolgee/react";
|
||||
@@ -22,6 +25,7 @@ interface SurveyAnalysisCTAProps {
|
||||
isReadOnly: boolean;
|
||||
user: TUser;
|
||||
surveyDomain: string;
|
||||
responseCount: number;
|
||||
}
|
||||
|
||||
interface ModalState {
|
||||
@@ -37,11 +41,13 @@ export const SurveyAnalysisCTA = ({
|
||||
isReadOnly,
|
||||
user,
|
||||
surveyDomain,
|
||||
responseCount,
|
||||
}: SurveyAnalysisCTAProps) => {
|
||||
const { t } = useTranslate();
|
||||
const searchParams = useSearchParams();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const [modalState, setModalState] = useState<ModalState>({
|
||||
share: searchParams.get("share") === "true",
|
||||
@@ -89,6 +95,24 @@ export const SurveyAnalysisCTA = ({
|
||||
setModalState((prev) => ({ ...prev, dropdown: false }));
|
||||
};
|
||||
|
||||
const duplicateSurveyAndRoute = async (surveyId: string) => {
|
||||
setLoading(true);
|
||||
const duplicatedSurveyResponse = await copySurveyToOtherEnvironmentAction({
|
||||
environmentId: environment.id,
|
||||
surveyId: surveyId,
|
||||
targetEnvironmentId: environment.id,
|
||||
});
|
||||
if (duplicatedSurveyResponse?.data) {
|
||||
toast.success(t("environments.surveys.survey_duplicated_successfully"));
|
||||
router.push(`/environments/${environment.id}/surveys/${duplicatedSurveyResponse.data.id}/edit`);
|
||||
} else {
|
||||
const errorMessage = getFormattedErrorMessage(duplicatedSurveyResponse);
|
||||
toast.error(errorMessage);
|
||||
}
|
||||
setIsCautionDialogOpen(false);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const getPreviewUrl = () => {
|
||||
const separator = surveyUrl.includes("?") ? "&" : "?";
|
||||
return `${surveyUrl}${separator}preview=true`;
|
||||
@@ -107,6 +131,8 @@ export const SurveyAnalysisCTA = ({
|
||||
{ key: "panel", modalView: "panel" as const, setOpen: handleModalState("panel") },
|
||||
];
|
||||
|
||||
const [isCautionDialogOpen, setIsCautionDialogOpen] = useState(false);
|
||||
|
||||
const iconActions = [
|
||||
{
|
||||
icon: Eye,
|
||||
@@ -144,7 +170,11 @@ export const SurveyAnalysisCTA = ({
|
||||
{
|
||||
icon: SquarePenIcon,
|
||||
tooltip: t("common.edit"),
|
||||
onClick: () => router.push(`/environments/${environment.id}/surveys/${survey.id}/edit`),
|
||||
onClick: () => {
|
||||
responseCount && responseCount > 0
|
||||
? setIsCautionDialogOpen(true)
|
||||
: router.push(`/environments/${environment.id}/surveys/${survey.id}/edit`);
|
||||
},
|
||||
isVisible: !isReadOnly,
|
||||
},
|
||||
];
|
||||
@@ -182,6 +212,20 @@ export const SurveyAnalysisCTA = ({
|
||||
<SuccessMessage environment={environment} survey={survey} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{responseCount > 0 && (
|
||||
<EditPublicSurveyAlertDialog
|
||||
open={isCautionDialogOpen}
|
||||
setOpen={setIsCautionDialogOpen}
|
||||
isLoading={loading}
|
||||
primaryButtonAction={() => duplicateSurveyAndRoute(survey.id)}
|
||||
primaryButtonText={t("environments.surveys.edit.caution_edit_duplicate")}
|
||||
secondaryButtonAction={() =>
|
||||
router.push(`/environments/${environment.id}/surveys/${survey.id}/edit`)
|
||||
}
|
||||
secondaryButtonText={t("common.edit")}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import toast from "react-hot-toast";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import { TEnvironment } from "@formbricks/types/environment";
|
||||
import { TSurvey } from "@formbricks/types/surveys/types";
|
||||
import { TUser } from "@formbricks/types/user";
|
||||
@@ -25,12 +25,6 @@ vi.mock("@/lib/constants", () => ({
|
||||
OIDC_DISPLAY_NAME: "mock-oidc-display-name",
|
||||
OIDC_SIGNING_ALGORITHM: "mock-oidc-signing-algorithm",
|
||||
WEBAPP_URL: "mock-webapp-url",
|
||||
AI_AZURE_LLM_RESSOURCE_NAME: "mock-azure-llm-resource-name",
|
||||
AI_AZURE_LLM_API_KEY: "mock-azure-llm-api-key",
|
||||
AI_AZURE_LLM_DEPLOYMENT_ID: "mock-azure-llm-deployment-id",
|
||||
AI_AZURE_EMBEDDINGS_RESSOURCE_NAME: "mock-azure-embeddings-resource-name",
|
||||
AI_AZURE_EMBEDDINGS_API_KEY: "mock-azure-embeddings-api-key",
|
||||
AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID: "mock-azure-embeddings-deployment-id",
|
||||
IS_PRODUCTION: true,
|
||||
FB_LOGO_URL: "https://example.com/mock-logo.png",
|
||||
SMTP_HOST: "mock-smtp-host",
|
||||
@@ -49,10 +43,12 @@ vi.mock("@/modules/survey/hooks/useSingleUseId", () => ({
|
||||
}));
|
||||
|
||||
const mockSearchParams = new URLSearchParams();
|
||||
const mockPush = vi.fn();
|
||||
|
||||
// Mock next/navigation
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({ push: vi.fn() }),
|
||||
useSearchParams: () => mockSearchParams, // Reuse the same object
|
||||
useRouter: () => ({ push: mockPush }),
|
||||
useSearchParams: () => mockSearchParams,
|
||||
usePathname: () => "/current",
|
||||
}));
|
||||
|
||||
@@ -61,13 +57,27 @@ vi.mock("@/modules/survey/lib/client-utils", () => ({
|
||||
copySurveyLink: vi.fn((url: string, id: string) => `${url}?id=${id}`),
|
||||
}));
|
||||
|
||||
// Mock the copy survey action
|
||||
const mockCopySurveyToOtherEnvironmentAction = vi.fn();
|
||||
vi.mock("@/modules/survey/list/actions", () => ({
|
||||
copySurveyToOtherEnvironmentAction: (args: any) => mockCopySurveyToOtherEnvironmentAction(args),
|
||||
}));
|
||||
|
||||
// Mock getFormattedErrorMessage function
|
||||
vi.mock("@/lib/utils/helper", () => ({
|
||||
getFormattedErrorMessage: vi.fn((response) => response?.error || "Unknown error"),
|
||||
}));
|
||||
|
||||
vi.spyOn(toast, "success");
|
||||
vi.spyOn(toast, "error");
|
||||
|
||||
// Set up a fake clipboard
|
||||
const writeTextMock = vi.fn(() => Promise.resolve());
|
||||
Object.assign(navigator, {
|
||||
clipboard: { writeText: writeTextMock },
|
||||
// Mock clipboard API
|
||||
const writeTextMock = vi.fn().mockImplementation(() => Promise.resolve());
|
||||
|
||||
// Define it at the global level
|
||||
Object.defineProperty(navigator, "clipboard", {
|
||||
value: { writeText: writeTextMock },
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const dummySurvey = {
|
||||
@@ -93,6 +103,7 @@ describe("SurveyAnalysisCTA - handleCopyLink", () => {
|
||||
isReadOnly={false}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={5}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -117,6 +128,7 @@ describe("SurveyAnalysisCTA - handleCopyLink", () => {
|
||||
isReadOnly={false}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={5}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -130,3 +142,225 @@ describe("SurveyAnalysisCTA - handleCopyLink", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// New tests for squarePenIcon and edit functionality
|
||||
describe("SurveyAnalysisCTA - Edit functionality", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("opens EditPublicSurveyAlertDialog when edit icon is clicked and response count > 0", async () => {
|
||||
render(
|
||||
<SurveyAnalysisCTA
|
||||
survey={dummySurvey}
|
||||
environment={dummyEnvironment}
|
||||
isReadOnly={false}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={5}
|
||||
/>
|
||||
);
|
||||
|
||||
// Find the edit button
|
||||
const editButton = screen.getByRole("button", { name: "common.edit" });
|
||||
await fireEvent.click(editButton);
|
||||
|
||||
// Check if dialog is shown
|
||||
const dialogTitle = screen.getByText("environments.surveys.edit.caution_edit_published_survey");
|
||||
expect(dialogTitle).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("navigates directly to edit page when response count = 0", async () => {
|
||||
render(
|
||||
<SurveyAnalysisCTA
|
||||
survey={dummySurvey}
|
||||
environment={dummyEnvironment}
|
||||
isReadOnly={false}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={0}
|
||||
/>
|
||||
);
|
||||
|
||||
// Find the edit button
|
||||
const editButton = screen.getByRole("button", { name: "common.edit" });
|
||||
await fireEvent.click(editButton);
|
||||
|
||||
// Should navigate directly to edit page
|
||||
expect(mockPush).toHaveBeenCalledWith(
|
||||
`/environments/${dummyEnvironment.id}/surveys/${dummySurvey.id}/edit`
|
||||
);
|
||||
});
|
||||
|
||||
test("doesn't show edit button when isReadOnly is true", () => {
|
||||
render(
|
||||
<SurveyAnalysisCTA
|
||||
survey={dummySurvey}
|
||||
environment={dummyEnvironment}
|
||||
isReadOnly={true}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={5}
|
||||
/>
|
||||
);
|
||||
|
||||
// Try to find the edit button (it shouldn't exist)
|
||||
const editButton = screen.queryByRole("button", { name: "common.edit" });
|
||||
expect(editButton).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
// Updated test description to mention EditPublicSurveyAlertDialog
|
||||
describe("SurveyAnalysisCTA - duplicateSurveyAndRoute and EditPublicSurveyAlertDialog", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("duplicates survey successfully and navigates to edit page", async () => {
|
||||
// Mock the API response
|
||||
mockCopySurveyToOtherEnvironmentAction.mockResolvedValueOnce({
|
||||
data: { id: "duplicated-survey-456" },
|
||||
});
|
||||
|
||||
render(
|
||||
<SurveyAnalysisCTA
|
||||
survey={dummySurvey}
|
||||
environment={dummyEnvironment}
|
||||
isReadOnly={false}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={5}
|
||||
/>
|
||||
);
|
||||
|
||||
// Find and click the edit button to show dialog
|
||||
const editButton = screen.getByRole("button", { name: "common.edit" });
|
||||
await fireEvent.click(editButton);
|
||||
|
||||
// Find and click the duplicate button in dialog
|
||||
const duplicateButton = screen.getByRole("button", {
|
||||
name: "environments.surveys.edit.caution_edit_duplicate",
|
||||
});
|
||||
await fireEvent.click(duplicateButton);
|
||||
|
||||
// Verify the API was called with correct parameters
|
||||
expect(mockCopySurveyToOtherEnvironmentAction).toHaveBeenCalledWith({
|
||||
environmentId: dummyEnvironment.id,
|
||||
surveyId: dummySurvey.id,
|
||||
targetEnvironmentId: dummyEnvironment.id,
|
||||
});
|
||||
|
||||
// Verify success toast was shown
|
||||
expect(toast.success).toHaveBeenCalledWith("environments.surveys.survey_duplicated_successfully");
|
||||
|
||||
// Verify navigation to edit page
|
||||
expect(mockPush).toHaveBeenCalledWith(
|
||||
`/environments/${dummyEnvironment.id}/surveys/duplicated-survey-456/edit`
|
||||
);
|
||||
});
|
||||
|
||||
test("shows error toast when duplication fails with error object", async () => {
|
||||
// Mock API failure with error object
|
||||
mockCopySurveyToOtherEnvironmentAction.mockResolvedValueOnce({
|
||||
error: "Test error message",
|
||||
});
|
||||
|
||||
render(
|
||||
<SurveyAnalysisCTA
|
||||
survey={dummySurvey}
|
||||
environment={dummyEnvironment}
|
||||
isReadOnly={false}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={5}
|
||||
/>
|
||||
);
|
||||
|
||||
// Open dialog
|
||||
const editButton = screen.getByRole("button", { name: "common.edit" });
|
||||
await fireEvent.click(editButton);
|
||||
|
||||
// Click duplicate
|
||||
const duplicateButton = screen.getByRole("button", {
|
||||
name: "environments.surveys.edit.caution_edit_duplicate",
|
||||
});
|
||||
await fireEvent.click(duplicateButton);
|
||||
|
||||
// Verify error toast
|
||||
expect(toast.error).toHaveBeenCalledWith("Test error message");
|
||||
});
|
||||
|
||||
test("navigates to edit page when cancel button is clicked in dialog", async () => {
|
||||
render(
|
||||
<SurveyAnalysisCTA
|
||||
survey={dummySurvey}
|
||||
environment={dummyEnvironment}
|
||||
isReadOnly={false}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={5}
|
||||
/>
|
||||
);
|
||||
|
||||
// Open dialog
|
||||
const editButton = screen.getByRole("button", { name: "common.edit" });
|
||||
await fireEvent.click(editButton);
|
||||
|
||||
// Click edit (cancel) button
|
||||
const editButtonInDialog = screen.getByRole("button", { name: "common.edit" });
|
||||
await fireEvent.click(editButtonInDialog);
|
||||
|
||||
// Verify navigation
|
||||
expect(mockPush).toHaveBeenCalledWith(
|
||||
`/environments/${dummyEnvironment.id}/surveys/${dummySurvey.id}/edit`
|
||||
);
|
||||
});
|
||||
|
||||
test("shows loading state when duplicating survey", async () => {
|
||||
// Create a promise that we can resolve manually
|
||||
let resolvePromise: (value: any) => void;
|
||||
const promise = new Promise((resolve) => {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
|
||||
mockCopySurveyToOtherEnvironmentAction.mockImplementation(() => promise);
|
||||
|
||||
render(
|
||||
<SurveyAnalysisCTA
|
||||
survey={dummySurvey}
|
||||
environment={dummyEnvironment}
|
||||
isReadOnly={false}
|
||||
surveyDomain={surveyDomain}
|
||||
user={dummyUser}
|
||||
responseCount={5}
|
||||
/>
|
||||
);
|
||||
|
||||
// Open dialog
|
||||
const editButton = screen.getByRole("button", { name: "common.edit" });
|
||||
await fireEvent.click(editButton);
|
||||
|
||||
// Click duplicate
|
||||
const duplicateButton = screen.getByRole("button", {
|
||||
name: "environments.surveys.edit.caution_edit_duplicate",
|
||||
});
|
||||
await fireEvent.click(duplicateButton);
|
||||
|
||||
// Button should now be in loading state
|
||||
// expect(duplicateButton).toHaveAttribute("data-state", "loading");
|
||||
|
||||
// Resolve the promise
|
||||
resolvePromise!({
|
||||
data: { id: "duplicated-survey-456" },
|
||||
});
|
||||
|
||||
// Wait for the promise to resolve
|
||||
await waitFor(() => {
|
||||
expect(mockPush).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
import { cache } from "@/lib/cache";
|
||||
import { documentCache } from "@/lib/cache/document";
|
||||
import { INSIGHTS_PER_PAGE } from "@/lib/constants";
|
||||
import { validateInputs } from "@/lib/utils/validate";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { cache as reactCache } from "react";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { ZId } from "@formbricks/types/common";
|
||||
import { DatabaseError } from "@formbricks/types/errors";
|
||||
import {
|
||||
TSurveyQuestionId,
|
||||
TSurveyQuestionSummaryOpenText,
|
||||
ZSurveyQuestionId,
|
||||
} from "@formbricks/types/surveys/types";
|
||||
|
||||
export const getInsightsBySurveyIdQuestionId = reactCache(
|
||||
async (
|
||||
surveyId: string,
|
||||
questionId: TSurveyQuestionId,
|
||||
insightResponsesIds: string[],
|
||||
limit?: number,
|
||||
offset?: number
|
||||
): Promise<TSurveyQuestionSummaryOpenText["insights"]> =>
|
||||
cache(
|
||||
async () => {
|
||||
validateInputs([surveyId, ZId], [questionId, ZSurveyQuestionId]);
|
||||
|
||||
limit = limit ?? INSIGHTS_PER_PAGE;
|
||||
try {
|
||||
const insights = await prisma.insight.findMany({
|
||||
where: {
|
||||
documentInsights: {
|
||||
some: {
|
||||
document: {
|
||||
surveyId,
|
||||
questionId,
|
||||
...(insightResponsesIds.length > 0 && {
|
||||
responseId: {
|
||||
in: insightResponsesIds,
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
documentInsights: {
|
||||
where: {
|
||||
document: {
|
||||
surveyId,
|
||||
questionId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
documentInsights: {
|
||||
_count: "desc",
|
||||
},
|
||||
},
|
||||
{
|
||||
createdAt: "desc",
|
||||
},
|
||||
],
|
||||
take: limit ? limit : undefined,
|
||||
skip: offset ? offset : undefined,
|
||||
});
|
||||
|
||||
return insights;
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
[`getInsightsBySurveyIdQuestionId-${surveyId}-${questionId}-${limit}-${offset}`],
|
||||
{
|
||||
tags: [documentCache.tag.bySurveyId(surveyId)],
|
||||
}
|
||||
)()
|
||||
);
|
||||
@@ -1,5 +1,4 @@
|
||||
import "server-only";
|
||||
import { getInsightsBySurveyIdQuestionId } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/insights";
|
||||
import { cache } from "@/lib/cache";
|
||||
import { RESPONSES_PER_PAGE } from "@/lib/constants";
|
||||
import { displayCache } from "@/lib/display/cache";
|
||||
@@ -317,11 +316,9 @@ export const getQuestionSummary = async (
|
||||
switch (question.type) {
|
||||
case TSurveyQuestionTypeEnum.OpenText: {
|
||||
let values: TSurveyQuestionSummaryOpenText["samples"] = [];
|
||||
const insightResponsesIds: string[] = [];
|
||||
responses.forEach((response) => {
|
||||
const answer = response.data[question.id];
|
||||
if (answer && typeof answer === "string") {
|
||||
insightResponsesIds.push(response.id);
|
||||
values.push({
|
||||
id: response.id,
|
||||
updatedAt: response.updatedAt,
|
||||
@@ -331,20 +328,12 @@ export const getQuestionSummary = async (
|
||||
});
|
||||
}
|
||||
});
|
||||
const insights = await getInsightsBySurveyIdQuestionId(
|
||||
survey.id,
|
||||
question.id,
|
||||
insightResponsesIds,
|
||||
50
|
||||
);
|
||||
|
||||
summary.push({
|
||||
type: question.type,
|
||||
question,
|
||||
responseCount: values.length,
|
||||
samples: values.slice(0, VALUES_LIMIT),
|
||||
insights,
|
||||
insightsEnabled: question.insightsEnabled,
|
||||
});
|
||||
|
||||
values = [];
|
||||
|
||||
@@ -38,12 +38,3 @@ export const constructToastMessage = (
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const needsInsightsGeneration = (survey: TSurvey): boolean => {
|
||||
const openTextQuestions = survey.questions.filter((question) => question.type === "openText");
|
||||
const questionWithoutInsightsEnabled = openTextQuestions.some(
|
||||
(question) => question.type === "openText" && typeof question.insightsEnabled === "undefined"
|
||||
);
|
||||
|
||||
return openTextQuestions.length > 0 && questionWithoutInsightsEnabled;
|
||||
};
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
import { SurveyAnalysisNavigation } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/components/SurveyAnalysisNavigation";
|
||||
import { EnableInsightsBanner } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/EnableInsightsBanner";
|
||||
import { SummaryPage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryPage";
|
||||
import { SurveyAnalysisCTA } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA";
|
||||
import { needsInsightsGeneration } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/utils";
|
||||
import {
|
||||
DEFAULT_LOCALE,
|
||||
DOCUMENTS_PER_PAGE,
|
||||
MAX_RESPONSES_FOR_INSIGHT_GENERATION,
|
||||
WEBAPP_URL,
|
||||
} from "@/lib/constants";
|
||||
import { DEFAULT_LOCALE, DOCUMENTS_PER_PAGE, WEBAPP_URL } from "@/lib/constants";
|
||||
import { getSurveyDomain } from "@/lib/getSurveyUrl";
|
||||
import { getResponseCountBySurveyId } from "@/lib/response/service";
|
||||
import { getSurvey } from "@/lib/survey/service";
|
||||
import { getUser } from "@/lib/user/service";
|
||||
import { getIsAIEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
import { getEnvironmentAuth } from "@/modules/environments/lib/utils";
|
||||
import { PageContentWrapper } from "@/modules/ui/components/page-content-wrapper";
|
||||
import { PageHeader } from "@/modules/ui/components/page-header";
|
||||
@@ -25,7 +17,7 @@ const SurveyPage = async (props: { params: Promise<{ environmentId: string; surv
|
||||
const params = await props.params;
|
||||
const t = await getTranslate();
|
||||
|
||||
const { session, environment, organization, isReadOnly } = await getEnvironmentAuth(params.environmentId);
|
||||
const { session, environment, isReadOnly } = await getEnvironmentAuth(params.environmentId);
|
||||
|
||||
const surveyId = params.surveyId;
|
||||
|
||||
@@ -50,11 +42,6 @@ const SurveyPage = async (props: { params: Promise<{ environmentId: string; surv
|
||||
// I took this out cause it's cloud only right?
|
||||
// const { active: isEnterpriseEdition } = await getEnterpriseLicense();
|
||||
|
||||
const isAIEnabled = await getIsAIEnabled({
|
||||
isAIEnabled: organization.isAIEnabled,
|
||||
billing: organization.billing,
|
||||
});
|
||||
const shouldGenerateInsights = needsInsightsGeneration(survey);
|
||||
const surveyDomain = getSurveyDomain();
|
||||
|
||||
return (
|
||||
@@ -68,15 +55,9 @@ const SurveyPage = async (props: { params: Promise<{ environmentId: string; surv
|
||||
isReadOnly={isReadOnly}
|
||||
user={user}
|
||||
surveyDomain={surveyDomain}
|
||||
responseCount={totalResponseCount}
|
||||
/>
|
||||
}>
|
||||
{isAIEnabled && shouldGenerateInsights && (
|
||||
<EnableInsightsBanner
|
||||
surveyId={survey.id}
|
||||
surveyResponseCount={totalResponseCount}
|
||||
maxResponseCount={MAX_RESPONSES_FOR_INSIGHT_GENERATION}
|
||||
/>
|
||||
)}
|
||||
<SurveyAnalysisNavigation
|
||||
environmentId={environment.id}
|
||||
survey={survey}
|
||||
@@ -91,7 +72,6 @@ const SurveyPage = async (props: { params: Promise<{ environmentId: string; surv
|
||||
webAppUrl={WEBAPP_URL}
|
||||
user={user}
|
||||
totalResponseCount={totalResponseCount}
|
||||
isAIEnabled={isAIEnabled}
|
||||
documentsPerPage={DOCUMENTS_PER_PAGE}
|
||||
isReadOnly={isReadOnly}
|
||||
locale={user.locale ?? DEFAULT_LOCALE}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
import { embeddingsModel, llmModel } from "@/lib/aiModels";
|
||||
import { documentCache } from "@/lib/cache/document";
|
||||
import { validateInputs } from "@/lib/utils/validate";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { embed, generateObject } from "ai";
|
||||
import { z } from "zod";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import {
|
||||
TDocument,
|
||||
TDocumentCreateInput,
|
||||
TGenerateDocumentObjectSchema,
|
||||
ZDocumentCreateInput,
|
||||
ZGenerateDocumentObjectSchema,
|
||||
} from "@formbricks/types/documents";
|
||||
import { DatabaseError } from "@formbricks/types/errors";
|
||||
|
||||
export type TCreatedDocument = TDocument & {
|
||||
isSpam: boolean;
|
||||
insights: TGenerateDocumentObjectSchema["insights"];
|
||||
};
|
||||
|
||||
export const createDocument = async (
|
||||
surveyName: string,
|
||||
documentInput: TDocumentCreateInput
|
||||
): Promise<TCreatedDocument> => {
|
||||
validateInputs([surveyName, z.string()], [documentInput, ZDocumentCreateInput]);
|
||||
|
||||
try {
|
||||
// Generate text embedding
|
||||
const { embedding } = await embed({
|
||||
model: embeddingsModel,
|
||||
value: documentInput.text,
|
||||
experimental_telemetry: { isEnabled: true },
|
||||
});
|
||||
|
||||
// generate sentiment and insights
|
||||
const { object } = await generateObject({
|
||||
model: llmModel,
|
||||
schema: ZGenerateDocumentObjectSchema,
|
||||
system: `You are an XM researcher. You analyse a survey response (survey name, question headline & user answer) and generate insights from it. The insight title (1-3 words) should concisely answer the question, e.g., "What type of people do you think would most benefit" -> "Developers". You are very objective. For the insights, split the feedback into the smallest parts possible and only use the feedback itself to draw conclusions. You must output at least one insight. Always generate insights and titles in English, regardless of the input language.`,
|
||||
prompt: `Survey: ${surveyName}\n${documentInput.text}`,
|
||||
temperature: 0,
|
||||
experimental_telemetry: { isEnabled: true },
|
||||
});
|
||||
|
||||
const sentiment = object.sentiment;
|
||||
const isSpam = object.isSpam;
|
||||
|
||||
// create document
|
||||
const prismaDocument = await prisma.document.create({
|
||||
data: {
|
||||
...documentInput,
|
||||
sentiment,
|
||||
isSpam,
|
||||
},
|
||||
});
|
||||
|
||||
const document = {
|
||||
...prismaDocument,
|
||||
vector: embedding,
|
||||
};
|
||||
|
||||
// update document vector with the embedding
|
||||
const vectorString = `[${embedding.join(",")}]`;
|
||||
await prisma.$executeRaw`
|
||||
UPDATE "Document"
|
||||
SET "vector" = ${vectorString}::vector(512)
|
||||
WHERE "id" = ${document.id};
|
||||
`;
|
||||
|
||||
documentCache.revalidate({
|
||||
id: document.id,
|
||||
responseId: document.responseId,
|
||||
questionId: document.questionId,
|
||||
});
|
||||
|
||||
return { ...document, insights: object.insights, isSpam };
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -1,430 +0,0 @@
|
||||
import { createDocument } from "@/app/api/(internal)/insights/lib/document";
|
||||
import { doesResponseHasAnyOpenTextAnswer } from "@/app/api/(internal)/insights/lib/utils";
|
||||
import { embeddingsModel } from "@/lib/aiModels";
|
||||
import { documentCache } from "@/lib/cache/document";
|
||||
import { insightCache } from "@/lib/cache/insight";
|
||||
import { getPromptText } from "@/lib/utils/ai";
|
||||
import { parseRecallInfo } from "@/lib/utils/recall";
|
||||
import { validateInputs } from "@/lib/utils/validate";
|
||||
import { Insight, InsightCategory, Prisma } from "@prisma/client";
|
||||
import { embed } from "ai";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { ZId } from "@formbricks/types/common";
|
||||
import { TCreatedDocument } from "@formbricks/types/documents";
|
||||
import { DatabaseError } from "@formbricks/types/errors";
|
||||
import {
|
||||
TSurvey,
|
||||
TSurveyQuestionId,
|
||||
TSurveyQuestionTypeEnum,
|
||||
ZSurveyQuestions,
|
||||
} from "@formbricks/types/surveys/types";
|
||||
import { TInsightCreateInput, TNearestInsights, ZInsightCreateInput } from "./types";
|
||||
|
||||
export const generateInsightsForSurveyResponsesConcept = async (
|
||||
survey: Pick<TSurvey, "id" | "name" | "environmentId" | "questions">
|
||||
): Promise<void> => {
|
||||
const { id: surveyId, name, environmentId, questions } = survey;
|
||||
|
||||
validateInputs([surveyId, ZId], [environmentId, ZId], [questions, ZSurveyQuestions]);
|
||||
|
||||
try {
|
||||
const openTextQuestionsWithInsights = questions.filter(
|
||||
(question) => question.type === TSurveyQuestionTypeEnum.OpenText && question.insightsEnabled
|
||||
);
|
||||
|
||||
const openTextQuestionIds = openTextQuestionsWithInsights.map((question) => question.id);
|
||||
|
||||
if (openTextQuestionIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetching responses
|
||||
const batchSize = 200;
|
||||
let skip = 0;
|
||||
let rateLimit: number | undefined;
|
||||
const spillover: { responseId: string; questionId: string; text: string }[] = [];
|
||||
let allResponsesProcessed = false;
|
||||
|
||||
// Fetch the rate limit once, if not already set
|
||||
if (rateLimit === undefined) {
|
||||
const { rawResponse } = await embed({
|
||||
model: embeddingsModel,
|
||||
value: "Test",
|
||||
experimental_telemetry: { isEnabled: true },
|
||||
});
|
||||
|
||||
const rateLimitHeader = rawResponse?.headers?.["x-ratelimit-remaining-requests"];
|
||||
rateLimit = rateLimitHeader ? parseInt(rateLimitHeader, 10) : undefined;
|
||||
}
|
||||
|
||||
while (!allResponsesProcessed || spillover.length > 0) {
|
||||
// If there are any spillover documents from the previous iteration, prioritize them
|
||||
let answersForDocumentCreation = [...spillover];
|
||||
spillover.length = 0; // Empty the spillover array after moving contents
|
||||
|
||||
// Fetch new responses only if spillover is empty
|
||||
if (answersForDocumentCreation.length === 0 && !allResponsesProcessed) {
|
||||
const responses = await prisma.response.findMany({
|
||||
where: {
|
||||
surveyId,
|
||||
documents: {
|
||||
none: {},
|
||||
},
|
||||
finished: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
data: true,
|
||||
variables: true,
|
||||
contactId: true,
|
||||
language: true,
|
||||
},
|
||||
take: batchSize,
|
||||
skip,
|
||||
});
|
||||
|
||||
if (
|
||||
responses.length === 0 ||
|
||||
(responses.length < batchSize && rateLimit && responses.length < rateLimit)
|
||||
) {
|
||||
allResponsesProcessed = true; // Mark as finished when no more responses are found
|
||||
}
|
||||
|
||||
const responsesWithOpenTextAnswers = responses.filter((response) =>
|
||||
doesResponseHasAnyOpenTextAnswer(openTextQuestionIds, response.data)
|
||||
);
|
||||
|
||||
skip += batchSize - responsesWithOpenTextAnswers.length;
|
||||
|
||||
const answersForDocumentCreationPromises = await Promise.all(
|
||||
responsesWithOpenTextAnswers.map(async (response) => {
|
||||
const responseEntries = openTextQuestionsWithInsights.map((question) => {
|
||||
const responseText = response.data[question.id] as string;
|
||||
if (!responseText) {
|
||||
return;
|
||||
}
|
||||
|
||||
const headline = parseRecallInfo(
|
||||
question.headline[response.language ?? "default"],
|
||||
response.data,
|
||||
response.variables
|
||||
);
|
||||
|
||||
const text = getPromptText(headline, responseText);
|
||||
|
||||
return {
|
||||
responseId: response.id,
|
||||
questionId: question.id,
|
||||
text,
|
||||
};
|
||||
});
|
||||
|
||||
return responseEntries;
|
||||
})
|
||||
);
|
||||
|
||||
const answersForDocumentCreationResult = answersForDocumentCreationPromises.flat();
|
||||
answersForDocumentCreationResult.forEach((answer) => {
|
||||
if (answer) {
|
||||
answersForDocumentCreation.push(answer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Process documents only up to the rate limit
|
||||
if (rateLimit !== undefined && rateLimit < answersForDocumentCreation.length) {
|
||||
// Push excess documents to the spillover array
|
||||
spillover.push(...answersForDocumentCreation.slice(rateLimit));
|
||||
answersForDocumentCreation = answersForDocumentCreation.slice(0, rateLimit);
|
||||
}
|
||||
|
||||
const createDocumentPromises = answersForDocumentCreation.map((answer) => {
|
||||
return createDocument(name, {
|
||||
environmentId,
|
||||
surveyId,
|
||||
responseId: answer.responseId,
|
||||
questionId: answer.questionId,
|
||||
text: answer.text,
|
||||
});
|
||||
});
|
||||
|
||||
const createDocumentResults = await Promise.allSettled(createDocumentPromises);
|
||||
const fullfilledCreateDocumentResults = createDocumentResults.filter(
|
||||
(result) => result.status === "fulfilled"
|
||||
) as PromiseFulfilledResult<TCreatedDocument>[];
|
||||
const createdDocuments = fullfilledCreateDocumentResults.filter(Boolean).map((result) => result.value);
|
||||
|
||||
for (const document of createdDocuments) {
|
||||
if (document) {
|
||||
const insightPromises: Promise<void>[] = [];
|
||||
const { insights, isSpam, id, environmentId } = document;
|
||||
if (!isSpam) {
|
||||
for (const insight of insights) {
|
||||
if (typeof insight.title !== "string" || typeof insight.description !== "string") {
|
||||
throw new Error("Insight title and description must be a string");
|
||||
}
|
||||
|
||||
// Create or connect the insight
|
||||
insightPromises.push(handleInsightAssignments(environmentId, id, insight));
|
||||
}
|
||||
await Promise.allSettled(insightPromises);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
documentCache.revalidate({
|
||||
environmentId: environmentId,
|
||||
surveyId: surveyId,
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const generateInsightsForSurveyResponses = async (
|
||||
survey: Pick<TSurvey, "id" | "name" | "environmentId" | "questions">
|
||||
): Promise<void> => {
|
||||
const { id: surveyId, name, environmentId, questions } = survey;
|
||||
|
||||
validateInputs([surveyId, ZId], [environmentId, ZId], [questions, ZSurveyQuestions]);
|
||||
try {
|
||||
const openTextQuestionsWithInsights = questions.filter(
|
||||
(question) => question.type === TSurveyQuestionTypeEnum.OpenText && question.insightsEnabled
|
||||
);
|
||||
|
||||
const openTextQuestionIds = openTextQuestionsWithInsights.map((question) => question.id);
|
||||
|
||||
if (openTextQuestionIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetching responses
|
||||
const batchSize = 200;
|
||||
let skip = 0;
|
||||
|
||||
const totalResponseCount = await prisma.response.count({
|
||||
where: {
|
||||
surveyId,
|
||||
documents: {
|
||||
none: {},
|
||||
},
|
||||
finished: true,
|
||||
},
|
||||
});
|
||||
|
||||
const pages = Math.ceil(totalResponseCount / batchSize);
|
||||
|
||||
for (let i = 0; i < pages; i++) {
|
||||
const responses = await prisma.response.findMany({
|
||||
where: {
|
||||
surveyId,
|
||||
documents: {
|
||||
none: {},
|
||||
},
|
||||
finished: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
data: true,
|
||||
variables: true,
|
||||
contactId: true,
|
||||
language: true,
|
||||
},
|
||||
take: batchSize,
|
||||
skip,
|
||||
});
|
||||
|
||||
const responsesWithOpenTextAnswers = responses.filter((response) =>
|
||||
doesResponseHasAnyOpenTextAnswer(openTextQuestionIds, response.data)
|
||||
);
|
||||
|
||||
skip += batchSize - responsesWithOpenTextAnswers.length;
|
||||
|
||||
const createDocumentPromises: Promise<TCreatedDocument | undefined>[] = [];
|
||||
|
||||
for (const response of responsesWithOpenTextAnswers) {
|
||||
for (const question of openTextQuestionsWithInsights) {
|
||||
const responseText = response.data[question.id] as string;
|
||||
if (!responseText) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const headline = parseRecallInfo(
|
||||
question.headline[response.language ?? "default"],
|
||||
response.data,
|
||||
response.variables
|
||||
);
|
||||
|
||||
const text = getPromptText(headline, responseText);
|
||||
|
||||
const createDocumentPromise = createDocument(name, {
|
||||
environmentId,
|
||||
surveyId,
|
||||
responseId: response.id,
|
||||
questionId: question.id,
|
||||
text,
|
||||
});
|
||||
|
||||
createDocumentPromises.push(createDocumentPromise);
|
||||
}
|
||||
}
|
||||
|
||||
const createdDocuments = (await Promise.all(createDocumentPromises)).filter(
|
||||
Boolean
|
||||
) as TCreatedDocument[];
|
||||
|
||||
for (const document of createdDocuments) {
|
||||
if (document) {
|
||||
const insightPromises: Promise<void>[] = [];
|
||||
const { insights, isSpam, id, environmentId } = document;
|
||||
if (!isSpam) {
|
||||
for (const insight of insights) {
|
||||
if (typeof insight.title !== "string" || typeof insight.description !== "string") {
|
||||
throw new Error("Insight title and description must be a string");
|
||||
}
|
||||
|
||||
// create or connect the insight
|
||||
insightPromises.push(handleInsightAssignments(environmentId, id, insight));
|
||||
}
|
||||
await Promise.all(insightPromises);
|
||||
}
|
||||
}
|
||||
}
|
||||
documentCache.revalidate({
|
||||
environmentId: environmentId,
|
||||
surveyId: surveyId,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const getQuestionResponseReferenceId = (surveyId: string, questionId: TSurveyQuestionId) => {
|
||||
return `${surveyId}-${questionId}`;
|
||||
};
|
||||
|
||||
export const createInsight = async (insightGroupInput: TInsightCreateInput): Promise<Insight> => {
|
||||
validateInputs([insightGroupInput, ZInsightCreateInput]);
|
||||
|
||||
try {
|
||||
// create document
|
||||
const { vector, ...data } = insightGroupInput;
|
||||
const insight = await prisma.insight.create({
|
||||
data,
|
||||
});
|
||||
|
||||
// update document vector with the embedding
|
||||
const vectorString = `[${insightGroupInput.vector.join(",")}]`;
|
||||
await prisma.$executeRaw`
|
||||
UPDATE "Insight"
|
||||
SET "vector" = ${vectorString}::vector(512)
|
||||
WHERE "id" = ${insight.id};
|
||||
`;
|
||||
|
||||
insightCache.revalidate({
|
||||
id: insight.id,
|
||||
environmentId: insight.environmentId,
|
||||
});
|
||||
|
||||
return insight;
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const handleInsightAssignments = async (
|
||||
environmentId: string,
|
||||
documentId: string,
|
||||
insight: {
|
||||
title: string;
|
||||
description: string;
|
||||
category: InsightCategory;
|
||||
}
|
||||
) => {
|
||||
try {
|
||||
// create embedding for insight
|
||||
const { embedding } = await embed({
|
||||
model: embeddingsModel,
|
||||
value: getInsightVectorText(insight.title, insight.description),
|
||||
experimental_telemetry: { isEnabled: true },
|
||||
});
|
||||
// find close insight to merge it with
|
||||
const nearestInsights = await findNearestInsights(environmentId, embedding, 1, 0.2);
|
||||
|
||||
if (nearestInsights.length > 0) {
|
||||
// create a documentInsight with this insight
|
||||
await prisma.documentInsight.create({
|
||||
data: {
|
||||
documentId,
|
||||
insightId: nearestInsights[0].id,
|
||||
},
|
||||
});
|
||||
documentCache.revalidate({
|
||||
insightId: nearestInsights[0].id,
|
||||
});
|
||||
} else {
|
||||
// create new insight and documentInsight
|
||||
const newInsight = await createInsight({
|
||||
environmentId: environmentId,
|
||||
title: insight.title,
|
||||
description: insight.description,
|
||||
category: insight.category ?? "other",
|
||||
vector: embedding,
|
||||
});
|
||||
// create a documentInsight with this insight
|
||||
await prisma.documentInsight.create({
|
||||
data: {
|
||||
documentId,
|
||||
insightId: newInsight.id,
|
||||
},
|
||||
});
|
||||
documentCache.revalidate({
|
||||
insightId: newInsight.id,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const findNearestInsights = async (
|
||||
environmentId: string,
|
||||
vector: number[],
|
||||
limit: number = 5,
|
||||
threshold: number = 0.5
|
||||
): Promise<TNearestInsights[]> => {
|
||||
validateInputs([environmentId, ZId]);
|
||||
// Convert the embedding array to a JSON-like string representation
|
||||
const vectorString = `[${vector.join(",")}]`;
|
||||
|
||||
// Execute raw SQL query to find nearest neighbors and exclude the vector column
|
||||
const insights: TNearestInsights[] = await prisma.$queryRaw`
|
||||
SELECT
|
||||
id
|
||||
FROM "Insight" d
|
||||
WHERE d."environmentId" = ${environmentId}
|
||||
AND d."vector" <=> ${vectorString}::vector(512) <= ${threshold}
|
||||
ORDER BY d."vector" <=> ${vectorString}::vector(512)
|
||||
LIMIT ${limit};
|
||||
`;
|
||||
|
||||
return insights;
|
||||
};
|
||||
|
||||
export const getInsightVectorText = (title: string, description: string): string =>
|
||||
`${title}: ${description}`;
|
||||
@@ -1,16 +0,0 @@
|
||||
import { Insight } from "@prisma/client";
|
||||
import { z } from "zod";
|
||||
import { ZInsight } from "@formbricks/database/zod/insights";
|
||||
|
||||
export const ZInsightCreateInput = ZInsight.pick({
|
||||
environmentId: true,
|
||||
title: true,
|
||||
description: true,
|
||||
category: true,
|
||||
}).extend({
|
||||
vector: z.array(z.number()).length(512),
|
||||
});
|
||||
|
||||
export type TInsightCreateInput = z.infer<typeof ZInsightCreateInput>;
|
||||
|
||||
export type TNearestInsights = Pick<Insight, "id">;
|
||||
@@ -1,390 +0,0 @@
|
||||
import { CRON_SECRET, WEBAPP_URL } from "@/lib/constants";
|
||||
import { getSurvey, updateSurvey } from "@/lib/survey/service";
|
||||
import { mockSurveyOutput } from "@/lib/survey/tests/__mock__/survey.mock";
|
||||
import { doesSurveyHasOpenTextQuestion } from "@/lib/survey/utils";
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import { ResourceNotFoundError } from "@formbricks/types/errors";
|
||||
import { TSurvey, TSurveyQuestionTypeEnum } from "@formbricks/types/surveys/types";
|
||||
import {
|
||||
doesResponseHasAnyOpenTextAnswer,
|
||||
generateInsightsEnabledForSurveyQuestions,
|
||||
generateInsightsForSurvey,
|
||||
} from "./utils";
|
||||
|
||||
// Mock all dependencies
|
||||
vi.mock("@/lib/constants", () => ({
|
||||
CRON_SECRET: vi.fn(() => "mocked-cron-secret"),
|
||||
WEBAPP_URL: "https://mocked-webapp-url.com",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/survey/cache", () => ({
|
||||
surveyCache: {
|
||||
revalidate: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/survey/service", () => ({
|
||||
getSurvey: vi.fn(),
|
||||
updateSurvey: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/survey/utils", () => ({
|
||||
doesSurveyHasOpenTextQuestion: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/utils/validate", () => ({
|
||||
validateInputs: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock global fetch
|
||||
const mockFetch = vi.fn();
|
||||
global.fetch = mockFetch;
|
||||
|
||||
describe("Insights Utils", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("generateInsightsForSurvey", () => {
|
||||
test("should call fetch with correct parameters", () => {
|
||||
const surveyId = "survey-123";
|
||||
mockFetch.mockResolvedValueOnce({ ok: true });
|
||||
|
||||
generateInsightsForSurvey(surveyId);
|
||||
|
||||
expect(mockFetch).toHaveBeenCalledWith(`${WEBAPP_URL}/api/insights`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": CRON_SECRET,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
surveyId,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
test("should handle errors and return error object", () => {
|
||||
const surveyId = "survey-123";
|
||||
mockFetch.mockImplementationOnce(() => {
|
||||
throw new Error("Network error");
|
||||
});
|
||||
|
||||
const result = generateInsightsForSurvey(surveyId);
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: new Error("Error while generating insights for survey: Network error"),
|
||||
});
|
||||
});
|
||||
|
||||
test("should throw error if CRON_SECRET is not set", async () => {
|
||||
// Reset modules to ensure clean state
|
||||
vi.resetModules();
|
||||
|
||||
// Mock CRON_SECRET as undefined
|
||||
vi.doMock("@/lib/constants", () => ({
|
||||
CRON_SECRET: undefined,
|
||||
WEBAPP_URL: "https://mocked-webapp-url.com",
|
||||
}));
|
||||
|
||||
// Re-import the utils module to get the mocked CRON_SECRET
|
||||
const { generateInsightsForSurvey } = await import("./utils");
|
||||
|
||||
expect(() => generateInsightsForSurvey("survey-123")).toThrow("CRON_SECRET is not set");
|
||||
|
||||
// Reset modules after test
|
||||
vi.resetModules();
|
||||
});
|
||||
});
|
||||
|
||||
describe("generateInsightsEnabledForSurveyQuestions", () => {
|
||||
test("should return success=false when survey has no open text questions", async () => {
|
||||
// Mock data
|
||||
const surveyId = "survey-123";
|
||||
const mockSurvey: TSurvey = {
|
||||
...mockSurveyOutput,
|
||||
type: "link",
|
||||
segment: null,
|
||||
displayPercentage: null,
|
||||
questions: [
|
||||
{
|
||||
id: "cm8cjnse3000009jxf20v91ic",
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
headline: { default: "Question 1" },
|
||||
required: true,
|
||||
choices: [
|
||||
{
|
||||
id: "cm8cjnse3000009jxf20v91ic",
|
||||
label: { default: "Choice 1" },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "cm8cjo19c000109jx6znygc0u",
|
||||
type: TSurveyQuestionTypeEnum.Rating,
|
||||
headline: { default: "Question 2" },
|
||||
required: true,
|
||||
scale: "number",
|
||||
range: 5,
|
||||
isColorCodingEnabled: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Setup mocks
|
||||
vi.mocked(getSurvey).mockResolvedValueOnce(mockSurvey);
|
||||
vi.mocked(doesSurveyHasOpenTextQuestion).mockReturnValueOnce(false);
|
||||
|
||||
// Execute function
|
||||
const result = await generateInsightsEnabledForSurveyQuestions(surveyId);
|
||||
|
||||
// Verify results
|
||||
expect(result).toEqual({ success: false });
|
||||
expect(updateSurvey).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("should return success=true when survey is updated with insights enabled", async () => {
|
||||
vi.clearAllMocks();
|
||||
// Mock data
|
||||
const surveyId = "cm8ckvchx000008lb710n0gdn";
|
||||
|
||||
// Mock survey with open text questions that have no insightsEnabled property
|
||||
const mockSurveyWithOpenTextQuestions: TSurvey = {
|
||||
...mockSurveyOutput,
|
||||
id: surveyId,
|
||||
type: "link",
|
||||
segment: null,
|
||||
displayPercentage: null,
|
||||
questions: [
|
||||
{
|
||||
id: "cm8cjnse3000009jxf20v91ic",
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: "Question 1" },
|
||||
required: true,
|
||||
inputType: "text",
|
||||
charLimit: {},
|
||||
},
|
||||
{
|
||||
id: "cm8cjo19c000109jx6znygc0u",
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: "Question 2" },
|
||||
required: true,
|
||||
inputType: "text",
|
||||
charLimit: {},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Define the updated survey that should be returned after updateSurvey
|
||||
const mockUpdatedSurveyWithOpenTextQuestions: TSurvey = {
|
||||
...mockSurveyWithOpenTextQuestions,
|
||||
questions: mockSurveyWithOpenTextQuestions.questions.map((q) => ({
|
||||
...q,
|
||||
insightsEnabled: true, // Updated property
|
||||
})),
|
||||
};
|
||||
|
||||
// Setup mocks
|
||||
vi.mocked(getSurvey).mockResolvedValueOnce(mockSurveyWithOpenTextQuestions);
|
||||
vi.mocked(doesSurveyHasOpenTextQuestion).mockReturnValueOnce(true);
|
||||
vi.mocked(updateSurvey).mockResolvedValueOnce(mockUpdatedSurveyWithOpenTextQuestions);
|
||||
|
||||
// Execute function
|
||||
const result = await generateInsightsEnabledForSurveyQuestions(surveyId);
|
||||
|
||||
expect(result).toEqual({
|
||||
success: true,
|
||||
survey: mockUpdatedSurveyWithOpenTextQuestions,
|
||||
});
|
||||
});
|
||||
|
||||
test("should return success=false when all open text questions already have insightsEnabled defined", async () => {
|
||||
// Mock data
|
||||
const surveyId = "survey-123";
|
||||
const mockSurvey: TSurvey = {
|
||||
...mockSurveyOutput,
|
||||
type: "link",
|
||||
segment: null,
|
||||
displayPercentage: null,
|
||||
questions: [
|
||||
{
|
||||
id: "cm8cjnse3000009jxf20v91ic",
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: "Question 1" },
|
||||
required: true,
|
||||
inputType: "text",
|
||||
charLimit: {},
|
||||
insightsEnabled: true,
|
||||
},
|
||||
{
|
||||
id: "cm8cjo19c000109jx6znygc0u",
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
headline: { default: "Question 2" },
|
||||
required: true,
|
||||
choices: [
|
||||
{
|
||||
id: "cm8cjnse3000009jxf20v91ic",
|
||||
label: { default: "Choice 1" },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Setup mocks
|
||||
vi.mocked(getSurvey).mockResolvedValueOnce(mockSurvey);
|
||||
vi.mocked(doesSurveyHasOpenTextQuestion).mockReturnValueOnce(true);
|
||||
|
||||
// Execute function
|
||||
const result = await generateInsightsEnabledForSurveyQuestions(surveyId);
|
||||
|
||||
// Verify results
|
||||
expect(result).toEqual({ success: false });
|
||||
expect(updateSurvey).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("should throw ResourceNotFoundError if survey is not found", async () => {
|
||||
// Setup mocks
|
||||
vi.mocked(getSurvey).mockResolvedValueOnce(null);
|
||||
|
||||
// Execute and verify function
|
||||
await expect(generateInsightsEnabledForSurveyQuestions("survey-123")).rejects.toThrow(
|
||||
new ResourceNotFoundError("Survey", "survey-123")
|
||||
);
|
||||
});
|
||||
|
||||
test("should throw ResourceNotFoundError if updateSurvey returns null", async () => {
|
||||
// Mock data
|
||||
const surveyId = "survey-123";
|
||||
const mockSurvey: TSurvey = {
|
||||
...mockSurveyOutput,
|
||||
type: "link",
|
||||
segment: null,
|
||||
displayPercentage: null,
|
||||
questions: [
|
||||
{
|
||||
id: "cm8cjnse3000009jxf20v91ic",
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: "Question 1" },
|
||||
required: true,
|
||||
inputType: "text",
|
||||
charLimit: {},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Setup mocks
|
||||
vi.mocked(getSurvey).mockResolvedValueOnce(mockSurvey);
|
||||
vi.mocked(doesSurveyHasOpenTextQuestion).mockReturnValueOnce(true);
|
||||
// Type assertion to handle the null case
|
||||
vi.mocked(updateSurvey).mockResolvedValueOnce(null as unknown as TSurvey);
|
||||
|
||||
// Execute and verify function
|
||||
await expect(generateInsightsEnabledForSurveyQuestions(surveyId)).rejects.toThrow(
|
||||
new ResourceNotFoundError("Survey", surveyId)
|
||||
);
|
||||
});
|
||||
|
||||
test("should return success=false when no questions have insights enabled after update", async () => {
|
||||
// Mock data
|
||||
const surveyId = "survey-123";
|
||||
const mockSurvey: TSurvey = {
|
||||
...mockSurveyOutput,
|
||||
type: "link",
|
||||
segment: null,
|
||||
displayPercentage: null,
|
||||
questions: [
|
||||
{
|
||||
id: "cm8cjnse3000009jxf20v91ic",
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: "Question 1" },
|
||||
required: true,
|
||||
inputType: "text",
|
||||
charLimit: {},
|
||||
insightsEnabled: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Setup mocks
|
||||
vi.mocked(getSurvey).mockResolvedValueOnce(mockSurvey);
|
||||
vi.mocked(doesSurveyHasOpenTextQuestion).mockReturnValueOnce(true);
|
||||
vi.mocked(updateSurvey).mockResolvedValueOnce(mockSurvey);
|
||||
|
||||
// Execute function
|
||||
const result = await generateInsightsEnabledForSurveyQuestions(surveyId);
|
||||
|
||||
// Verify results
|
||||
expect(result).toEqual({ success: false });
|
||||
});
|
||||
|
||||
test("should propagate any errors that occur", async () => {
|
||||
// Setup mocks
|
||||
const testError = new Error("Test error");
|
||||
vi.mocked(getSurvey).mockRejectedValueOnce(testError);
|
||||
|
||||
// Execute and verify function
|
||||
await expect(generateInsightsEnabledForSurveyQuestions("survey-123")).rejects.toThrow(testError);
|
||||
});
|
||||
});
|
||||
|
||||
describe("doesResponseHasAnyOpenTextAnswer", () => {
|
||||
test("should return true when at least one open text question has an answer", () => {
|
||||
const openTextQuestionIds = ["q1", "q2", "q3"];
|
||||
const response = {
|
||||
q1: "",
|
||||
q2: "This is an answer",
|
||||
q3: "",
|
||||
q4: "This is not an open text answer",
|
||||
};
|
||||
|
||||
const result = doesResponseHasAnyOpenTextAnswer(openTextQuestionIds, response);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("should return false when no open text questions have answers", () => {
|
||||
const openTextQuestionIds = ["q1", "q2", "q3"];
|
||||
const response = {
|
||||
q1: "",
|
||||
q2: "",
|
||||
q3: "",
|
||||
q4: "This is not an open text answer",
|
||||
};
|
||||
|
||||
const result = doesResponseHasAnyOpenTextAnswer(openTextQuestionIds, response);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when response does not contain any open text question IDs", () => {
|
||||
const openTextQuestionIds = ["q1", "q2", "q3"];
|
||||
const response = {
|
||||
q4: "This is not an open text answer",
|
||||
q5: "Another answer",
|
||||
};
|
||||
|
||||
const result = doesResponseHasAnyOpenTextAnswer(openTextQuestionIds, response);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false for non-string answers", () => {
|
||||
const openTextQuestionIds = ["q1", "q2", "q3"];
|
||||
const response = {
|
||||
q1: "",
|
||||
q2: 123,
|
||||
q3: true,
|
||||
} as any; // Use type assertion to handle mixed types in the test
|
||||
|
||||
const result = doesResponseHasAnyOpenTextAnswer(openTextQuestionIds, response);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,101 +0,0 @@
|
||||
import "server-only";
|
||||
import { CRON_SECRET, WEBAPP_URL } from "@/lib/constants";
|
||||
import { surveyCache } from "@/lib/survey/cache";
|
||||
import { getSurvey, updateSurvey } from "@/lib/survey/service";
|
||||
import { doesSurveyHasOpenTextQuestion } from "@/lib/survey/utils";
|
||||
import { validateInputs } from "@/lib/utils/validate";
|
||||
import { logger } from "@formbricks/logger";
|
||||
import { ZId } from "@formbricks/types/common";
|
||||
import { ResourceNotFoundError } from "@formbricks/types/errors";
|
||||
import { TResponse } from "@formbricks/types/responses";
|
||||
import { TSurvey } from "@formbricks/types/surveys/types";
|
||||
|
||||
export const generateInsightsForSurvey = (surveyId: string) => {
|
||||
if (!CRON_SECRET) {
|
||||
throw new Error("CRON_SECRET is not set");
|
||||
}
|
||||
|
||||
try {
|
||||
return fetch(`${WEBAPP_URL}/api/insights`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": CRON_SECRET,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
surveyId,
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
return {
|
||||
ok: false,
|
||||
error: new Error(`Error while generating insights for survey: ${error.message}`),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const generateInsightsEnabledForSurveyQuestions = async (
|
||||
surveyId: string
|
||||
): Promise<
|
||||
| {
|
||||
success: false;
|
||||
}
|
||||
| {
|
||||
success: true;
|
||||
survey: Pick<TSurvey, "id" | "name" | "environmentId" | "questions">;
|
||||
}
|
||||
> => {
|
||||
validateInputs([surveyId, ZId]);
|
||||
try {
|
||||
const survey = await getSurvey(surveyId);
|
||||
|
||||
if (!survey) {
|
||||
throw new ResourceNotFoundError("Survey", surveyId);
|
||||
}
|
||||
|
||||
if (!doesSurveyHasOpenTextQuestion(survey.questions)) {
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
const openTextQuestions = survey.questions.filter((question) => question.type === "openText");
|
||||
|
||||
const openTextQuestionsWithoutInsightsEnabled = openTextQuestions.filter(
|
||||
(question) => question.type === "openText" && typeof question.insightsEnabled === "undefined"
|
||||
);
|
||||
|
||||
if (openTextQuestionsWithoutInsightsEnabled.length === 0) {
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
const updatedSurvey = await updateSurvey(survey);
|
||||
|
||||
if (!updatedSurvey) {
|
||||
throw new ResourceNotFoundError("Survey", surveyId);
|
||||
}
|
||||
|
||||
const doesSurveyHasInsightsEnabledQuestion = updatedSurvey.questions.some(
|
||||
(question) => question.type === "openText" && question.insightsEnabled === true
|
||||
);
|
||||
|
||||
surveyCache.revalidate({ id: surveyId, environmentId: survey.environmentId });
|
||||
|
||||
if (doesSurveyHasInsightsEnabledQuestion) {
|
||||
return { success: true, survey: updatedSurvey };
|
||||
}
|
||||
|
||||
return { success: false };
|
||||
} catch (error) {
|
||||
logger.error(error, "Error generating insights for surveys");
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const doesResponseHasAnyOpenTextAnswer = (
|
||||
openTextQuestionIds: string[],
|
||||
response: TResponse["data"]
|
||||
): boolean => {
|
||||
return openTextQuestionIds.some((questionId) => {
|
||||
const answer = response[questionId];
|
||||
return typeof answer === "string" && answer.length > 0;
|
||||
});
|
||||
};
|
||||
@@ -1,51 +0,0 @@
|
||||
// This function can run for a maximum of 300 seconds
|
||||
import { generateInsightsForSurveyResponsesConcept } from "@/app/api/(internal)/insights/lib/insights";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { CRON_SECRET } from "@/lib/constants";
|
||||
import { headers } from "next/headers";
|
||||
import { z } from "zod";
|
||||
import { logger } from "@formbricks/logger";
|
||||
import { generateInsightsEnabledForSurveyQuestions } from "./lib/utils";
|
||||
|
||||
export const maxDuration = 300; // This function can run for a maximum of 300 seconds
|
||||
|
||||
const ZGenerateInsightsInput = z.object({
|
||||
surveyId: z.string(),
|
||||
});
|
||||
|
||||
export const POST = async (request: Request) => {
|
||||
try {
|
||||
const requestHeaders = await headers();
|
||||
// Check authentication
|
||||
if (requestHeaders.get("x-api-key") !== CRON_SECRET) {
|
||||
return responses.notAuthenticatedResponse();
|
||||
}
|
||||
|
||||
const jsonInput = await request.json();
|
||||
const inputValidation = ZGenerateInsightsInput.safeParse(jsonInput);
|
||||
|
||||
if (!inputValidation.success) {
|
||||
logger.error({ error: inputValidation.error, url: request.url }, "Error in POST /api/insights");
|
||||
return responses.badRequestResponse(
|
||||
"Fields are missing or incorrectly formatted",
|
||||
transformErrorToDetails(inputValidation.error),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
const { surveyId } = inputValidation.data;
|
||||
|
||||
const data = await generateInsightsEnabledForSurveyQuestions(surveyId);
|
||||
|
||||
if (!data.success) {
|
||||
return responses.successResponse({ message: "No insights enabled questions found" });
|
||||
}
|
||||
|
||||
await generateInsightsForSurveyResponsesConcept(data.survey);
|
||||
|
||||
return responses.successResponse({ message: "Insights generated successfully" });
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -1,107 +0,0 @@
|
||||
import { handleInsightAssignments } from "@/app/api/(internal)/insights/lib/insights";
|
||||
import { embeddingsModel, llmModel } from "@/lib/aiModels";
|
||||
import { documentCache } from "@/lib/cache/document";
|
||||
import { validateInputs } from "@/lib/utils/validate";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { embed, generateObject } from "ai";
|
||||
import { z } from "zod";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { ZInsight } from "@formbricks/database/zod/insights";
|
||||
import {
|
||||
TDocument,
|
||||
TDocumentCreateInput,
|
||||
ZDocumentCreateInput,
|
||||
ZDocumentSentiment,
|
||||
} from "@formbricks/types/documents";
|
||||
import { DatabaseError } from "@formbricks/types/errors";
|
||||
|
||||
export const createDocumentAndAssignInsight = async (
|
||||
surveyName: string,
|
||||
documentInput: TDocumentCreateInput
|
||||
): Promise<TDocument> => {
|
||||
validateInputs([surveyName, z.string()], [documentInput, ZDocumentCreateInput]);
|
||||
|
||||
try {
|
||||
// Generate text embedding
|
||||
const { embedding } = await embed({
|
||||
model: embeddingsModel,
|
||||
value: documentInput.text,
|
||||
experimental_telemetry: { isEnabled: true },
|
||||
});
|
||||
|
||||
// generate sentiment and insights
|
||||
const { object } = await generateObject({
|
||||
model: llmModel,
|
||||
schema: z.object({
|
||||
sentiment: ZDocumentSentiment,
|
||||
insights: z.array(
|
||||
z.object({
|
||||
title: z.string().describe("insight title, very specific"),
|
||||
description: z.string().describe("very brief insight description"),
|
||||
category: ZInsight.shape.category,
|
||||
})
|
||||
),
|
||||
isSpam: z.boolean(),
|
||||
}),
|
||||
system: `You are an XM researcher. You analyse a survey response (survey name, question headline & user answer) and generate insights from it. The insight title (1-3 words) should concisely answer the question, e.g., "What type of people do you think would most benefit" -> "Developers". You are very objective. For the insights, split the feedback into the smallest parts possible and only use the feedback itself to draw conclusions. You must output at least one insight. Always generate insights and titles in English, regardless of the input language.`,
|
||||
prompt: `Survey: ${surveyName}\n${documentInput.text}`,
|
||||
temperature: 0,
|
||||
experimental_telemetry: { isEnabled: true },
|
||||
});
|
||||
|
||||
const sentiment = object.sentiment;
|
||||
const isSpam = object.isSpam;
|
||||
const insights = object.insights;
|
||||
|
||||
// create document
|
||||
const prismaDocument = await prisma.document.create({
|
||||
data: {
|
||||
...documentInput,
|
||||
sentiment,
|
||||
isSpam,
|
||||
},
|
||||
});
|
||||
|
||||
const document = {
|
||||
...prismaDocument,
|
||||
vector: embedding,
|
||||
};
|
||||
|
||||
// update document vector with the embedding
|
||||
const vectorString = `[${embedding.join(",")}]`;
|
||||
await prisma.$executeRaw`
|
||||
UPDATE "Document"
|
||||
SET "vector" = ${vectorString}::vector(512)
|
||||
WHERE "id" = ${document.id};
|
||||
`;
|
||||
|
||||
// connect or create the insights
|
||||
const insightPromises: Promise<void>[] = [];
|
||||
if (!isSpam) {
|
||||
for (const insight of insights) {
|
||||
if (typeof insight.title !== "string" || typeof insight.description !== "string") {
|
||||
throw new Error("Insight title and description must be a string");
|
||||
}
|
||||
|
||||
// create or connect the insight
|
||||
insightPromises.push(handleInsightAssignments(documentInput.environmentId, document.id, insight));
|
||||
}
|
||||
await Promise.allSettled(insightPromises);
|
||||
}
|
||||
|
||||
documentCache.revalidate({
|
||||
id: document.id,
|
||||
environmentId: document.environmentId,
|
||||
surveyId: document.surveyId,
|
||||
responseId: document.responseId,
|
||||
questionId: document.questionId,
|
||||
});
|
||||
|
||||
return document;
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -1,19 +1,15 @@
|
||||
import { createDocumentAndAssignInsight } from "@/app/api/(internal)/pipeline/lib/documents";
|
||||
import { sendSurveyFollowUps } from "@/app/api/(internal)/pipeline/lib/survey-follow-up";
|
||||
import { ZPipelineInput } from "@/app/api/(internal)/pipeline/types/pipelines";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { cache } from "@/lib/cache";
|
||||
import { webhookCache } from "@/lib/cache/webhook";
|
||||
import { CRON_SECRET, IS_AI_CONFIGURED } from "@/lib/constants";
|
||||
import { CRON_SECRET } from "@/lib/constants";
|
||||
import { getIntegrations } from "@/lib/integration/service";
|
||||
import { getOrganizationByEnvironmentId } from "@/lib/organization/service";
|
||||
import { getResponseCountBySurveyId } from "@/lib/response/service";
|
||||
import { getSurvey, updateSurvey } from "@/lib/survey/service";
|
||||
import { convertDatesInObject } from "@/lib/time";
|
||||
import { getPromptText } from "@/lib/utils/ai";
|
||||
import { parseRecallInfo } from "@/lib/utils/recall";
|
||||
import { getIsAIEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
import { sendResponseFinishedEmail } from "@/modules/email";
|
||||
import { getSurveyFollowUpsPermission } from "@/modules/survey/follow-ups/lib/utils";
|
||||
import { PipelineTriggers, Webhook } from "@prisma/client";
|
||||
@@ -199,50 +195,6 @@ export const POST = async (request: Request) => {
|
||||
logger.error({ error: result.reason, url: request.url }, "Promise rejected");
|
||||
}
|
||||
});
|
||||
|
||||
// generate embeddings for all open text question responses for all paid plans
|
||||
const hasSurveyOpenTextQuestions = survey.questions.some((question) => question.type === "openText");
|
||||
if (hasSurveyOpenTextQuestions) {
|
||||
const isAICofigured = IS_AI_CONFIGURED;
|
||||
if (hasSurveyOpenTextQuestions && isAICofigured) {
|
||||
const isAIEnabled = await getIsAIEnabled({
|
||||
isAIEnabled: organization.isAIEnabled,
|
||||
billing: organization.billing,
|
||||
});
|
||||
|
||||
if (isAIEnabled) {
|
||||
for (const question of survey.questions) {
|
||||
if (question.type === "openText" && question.insightsEnabled) {
|
||||
const isQuestionAnswered =
|
||||
response.data[question.id] !== undefined && response.data[question.id] !== "";
|
||||
if (!isQuestionAnswered) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const headline = parseRecallInfo(
|
||||
question.headline[response.language ?? "default"],
|
||||
response.data,
|
||||
response.variables
|
||||
);
|
||||
|
||||
const text = getPromptText(headline, response.data[question.id] as string);
|
||||
// TODO: check if subheadline gives more context and better embeddings
|
||||
try {
|
||||
await createDocumentAndAssignInsight(survey.name, {
|
||||
environmentId,
|
||||
surveyId,
|
||||
responseId: response.id,
|
||||
questionId: question.id,
|
||||
text,
|
||||
});
|
||||
} catch (e) {
|
||||
logger.error({ error: e, url: request.url }, "Error creating document and assigning insight");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Await webhook promises if no emails are sent (with allSettled to prevent early rejection)
|
||||
const results = await Promise.allSettled(webhookPromises);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { sendToPipeline } from "@/app/lib/pipelines";
|
||||
import { validateFileUploads } from "@/lib/fileValidation";
|
||||
import { updateResponse } from "@/lib/response/service";
|
||||
import { getSurvey } from "@/lib/survey/service";
|
||||
import { logger } from "@formbricks/logger";
|
||||
@@ -11,6 +12,20 @@ export const OPTIONS = async (): Promise<Response> => {
|
||||
return responses.successResponse({}, true);
|
||||
};
|
||||
|
||||
const handleDatabaseError = (error: Error, url: string, endpoint: string, responseId: string): Response => {
|
||||
if (error instanceof ResourceNotFoundError) {
|
||||
return responses.notFoundResponse("Response", responseId, true);
|
||||
}
|
||||
if (error instanceof InvalidInputError) {
|
||||
return responses.badRequestResponse(error.message, undefined, true);
|
||||
}
|
||||
if (error instanceof DatabaseError) {
|
||||
logger.error({ error, url }, `Error in ${endpoint}`);
|
||||
return responses.internalServerErrorResponse(error.message, true);
|
||||
}
|
||||
return responses.internalServerErrorResponse("Unknown error occurred", true);
|
||||
};
|
||||
|
||||
export const PUT = async (
|
||||
request: Request,
|
||||
props: { params: Promise<{ responseId: string }> }
|
||||
@@ -23,7 +38,6 @@ export const PUT = async (
|
||||
}
|
||||
|
||||
const responseUpdate = await request.json();
|
||||
|
||||
const inputValidation = ZResponseUpdateInput.safeParse(responseUpdate);
|
||||
|
||||
if (!inputValidation.success) {
|
||||
@@ -39,19 +53,8 @@ export const PUT = async (
|
||||
try {
|
||||
response = await updateResponse(responseId, inputValidation.data);
|
||||
} catch (error) {
|
||||
if (error instanceof ResourceNotFoundError) {
|
||||
return responses.notFoundResponse("Response", responseId, true);
|
||||
}
|
||||
if (error instanceof InvalidInputError) {
|
||||
return responses.badRequestResponse(error.message);
|
||||
}
|
||||
if (error instanceof DatabaseError) {
|
||||
logger.error(
|
||||
{ error, url: request.url },
|
||||
"Error in PUT /api/v1/client/[environmentId]/responses/[responseId]"
|
||||
);
|
||||
return responses.internalServerErrorResponse(error.message);
|
||||
}
|
||||
const endpoint = "PUT /api/v1/client/[environmentId]/responses/[responseId]";
|
||||
return handleDatabaseError(error, request.url, endpoint, responseId);
|
||||
}
|
||||
|
||||
// get survey to get environmentId
|
||||
@@ -59,16 +62,12 @@ export const PUT = async (
|
||||
try {
|
||||
survey = await getSurvey(response.surveyId);
|
||||
} catch (error) {
|
||||
if (error instanceof InvalidInputError) {
|
||||
return responses.badRequestResponse(error.message);
|
||||
}
|
||||
if (error instanceof DatabaseError) {
|
||||
logger.error(
|
||||
{ error, url: request.url },
|
||||
"Error in PUT /api/v1/client/[environmentId]/responses/[responseId]"
|
||||
);
|
||||
return responses.internalServerErrorResponse(error.message);
|
||||
}
|
||||
const endpoint = "PUT /api/v1/client/[environmentId]/responses/[responseId]";
|
||||
return handleDatabaseError(error, request.url, endpoint, responseId);
|
||||
}
|
||||
|
||||
if (!validateFileUploads(response.data, survey.questions)) {
|
||||
return responses.badRequestResponse("Invalid file upload response", undefined, true);
|
||||
}
|
||||
|
||||
// send response update to pipeline
|
||||
@@ -87,7 +86,7 @@ export const PUT = async (
|
||||
event: "responseFinished",
|
||||
environmentId: survey.environmentId,
|
||||
surveyId: survey.id,
|
||||
response: response,
|
||||
response,
|
||||
});
|
||||
}
|
||||
return responses.successResponse({}, true);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { sendToPipeline } from "@/app/lib/pipelines";
|
||||
import { validateFileUploads } from "@/lib/fileValidation";
|
||||
import { capturePosthogEnvironmentEvent } from "@/lib/posthogServer";
|
||||
import { getSurvey } from "@/lib/survey/service";
|
||||
import { getIsContactsEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
@@ -86,6 +87,10 @@ export const POST = async (request: Request, context: Context): Promise<Response
|
||||
);
|
||||
}
|
||||
|
||||
if (!validateFileUploads(responseInputData.data, survey.questions)) {
|
||||
return responses.badRequestResponse("Invalid file upload response");
|
||||
}
|
||||
|
||||
let response: TResponse;
|
||||
try {
|
||||
const meta: TResponseInput["meta"] = {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { ENCRYPTION_KEY, UPLOADS_DIR } from "@/lib/constants";
|
||||
import { validateLocalSignedUrl } from "@/lib/crypto";
|
||||
import { validateFile } from "@/lib/fileValidation";
|
||||
import { getOrganizationByEnvironmentId } from "@/lib/organization/service";
|
||||
import { putFileToLocalStorage } from "@/lib/storage/service";
|
||||
import { getSurvey } from "@/lib/survey/service";
|
||||
@@ -86,8 +87,14 @@ export const POST = async (req: NextRequest, context: Context): Promise<Response
|
||||
|
||||
const fileName = decodeURIComponent(encodedFileName);
|
||||
|
||||
// validate signature
|
||||
// Perform server-side file validation again
|
||||
// This is crucial as attackers could bypass the initial validation and directly call this endpoint
|
||||
const fileValidation = validateFile(fileName, fileType);
|
||||
if (!fileValidation.valid) {
|
||||
return responses.badRequestResponse(fileValidation.error ?? "Invalid file", { fileName, fileType });
|
||||
}
|
||||
|
||||
// validate signature
|
||||
const validated = validateLocalSignedUrl(
|
||||
signedUuid,
|
||||
fileName,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { validateFile } from "@/lib/fileValidation";
|
||||
import { getOrganizationByEnvironmentId } from "@/lib/organization/service";
|
||||
import { getSurvey } from "@/lib/survey/service";
|
||||
import { getBiggerUploadFileSizePermission } from "@/modules/ee/license-check/lib/utils";
|
||||
@@ -28,7 +29,6 @@ export const POST = async (req: NextRequest, context: Context): Promise<Response
|
||||
const environmentId = params.environmentId;
|
||||
|
||||
const jsonInput = await req.json();
|
||||
|
||||
const inputValidation = ZUploadFileRequest.safeParse({
|
||||
...jsonInput,
|
||||
environmentId,
|
||||
@@ -44,6 +44,12 @@ export const POST = async (req: NextRequest, context: Context): Promise<Response
|
||||
|
||||
const { fileName, fileType, surveyId } = inputValidation.data;
|
||||
|
||||
// Perform server-side file validation
|
||||
const fileValidation = validateFile(fileName, fileType);
|
||||
if (!fileValidation.valid) {
|
||||
return responses.badRequestResponse(fileValidation.error ?? "Invalid file", { fileName, fileType }, true);
|
||||
}
|
||||
|
||||
const [survey, organization] = await Promise.all([
|
||||
getSurvey(surveyId),
|
||||
getOrganizationByEnvironmentId(environmentId),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { authenticateRequest, handleErrorResponse } from "@/app/api/v1/auth";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { validateFileUploads } from "@/lib/fileValidation";
|
||||
import { deleteResponse, getResponse, updateResponse } from "@/lib/response/service";
|
||||
import { getSurvey } from "@/lib/survey/service";
|
||||
import { hasPermission } from "@/modules/organization/settings/api-keys/lib/utils";
|
||||
@@ -26,7 +27,7 @@ async function fetchAndAuthorizeResponse(
|
||||
return { error: responses.unauthorizedResponse() };
|
||||
}
|
||||
|
||||
return { response };
|
||||
return { response, survey };
|
||||
}
|
||||
|
||||
export const GET = async (
|
||||
@@ -86,6 +87,10 @@ export const PUT = async (
|
||||
return responses.badRequestResponse("Malformed JSON input, please check your request body");
|
||||
}
|
||||
|
||||
if (!validateFileUploads(responseUpdate.data, result.survey.questions)) {
|
||||
return responses.badRequestResponse("Invalid file upload response");
|
||||
}
|
||||
|
||||
const inputValidation = ZResponseUpdateInput.safeParse(responseUpdate);
|
||||
if (!inputValidation.success) {
|
||||
return responses.badRequestResponse(
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { authenticateRequest } from "@/app/api/v1/auth";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { validateFileUploads } from "@/lib/fileValidation";
|
||||
import { getResponses } from "@/lib/response/service";
|
||||
import { getSurvey } from "@/lib/survey/service";
|
||||
import { hasPermission } from "@/modules/organization/settings/api-keys/lib/utils";
|
||||
import { NextRequest } from "next/server";
|
||||
import { logger } from "@formbricks/logger";
|
||||
import { DatabaseError, InvalidInputError } from "@formbricks/types/errors";
|
||||
import { TResponse, ZResponseInput } from "@formbricks/types/responses";
|
||||
import { TResponse, TResponseInput, ZResponseInput } from "@formbricks/types/responses";
|
||||
import { createResponse, getResponsesByEnvironmentIds } from "./lib/response";
|
||||
|
||||
export const GET = async (request: NextRequest) => {
|
||||
@@ -47,72 +48,85 @@ export const GET = async (request: NextRequest) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const POST = async (request: Request): Promise<Response> => {
|
||||
const validateInput = async (request: Request) => {
|
||||
let jsonInput;
|
||||
try {
|
||||
const authentication = await authenticateRequest(request);
|
||||
if (!authentication) return responses.notAuthenticatedResponse();
|
||||
jsonInput = await request.json();
|
||||
} catch (err) {
|
||||
logger.error({ error: err, url: request.url }, "Error parsing JSON input");
|
||||
return { error: responses.badRequestResponse("Malformed JSON input, please check your request body") };
|
||||
}
|
||||
|
||||
let jsonInput;
|
||||
|
||||
try {
|
||||
jsonInput = await request.json();
|
||||
} catch (err) {
|
||||
logger.error({ error: err, url: request.url }, "Error parsing JSON input");
|
||||
return responses.badRequestResponse("Malformed JSON input, please check your request body");
|
||||
}
|
||||
|
||||
const inputValidation = ZResponseInput.safeParse(jsonInput);
|
||||
|
||||
if (!inputValidation.success) {
|
||||
return responses.badRequestResponse(
|
||||
const inputValidation = ZResponseInput.safeParse(jsonInput);
|
||||
if (!inputValidation.success) {
|
||||
return {
|
||||
error: responses.badRequestResponse(
|
||||
"Fields are missing or incorrectly formatted",
|
||||
transformErrorToDetails(inputValidation.error),
|
||||
true
|
||||
);
|
||||
}
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
const responseInput = inputValidation.data;
|
||||
return { data: inputValidation.data };
|
||||
};
|
||||
|
||||
const environmentId = responseInput.environmentId;
|
||||
|
||||
if (!hasPermission(authentication.environmentPermissions, environmentId, "POST")) {
|
||||
return responses.unauthorizedResponse();
|
||||
}
|
||||
|
||||
// get and check survey
|
||||
const survey = await getSurvey(responseInput.surveyId);
|
||||
if (!survey) {
|
||||
return responses.notFoundResponse("Survey", responseInput.surveyId, true);
|
||||
}
|
||||
if (survey.environmentId !== environmentId) {
|
||||
return responses.badRequestResponse(
|
||||
const validateSurvey = async (responseInput: TResponseInput, environmentId: string) => {
|
||||
const survey = await getSurvey(responseInput.surveyId);
|
||||
if (!survey) {
|
||||
return { error: responses.notFoundResponse("Survey", responseInput.surveyId, true) };
|
||||
}
|
||||
if (survey.environmentId !== environmentId) {
|
||||
return {
|
||||
error: responses.badRequestResponse(
|
||||
"Survey is part of another environment",
|
||||
{
|
||||
"survey.environmentId": survey.environmentId,
|
||||
environmentId,
|
||||
},
|
||||
true
|
||||
);
|
||||
),
|
||||
};
|
||||
}
|
||||
return { survey };
|
||||
};
|
||||
|
||||
export const POST = async (request: Request): Promise<Response> => {
|
||||
try {
|
||||
const authentication = await authenticateRequest(request);
|
||||
if (!authentication) return responses.notAuthenticatedResponse();
|
||||
|
||||
const inputResult = await validateInput(request);
|
||||
if (inputResult.error) return inputResult.error;
|
||||
|
||||
const responseInput = inputResult.data;
|
||||
const environmentId = responseInput.environmentId;
|
||||
|
||||
if (!hasPermission(authentication.environmentPermissions, environmentId, "POST")) {
|
||||
return responses.unauthorizedResponse();
|
||||
}
|
||||
|
||||
const surveyResult = await validateSurvey(responseInput, environmentId);
|
||||
if (surveyResult.error) return surveyResult.error;
|
||||
|
||||
if (!validateFileUploads(responseInput.data, surveyResult.survey.questions)) {
|
||||
return responses.badRequestResponse("Invalid file upload response");
|
||||
}
|
||||
|
||||
// if there is a createdAt but no updatedAt, set updatedAt to createdAt
|
||||
if (responseInput.createdAt && !responseInput.updatedAt) {
|
||||
responseInput.updatedAt = responseInput.createdAt;
|
||||
}
|
||||
|
||||
let response: TResponse;
|
||||
try {
|
||||
response = await createResponse(inputValidation.data);
|
||||
const response = await createResponse(responseInput);
|
||||
return responses.successResponse(response, true);
|
||||
} catch (error) {
|
||||
if (error instanceof InvalidInputError) {
|
||||
return responses.badRequestResponse(error.message);
|
||||
} else {
|
||||
logger.error({ error, url: request.url }, "Error in POST /api/v1/management/responses");
|
||||
return responses.internalServerErrorResponse(error.message);
|
||||
}
|
||||
logger.error({ error, url: request.url }, "Error in POST /api/v1/management/responses");
|
||||
return responses.internalServerErrorResponse(error.message);
|
||||
}
|
||||
|
||||
return responses.successResponse(response, true);
|
||||
} catch (error) {
|
||||
if (error instanceof DatabaseError) {
|
||||
return responses.badRequestResponse(error.message);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { responses } from "@/app/lib/api/response";
|
||||
import { ENCRYPTION_KEY, UPLOADS_DIR } from "@/lib/constants";
|
||||
import { validateLocalSignedUrl } from "@/lib/crypto";
|
||||
import { hasUserEnvironmentAccess } from "@/lib/environment/auth";
|
||||
import { validateFile } from "@/lib/fileValidation";
|
||||
import { putFileToLocalStorage } from "@/lib/storage/service";
|
||||
import { authOptions } from "@/modules/auth/lib/authOptions";
|
||||
import { getServerSession } from "next-auth";
|
||||
@@ -65,6 +66,12 @@ export const POST = async (req: NextRequest): Promise<Response> => {
|
||||
|
||||
const fileName = decodeURIComponent(encodedFileName);
|
||||
|
||||
// Perform server-side file validation
|
||||
const fileValidation = validateFile(fileName, fileType);
|
||||
if (!fileValidation.valid) {
|
||||
return responses.badRequestResponse(fileValidation.error ?? "Invalid file");
|
||||
}
|
||||
|
||||
// validate signature
|
||||
|
||||
const validated = validateLocalSignedUrl(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { hasUserEnvironmentAccess } from "@/lib/environment/auth";
|
||||
import { validateFile } from "@/lib/fileValidation";
|
||||
import { authOptions } from "@/modules/auth/lib/authOptions";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { NextRequest } from "next/server";
|
||||
@@ -36,8 +37,15 @@ export const POST = async (req: NextRequest): Promise<Response> => {
|
||||
return responses.badRequestResponse("environmentId is required");
|
||||
}
|
||||
|
||||
// Perform server-side file validation first to block dangerous file types
|
||||
const fileValidation = validateFile(fileName, fileType);
|
||||
if (!fileValidation.valid) {
|
||||
return responses.badRequestResponse(fileValidation.error ?? "Invalid file type");
|
||||
}
|
||||
|
||||
// Also perform client-specified allowed file extensions validation if provided
|
||||
if (allowedFileExtensions?.length) {
|
||||
const fileExtension = fileName.split(".").pop();
|
||||
const fileExtension = fileName.split(".").pop()?.toLowerCase();
|
||||
if (!fileExtension || !allowedFileExtensions.includes(fileExtension)) {
|
||||
return responses.badRequestResponse(
|
||||
`File extension is not allowed, allowed extensions are: ${allowedFileExtensions.join(", ")}`
|
||||
|
||||
612
apps/web/app/lib/survey-builder.test.ts
Normal file
612
apps/web/app/lib/survey-builder.test.ts
Normal file
@@ -0,0 +1,612 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { TShuffleOption, TSurveyLogic, TSurveyQuestionTypeEnum } from "@formbricks/types/surveys/types";
|
||||
import { TTemplateRole } from "@formbricks/types/templates";
|
||||
import {
|
||||
buildCTAQuestion,
|
||||
buildConsentQuestion,
|
||||
buildMultipleChoiceQuestion,
|
||||
buildNPSQuestion,
|
||||
buildOpenTextQuestion,
|
||||
buildRatingQuestion,
|
||||
buildSurvey,
|
||||
createChoiceJumpLogic,
|
||||
createJumpLogic,
|
||||
getDefaultEndingCard,
|
||||
getDefaultSurveyPreset,
|
||||
getDefaultWelcomeCard,
|
||||
hiddenFieldsDefault,
|
||||
} from "./survey-builder";
|
||||
|
||||
// Mock the TFnType from @tolgee/react
|
||||
const mockT = (props: any): string => (typeof props === "string" ? props : props.key);
|
||||
|
||||
describe("Survey Builder", () => {
|
||||
describe("buildMultipleChoiceQuestion", () => {
|
||||
test("creates a single choice question with required fields", () => {
|
||||
const question = buildMultipleChoiceQuestion({
|
||||
headline: "Test Question",
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
choices: ["Option 1", "Option 2", "Option 3"],
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question).toMatchObject({
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
headline: { default: "Test Question" },
|
||||
choices: expect.arrayContaining([
|
||||
expect.objectContaining({ label: { default: "Option 1" } }),
|
||||
expect.objectContaining({ label: { default: "Option 2" } }),
|
||||
expect.objectContaining({ label: { default: "Option 3" } }),
|
||||
]),
|
||||
buttonLabel: { default: "common.next" },
|
||||
backButtonLabel: { default: "common.back" },
|
||||
shuffleOption: "none",
|
||||
required: true,
|
||||
});
|
||||
expect(question.choices.length).toBe(3);
|
||||
expect(question.id).toBeDefined();
|
||||
});
|
||||
|
||||
test("creates a multiple choice question with provided ID", () => {
|
||||
const customId = "custom-id-123";
|
||||
const question = buildMultipleChoiceQuestion({
|
||||
id: customId,
|
||||
headline: "Test Question",
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceMulti,
|
||||
choices: ["Option 1", "Option 2"],
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.id).toBe(customId);
|
||||
expect(question.type).toBe(TSurveyQuestionTypeEnum.MultipleChoiceMulti);
|
||||
});
|
||||
|
||||
test("handles 'other' option correctly", () => {
|
||||
const choices = ["Option 1", "Option 2", "Other"];
|
||||
const question = buildMultipleChoiceQuestion({
|
||||
headline: "Test Question",
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
choices,
|
||||
containsOther: true,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.choices.length).toBe(3);
|
||||
expect(question.choices[2].id).toBe("other");
|
||||
});
|
||||
|
||||
test("uses provided choice IDs when available", () => {
|
||||
const choiceIds = ["id1", "id2", "id3"];
|
||||
const question = buildMultipleChoiceQuestion({
|
||||
headline: "Test Question",
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
choices: ["Option 1", "Option 2", "Option 3"],
|
||||
choiceIds,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.choices[0].id).toBe(choiceIds[0]);
|
||||
expect(question.choices[1].id).toBe(choiceIds[1]);
|
||||
expect(question.choices[2].id).toBe(choiceIds[2]);
|
||||
});
|
||||
|
||||
test("applies all optional parameters correctly", () => {
|
||||
const logic: TSurveyLogic[] = [
|
||||
{
|
||||
id: "logic-1",
|
||||
conditions: {
|
||||
id: "cond-1",
|
||||
connector: "and",
|
||||
conditions: [],
|
||||
},
|
||||
actions: [],
|
||||
},
|
||||
];
|
||||
|
||||
const shuffleOption: TShuffleOption = "all";
|
||||
|
||||
const question = buildMultipleChoiceQuestion({
|
||||
headline: "Test Question",
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
subheader: "This is a subheader",
|
||||
choices: ["Option 1", "Option 2"],
|
||||
buttonLabel: "Custom Next",
|
||||
backButtonLabel: "Custom Back",
|
||||
shuffleOption,
|
||||
required: false,
|
||||
logic,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.subheader).toEqual({ default: "This is a subheader" });
|
||||
expect(question.buttonLabel).toEqual({ default: "Custom Next" });
|
||||
expect(question.backButtonLabel).toEqual({ default: "Custom Back" });
|
||||
expect(question.shuffleOption).toBe("all");
|
||||
expect(question.required).toBe(false);
|
||||
expect(question.logic).toBe(logic);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildOpenTextQuestion", () => {
|
||||
test("creates an open text question with required fields", () => {
|
||||
const question = buildOpenTextQuestion({
|
||||
headline: "Open Question",
|
||||
inputType: "text",
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question).toMatchObject({
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: "Open Question" },
|
||||
inputType: "text",
|
||||
buttonLabel: { default: "common.next" },
|
||||
backButtonLabel: { default: "common.back" },
|
||||
required: true,
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
expect(question.id).toBeDefined();
|
||||
});
|
||||
|
||||
test("applies all optional parameters correctly", () => {
|
||||
const logic: TSurveyLogic[] = [
|
||||
{
|
||||
id: "logic-1",
|
||||
conditions: {
|
||||
id: "cond-1",
|
||||
connector: "and",
|
||||
conditions: [],
|
||||
},
|
||||
actions: [],
|
||||
},
|
||||
];
|
||||
|
||||
const question = buildOpenTextQuestion({
|
||||
id: "custom-id",
|
||||
headline: "Open Question",
|
||||
subheader: "Answer this question",
|
||||
placeholder: "Type here",
|
||||
buttonLabel: "Submit",
|
||||
backButtonLabel: "Previous",
|
||||
required: false,
|
||||
longAnswer: true,
|
||||
inputType: "email",
|
||||
logic,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.id).toBe("custom-id");
|
||||
expect(question.subheader).toEqual({ default: "Answer this question" });
|
||||
expect(question.placeholder).toEqual({ default: "Type here" });
|
||||
expect(question.buttonLabel).toEqual({ default: "Submit" });
|
||||
expect(question.backButtonLabel).toEqual({ default: "Previous" });
|
||||
expect(question.required).toBe(false);
|
||||
expect(question.longAnswer).toBe(true);
|
||||
expect(question.inputType).toBe("email");
|
||||
expect(question.logic).toBe(logic);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildRatingQuestion", () => {
|
||||
test("creates a rating question with required fields", () => {
|
||||
const question = buildRatingQuestion({
|
||||
headline: "Rating Question",
|
||||
scale: "number",
|
||||
range: 5,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question).toMatchObject({
|
||||
type: TSurveyQuestionTypeEnum.Rating,
|
||||
headline: { default: "Rating Question" },
|
||||
scale: "number",
|
||||
range: 5,
|
||||
buttonLabel: { default: "common.next" },
|
||||
backButtonLabel: { default: "common.back" },
|
||||
required: true,
|
||||
isColorCodingEnabled: false,
|
||||
});
|
||||
expect(question.id).toBeDefined();
|
||||
});
|
||||
|
||||
test("applies all optional parameters correctly", () => {
|
||||
const logic: TSurveyLogic[] = [
|
||||
{
|
||||
id: "logic-1",
|
||||
conditions: {
|
||||
id: "cond-1",
|
||||
connector: "and",
|
||||
conditions: [],
|
||||
},
|
||||
actions: [],
|
||||
},
|
||||
];
|
||||
|
||||
const question = buildRatingQuestion({
|
||||
id: "custom-id",
|
||||
headline: "Rating Question",
|
||||
subheader: "Rate us",
|
||||
scale: "star",
|
||||
range: 10,
|
||||
lowerLabel: "Poor",
|
||||
upperLabel: "Excellent",
|
||||
buttonLabel: "Submit",
|
||||
backButtonLabel: "Previous",
|
||||
required: false,
|
||||
isColorCodingEnabled: true,
|
||||
logic,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.id).toBe("custom-id");
|
||||
expect(question.subheader).toEqual({ default: "Rate us" });
|
||||
expect(question.scale).toBe("star");
|
||||
expect(question.range).toBe(10);
|
||||
expect(question.lowerLabel).toEqual({ default: "Poor" });
|
||||
expect(question.upperLabel).toEqual({ default: "Excellent" });
|
||||
expect(question.buttonLabel).toEqual({ default: "Submit" });
|
||||
expect(question.backButtonLabel).toEqual({ default: "Previous" });
|
||||
expect(question.required).toBe(false);
|
||||
expect(question.isColorCodingEnabled).toBe(true);
|
||||
expect(question.logic).toBe(logic);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildNPSQuestion", () => {
|
||||
test("creates an NPS question with required fields", () => {
|
||||
const question = buildNPSQuestion({
|
||||
headline: "NPS Question",
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question).toMatchObject({
|
||||
type: TSurveyQuestionTypeEnum.NPS,
|
||||
headline: { default: "NPS Question" },
|
||||
buttonLabel: { default: "common.next" },
|
||||
backButtonLabel: { default: "common.back" },
|
||||
required: true,
|
||||
isColorCodingEnabled: false,
|
||||
});
|
||||
expect(question.id).toBeDefined();
|
||||
});
|
||||
|
||||
test("applies all optional parameters correctly", () => {
|
||||
const logic: TSurveyLogic[] = [
|
||||
{
|
||||
id: "logic-1",
|
||||
conditions: {
|
||||
id: "cond-1",
|
||||
connector: "and",
|
||||
conditions: [],
|
||||
},
|
||||
actions: [],
|
||||
},
|
||||
];
|
||||
|
||||
const question = buildNPSQuestion({
|
||||
id: "custom-id",
|
||||
headline: "NPS Question",
|
||||
subheader: "How likely are you to recommend us?",
|
||||
lowerLabel: "Not likely",
|
||||
upperLabel: "Very likely",
|
||||
buttonLabel: "Submit",
|
||||
backButtonLabel: "Previous",
|
||||
required: false,
|
||||
isColorCodingEnabled: true,
|
||||
logic,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.id).toBe("custom-id");
|
||||
expect(question.subheader).toEqual({ default: "How likely are you to recommend us?" });
|
||||
expect(question.lowerLabel).toEqual({ default: "Not likely" });
|
||||
expect(question.upperLabel).toEqual({ default: "Very likely" });
|
||||
expect(question.buttonLabel).toEqual({ default: "Submit" });
|
||||
expect(question.backButtonLabel).toEqual({ default: "Previous" });
|
||||
expect(question.required).toBe(false);
|
||||
expect(question.isColorCodingEnabled).toBe(true);
|
||||
expect(question.logic).toBe(logic);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildConsentQuestion", () => {
|
||||
test("creates a consent question with required fields", () => {
|
||||
const question = buildConsentQuestion({
|
||||
headline: "Consent Question",
|
||||
label: "I agree to terms",
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question).toMatchObject({
|
||||
type: TSurveyQuestionTypeEnum.Consent,
|
||||
headline: { default: "Consent Question" },
|
||||
label: { default: "I agree to terms" },
|
||||
buttonLabel: { default: "common.next" },
|
||||
backButtonLabel: { default: "common.back" },
|
||||
required: true,
|
||||
});
|
||||
expect(question.id).toBeDefined();
|
||||
});
|
||||
|
||||
test("applies all optional parameters correctly", () => {
|
||||
const logic: TSurveyLogic[] = [
|
||||
{
|
||||
id: "logic-1",
|
||||
conditions: {
|
||||
id: "cond-1",
|
||||
connector: "and",
|
||||
conditions: [],
|
||||
},
|
||||
actions: [],
|
||||
},
|
||||
];
|
||||
|
||||
const question = buildConsentQuestion({
|
||||
id: "custom-id",
|
||||
headline: "Consent Question",
|
||||
subheader: "Please read the terms",
|
||||
label: "I agree to terms",
|
||||
buttonLabel: "Submit",
|
||||
backButtonLabel: "Previous",
|
||||
required: false,
|
||||
logic,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.id).toBe("custom-id");
|
||||
expect(question.subheader).toEqual({ default: "Please read the terms" });
|
||||
expect(question.label).toEqual({ default: "I agree to terms" });
|
||||
expect(question.buttonLabel).toEqual({ default: "Submit" });
|
||||
expect(question.backButtonLabel).toEqual({ default: "Previous" });
|
||||
expect(question.required).toBe(false);
|
||||
expect(question.logic).toBe(logic);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildCTAQuestion", () => {
|
||||
test("creates a CTA question with required fields", () => {
|
||||
const question = buildCTAQuestion({
|
||||
headline: "CTA Question",
|
||||
buttonExternal: false,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question).toMatchObject({
|
||||
type: TSurveyQuestionTypeEnum.CTA,
|
||||
headline: { default: "CTA Question" },
|
||||
buttonLabel: { default: "common.next" },
|
||||
backButtonLabel: { default: "common.back" },
|
||||
required: true,
|
||||
buttonExternal: false,
|
||||
});
|
||||
expect(question.id).toBeDefined();
|
||||
});
|
||||
|
||||
test("applies all optional parameters correctly", () => {
|
||||
const logic: TSurveyLogic[] = [
|
||||
{
|
||||
id: "logic-1",
|
||||
conditions: {
|
||||
id: "cond-1",
|
||||
connector: "and",
|
||||
conditions: [],
|
||||
},
|
||||
actions: [],
|
||||
},
|
||||
];
|
||||
|
||||
const question = buildCTAQuestion({
|
||||
id: "custom-id",
|
||||
headline: "CTA Question",
|
||||
html: "<p>Click the button</p>",
|
||||
buttonLabel: "Click me",
|
||||
buttonExternal: true,
|
||||
buttonUrl: "https://example.com",
|
||||
backButtonLabel: "Previous",
|
||||
required: false,
|
||||
dismissButtonLabel: "No thanks",
|
||||
logic,
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.id).toBe("custom-id");
|
||||
expect(question.html).toEqual({ default: "<p>Click the button</p>" });
|
||||
expect(question.buttonLabel).toEqual({ default: "Click me" });
|
||||
expect(question.buttonExternal).toBe(true);
|
||||
expect(question.buttonUrl).toBe("https://example.com");
|
||||
expect(question.backButtonLabel).toEqual({ default: "Previous" });
|
||||
expect(question.required).toBe(false);
|
||||
expect(question.dismissButtonLabel).toEqual({ default: "No thanks" });
|
||||
expect(question.logic).toBe(logic);
|
||||
});
|
||||
|
||||
test("handles external button with URL", () => {
|
||||
const question = buildCTAQuestion({
|
||||
headline: "CTA Question",
|
||||
buttonExternal: true,
|
||||
buttonUrl: "https://formbricks.com",
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.buttonExternal).toBe(true);
|
||||
expect(question.buttonUrl).toBe("https://formbricks.com");
|
||||
});
|
||||
});
|
||||
|
||||
// Test combinations of parameters for edge cases
|
||||
describe("Edge cases", () => {
|
||||
test("multiple choice question with empty choices array", () => {
|
||||
const question = buildMultipleChoiceQuestion({
|
||||
headline: "Test Question",
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
choices: [],
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question.choices).toEqual([]);
|
||||
});
|
||||
|
||||
test("open text question with all parameters", () => {
|
||||
const question = buildOpenTextQuestion({
|
||||
id: "custom-id",
|
||||
headline: "Open Question",
|
||||
subheader: "Answer this question",
|
||||
placeholder: "Type here",
|
||||
buttonLabel: "Submit",
|
||||
backButtonLabel: "Previous",
|
||||
required: false,
|
||||
longAnswer: true,
|
||||
inputType: "email",
|
||||
logic: [],
|
||||
t: mockT,
|
||||
});
|
||||
|
||||
expect(question).toMatchObject({
|
||||
id: "custom-id",
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
headline: { default: "Open Question" },
|
||||
subheader: { default: "Answer this question" },
|
||||
placeholder: { default: "Type here" },
|
||||
buttonLabel: { default: "Submit" },
|
||||
backButtonLabel: { default: "Previous" },
|
||||
required: false,
|
||||
longAnswer: true,
|
||||
inputType: "email",
|
||||
logic: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Helper Functions", () => {
|
||||
test("createJumpLogic returns valid jump logic", () => {
|
||||
const sourceId = "q1";
|
||||
const targetId = "q2";
|
||||
const operator: "isClicked" = "isClicked";
|
||||
const logic = createJumpLogic(sourceId, targetId, operator);
|
||||
|
||||
// Check structure
|
||||
expect(logic).toHaveProperty("id");
|
||||
expect(logic).toHaveProperty("conditions");
|
||||
expect(logic.conditions).toHaveProperty("conditions");
|
||||
expect(Array.isArray(logic.conditions.conditions)).toBe(true);
|
||||
|
||||
// Check one of the inner conditions
|
||||
const condition = logic.conditions.conditions[0];
|
||||
// Need to use type checking to ensure condition is a TSingleCondition not a TConditionGroup
|
||||
if (!("connector" in condition)) {
|
||||
expect(condition.leftOperand.value).toBe(sourceId);
|
||||
expect(condition.operator).toBe(operator);
|
||||
}
|
||||
|
||||
// Check actions
|
||||
expect(Array.isArray(logic.actions)).toBe(true);
|
||||
const action = logic.actions[0];
|
||||
if (action.objective === "jumpToQuestion") {
|
||||
expect(action.target).toBe(targetId);
|
||||
}
|
||||
});
|
||||
|
||||
test("createChoiceJumpLogic returns valid jump logic based on choice selection", () => {
|
||||
const sourceId = "q1";
|
||||
const choiceId = "choice1";
|
||||
const targetId = "q2";
|
||||
const logic = createChoiceJumpLogic(sourceId, choiceId, targetId);
|
||||
|
||||
expect(logic).toHaveProperty("id");
|
||||
expect(logic.conditions).toHaveProperty("conditions");
|
||||
|
||||
const condition = logic.conditions.conditions[0];
|
||||
if (!("connector" in condition)) {
|
||||
expect(condition.leftOperand.value).toBe(sourceId);
|
||||
expect(condition.operator).toBe("equals");
|
||||
expect(condition.rightOperand?.value).toBe(choiceId);
|
||||
}
|
||||
|
||||
const action = logic.actions[0];
|
||||
if (action.objective === "jumpToQuestion") {
|
||||
expect(action.target).toBe(targetId);
|
||||
}
|
||||
});
|
||||
|
||||
test("getDefaultWelcomeCard returns expected welcome card", () => {
|
||||
const card = getDefaultWelcomeCard(mockT);
|
||||
expect(card.enabled).toBe(false);
|
||||
expect(card.headline).toEqual({ default: "templates.default_welcome_card_headline" });
|
||||
expect(card.html).toEqual({ default: "templates.default_welcome_card_html" });
|
||||
expect(card.buttonLabel).toEqual({ default: "templates.default_welcome_card_button_label" });
|
||||
// boolean flags
|
||||
expect(card.timeToFinish).toBe(false);
|
||||
expect(card.showResponseCount).toBe(false);
|
||||
});
|
||||
|
||||
test("getDefaultEndingCard returns expected end screen card", () => {
|
||||
// Pass empty languages array to simulate no languages
|
||||
const card = getDefaultEndingCard([], mockT);
|
||||
expect(card).toHaveProperty("id");
|
||||
expect(card.type).toBe("endScreen");
|
||||
expect(card.headline).toEqual({ default: "templates.default_ending_card_headline" });
|
||||
expect(card.subheader).toEqual({ default: "templates.default_ending_card_subheader" });
|
||||
expect(card.buttonLabel).toEqual({ default: "templates.default_ending_card_button_label" });
|
||||
expect(card.buttonLink).toBe("https://formbricks.com");
|
||||
});
|
||||
|
||||
test("getDefaultSurveyPreset returns expected default survey preset", () => {
|
||||
const preset = getDefaultSurveyPreset(mockT);
|
||||
expect(preset.name).toBe("New Survey");
|
||||
expect(preset.questions).toEqual([]);
|
||||
// test welcomeCard and endings
|
||||
expect(preset.welcomeCard).toHaveProperty("headline");
|
||||
expect(Array.isArray(preset.endings)).toBe(true);
|
||||
expect(preset.hiddenFields).toEqual(hiddenFieldsDefault);
|
||||
});
|
||||
|
||||
test("buildSurvey returns built survey with overridden preset properties", () => {
|
||||
const config = {
|
||||
name: "Custom Survey",
|
||||
role: "productManager" as TTemplateRole,
|
||||
industries: ["eCommerce"] as string[],
|
||||
channels: ["link"],
|
||||
description: "Test survey",
|
||||
questions: [
|
||||
{
|
||||
id: "q1",
|
||||
type: TSurveyQuestionTypeEnum.OpenText, // changed from "OpenText"
|
||||
headline: { default: "Question 1" },
|
||||
inputType: "text",
|
||||
buttonLabel: { default: "Next" },
|
||||
backButtonLabel: { default: "Back" },
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
endings: [
|
||||
{
|
||||
id: "end1",
|
||||
type: "endScreen",
|
||||
headline: { default: "End Screen" },
|
||||
subheader: { default: "Thanks" },
|
||||
buttonLabel: { default: "Finish" },
|
||||
buttonLink: "https://formbricks.com",
|
||||
},
|
||||
],
|
||||
hiddenFields: { enabled: false, fieldIds: ["f1"] },
|
||||
};
|
||||
|
||||
const survey = buildSurvey(config as any, mockT);
|
||||
expect(survey.name).toBe(config.name);
|
||||
expect(survey.role).toBe(config.role);
|
||||
expect(survey.industries).toEqual(config.industries);
|
||||
expect(survey.channels).toEqual(config.channels);
|
||||
expect(survey.description).toBe(config.description);
|
||||
// preset overrides
|
||||
expect(survey.preset.name).toBe(config.name);
|
||||
expect(survey.preset.questions).toEqual(config.questions);
|
||||
expect(survey.preset.endings).toEqual(config.endings);
|
||||
expect(survey.preset.hiddenFields).toEqual(config.hiddenFields);
|
||||
});
|
||||
|
||||
test("hiddenFieldsDefault has expected default configuration", () => {
|
||||
expect(hiddenFieldsDefault).toEqual({ enabled: true, fieldIds: [] });
|
||||
});
|
||||
});
|
||||
414
apps/web/app/lib/survey-builder.ts
Normal file
414
apps/web/app/lib/survey-builder.ts
Normal file
@@ -0,0 +1,414 @@
|
||||
import { createI18nString, extractLanguageCodes } from "@/lib/i18n/utils";
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
import { TFnType } from "@tolgee/react";
|
||||
import {
|
||||
TShuffleOption,
|
||||
TSurveyCTAQuestion,
|
||||
TSurveyConsentQuestion,
|
||||
TSurveyEndScreenCard,
|
||||
TSurveyEnding,
|
||||
TSurveyHiddenFields,
|
||||
TSurveyLanguage,
|
||||
TSurveyLogic,
|
||||
TSurveyMultipleChoiceQuestion,
|
||||
TSurveyNPSQuestion,
|
||||
TSurveyOpenTextQuestion,
|
||||
TSurveyOpenTextQuestionInputType,
|
||||
TSurveyQuestion,
|
||||
TSurveyQuestionTypeEnum,
|
||||
TSurveyRatingQuestion,
|
||||
TSurveyWelcomeCard,
|
||||
} from "@formbricks/types/surveys/types";
|
||||
import { TTemplate, TTemplateRole } from "@formbricks/types/templates";
|
||||
|
||||
const defaultButtonLabel = "common.next";
|
||||
const defaultBackButtonLabel = "common.back";
|
||||
|
||||
export const buildMultipleChoiceQuestion = ({
|
||||
id,
|
||||
headline,
|
||||
type,
|
||||
subheader,
|
||||
choices,
|
||||
choiceIds,
|
||||
buttonLabel,
|
||||
backButtonLabel,
|
||||
shuffleOption,
|
||||
required,
|
||||
logic,
|
||||
containsOther = false,
|
||||
t,
|
||||
}: {
|
||||
id?: string;
|
||||
headline: string;
|
||||
type: TSurveyQuestionTypeEnum.MultipleChoiceMulti | TSurveyQuestionTypeEnum.MultipleChoiceSingle;
|
||||
subheader?: string;
|
||||
choices: string[];
|
||||
choiceIds?: string[];
|
||||
buttonLabel?: string;
|
||||
backButtonLabel?: string;
|
||||
shuffleOption?: TShuffleOption;
|
||||
required?: boolean;
|
||||
logic?: TSurveyLogic[];
|
||||
containsOther?: boolean;
|
||||
t: TFnType;
|
||||
}): TSurveyMultipleChoiceQuestion => {
|
||||
return {
|
||||
id: id ?? createId(),
|
||||
type,
|
||||
subheader: subheader ? { default: subheader } : undefined,
|
||||
headline: { default: headline },
|
||||
choices: choices.map((choice, index) => {
|
||||
const isLastIndex = index === choices.length - 1;
|
||||
const id = containsOther && isLastIndex ? "other" : choiceIds ? choiceIds[index] : createId();
|
||||
return { id, label: { default: choice } };
|
||||
}),
|
||||
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
|
||||
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
|
||||
shuffleOption: shuffleOption || "none",
|
||||
required: required ?? true,
|
||||
logic,
|
||||
};
|
||||
};
|
||||
|
||||
export const buildOpenTextQuestion = ({
|
||||
id,
|
||||
headline,
|
||||
subheader,
|
||||
placeholder,
|
||||
inputType,
|
||||
buttonLabel,
|
||||
backButtonLabel,
|
||||
required,
|
||||
logic,
|
||||
longAnswer,
|
||||
t,
|
||||
}: {
|
||||
id?: string;
|
||||
headline: string;
|
||||
subheader?: string;
|
||||
placeholder?: string;
|
||||
buttonLabel?: string;
|
||||
backButtonLabel?: string;
|
||||
required?: boolean;
|
||||
logic?: TSurveyLogic[];
|
||||
inputType: TSurveyOpenTextQuestionInputType;
|
||||
longAnswer?: boolean;
|
||||
t: TFnType;
|
||||
}): TSurveyOpenTextQuestion => {
|
||||
return {
|
||||
id: id ?? createId(),
|
||||
type: TSurveyQuestionTypeEnum.OpenText,
|
||||
inputType,
|
||||
subheader: subheader ? { default: subheader } : undefined,
|
||||
placeholder: placeholder ? { default: placeholder } : undefined,
|
||||
headline: { default: headline },
|
||||
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
|
||||
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
|
||||
required: required ?? true,
|
||||
longAnswer,
|
||||
logic,
|
||||
charLimit: {
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const buildRatingQuestion = ({
|
||||
id,
|
||||
headline,
|
||||
subheader,
|
||||
scale,
|
||||
range,
|
||||
lowerLabel,
|
||||
upperLabel,
|
||||
buttonLabel,
|
||||
backButtonLabel,
|
||||
required,
|
||||
logic,
|
||||
isColorCodingEnabled = false,
|
||||
t,
|
||||
}: {
|
||||
id?: string;
|
||||
headline: string;
|
||||
scale: TSurveyRatingQuestion["scale"];
|
||||
range: TSurveyRatingQuestion["range"];
|
||||
lowerLabel?: string;
|
||||
upperLabel?: string;
|
||||
subheader?: string;
|
||||
placeholder?: string;
|
||||
buttonLabel?: string;
|
||||
backButtonLabel?: string;
|
||||
required?: boolean;
|
||||
logic?: TSurveyLogic[];
|
||||
isColorCodingEnabled?: boolean;
|
||||
t: TFnType;
|
||||
}): TSurveyRatingQuestion => {
|
||||
return {
|
||||
id: id ?? createId(),
|
||||
type: TSurveyQuestionTypeEnum.Rating,
|
||||
subheader: subheader ? { default: subheader } : undefined,
|
||||
headline: { default: headline },
|
||||
scale,
|
||||
range,
|
||||
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
|
||||
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
|
||||
required: required ?? true,
|
||||
isColorCodingEnabled,
|
||||
lowerLabel: lowerLabel ? { default: lowerLabel } : undefined,
|
||||
upperLabel: upperLabel ? { default: upperLabel } : undefined,
|
||||
logic,
|
||||
};
|
||||
};
|
||||
|
||||
export const buildNPSQuestion = ({
|
||||
id,
|
||||
headline,
|
||||
subheader,
|
||||
lowerLabel,
|
||||
upperLabel,
|
||||
buttonLabel,
|
||||
backButtonLabel,
|
||||
required,
|
||||
logic,
|
||||
isColorCodingEnabled = false,
|
||||
t,
|
||||
}: {
|
||||
id?: string;
|
||||
headline: string;
|
||||
lowerLabel?: string;
|
||||
upperLabel?: string;
|
||||
subheader?: string;
|
||||
placeholder?: string;
|
||||
buttonLabel?: string;
|
||||
backButtonLabel?: string;
|
||||
required?: boolean;
|
||||
logic?: TSurveyLogic[];
|
||||
isColorCodingEnabled?: boolean;
|
||||
t: TFnType;
|
||||
}): TSurveyNPSQuestion => {
|
||||
return {
|
||||
id: id ?? createId(),
|
||||
type: TSurveyQuestionTypeEnum.NPS,
|
||||
subheader: subheader ? { default: subheader } : undefined,
|
||||
headline: { default: headline },
|
||||
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
|
||||
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
|
||||
required: required ?? true,
|
||||
isColorCodingEnabled,
|
||||
lowerLabel: lowerLabel ? { default: lowerLabel } : undefined,
|
||||
upperLabel: upperLabel ? { default: upperLabel } : undefined,
|
||||
logic,
|
||||
};
|
||||
};
|
||||
|
||||
export const buildConsentQuestion = ({
|
||||
id,
|
||||
headline,
|
||||
subheader,
|
||||
label,
|
||||
buttonLabel,
|
||||
backButtonLabel,
|
||||
required,
|
||||
logic,
|
||||
t,
|
||||
}: {
|
||||
id?: string;
|
||||
headline: string;
|
||||
subheader?: string;
|
||||
buttonLabel?: string;
|
||||
backButtonLabel?: string;
|
||||
required?: boolean;
|
||||
logic?: TSurveyLogic[];
|
||||
label: string;
|
||||
t: TFnType;
|
||||
}): TSurveyConsentQuestion => {
|
||||
return {
|
||||
id: id ?? createId(),
|
||||
type: TSurveyQuestionTypeEnum.Consent,
|
||||
subheader: subheader ? { default: subheader } : undefined,
|
||||
headline: { default: headline },
|
||||
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
|
||||
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
|
||||
required: required ?? true,
|
||||
label: { default: label },
|
||||
logic,
|
||||
};
|
||||
};
|
||||
|
||||
export const buildCTAQuestion = ({
|
||||
id,
|
||||
headline,
|
||||
html,
|
||||
buttonLabel,
|
||||
buttonExternal,
|
||||
backButtonLabel,
|
||||
required,
|
||||
logic,
|
||||
dismissButtonLabel,
|
||||
buttonUrl,
|
||||
t,
|
||||
}: {
|
||||
id?: string;
|
||||
headline: string;
|
||||
buttonExternal: boolean;
|
||||
html?: string;
|
||||
buttonLabel?: string;
|
||||
backButtonLabel?: string;
|
||||
required?: boolean;
|
||||
logic?: TSurveyLogic[];
|
||||
dismissButtonLabel?: string;
|
||||
buttonUrl?: string;
|
||||
t: TFnType;
|
||||
}): TSurveyCTAQuestion => {
|
||||
return {
|
||||
id: id ?? createId(),
|
||||
type: TSurveyQuestionTypeEnum.CTA,
|
||||
html: html ? { default: html } : undefined,
|
||||
headline: { default: headline },
|
||||
buttonLabel: { default: buttonLabel || t(defaultButtonLabel) },
|
||||
backButtonLabel: { default: backButtonLabel || t(defaultBackButtonLabel) },
|
||||
dismissButtonLabel: dismissButtonLabel ? { default: dismissButtonLabel } : undefined,
|
||||
required: required ?? true,
|
||||
buttonExternal,
|
||||
buttonUrl,
|
||||
logic,
|
||||
};
|
||||
};
|
||||
|
||||
// Helper function to create standard jump logic based on operator
|
||||
export const createJumpLogic = (
|
||||
sourceQuestionId: string,
|
||||
targetId: string,
|
||||
operator: "isSkipped" | "isSubmitted" | "isClicked"
|
||||
): TSurveyLogic => ({
|
||||
id: createId(),
|
||||
conditions: {
|
||||
id: createId(),
|
||||
connector: "and",
|
||||
conditions: [
|
||||
{
|
||||
id: createId(),
|
||||
leftOperand: {
|
||||
value: sourceQuestionId,
|
||||
type: "question",
|
||||
},
|
||||
operator: operator,
|
||||
},
|
||||
],
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
id: createId(),
|
||||
objective: "jumpToQuestion",
|
||||
target: targetId,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Helper function to create jump logic based on choice selection
|
||||
export const createChoiceJumpLogic = (
|
||||
sourceQuestionId: string,
|
||||
choiceId: string,
|
||||
targetId: string
|
||||
): TSurveyLogic => ({
|
||||
id: createId(),
|
||||
conditions: {
|
||||
id: createId(),
|
||||
connector: "and",
|
||||
conditions: [
|
||||
{
|
||||
id: createId(),
|
||||
leftOperand: {
|
||||
value: sourceQuestionId,
|
||||
type: "question",
|
||||
},
|
||||
operator: "equals",
|
||||
rightOperand: {
|
||||
type: "static",
|
||||
value: choiceId,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
id: createId(),
|
||||
objective: "jumpToQuestion",
|
||||
target: targetId,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export const getDefaultEndingCard = (languages: TSurveyLanguage[], t: TFnType): TSurveyEndScreenCard => {
|
||||
const languageCodes = extractLanguageCodes(languages);
|
||||
return {
|
||||
id: createId(),
|
||||
type: "endScreen",
|
||||
headline: createI18nString(t("templates.default_ending_card_headline"), languageCodes),
|
||||
subheader: createI18nString(t("templates.default_ending_card_subheader"), languageCodes),
|
||||
buttonLabel: createI18nString(t("templates.default_ending_card_button_label"), languageCodes),
|
||||
buttonLink: "https://formbricks.com",
|
||||
};
|
||||
};
|
||||
|
||||
export const hiddenFieldsDefault: TSurveyHiddenFields = {
|
||||
enabled: true,
|
||||
fieldIds: [],
|
||||
};
|
||||
|
||||
export const getDefaultWelcomeCard = (t: TFnType): TSurveyWelcomeCard => {
|
||||
return {
|
||||
enabled: false,
|
||||
headline: { default: t("templates.default_welcome_card_headline") },
|
||||
html: { default: t("templates.default_welcome_card_html") },
|
||||
buttonLabel: { default: t("templates.default_welcome_card_button_label") },
|
||||
timeToFinish: false,
|
||||
showResponseCount: false,
|
||||
};
|
||||
};
|
||||
|
||||
export const getDefaultSurveyPreset = (t: TFnType): TTemplate["preset"] => {
|
||||
return {
|
||||
name: "New Survey",
|
||||
welcomeCard: getDefaultWelcomeCard(t),
|
||||
endings: [getDefaultEndingCard([], t)],
|
||||
hiddenFields: hiddenFieldsDefault,
|
||||
questions: [],
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic builder for survey.
|
||||
* @param config - The configuration for survey settings and questions.
|
||||
* @param t - The translation function.
|
||||
*/
|
||||
export const buildSurvey = (
|
||||
config: {
|
||||
name: string;
|
||||
role: TTemplateRole;
|
||||
industries: ("eCommerce" | "saas" | "other")[];
|
||||
channels: ("link" | "app" | "website")[];
|
||||
description: string;
|
||||
questions: TSurveyQuestion[];
|
||||
endings?: TSurveyEnding[];
|
||||
hiddenFields?: TSurveyHiddenFields;
|
||||
},
|
||||
t: TFnType
|
||||
): TTemplate => {
|
||||
const localSurvey = getDefaultSurveyPreset(t);
|
||||
return {
|
||||
name: config.name,
|
||||
role: config.role,
|
||||
industries: config.industries,
|
||||
channels: config.channels,
|
||||
description: config.description,
|
||||
preset: {
|
||||
...localSurvey,
|
||||
name: config.name,
|
||||
questions: config.questions,
|
||||
endings: config.endings ?? localSurvey.endings,
|
||||
hiddenFields: config.hiddenFields ?? hiddenFieldsDefault,
|
||||
},
|
||||
};
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -66,7 +66,6 @@ const Page = async (props: SummaryPageProps) => {
|
||||
surveyId={survey.id}
|
||||
webAppUrl={WEBAPP_URL}
|
||||
totalResponseCount={totalResponseCount}
|
||||
isAIEnabled={false} // Disable AI for sharing page for now
|
||||
isReadOnly={true}
|
||||
locale={DEFAULT_LOCALE}
|
||||
/>
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { createAzure } from "@ai-sdk/azure";
|
||||
import {
|
||||
AI_AZURE_EMBEDDINGS_API_KEY,
|
||||
AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID,
|
||||
AI_AZURE_EMBEDDINGS_RESSOURCE_NAME,
|
||||
AI_AZURE_LLM_API_KEY,
|
||||
AI_AZURE_LLM_DEPLOYMENT_ID,
|
||||
AI_AZURE_LLM_RESSOURCE_NAME,
|
||||
} from "./constants";
|
||||
|
||||
export const llmModel = createAzure({
|
||||
resourceName: AI_AZURE_LLM_RESSOURCE_NAME, // Azure resource name
|
||||
apiKey: AI_AZURE_LLM_API_KEY, // Azure API key
|
||||
})(AI_AZURE_LLM_DEPLOYMENT_ID || "llm");
|
||||
|
||||
export const embeddingsModel = createAzure({
|
||||
resourceName: AI_AZURE_EMBEDDINGS_RESSOURCE_NAME, // Azure resource name
|
||||
apiKey: AI_AZURE_EMBEDDINGS_API_KEY, // Azure API key
|
||||
}).embedding(AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID || "embeddings", {
|
||||
dimensions: 512,
|
||||
});
|
||||
@@ -96,7 +96,6 @@ export const RESPONSES_PER_PAGE = 25;
|
||||
export const TEXT_RESPONSES_PER_PAGE = 5;
|
||||
export const INSIGHTS_PER_PAGE = 10;
|
||||
export const DOCUMENTS_PER_PAGE = 10;
|
||||
export const MAX_RESPONSES_FOR_INSIGHT_GENERATION = 500;
|
||||
|
||||
export const DEFAULT_ORGANIZATION_ID = env.DEFAULT_ORGANIZATION_ID;
|
||||
export const DEFAULT_ORGANIZATION_ROLE = env.DEFAULT_ORGANIZATION_ROLE;
|
||||
@@ -262,21 +261,6 @@ export const BILLING_LIMITS = {
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const AI_AZURE_LLM_RESSOURCE_NAME = env.AI_AZURE_LLM_RESSOURCE_NAME;
|
||||
export const AI_AZURE_LLM_API_KEY = env.AI_AZURE_LLM_API_KEY;
|
||||
export const AI_AZURE_LLM_DEPLOYMENT_ID = env.AI_AZURE_LLM_DEPLOYMENT_ID;
|
||||
export const AI_AZURE_EMBEDDINGS_RESSOURCE_NAME = env.AI_AZURE_EMBEDDINGS_RESSOURCE_NAME;
|
||||
export const AI_AZURE_EMBEDDINGS_API_KEY = env.AI_AZURE_EMBEDDINGS_API_KEY;
|
||||
export const AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID = env.AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID;
|
||||
export const IS_AI_CONFIGURED = Boolean(
|
||||
env.AI_AZURE_EMBEDDINGS_API_KEY &&
|
||||
env.AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID &&
|
||||
env.AI_AZURE_EMBEDDINGS_RESSOURCE_NAME &&
|
||||
env.AI_AZURE_LLM_API_KEY &&
|
||||
env.AI_AZURE_LLM_DEPLOYMENT_ID &&
|
||||
env.AI_AZURE_LLM_RESSOURCE_NAME
|
||||
);
|
||||
|
||||
export const INTERCOM_SECRET_KEY = env.INTERCOM_SECRET_KEY;
|
||||
export const INTERCOM_APP_ID = env.INTERCOM_APP_ID;
|
||||
export const IS_INTERCOM_CONFIGURED = Boolean(env.INTERCOM_APP_ID && INTERCOM_SECRET_KEY);
|
||||
@@ -296,3 +280,5 @@ export const IS_DEVELOPMENT = env.NODE_ENV === "development";
|
||||
export const SENTRY_DSN = env.SENTRY_DSN;
|
||||
|
||||
export const PROMETHEUS_ENABLED = env.PROMETHEUS_ENABLED === "1";
|
||||
|
||||
export const DISABLE_USER_MANAGEMENT = env.DISABLE_USER_MANAGEMENT === "1";
|
||||
|
||||
@@ -7,12 +7,6 @@ export const env = createEnv({
|
||||
* Will throw if you access these variables on the client.
|
||||
*/
|
||||
server: {
|
||||
AI_AZURE_EMBEDDINGS_API_KEY: z.string().optional(),
|
||||
AI_AZURE_LLM_API_KEY: z.string().optional(),
|
||||
AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID: z.string().optional(),
|
||||
AI_AZURE_LLM_DEPLOYMENT_ID: z.string().optional(),
|
||||
AI_AZURE_EMBEDDINGS_RESSOURCE_NAME: z.string().optional(),
|
||||
AI_AZURE_LLM_RESSOURCE_NAME: z.string().optional(),
|
||||
AIRTABLE_CLIENT_ID: z.string().optional(),
|
||||
AZUREAD_CLIENT_ID: z.string().optional(),
|
||||
AZUREAD_CLIENT_SECRET: z.string().optional(),
|
||||
@@ -112,13 +106,11 @@ export const env = createEnv({
|
||||
VERCEL_URL: z.string().optional(),
|
||||
WEBAPP_URL: z.string().url().optional(),
|
||||
UNSPLASH_ACCESS_KEY: z.string().optional(),
|
||||
LANGFUSE_SECRET_KEY: z.string().optional(),
|
||||
LANGFUSE_PUBLIC_KEY: z.string().optional(),
|
||||
LANGFUSE_BASEURL: z.string().optional(),
|
||||
UNKEY_ROOT_KEY: z.string().optional(),
|
||||
NODE_ENV: z.enum(["development", "production", "test"]).optional(),
|
||||
PROMETHEUS_EXPORTER_PORT: z.string().optional(),
|
||||
PROMETHEUS_ENABLED: z.enum(["1", "0"]).optional(),
|
||||
DISABLE_USER_MANAGEMENT: z.enum(["1", "0"]).optional(),
|
||||
},
|
||||
|
||||
/*
|
||||
@@ -128,15 +120,6 @@ export const env = createEnv({
|
||||
* 💡 You'll get type errors if not all variables from `server` & `client` are included here.
|
||||
*/
|
||||
runtimeEnv: {
|
||||
AI_AZURE_EMBEDDINGS_API_KEY: process.env.AI_AZURE_EMBEDDINGS_API_KEY,
|
||||
AI_AZURE_LLM_API_KEY: process.env.AI_AZURE_LLM_API_KEY,
|
||||
AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID: process.env.AI_AZURE_EMBEDDINGS_DEPLOYMENT_ID,
|
||||
AI_AZURE_LLM_DEPLOYMENT_ID: process.env.AI_AZURE_LLM_DEPLOYMENT_ID,
|
||||
AI_AZURE_EMBEDDINGS_RESSOURCE_NAME: process.env.AI_AZURE_EMBEDDINGS_RESSOURCE_NAME,
|
||||
AI_AZURE_LLM_RESSOURCE_NAME: process.env.AI_AZURE_LLM_RESSOURCE_NAME,
|
||||
LANGFUSE_SECRET_KEY: process.env.LANGFUSE_SECRET_KEY,
|
||||
LANGFUSE_PUBLIC_KEY: process.env.LANGFUSE_PUBLIC_KEY,
|
||||
LANGFUSE_BASEURL: process.env.LANGFUSE_BASEURL,
|
||||
AIRTABLE_CLIENT_ID: process.env.AIRTABLE_CLIENT_ID,
|
||||
AZUREAD_CLIENT_ID: process.env.AZUREAD_CLIENT_ID,
|
||||
AZUREAD_CLIENT_SECRET: process.env.AZUREAD_CLIENT_SECRET,
|
||||
@@ -224,5 +207,6 @@ export const env = createEnv({
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
PROMETHEUS_ENABLED: process.env.PROMETHEUS_ENABLED,
|
||||
PROMETHEUS_EXPORTER_PORT: process.env.PROMETHEUS_EXPORTER_PORT,
|
||||
DISABLE_USER_MANAGEMENT: process.env.DISABLE_USER_MANAGEMENT,
|
||||
},
|
||||
});
|
||||
|
||||
316
apps/web/lib/fileValidation.test.ts
Normal file
316
apps/web/lib/fileValidation.test.ts
Normal file
@@ -0,0 +1,316 @@
|
||||
import * as storageUtils from "@/lib/storage/utils";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { ZAllowedFileExtension } from "@formbricks/types/common";
|
||||
import { TResponseData } from "@formbricks/types/responses";
|
||||
import { TSurveyQuestion } from "@formbricks/types/surveys/types";
|
||||
import {
|
||||
isAllowedFileExtension,
|
||||
isValidFileTypeForExtension,
|
||||
isValidImageFile,
|
||||
validateFile,
|
||||
validateFileUploads,
|
||||
validateSingleFile,
|
||||
} from "./fileValidation";
|
||||
|
||||
// Mock getOriginalFileNameFromUrl function
|
||||
vi.mock("@/lib/storage/utils", () => ({
|
||||
getOriginalFileNameFromUrl: vi.fn((url) => {
|
||||
// Extract filename from the URL for testing purposes
|
||||
const parts = url.split("/");
|
||||
return parts[parts.length - 1];
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("fileValidation", () => {
|
||||
describe("isAllowedFileExtension", () => {
|
||||
test("should return false for a file with no extension", () => {
|
||||
expect(isAllowedFileExtension("filename")).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false for a file with extension not in allowed list", () => {
|
||||
expect(isAllowedFileExtension("malicious.exe")).toBe(false);
|
||||
expect(isAllowedFileExtension("script.php")).toBe(false);
|
||||
expect(isAllowedFileExtension("config.js")).toBe(false);
|
||||
expect(isAllowedFileExtension("page.html")).toBe(false);
|
||||
});
|
||||
|
||||
test("should return true for an allowed file extension", () => {
|
||||
Object.values(ZAllowedFileExtension.enum).forEach((ext) => {
|
||||
expect(isAllowedFileExtension(`file.${ext}`)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
test("should handle case insensitivity correctly", () => {
|
||||
expect(isAllowedFileExtension("image.PNG")).toBe(true);
|
||||
expect(isAllowedFileExtension("document.PDF")).toBe(true);
|
||||
});
|
||||
|
||||
test("should handle filenames with multiple dots", () => {
|
||||
expect(isAllowedFileExtension("example.backup.pdf")).toBe(true);
|
||||
expect(isAllowedFileExtension("document.old.exe")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isValidFileTypeForExtension", () => {
|
||||
test("should return false for a file with no extension", () => {
|
||||
expect(isValidFileTypeForExtension("filename", "application/octet-stream")).toBe(false);
|
||||
});
|
||||
|
||||
test("should return true for valid extension and MIME type combinations", () => {
|
||||
expect(isValidFileTypeForExtension("image.jpg", "image/jpeg")).toBe(true);
|
||||
expect(isValidFileTypeForExtension("image.png", "image/png")).toBe(true);
|
||||
expect(isValidFileTypeForExtension("document.pdf", "application/pdf")).toBe(true);
|
||||
});
|
||||
|
||||
test("should return false for mismatched extension and MIME type", () => {
|
||||
expect(isValidFileTypeForExtension("image.jpg", "image/png")).toBe(false);
|
||||
expect(isValidFileTypeForExtension("document.pdf", "image/jpeg")).toBe(false);
|
||||
expect(isValidFileTypeForExtension("image.png", "application/pdf")).toBe(false);
|
||||
});
|
||||
|
||||
test("should handle case insensitivity correctly", () => {
|
||||
expect(isValidFileTypeForExtension("image.JPG", "image/jpeg")).toBe(true);
|
||||
expect(isValidFileTypeForExtension("image.jpg", "IMAGE/JPEG")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateFile", () => {
|
||||
test("should return valid: false when file extension is not allowed", () => {
|
||||
const result = validateFile("script.php", "application/php");
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toContain("File type not allowed");
|
||||
});
|
||||
|
||||
test("should return valid: false when file type does not match extension", () => {
|
||||
const result = validateFile("image.png", "application/pdf");
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toContain("File type doesn't match");
|
||||
});
|
||||
|
||||
test("should return valid: true when file is allowed and type matches extension", () => {
|
||||
const result = validateFile("image.jpg", "image/jpeg");
|
||||
expect(result.valid).toBe(true);
|
||||
expect(result.error).toBeUndefined();
|
||||
});
|
||||
|
||||
test("should return valid: true for allowed file types", () => {
|
||||
Object.values(ZAllowedFileExtension.enum).forEach((ext) => {
|
||||
// Skip testing extensions that don't have defined MIME types in the test
|
||||
if (["jpg", "png", "pdf"].includes(ext)) {
|
||||
const mimeType = ext === "jpg" ? "image/jpeg" : ext === "png" ? "image/png" : "application/pdf";
|
||||
const result = validateFile(`file.${ext}`, mimeType);
|
||||
expect(result.valid).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("should return valid: false for files with no extension", () => {
|
||||
const result = validateFile("noextension", "application/octet-stream");
|
||||
expect(result.valid).toBe(false);
|
||||
});
|
||||
|
||||
test("should handle attempts to bypass with double extension", () => {
|
||||
const result = validateFile("malicious.jpg.php", "image/jpeg");
|
||||
expect(result.valid).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateSingleFile", () => {
|
||||
test("should return true for allowed file extension", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockReturnValueOnce("image.jpg");
|
||||
expect(validateSingleFile("https://example.com/image.jpg", ["jpg", "png"])).toBe(true);
|
||||
});
|
||||
|
||||
test("should return false for disallowed file extension", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockReturnValueOnce("malicious.exe");
|
||||
expect(validateSingleFile("https://example.com/malicious.exe", ["jpg", "png"])).toBe(false);
|
||||
});
|
||||
|
||||
test("should return true when no allowed extensions are specified", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockReturnValueOnce("image.jpg");
|
||||
expect(validateSingleFile("https://example.com/image.jpg")).toBe(true);
|
||||
});
|
||||
|
||||
test("should return false when file name cannot be extracted", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockReturnValueOnce(undefined);
|
||||
expect(validateSingleFile("https://example.com/unknown")).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when file has no extension", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockReturnValueOnce("filewithoutextension");
|
||||
expect(validateSingleFile("https://example.com/filewithoutextension", ["jpg"])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateFileUploads", () => {
|
||||
test("should return true for valid file uploads in response data", () => {
|
||||
const responseData = {
|
||||
question1: ["https://example.com/storage/file1.jpg", "https://example.com/storage/file2.pdf"],
|
||||
};
|
||||
|
||||
const questions = [
|
||||
{
|
||||
id: "question1",
|
||||
type: "fileUpload" as const,
|
||||
allowedFileExtensions: ["jpg", "pdf"],
|
||||
} as TSurveyQuestion,
|
||||
];
|
||||
|
||||
expect(validateFileUploads(responseData, questions)).toBe(true);
|
||||
});
|
||||
|
||||
test("should return false when file url is not a string", () => {
|
||||
const responseData = {
|
||||
question1: [123, "https://example.com/storage/file.jpg"],
|
||||
} as TResponseData;
|
||||
|
||||
const questions = [
|
||||
{
|
||||
id: "question1",
|
||||
type: "fileUpload" as const,
|
||||
allowedFileExtensions: ["jpg"],
|
||||
} as TSurveyQuestion,
|
||||
];
|
||||
|
||||
expect(validateFileUploads(responseData, questions)).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when file urls are not in an array", () => {
|
||||
const responseData = {
|
||||
question1: "https://example.com/storage/file.jpg",
|
||||
};
|
||||
|
||||
const questions = [
|
||||
{
|
||||
id: "question1",
|
||||
type: "fileUpload" as const,
|
||||
allowedFileExtensions: ["jpg"],
|
||||
} as TSurveyQuestion,
|
||||
];
|
||||
|
||||
expect(validateFileUploads(responseData, questions)).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when file extension is not allowed", () => {
|
||||
const responseData = {
|
||||
question1: ["https://example.com/storage/file.exe"],
|
||||
};
|
||||
|
||||
const questions = [
|
||||
{
|
||||
id: "question1",
|
||||
type: "fileUpload" as const,
|
||||
allowedFileExtensions: ["jpg", "pdf"],
|
||||
} as TSurveyQuestion,
|
||||
];
|
||||
|
||||
expect(validateFileUploads(responseData, questions)).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when file name cannot be extracted", () => {
|
||||
// Mock implementation to return null for this specific URL
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockImplementationOnce(() => undefined);
|
||||
|
||||
const responseData = {
|
||||
question1: ["https://example.com/invalid-url"],
|
||||
};
|
||||
|
||||
const questions = [
|
||||
{
|
||||
id: "question1",
|
||||
type: "fileUpload" as const,
|
||||
allowedFileExtensions: ["jpg"],
|
||||
} as TSurveyQuestion,
|
||||
];
|
||||
|
||||
expect(validateFileUploads(responseData, questions)).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when file has no extension", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockImplementationOnce(
|
||||
() => "file-without-extension"
|
||||
);
|
||||
|
||||
const responseData = {
|
||||
question1: ["https://example.com/storage/file-without-extension"],
|
||||
};
|
||||
|
||||
const questions = [
|
||||
{
|
||||
id: "question1",
|
||||
type: "fileUpload" as const,
|
||||
allowedFileExtensions: ["jpg"],
|
||||
} as TSurveyQuestion,
|
||||
];
|
||||
|
||||
expect(validateFileUploads(responseData, questions)).toBe(false);
|
||||
});
|
||||
|
||||
test("should ignore non-fileUpload questions", () => {
|
||||
const responseData = {
|
||||
question1: ["https://example.com/storage/file.jpg"],
|
||||
question2: "Some text answer",
|
||||
};
|
||||
|
||||
const questions = [
|
||||
{
|
||||
id: "question1",
|
||||
type: "fileUpload" as const,
|
||||
allowedFileExtensions: ["jpg"],
|
||||
},
|
||||
{
|
||||
id: "question2",
|
||||
type: "text" as const,
|
||||
},
|
||||
] as TSurveyQuestion[];
|
||||
|
||||
expect(validateFileUploads(responseData, questions)).toBe(true);
|
||||
});
|
||||
|
||||
test("should return true when no questions are provided", () => {
|
||||
const responseData = {
|
||||
question1: ["https://example.com/storage/file.jpg"],
|
||||
};
|
||||
|
||||
expect(validateFileUploads(responseData)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isValidImageFile", () => {
|
||||
test("should return true for valid image file extensions", () => {
|
||||
expect(isValidImageFile("https://example.com/image.jpg")).toBe(true);
|
||||
expect(isValidImageFile("https://example.com/image.jpeg")).toBe(true);
|
||||
expect(isValidImageFile("https://example.com/image.png")).toBe(true);
|
||||
expect(isValidImageFile("https://example.com/image.webp")).toBe(true);
|
||||
expect(isValidImageFile("https://example.com/image.heic")).toBe(true);
|
||||
});
|
||||
|
||||
test("should return false for non-image file extensions", () => {
|
||||
expect(isValidImageFile("https://example.com/document.pdf")).toBe(false);
|
||||
expect(isValidImageFile("https://example.com/document.docx")).toBe(false);
|
||||
expect(isValidImageFile("https://example.com/document.txt")).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when file name cannot be extracted", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockImplementationOnce(() => undefined);
|
||||
expect(isValidImageFile("https://example.com/invalid-url")).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when file has no extension", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockImplementationOnce(
|
||||
() => "image-without-extension"
|
||||
);
|
||||
expect(isValidImageFile("https://example.com/image-without-extension")).toBe(false);
|
||||
});
|
||||
|
||||
test("should return false when file name ends with a dot", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockImplementationOnce(() => "image.");
|
||||
expect(isValidImageFile("https://example.com/image.")).toBe(false);
|
||||
});
|
||||
|
||||
test("should handle case insensitivity correctly", () => {
|
||||
vi.mocked(storageUtils.getOriginalFileNameFromUrl).mockImplementationOnce(() => "image.JPG");
|
||||
expect(isValidImageFile("https://example.com/image.JPG")).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
94
apps/web/lib/fileValidation.ts
Normal file
94
apps/web/lib/fileValidation.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { getOriginalFileNameFromUrl } from "@/lib/storage/utils";
|
||||
import { TAllowedFileExtension, ZAllowedFileExtension, mimeTypes } from "@formbricks/types/common";
|
||||
import { TResponseData } from "@formbricks/types/responses";
|
||||
import { TSurveyQuestion, TSurveyQuestionTypeEnum } from "@formbricks/types/surveys/types";
|
||||
|
||||
/**
|
||||
* Validates if the file extension is allowed
|
||||
* @param fileName The name of the file to validate
|
||||
* @returns {boolean} True if the file extension is allowed, false otherwise
|
||||
*/
|
||||
export const isAllowedFileExtension = (fileName: string): boolean => {
|
||||
// Extract the file extension
|
||||
const extension = fileName.split(".").pop()?.toLowerCase();
|
||||
if (!extension || extension === fileName.toLowerCase()) return false;
|
||||
|
||||
// Check if the extension is in the allowed list
|
||||
return Object.values(ZAllowedFileExtension.enum).includes(extension as TAllowedFileExtension);
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates if the file type matches the extension
|
||||
* @param fileName The name of the file
|
||||
* @param mimeType The MIME type of the file
|
||||
* @returns {boolean} True if the file type matches the extension, false otherwise
|
||||
*/
|
||||
export const isValidFileTypeForExtension = (fileName: string, mimeType: string): boolean => {
|
||||
const extension = fileName.split(".").pop()?.toLowerCase();
|
||||
if (!extension || extension === fileName.toLowerCase()) return false;
|
||||
|
||||
// Basic MIME type validation for common file types
|
||||
const mimeTypeLower = mimeType.toLowerCase();
|
||||
|
||||
// Check if the MIME type matches the expected type for this extension
|
||||
return mimeTypes[extension] === mimeTypeLower;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a file for security concerns
|
||||
* @param fileName The name of the file to validate
|
||||
* @param mimeType The MIME type of the file
|
||||
* @returns {object} An object with validation result and error message if any
|
||||
*/
|
||||
export const validateFile = (fileName: string, mimeType: string): { valid: boolean; error?: string } => {
|
||||
// Check for disallowed extensions
|
||||
if (!isAllowedFileExtension(fileName)) {
|
||||
return { valid: false, error: "File type not allowed for security reasons." };
|
||||
}
|
||||
|
||||
// Check if the file type matches the extension
|
||||
if (!isValidFileTypeForExtension(fileName, mimeType)) {
|
||||
return { valid: false, error: "File type doesn't match the file extension." };
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
};
|
||||
|
||||
export const validateSingleFile = (
|
||||
fileUrl: string,
|
||||
allowedFileExtensions?: TAllowedFileExtension[]
|
||||
): boolean => {
|
||||
const fileName = getOriginalFileNameFromUrl(fileUrl);
|
||||
if (!fileName) return false;
|
||||
const extension = fileName.split(".").pop();
|
||||
if (!extension) return false;
|
||||
return !allowedFileExtensions || allowedFileExtensions.includes(extension as TAllowedFileExtension);
|
||||
};
|
||||
|
||||
export const validateFileUploads = (data: TResponseData, questions?: TSurveyQuestion[]): boolean => {
|
||||
for (const key of Object.keys(data)) {
|
||||
const question = questions?.find((q) => q.id === key);
|
||||
if (!question || question.type !== TSurveyQuestionTypeEnum.FileUpload) continue;
|
||||
|
||||
const fileUrls = data[key];
|
||||
|
||||
if (!Array.isArray(fileUrls) || !fileUrls.every((url) => typeof url === "string")) return false;
|
||||
|
||||
for (const fileUrl of fileUrls) {
|
||||
if (!validateSingleFile(fileUrl, question.allowedFileExtensions)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const isValidImageFile = (fileUrl: string): boolean => {
|
||||
const fileName = getOriginalFileNameFromUrl(fileUrl);
|
||||
if (!fileName || fileName.endsWith(".")) return false;
|
||||
|
||||
const extension = fileName.split(".").pop()?.toLowerCase();
|
||||
if (!extension) return false;
|
||||
|
||||
const imageExtensions = ["png", "jpeg", "jpg", "webp", "heic"];
|
||||
return imageExtensions.includes(extension);
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -392,8 +392,6 @@ export const mockSurveySummaryOutput = {
|
||||
},
|
||||
summary: [
|
||||
{
|
||||
insights: undefined,
|
||||
insightsEnabled: undefined,
|
||||
question: {
|
||||
headline: { default: "Question Text", de: "Fragetext" },
|
||||
id: "ars2tjk8hsi8oqk1uac00mo8",
|
||||
|
||||
@@ -69,7 +69,7 @@ export const processResponseData = (
|
||||
if (Array.isArray(responseData)) {
|
||||
responseData = responseData
|
||||
.filter((item) => item !== null && item !== undefined && item !== "")
|
||||
.join(", ");
|
||||
.join("; ");
|
||||
return responseData;
|
||||
} else {
|
||||
const formattedString = Object.entries(responseData)
|
||||
|
||||
@@ -9,25 +9,16 @@ import { ActionClass, Prisma } from "@prisma/client";
|
||||
import { cache as reactCache } from "react";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { logger } from "@formbricks/logger";
|
||||
import { ZOptionalNumber } from "@formbricks/types/common";
|
||||
import { ZId } from "@formbricks/types/common";
|
||||
import { ZId, ZOptionalNumber } from "@formbricks/types/common";
|
||||
import { DatabaseError, InvalidInputError, ResourceNotFoundError } from "@formbricks/types/errors";
|
||||
import { TSegment, ZSegmentFilters } from "@formbricks/types/segment";
|
||||
import {
|
||||
TSurvey,
|
||||
TSurveyCreateInput,
|
||||
TSurveyOpenTextQuestion,
|
||||
TSurveyQuestions,
|
||||
ZSurvey,
|
||||
ZSurveyCreateInput,
|
||||
} from "@formbricks/types/surveys/types";
|
||||
import { TSurvey, TSurveyCreateInput, ZSurvey, ZSurveyCreateInput } from "@formbricks/types/surveys/types";
|
||||
import { getActionClasses } from "../actionClass/service";
|
||||
import { ITEMS_PER_PAGE } from "../constants";
|
||||
import { capturePosthogEnvironmentEvent } from "../posthogServer";
|
||||
import { getIsAIEnabled } from "../utils/ai";
|
||||
import { validateInputs } from "../utils/validate";
|
||||
import { surveyCache } from "./cache";
|
||||
import { doesSurveyHasOpenTextQuestion, getInsightsEnabled, transformPrismaSurvey } from "./utils";
|
||||
import { checkForInvalidImagesInQuestions, transformPrismaSurvey } from "./utils";
|
||||
|
||||
interface TriggerUpdate {
|
||||
create?: Array<{ actionClassId: string }>;
|
||||
@@ -346,6 +337,8 @@ export const updateSurvey = async (updatedSurvey: TSurvey): Promise<TSurvey> =>
|
||||
const { triggers, environmentId, segment, questions, languages, type, followUps, ...surveyData } =
|
||||
updatedSurvey;
|
||||
|
||||
checkForInvalidImagesInQuestions(questions);
|
||||
|
||||
if (languages) {
|
||||
// Process languages update logic here
|
||||
// Extract currentLanguageIds and updatedLanguageIds
|
||||
@@ -570,71 +563,6 @@ export const updateSurvey = async (updatedSurvey: TSurvey): Promise<TSurvey> =>
|
||||
throw new ResourceNotFoundError("Organization", null);
|
||||
}
|
||||
|
||||
//AI Insights
|
||||
const isAIEnabled = await getIsAIEnabled(organization);
|
||||
if (isAIEnabled) {
|
||||
if (doesSurveyHasOpenTextQuestion(data.questions ?? [])) {
|
||||
const openTextQuestions = data.questions?.filter((question) => question.type === "openText") ?? [];
|
||||
const currentSurveyOpenTextQuestions = currentSurvey.questions?.filter(
|
||||
(question) => question.type === "openText"
|
||||
);
|
||||
|
||||
// find the questions that have been updated or added
|
||||
const questionsToCheckForInsights: TSurveyQuestions = [];
|
||||
|
||||
for (const question of openTextQuestions) {
|
||||
const existingQuestion = currentSurveyOpenTextQuestions?.find((ques) => ques.id === question.id) as
|
||||
| TSurveyOpenTextQuestion
|
||||
| undefined;
|
||||
const isExistingQuestion = !!existingQuestion;
|
||||
|
||||
if (
|
||||
isExistingQuestion &&
|
||||
question.headline.default === existingQuestion.headline.default &&
|
||||
existingQuestion.insightsEnabled !== undefined
|
||||
) {
|
||||
continue;
|
||||
} else {
|
||||
questionsToCheckForInsights.push(question);
|
||||
}
|
||||
}
|
||||
|
||||
if (questionsToCheckForInsights.length > 0) {
|
||||
const insightsEnabledValues = await Promise.all(
|
||||
questionsToCheckForInsights.map(async (question) => {
|
||||
const insightsEnabled = await getInsightsEnabled(question);
|
||||
|
||||
return { id: question.id, insightsEnabled };
|
||||
})
|
||||
);
|
||||
|
||||
data.questions = data.questions?.map((question) => {
|
||||
const index = insightsEnabledValues.findIndex((item) => item.id === question.id);
|
||||
if (index !== -1) {
|
||||
return {
|
||||
...question,
|
||||
insightsEnabled: insightsEnabledValues[index].insightsEnabled,
|
||||
};
|
||||
}
|
||||
|
||||
return question;
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// check if an existing question got changed that had insights enabled
|
||||
const insightsEnabledOpenTextQuestions = currentSurvey.questions?.filter(
|
||||
(question) => question.type === "openText" && question.insightsEnabled !== undefined
|
||||
);
|
||||
// if question headline changed, remove insightsEnabled
|
||||
for (const question of insightsEnabledOpenTextQuestions) {
|
||||
const updatedQuestion = data.questions?.find((q) => q.id === question.id);
|
||||
if (updatedQuestion && updatedQuestion.headline.default !== question.headline.default) {
|
||||
updatedQuestion.insightsEnabled = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
surveyData.updatedAt = new Date();
|
||||
|
||||
data = {
|
||||
@@ -739,33 +667,6 @@ export const createSurvey = async (
|
||||
throw new ResourceNotFoundError("Organization", null);
|
||||
}
|
||||
|
||||
//AI Insights
|
||||
const isAIEnabled = await getIsAIEnabled(organization);
|
||||
if (isAIEnabled) {
|
||||
if (doesSurveyHasOpenTextQuestion(data.questions ?? [])) {
|
||||
const openTextQuestions = data.questions?.filter((question) => question.type === "openText") ?? [];
|
||||
const insightsEnabledValues = await Promise.all(
|
||||
openTextQuestions.map(async (question) => {
|
||||
const insightsEnabled = await getInsightsEnabled(question);
|
||||
|
||||
return { id: question.id, insightsEnabled };
|
||||
})
|
||||
);
|
||||
|
||||
data.questions = data.questions?.map((question) => {
|
||||
const index = insightsEnabledValues.findIndex((item) => item.id === question.id);
|
||||
if (index !== -1) {
|
||||
return {
|
||||
...question,
|
||||
insightsEnabled: insightsEnabledValues[index].insightsEnabled,
|
||||
};
|
||||
}
|
||||
|
||||
return question;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Survey follow-ups
|
||||
if (restSurveyBody.followUps?.length) {
|
||||
data.followUps = {
|
||||
@@ -779,6 +680,10 @@ export const createSurvey = async (
|
||||
delete data.followUps;
|
||||
}
|
||||
|
||||
if (data.questions) {
|
||||
checkForInvalidImagesInQuestions(data.questions);
|
||||
}
|
||||
|
||||
const survey = await prisma.survey.create({
|
||||
data: {
|
||||
...data,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import "server-only";
|
||||
import { generateObject } from "ai";
|
||||
import { z } from "zod";
|
||||
import { isValidImageFile } from "@/lib/fileValidation";
|
||||
import { InvalidInputError } from "@formbricks/types/errors";
|
||||
import { TJsEnvironmentStateSurvey } from "@formbricks/types/js";
|
||||
import { TSegment } from "@formbricks/types/segment";
|
||||
import { TSurvey, TSurveyQuestion, TSurveyQuestions } from "@formbricks/types/surveys/types";
|
||||
import { llmModel } from "../aiModels";
|
||||
import { TSurvey, TSurveyQuestion, TSurveyQuestionTypeEnum } from "@formbricks/types/surveys/types";
|
||||
|
||||
export const transformPrismaSurvey = <T extends TSurvey | TJsEnvironmentStateSurvey>(
|
||||
surveyPrisma: any
|
||||
@@ -36,23 +35,24 @@ export const anySurveyHasFilters = (surveys: TSurvey[]): boolean => {
|
||||
});
|
||||
};
|
||||
|
||||
export const doesSurveyHasOpenTextQuestion = (questions: TSurveyQuestions): boolean => {
|
||||
return questions.some((question) => question.type === "openText");
|
||||
};
|
||||
export const checkForInvalidImagesInQuestions = (questions: TSurveyQuestion[]) => {
|
||||
questions.forEach((question, qIndex) => {
|
||||
if (question.imageUrl && !isValidImageFile(question.imageUrl)) {
|
||||
throw new InvalidInputError(`Invalid image file in question ${String(qIndex + 1)}`);
|
||||
}
|
||||
|
||||
export const getInsightsEnabled = async (question: TSurveyQuestion): Promise<boolean> => {
|
||||
try {
|
||||
const { object } = await generateObject({
|
||||
model: llmModel,
|
||||
schema: z.object({
|
||||
insightsEnabled: z.boolean(),
|
||||
}),
|
||||
prompt: `We extract insights (e.g. feature requests, complaints, other) from survey questions. Can we find them in this question?: ${question.headline.default}`,
|
||||
experimental_telemetry: { isEnabled: true },
|
||||
});
|
||||
if (question.type === TSurveyQuestionTypeEnum.PictureSelection) {
|
||||
if (!Array.isArray(question.choices)) {
|
||||
throw new InvalidInputError(`Choices missing for question ${String(qIndex + 1)}`);
|
||||
}
|
||||
|
||||
return object.insightsEnabled;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
question.choices.forEach((choice, cIndex) => {
|
||||
if (!isValidImageFile(choice.imageUrl)) {
|
||||
throw new InvalidInputError(
|
||||
`Invalid image file for choice ${String(cIndex + 1)} in question ${String(qIndex + 1)}`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
1169
apps/web/lib/surveyLogic/utils.test.ts
Normal file
1169
apps/web/lib/surveyLogic/utils.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -457,9 +457,17 @@ const evaluateSingleCondition = (
|
||||
return values.length > 0 && !values.includes("");
|
||||
} else return false;
|
||||
case "isSet":
|
||||
case "isNotEmpty":
|
||||
return leftValue !== undefined && leftValue !== null && leftValue !== "";
|
||||
case "isNotSet":
|
||||
return leftValue === undefined || leftValue === null || leftValue === "";
|
||||
case "isEmpty":
|
||||
return leftValue === "";
|
||||
case "isAnyOf":
|
||||
if (Array.isArray(rightValue) && typeof leftValue === "string") {
|
||||
return rightValue.includes(leftValue);
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -533,6 +541,33 @@ const getLeftOperandValue = (
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
currentQuestion.type === "matrix" &&
|
||||
typeof responseValue === "object" &&
|
||||
!Array.isArray(responseValue)
|
||||
) {
|
||||
if (leftOperand.meta && leftOperand.meta.row !== undefined) {
|
||||
const rowIndex = Number(leftOperand.meta.row);
|
||||
|
||||
if (isNaN(rowIndex) || rowIndex < 0 || rowIndex >= currentQuestion.rows.length) {
|
||||
return undefined;
|
||||
}
|
||||
const row = getLocalizedValue(currentQuestion.rows[rowIndex], selectedLanguage);
|
||||
|
||||
const rowValue = responseValue[row];
|
||||
if (rowValue === "") return "";
|
||||
|
||||
if (rowValue) {
|
||||
const columnIndex = currentQuestion.columns.findIndex((column) => {
|
||||
return getLocalizedValue(column, selectedLanguage) === rowValue;
|
||||
});
|
||||
if (columnIndex === -1) return undefined;
|
||||
return columnIndex.toString();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return data[leftOperand.value];
|
||||
case "variable":
|
||||
const variables = localSurvey.variables || [];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import "server-only";
|
||||
import { cache } from "@/lib/cache";
|
||||
import { isValidImageFile } from "@/lib/fileValidation";
|
||||
import { deleteOrganization, getOrganizationsWhereUserIsSingleOwner } from "@/lib/organization/service";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { cache as reactCache } from "react";
|
||||
@@ -7,7 +8,7 @@ import { z } from "zod";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { PrismaErrorType } from "@formbricks/database/types/error";
|
||||
import { ZId } from "@formbricks/types/common";
|
||||
import { DatabaseError, ResourceNotFoundError } from "@formbricks/types/errors";
|
||||
import { DatabaseError, InvalidInputError, ResourceNotFoundError } from "@formbricks/types/errors";
|
||||
import { TUser, TUserLocale, TUserUpdateInput, ZUserUpdateInput } from "@formbricks/types/user";
|
||||
import { validateInputs } from "../utils/validate";
|
||||
import { userCache } from "./cache";
|
||||
@@ -97,6 +98,7 @@ export const getUserByEmail = reactCache(
|
||||
// function to update a user's user
|
||||
export const updateUser = async (personId: string, data: TUserUpdateInput): Promise<TUser> => {
|
||||
validateInputs([personId, ZId], [data, ZUserUpdateInput.partial()]);
|
||||
if (data.imageUrl && !isValidImageFile(data.imageUrl)) throw new InvalidInputError("Invalid image file");
|
||||
|
||||
try {
|
||||
const updatedUser = await prisma.user.update({
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { IS_AI_CONFIGURED } from "@/lib/constants";
|
||||
import { TOrganization } from "@formbricks/types/organizations";
|
||||
|
||||
export const getPromptText = (questionHeadline: string, response: string) => {
|
||||
return `**${questionHeadline.trim()}**\n${response.trim()}`;
|
||||
};
|
||||
|
||||
export const getIsAIEnabled = async (organization: TOrganization) => {
|
||||
// This is a temporary workaround to enable AI without checking the ee license validity, as the ee package is not available in the lib package.(but the billing plan check suffices the license check).
|
||||
const billingPlan = organization.billing.plan;
|
||||
return Boolean(
|
||||
organization.isAIEnabled &&
|
||||
IS_AI_CONFIGURED &&
|
||||
(billingPlan === "startup" || billingPlan === "scale" || billingPlan === "enterprise")
|
||||
);
|
||||
};
|
||||
@@ -209,7 +209,6 @@
|
||||
"in_progress": "Im Gange",
|
||||
"inactive_surveys": "Inaktive Umfragen",
|
||||
"input_type": "Eingabetyp",
|
||||
"insights": "Einblicke",
|
||||
"integration": "Integration",
|
||||
"integrations": "Integrationen",
|
||||
"invalid_date": "Ungültiges Datum",
|
||||
@@ -246,8 +245,6 @@
|
||||
"move_up": "Nach oben bewegen",
|
||||
"multiple_languages": "Mehrsprachigkeit",
|
||||
"name": "Name",
|
||||
"negative": "Negativ",
|
||||
"neutral": "Neutral",
|
||||
"new": "Neu",
|
||||
"new_survey": "Neue Umfrage",
|
||||
"new_version_available": "Formbricks {version} ist da. Jetzt aktualisieren!",
|
||||
@@ -289,11 +286,9 @@
|
||||
"please_select_at_least_one_survey": "Bitte wähle mindestens eine Umfrage aus",
|
||||
"please_select_at_least_one_trigger": "Bitte wähle mindestens einen Auslöser aus",
|
||||
"please_upgrade_your_plan": "Bitte upgrade deinen Plan.",
|
||||
"positive": "Positiv",
|
||||
"preview": "Vorschau",
|
||||
"preview_survey": "Umfragevorschau",
|
||||
"privacy": "Datenschutz",
|
||||
"privacy_policy": "Datenschutzerklärung",
|
||||
"product_manager": "Produktmanager",
|
||||
"profile": "Profil",
|
||||
"project": "Projekt",
|
||||
@@ -616,33 +611,6 @@
|
||||
"upload_contacts_modal_preview": "Hier ist eine Vorschau deiner Daten.",
|
||||
"upload_contacts_modal_upload_btn": "Kontakte hochladen"
|
||||
},
|
||||
"experience": {
|
||||
"all": "Alle",
|
||||
"all_time": "Gesamt",
|
||||
"analysed_feedbacks": "Analysierte Rückmeldungen",
|
||||
"category": "Kategorie",
|
||||
"category_updated_successfully": "Kategorie erfolgreich aktualisiert!",
|
||||
"complaint": "Beschwerde",
|
||||
"did_you_find_this_insight_helpful": "War diese Erkenntnis hilfreich?",
|
||||
"failed_to_update_category": "Kategorie konnte nicht aktualisiert werden",
|
||||
"feature_request": "Anfrage",
|
||||
"good_afternoon": "\uD83C\uDF24️ Guten Nachmittag",
|
||||
"good_evening": "\uD83C\uDF19 Guten Abend",
|
||||
"good_morning": "☀️ Guten Morgen",
|
||||
"insights_description": "Erkenntnisse, die aus den Antworten aller Umfragen gewonnen wurden",
|
||||
"insights_for_project": "Einblicke für {projectName}",
|
||||
"new_responses": "Neue Antworten",
|
||||
"no_insights_for_this_filter": "Keine Erkenntnisse für diesen Filter",
|
||||
"no_insights_found": "Keine Erkenntnisse gefunden. Sammle mehr Umfrageantworten oder aktiviere Erkenntnisse für deine bestehenden Umfragen, um loszulegen.",
|
||||
"praise": "Lob",
|
||||
"sentiment_score": "Stimmungswert",
|
||||
"templates_card_description": "Wähle deine Vorlage oder starte von Grund auf neu",
|
||||
"templates_card_title": "Miss die Kundenerfahrung",
|
||||
"this_month": "Dieser Monat",
|
||||
"this_quarter": "Dieses Quartal",
|
||||
"this_week": "Diese Woche",
|
||||
"today": "Heute"
|
||||
},
|
||||
"formbricks_logo": "Formbricks-Logo",
|
||||
"integrations": {
|
||||
"activepieces_integration_description": "Verbinde Formbricks sofort mit beliebten Apps, um Aufgaben ohne Programmierung zu automatisieren.",
|
||||
@@ -1065,7 +1033,6 @@
|
||||
"website_surveys": "Website-Umfragen"
|
||||
},
|
||||
"enterprise": {
|
||||
"ai": "KI-Analyse",
|
||||
"audit_logs": "Audit Logs",
|
||||
"coming_soon": "Kommt bald",
|
||||
"contacts_and_segments": "Kontaktverwaltung & Segmente",
|
||||
@@ -1103,13 +1070,7 @@
|
||||
"eliminate_branding_with_whitelabel": "Entferne Formbricks Branding und aktiviere zusätzliche White-Label-Anpassungsoptionen.",
|
||||
"email_customization_preview_email_heading": "Hey {userName}",
|
||||
"email_customization_preview_email_text": "Dies ist eine E-Mail-Vorschau, um dir zu zeigen, welches Logo in den E-Mails gerendert wird.",
|
||||
"enable_formbricks_ai": "Formbricks KI aktivieren",
|
||||
"error_deleting_organization_please_try_again": "Fehler beim Löschen der Organisation. Bitte versuche es erneut.",
|
||||
"formbricks_ai": "Formbricks KI",
|
||||
"formbricks_ai_description": "Erhalte personalisierte Einblicke aus deinen Umfrageantworten mit Formbricks KI",
|
||||
"formbricks_ai_disable_success_message": "Formbricks KI wurde erfolgreich deaktiviert.",
|
||||
"formbricks_ai_enable_success_message": "Formbricks KI erfolgreich aktiviert.",
|
||||
"formbricks_ai_privacy_policy_text": "Durch die Aktivierung von Formbricks KI stimmst Du den aktualisierten",
|
||||
"from_your_organization": "von deiner Organisation",
|
||||
"invitation_sent_once_more": "Einladung nochmal gesendet.",
|
||||
"invite_deleted_successfully": "Einladung erfolgreich gelöscht",
|
||||
@@ -1332,6 +1293,14 @@
|
||||
"card_shadow_color": "Farbton des Kartenschattens",
|
||||
"card_styling": "Kartenstil",
|
||||
"casual": "Lässig",
|
||||
"caution_edit_duplicate": "Duplizieren & bearbeiten",
|
||||
"caution_edit_published_survey": "Eine veröffentlichte Umfrage bearbeiten?",
|
||||
"caution_explanation_all_data_as_download": "Alle Daten, einschließlich früherer Antworten, stehen als Download zur Verfügung.",
|
||||
"caution_explanation_intro": "Wir verstehen, dass du vielleicht noch Änderungen vornehmen möchtest. Hier erfährst du, was passiert, wenn du das tust:",
|
||||
"caution_explanation_new_responses_separated": "Neue Antworten werden separat gesammelt.",
|
||||
"caution_explanation_only_new_responses_in_summary": "Nur neue Antworten erscheinen in der Umfragezusammenfassung.",
|
||||
"caution_explanation_responses_are_safe": "Vorhandene Antworten bleiben sicher.",
|
||||
"caution_recommendation": "Das Bearbeiten deiner Umfrage kann zu Dateninkonsistenzen in der Umfragezusammenfassung führen. Wir empfehlen stattdessen, die Umfrage zu duplizieren.",
|
||||
"caution_text": "Änderungen werden zu Inkonsistenzen führen",
|
||||
"centered_modal_overlay_color": "Zentrierte modale Überlagerungsfarbe",
|
||||
"change_anyway": "Trotzdem ändern",
|
||||
@@ -1357,6 +1326,7 @@
|
||||
"close_survey_on_date": "Umfrage am Datum schließen",
|
||||
"close_survey_on_response_limit": "Umfrage bei Erreichen des Antwortlimits schließen",
|
||||
"color": "Farbe",
|
||||
"column_used_in_logic_error": "Diese Spalte wird in der Logik der Frage {questionIndex} verwendet. Bitte entferne sie zuerst aus der Logik.",
|
||||
"columns": "Spalten",
|
||||
"company": "Firma",
|
||||
"company_logo": "Firmenlogo",
|
||||
@@ -1455,9 +1425,6 @@
|
||||
"follow_ups_new": "Neues Follow-up",
|
||||
"follow_ups_upgrade_button_text": "Upgrade, um Follow-ups zu aktivieren",
|
||||
"form_styling": "Umfrage Styling",
|
||||
"formbricks_ai_description": "Beschreibe deine Umfrage und lass Formbricks KI die Umfrage für Dich erstellen",
|
||||
"formbricks_ai_generate": "erzeugen",
|
||||
"formbricks_ai_prompt_placeholder": "Gib Umfrageinformationen ein (z.B. wichtige Themen, die abgedeckt werden sollen)",
|
||||
"formbricks_sdk_is_not_connected": "Formbricks SDK ist nicht verbunden",
|
||||
"four_points": "4 Punkte",
|
||||
"heading": "Überschrift",
|
||||
@@ -1486,10 +1453,13 @@
|
||||
"invalid_youtube_url": "Ungültige YouTube-URL",
|
||||
"is_accepted": "Ist akzeptiert",
|
||||
"is_after": "Ist nach",
|
||||
"is_any_of": "Ist eine von",
|
||||
"is_before": "Ist vor",
|
||||
"is_booked": "Ist gebucht",
|
||||
"is_clicked": "Wird geklickt",
|
||||
"is_completely_submitted": "Vollständig eingereicht",
|
||||
"is_empty": "Ist leer",
|
||||
"is_not_empty": "Ist nicht leer",
|
||||
"is_not_set": "Ist nicht festgelegt",
|
||||
"is_partially_submitted": "Teilweise eingereicht",
|
||||
"is_set": "Ist festgelegt",
|
||||
@@ -1521,6 +1491,7 @@
|
||||
"no_hidden_fields_yet_add_first_one_below": "Noch keine versteckten Felder. Füge das erste unten hinzu.",
|
||||
"no_images_found_for": "Keine Bilder gefunden für ''{query}\"",
|
||||
"no_languages_found_add_first_one_to_get_started": "Keine Sprachen gefunden. Füge die erste hinzu, um loszulegen.",
|
||||
"no_option_found": "Keine Option gefunden",
|
||||
"no_variables_yet_add_first_one_below": "Noch keine Variablen. Füge die erste hinzu.",
|
||||
"number": "Nummer",
|
||||
"once_set_the_default_language_for_this_survey_can_only_be_changed_by_disabling_the_multi_language_option_and_deleting_all_translations": "Sobald die Standardsprache für diese Umfrage festgelegt ist, kann sie nur geändert werden, indem die Mehrsprachigkeitsoption deaktiviert und alle Übersetzungen gelöscht werden.",
|
||||
@@ -1572,6 +1543,7 @@
|
||||
"response_limits_redirections_and_more": "Antwort Limits, Weiterleitungen und mehr.",
|
||||
"response_options": "Antwortoptionen",
|
||||
"roundness": "Rundheit",
|
||||
"row_used_in_logic_error": "Diese Zeile wird in der Logik der Frage {questionIndex} verwendet. Bitte entferne sie zuerst aus der Logik.",
|
||||
"rows": "Zeilen",
|
||||
"save_and_close": "Speichern & Schließen",
|
||||
"scale": "Scale",
|
||||
@@ -1597,6 +1569,7 @@
|
||||
"simple": "Einfach",
|
||||
"single_use_survey_links": "Einmalige Umfragelinks",
|
||||
"single_use_survey_links_description": "Erlaube nur eine Antwort pro Umfragelink.",
|
||||
"six_points": "6 Punkte",
|
||||
"skip_button_label": "Überspringen-Button-Beschriftung",
|
||||
"smiley": "Smiley",
|
||||
"star": "Stern",
|
||||
@@ -1741,11 +1714,6 @@
|
||||
"embed_on_website": "Auf Website einbetten",
|
||||
"embed_pop_up_survey_title": "Wie man eine Pop-up-Umfrage auf seiner Website einbindet",
|
||||
"embed_survey": "Umfrage einbetten",
|
||||
"enable_ai_insights_banner_button": "Insights aktivieren",
|
||||
"enable_ai_insights_banner_description": "Du kannst die neue Insights-Funktion für die Umfrage aktivieren, um KI-basierte Insights für deine Freitextantworten zu erhalten.",
|
||||
"enable_ai_insights_banner_success": "Erzeuge Insights für diese Umfrage. Bitte in ein paar Minuten die Seite neu laden.",
|
||||
"enable_ai_insights_banner_title": "Bereit, KI-Insights zu testen?",
|
||||
"enable_ai_insights_banner_tooltip": "Das sind ganz schön viele Freitextantworten! Kontaktiere uns bitte unter hola@formbricks.com, um Insights für diese Umfrage zu erhalten.",
|
||||
"failed_to_copy_link": "Kopieren des Links fehlgeschlagen",
|
||||
"filter_added_successfully": "Filter erfolgreich hinzugefügt",
|
||||
"filter_updated_successfully": "Filter erfolgreich aktualisiert",
|
||||
@@ -1767,7 +1735,6 @@
|
||||
"impressions_tooltip": "Anzahl der Aufrufe der Umfrage.",
|
||||
"includes_all": "Beinhaltet alles",
|
||||
"includes_either": "Beinhaltet entweder",
|
||||
"insights_disabled": "Insights deaktiviert",
|
||||
"install_widget": "Formbricks Widget installieren",
|
||||
"is_equal_to": "Ist gleich",
|
||||
"is_less_than": "ist weniger als",
|
||||
@@ -1974,7 +1941,6 @@
|
||||
"alignment_and_engagement_survey_question_1_upper_label": "Vollständiges Verständnis",
|
||||
"alignment_and_engagement_survey_question_2_headline": "Ich fühle, dass meine Werte mit der Mission und Kultur des Unternehmens übereinstimmen.",
|
||||
"alignment_and_engagement_survey_question_2_lower_label": "Keine Übereinstimmung",
|
||||
"alignment_and_engagement_survey_question_2_upper_label": "Vollständige Übereinstimmung",
|
||||
"alignment_and_engagement_survey_question_3_headline": "Ich arbeite effektiv mit meinem Team zusammen, um unsere Ziele zu erreichen.",
|
||||
"alignment_and_engagement_survey_question_3_lower_label": "Schlechte Zusammenarbeit",
|
||||
"alignment_and_engagement_survey_question_3_upper_label": "Ausgezeichnete Zusammenarbeit",
|
||||
@@ -1984,7 +1950,6 @@
|
||||
"book_interview": "Interview buchen",
|
||||
"build_product_roadmap_description": "Finde die EINE Sache heraus, die deine Nutzer am meisten wollen, und baue sie.",
|
||||
"build_product_roadmap_name": "Produkt Roadmap erstellen",
|
||||
"build_product_roadmap_name_with_project_name": "$[projectName] Roadmap Ideen",
|
||||
"build_product_roadmap_question_1_headline": "Wie zufrieden bist Du mit den Funktionen und der Benutzerfreundlichkeit von $[projectName]?",
|
||||
"build_product_roadmap_question_1_lower_label": "Überhaupt nicht zufrieden",
|
||||
"build_product_roadmap_question_1_upper_label": "Extrem zufrieden",
|
||||
@@ -2167,7 +2132,6 @@
|
||||
"csat_question_7_choice_3": "Etwas schnell",
|
||||
"csat_question_7_choice_4": "Nicht so schnell",
|
||||
"csat_question_7_choice_5": "Überhaupt nicht schnell",
|
||||
"csat_question_7_choice_6": "Nicht zutreffend",
|
||||
"csat_question_7_headline": "Wie schnell haben wir auf deine Fragen zu unseren Dienstleistungen reagiert?",
|
||||
"csat_question_7_subheader": "Bitte wähle eine aus:",
|
||||
"csat_question_8_choice_1": "Das ist mein erster Kauf",
|
||||
@@ -2175,7 +2139,6 @@
|
||||
"csat_question_8_choice_3": "Sechs Monate bis ein Jahr",
|
||||
"csat_question_8_choice_4": "1 - 2 Jahre",
|
||||
"csat_question_8_choice_5": "3 oder mehr Jahre",
|
||||
"csat_question_8_choice_6": "Ich habe noch keinen Kauf getätigt",
|
||||
"csat_question_8_headline": "Wie lange bist Du schon Kunde von $[projectName]?",
|
||||
"csat_question_8_subheader": "Bitte wähle eine aus:",
|
||||
"csat_question_9_choice_1": "Sehr wahrscheinlich",
|
||||
@@ -2390,7 +2353,6 @@
|
||||
"identify_sign_up_barriers_question_9_dismiss_button_label": "Erstmal überspringen",
|
||||
"identify_sign_up_barriers_question_9_headline": "Danke! Hier ist dein Code: SIGNUPNOW10",
|
||||
"identify_sign_up_barriers_question_9_html": "Vielen Dank, dass Du dir die Zeit genommen hast, Feedback zu geben \uD83D\uDE4F",
|
||||
"identify_sign_up_barriers_with_project_name": "Anmeldebarrieren für $[projectName]",
|
||||
"identify_upsell_opportunities_description": "Finde heraus, wie viel Zeit dein Produkt deinem Nutzer spart. Nutze dies, um mehr zu verkaufen.",
|
||||
"identify_upsell_opportunities_name": "Upsell-Möglichkeiten identifizieren",
|
||||
"identify_upsell_opportunities_question_1_choice_1": "Weniger als 1 Stunde",
|
||||
@@ -2643,7 +2605,6 @@
|
||||
"product_market_fit_superhuman_question_3_choice_3": "Produktmanager",
|
||||
"product_market_fit_superhuman_question_3_choice_4": "People Manager",
|
||||
"product_market_fit_superhuman_question_3_choice_5": "Softwareentwickler",
|
||||
"product_market_fit_superhuman_question_3_headline": "Was ist deine Rolle?",
|
||||
"product_market_fit_superhuman_question_3_subheader": "Bitte wähle eine der folgenden Optionen aus:",
|
||||
"product_market_fit_superhuman_question_4_headline": "Wer würde am ehesten von $[projectName] profitieren?",
|
||||
"product_market_fit_superhuman_question_5_headline": "Welchen Mehrwert ziehst Du aus $[projectName]?",
|
||||
@@ -2665,7 +2626,6 @@
|
||||
"professional_development_survey_description": "Bewerte die Zufriedenheit der Mitarbeiter mit beruflichen Entwicklungsmöglichkeiten.",
|
||||
"professional_development_survey_name": "Berufliche Entwicklungsbewertung",
|
||||
"professional_development_survey_question_1_choice_1": "Ja",
|
||||
"professional_development_survey_question_1_choice_2": "Nein",
|
||||
"professional_development_survey_question_1_headline": "Sind Sie an beruflichen Entwicklungsmöglichkeiten interessiert?",
|
||||
"professional_development_survey_question_2_choice_1": "Networking-Veranstaltungen",
|
||||
"professional_development_survey_question_2_choice_2": "Konferenzen oder Seminare",
|
||||
@@ -2755,7 +2715,6 @@
|
||||
"site_abandonment_survey_question_6_choice_3": "Mehr Produktvielfalt",
|
||||
"site_abandonment_survey_question_6_choice_4": "Verbesserte Seitengestaltung",
|
||||
"site_abandonment_survey_question_6_choice_5": "Mehr Kundenbewertungen",
|
||||
"site_abandonment_survey_question_6_choice_6": "Andere",
|
||||
"site_abandonment_survey_question_6_headline": "Welche Verbesserungen würden Dich dazu ermutigen, länger auf unserer Seite zu bleiben?",
|
||||
"site_abandonment_survey_question_6_subheader": "Bitte wähle alle zutreffenden Optionen aus:",
|
||||
"site_abandonment_survey_question_7_headline": "Möchtest Du Updates über neue Produkte und Aktionen erhalten?",
|
||||
@@ -209,7 +209,6 @@
|
||||
"in_progress": "In Progress",
|
||||
"inactive_surveys": "Inactive surveys",
|
||||
"input_type": "Input type",
|
||||
"insights": "Insights",
|
||||
"integration": "integration",
|
||||
"integrations": "Integrations",
|
||||
"invalid_date": "Invalid date",
|
||||
@@ -246,8 +245,6 @@
|
||||
"move_up": "Move up",
|
||||
"multiple_languages": "Multiple languages",
|
||||
"name": "Name",
|
||||
"negative": "Negative",
|
||||
"neutral": "Neutral",
|
||||
"new": "New",
|
||||
"new_survey": "New Survey",
|
||||
"new_version_available": "Formbricks {version} is here. Upgrade now!",
|
||||
@@ -289,11 +286,9 @@
|
||||
"please_select_at_least_one_survey": "Please select at least one survey",
|
||||
"please_select_at_least_one_trigger": "Please select at least one trigger",
|
||||
"please_upgrade_your_plan": "Please upgrade your plan.",
|
||||
"positive": "Positive",
|
||||
"preview": "Preview",
|
||||
"preview_survey": "Preview Survey",
|
||||
"privacy": "Privacy Policy",
|
||||
"privacy_policy": "Privacy Policy",
|
||||
"product_manager": "Product Manager",
|
||||
"profile": "Profile",
|
||||
"project": "Project",
|
||||
@@ -616,33 +611,6 @@
|
||||
"upload_contacts_modal_preview": "Here's a preview of your data.",
|
||||
"upload_contacts_modal_upload_btn": "Upload contacts"
|
||||
},
|
||||
"experience": {
|
||||
"all": "All",
|
||||
"all_time": "All time",
|
||||
"analysed_feedbacks": "Analysed Free Text Answers",
|
||||
"category": "Category",
|
||||
"category_updated_successfully": "Category updated successfully!",
|
||||
"complaint": "Complaint",
|
||||
"did_you_find_this_insight_helpful": "Did you find this insight helpful?",
|
||||
"failed_to_update_category": "Failed to update category",
|
||||
"feature_request": "Request",
|
||||
"good_afternoon": "\uD83C\uDF24️ Good afternoon",
|
||||
"good_evening": "\uD83C\uDF19 Good evening",
|
||||
"good_morning": "☀️ Good morning",
|
||||
"insights_description": "All insights generated from responses across all your surveys",
|
||||
"insights_for_project": "Insights for {projectName}",
|
||||
"new_responses": "Responses",
|
||||
"no_insights_for_this_filter": "No insights for this filter",
|
||||
"no_insights_found": "No insights found. Collect more survey responses or enable insights for your existing surveys to get started.",
|
||||
"praise": "Praise",
|
||||
"sentiment_score": "Sentiment Score",
|
||||
"templates_card_description": "Choose a template or start from scratch",
|
||||
"templates_card_title": "Measure your customer experience",
|
||||
"this_month": "This month",
|
||||
"this_quarter": "This quarter",
|
||||
"this_week": "This week",
|
||||
"today": "Today"
|
||||
},
|
||||
"formbricks_logo": "Formbricks Logo",
|
||||
"integrations": {
|
||||
"activepieces_integration_description": "Instantly connect Formbricks with popular apps to automate tasks without coding.",
|
||||
@@ -1065,7 +1033,6 @@
|
||||
"website_surveys": "Website Surveys"
|
||||
},
|
||||
"enterprise": {
|
||||
"ai": "AI Analysis",
|
||||
"audit_logs": "Audit Logs",
|
||||
"coming_soon": "Coming soon",
|
||||
"contacts_and_segments": "Contact management & segments",
|
||||
@@ -1103,13 +1070,7 @@
|
||||
"eliminate_branding_with_whitelabel": "Eliminate Formbricks branding and enable additional white-label customization options.",
|
||||
"email_customization_preview_email_heading": "Hey {userName}",
|
||||
"email_customization_preview_email_text": "This is an email preview to show you which logo will be rendered in the emails.",
|
||||
"enable_formbricks_ai": "Enable Formbricks AI",
|
||||
"error_deleting_organization_please_try_again": "Error deleting organization. Please try again.",
|
||||
"formbricks_ai": "Formbricks AI",
|
||||
"formbricks_ai_description": "Get personalised insights from your survey responses with Formbricks AI",
|
||||
"formbricks_ai_disable_success_message": "Formbricks AI disabled successfully.",
|
||||
"formbricks_ai_enable_success_message": "Formbricks AI enabled successfully.",
|
||||
"formbricks_ai_privacy_policy_text": "By activating Formbricks AI, you agree to the updated",
|
||||
"from_your_organization": "from your organization",
|
||||
"invitation_sent_once_more": "Invitation sent once more.",
|
||||
"invite_deleted_successfully": "Invite deleted successfully",
|
||||
@@ -1332,6 +1293,14 @@
|
||||
"card_shadow_color": "Card shadow color",
|
||||
"card_styling": "Card Styling",
|
||||
"casual": "Casual",
|
||||
"caution_edit_duplicate": "Duplicate & edit",
|
||||
"caution_edit_published_survey": "Edit a published survey?",
|
||||
"caution_explanation_all_data_as_download": "All data, including past responses are available as download.",
|
||||
"caution_explanation_intro": "We understand you might still want to make changes. Here’s what happens if you do: ",
|
||||
"caution_explanation_new_responses_separated": "New responses are collected separately.",
|
||||
"caution_explanation_only_new_responses_in_summary": "Only new responses appear in the survey summary.",
|
||||
"caution_explanation_responses_are_safe": "Existing responses remain safe.",
|
||||
"caution_recommendation": "Editing your survey may cause data inconsistencies in the survey summary. We recommend duplicating the survey instead.",
|
||||
"caution_text": "Changes will lead to inconsistencies",
|
||||
"centered_modal_overlay_color": "Centered modal overlay color",
|
||||
"change_anyway": "Change anyway",
|
||||
@@ -1357,6 +1326,7 @@
|
||||
"close_survey_on_date": "Close survey on date",
|
||||
"close_survey_on_response_limit": "Close survey on response limit",
|
||||
"color": "Color",
|
||||
"column_used_in_logic_error": "This column is used in logic of question {questionIndex}. Please remove it from logic first.",
|
||||
"columns": "Columns",
|
||||
"company": "Company",
|
||||
"company_logo": "Company logo",
|
||||
@@ -1455,9 +1425,6 @@
|
||||
"follow_ups_new": "New follow-up",
|
||||
"follow_ups_upgrade_button_text": "Upgrade to enable follow-ups",
|
||||
"form_styling": "Form styling",
|
||||
"formbricks_ai_description": "Describe your survey and let Formbricks AI create the survey for you",
|
||||
"formbricks_ai_generate": "Generate",
|
||||
"formbricks_ai_prompt_placeholder": "Enter survey information (e.g. key topics to cover)",
|
||||
"formbricks_sdk_is_not_connected": "Formbricks SDK is not connected",
|
||||
"four_points": "4 points",
|
||||
"heading": "Heading",
|
||||
@@ -1486,10 +1453,13 @@
|
||||
"invalid_youtube_url": "Invalid YouTube URL",
|
||||
"is_accepted": "Is accepted",
|
||||
"is_after": "Is after",
|
||||
"is_any_of": "Is any of",
|
||||
"is_before": "Is before",
|
||||
"is_booked": "Is booked",
|
||||
"is_clicked": "Is clicked",
|
||||
"is_completely_submitted": "Is completely submitted",
|
||||
"is_empty": "Is empty",
|
||||
"is_not_empty": "Is not empty",
|
||||
"is_not_set": "Is not set",
|
||||
"is_partially_submitted": "Is partially submitted",
|
||||
"is_set": "Is set",
|
||||
@@ -1521,6 +1491,7 @@
|
||||
"no_hidden_fields_yet_add_first_one_below": "No hidden fields yet. Add the first one below.",
|
||||
"no_images_found_for": "No images found for ''{query}\"",
|
||||
"no_languages_found_add_first_one_to_get_started": "No languages found. Add the first one to get started.",
|
||||
"no_option_found": "No option found",
|
||||
"no_variables_yet_add_first_one_below": "No variables yet. Add the first one below.",
|
||||
"number": "Number",
|
||||
"once_set_the_default_language_for_this_survey_can_only_be_changed_by_disabling_the_multi_language_option_and_deleting_all_translations": "Once set, the default language for this survey can only be changed by disabling the multi-language option and deleting all translations.",
|
||||
@@ -1572,6 +1543,7 @@
|
||||
"response_limits_redirections_and_more": "Response limits, redirections and more.",
|
||||
"response_options": "Response Options",
|
||||
"roundness": "Roundness",
|
||||
"row_used_in_logic_error": "This row is used in logic of question {questionIndex}. Please remove it from logic first.",
|
||||
"rows": "Rows",
|
||||
"save_and_close": "Save & Close",
|
||||
"scale": "Scale",
|
||||
@@ -1597,6 +1569,7 @@
|
||||
"simple": "Simple",
|
||||
"single_use_survey_links": "Single-use survey links",
|
||||
"single_use_survey_links_description": "Allow only 1 response per survey link.",
|
||||
"six_points": "6 points",
|
||||
"skip_button_label": "Skip Button Label",
|
||||
"smiley": "Smiley",
|
||||
"star": "Star",
|
||||
@@ -1741,11 +1714,6 @@
|
||||
"embed_on_website": "Embed on website",
|
||||
"embed_pop_up_survey_title": "How to embed a pop-up survey on your website",
|
||||
"embed_survey": "Embed survey",
|
||||
"enable_ai_insights_banner_button": "Enable insights",
|
||||
"enable_ai_insights_banner_description": "You can enable the new insights feature for the survey to get AI-based insights for your open-text responses.",
|
||||
"enable_ai_insights_banner_success": "Generating insights for this survey. Please check back in a few minutes.",
|
||||
"enable_ai_insights_banner_title": "Ready to test AI insights?",
|
||||
"enable_ai_insights_banner_tooltip": "Kindly contact us at hola@formbricks.com to generate insights for this survey",
|
||||
"failed_to_copy_link": "Failed to copy link",
|
||||
"filter_added_successfully": "Filter added successfully",
|
||||
"filter_updated_successfully": "Filter updated successfully",
|
||||
@@ -1767,7 +1735,6 @@
|
||||
"impressions_tooltip": "Number of times the survey has been viewed.",
|
||||
"includes_all": "Includes all",
|
||||
"includes_either": "Includes either",
|
||||
"insights_disabled": "Insights disabled",
|
||||
"install_widget": "Install Formbricks Widget",
|
||||
"is_equal_to": "Is equal to",
|
||||
"is_less_than": "Is less than",
|
||||
@@ -1974,7 +1941,6 @@
|
||||
"alignment_and_engagement_survey_question_1_upper_label": "Complete understanding",
|
||||
"alignment_and_engagement_survey_question_2_headline": "I feel that my values align with the company’s mission and culture.",
|
||||
"alignment_and_engagement_survey_question_2_lower_label": "Not aligned",
|
||||
"alignment_and_engagement_survey_question_2_upper_label": "Completely aligned",
|
||||
"alignment_and_engagement_survey_question_3_headline": "I collaborate effectively with my team to achieve our goals.",
|
||||
"alignment_and_engagement_survey_question_3_lower_label": "Poor collaboration",
|
||||
"alignment_and_engagement_survey_question_3_upper_label": "Excellent collaboration",
|
||||
@@ -1984,7 +1950,6 @@
|
||||
"book_interview": "Book interview",
|
||||
"build_product_roadmap_description": "Identify the ONE thing your users want the most and build it.",
|
||||
"build_product_roadmap_name": "Build Product Roadmap",
|
||||
"build_product_roadmap_name_with_project_name": "$[projectName] Roadmap Input",
|
||||
"build_product_roadmap_question_1_headline": "How satisfied are you with the features and functionality of $[projectName]?",
|
||||
"build_product_roadmap_question_1_lower_label": "Not at all satisfied",
|
||||
"build_product_roadmap_question_1_upper_label": "Extremely satisfied",
|
||||
@@ -2167,7 +2132,6 @@
|
||||
"csat_question_7_choice_3": "Somewhat responsive",
|
||||
"csat_question_7_choice_4": "Not so responsive",
|
||||
"csat_question_7_choice_5": "Not at all responsive",
|
||||
"csat_question_7_choice_6": "Not applicable",
|
||||
"csat_question_7_headline": "How responsive have we been to your questions about our services?",
|
||||
"csat_question_7_subheader": "Please select one:",
|
||||
"csat_question_8_choice_1": "This is my first purchase",
|
||||
@@ -2175,7 +2139,6 @@
|
||||
"csat_question_8_choice_3": "Six months to a year",
|
||||
"csat_question_8_choice_4": "1 - 2 years",
|
||||
"csat_question_8_choice_5": "3 or more years",
|
||||
"csat_question_8_choice_6": "I haven't made a purchase yet",
|
||||
"csat_question_8_headline": "How long have you been a customer of $[projectName]?",
|
||||
"csat_question_8_subheader": "Please select one:",
|
||||
"csat_question_9_choice_1": "Extremely likely",
|
||||
@@ -2390,7 +2353,6 @@
|
||||
"identify_sign_up_barriers_question_9_dismiss_button_label": "Skip for now",
|
||||
"identify_sign_up_barriers_question_9_headline": "Thanks! Here is your code: SIGNUPNOW10",
|
||||
"identify_sign_up_barriers_question_9_html": "<p class=\"fb-editor-paragraph\" dir=\"ltr\"><span>Thanks a lot for taking the time to share feedback \uD83D\uDE4F</span></p>",
|
||||
"identify_sign_up_barriers_with_project_name": "$[projectName] Sign Up Barriers",
|
||||
"identify_upsell_opportunities_description": "Find out how much time your product saves your user. Use it to upsell.",
|
||||
"identify_upsell_opportunities_name": "Identify Upsell Opportunities",
|
||||
"identify_upsell_opportunities_question_1_choice_1": "Less than 1 hour",
|
||||
@@ -2643,7 +2605,6 @@
|
||||
"product_market_fit_superhuman_question_3_choice_3": "Product Manager",
|
||||
"product_market_fit_superhuman_question_3_choice_4": "Product Owner",
|
||||
"product_market_fit_superhuman_question_3_choice_5": "Software Engineer",
|
||||
"product_market_fit_superhuman_question_3_headline": "What is your role?",
|
||||
"product_market_fit_superhuman_question_3_subheader": "Please select one of the following options:",
|
||||
"product_market_fit_superhuman_question_4_headline": "What type of people do you think would most benefit from $[projectName]?",
|
||||
"product_market_fit_superhuman_question_5_headline": "What is the main benefit you receive from $[projectName]?",
|
||||
@@ -2665,7 +2626,6 @@
|
||||
"professional_development_survey_description": "Assess employee satisfaction with professional growth and development opportunities.",
|
||||
"professional_development_survey_name": "Professional Development Survey",
|
||||
"professional_development_survey_question_1_choice_1": "Yes",
|
||||
"professional_development_survey_question_1_choice_2": "No",
|
||||
"professional_development_survey_question_1_headline": "Are you interested in professional development activities?",
|
||||
"professional_development_survey_question_2_choice_1": "Networking events",
|
||||
"professional_development_survey_question_2_choice_2": "Conferences or seminars",
|
||||
@@ -2755,7 +2715,6 @@
|
||||
"site_abandonment_survey_question_6_choice_3": "More product variety",
|
||||
"site_abandonment_survey_question_6_choice_4": "Improved site design",
|
||||
"site_abandonment_survey_question_6_choice_5": "More customer reviews",
|
||||
"site_abandonment_survey_question_6_choice_6": "Other",
|
||||
"site_abandonment_survey_question_6_headline": "What improvements would encourage you to stay longer on our site?",
|
||||
"site_abandonment_survey_question_6_subheader": "Please select all that apply:",
|
||||
"site_abandonment_survey_question_7_headline": "Would you like to receive updates about new products and promotions?",
|
||||
@@ -209,7 +209,6 @@
|
||||
"in_progress": "En cours",
|
||||
"inactive_surveys": "Sondages inactifs",
|
||||
"input_type": "Type d'entrée",
|
||||
"insights": "Perspectives",
|
||||
"integration": "intégration",
|
||||
"integrations": "Intégrations",
|
||||
"invalid_date": "Date invalide",
|
||||
@@ -246,8 +245,6 @@
|
||||
"move_up": "Déplacer vers le haut",
|
||||
"multiple_languages": "Plusieurs langues",
|
||||
"name": "Nom",
|
||||
"negative": "Négatif",
|
||||
"neutral": "Neutre",
|
||||
"new": "Nouveau",
|
||||
"new_survey": "Nouveau Sondage",
|
||||
"new_version_available": "Formbricks {version} est là. Mettez à jour maintenant !",
|
||||
@@ -289,11 +286,9 @@
|
||||
"please_select_at_least_one_survey": "Veuillez sélectionner au moins une enquête.",
|
||||
"please_select_at_least_one_trigger": "Veuillez sélectionner au moins un déclencheur.",
|
||||
"please_upgrade_your_plan": "Veuillez mettre à niveau votre plan.",
|
||||
"positive": "Positif",
|
||||
"preview": "Aperçu",
|
||||
"preview_survey": "Aperçu de l'enquête",
|
||||
"privacy": "Politique de confidentialité",
|
||||
"privacy_policy": "Politique de confidentialité",
|
||||
"product_manager": "Chef de produit",
|
||||
"profile": "Profil",
|
||||
"project": "Projet",
|
||||
@@ -616,33 +611,6 @@
|
||||
"upload_contacts_modal_preview": "Voici un aperçu de vos données.",
|
||||
"upload_contacts_modal_upload_btn": "Importer des contacts"
|
||||
},
|
||||
"experience": {
|
||||
"all": "Tout",
|
||||
"all_time": "Tout le temps",
|
||||
"analysed_feedbacks": "Réponses en texte libre analysées",
|
||||
"category": "Catégorie",
|
||||
"category_updated_successfully": "Catégorie mise à jour avec succès !",
|
||||
"complaint": "Plainte",
|
||||
"did_you_find_this_insight_helpful": "Avez-vous trouvé cette information utile ?",
|
||||
"failed_to_update_category": "Échec de la mise à jour de la catégorie",
|
||||
"feature_request": "Demande",
|
||||
"good_afternoon": "\uD83C\uDF24️ Bon après-midi",
|
||||
"good_evening": "\uD83C\uDF19 Bonsoir",
|
||||
"good_morning": "☀️ Bonjour",
|
||||
"insights_description": "Toutes les informations générées à partir des réponses de toutes vos enquêtes",
|
||||
"insights_for_project": "Aperçus pour {projectName}",
|
||||
"new_responses": "Réponses",
|
||||
"no_insights_for_this_filter": "Aucune information pour ce filtre",
|
||||
"no_insights_found": "Aucune information trouvée. Collectez plus de réponses à l'enquête ou activez les insights pour vos enquêtes existantes pour commencer.",
|
||||
"praise": "Éloge",
|
||||
"sentiment_score": "Score de sentiment",
|
||||
"templates_card_description": "Choisissez un modèle ou commencez à partir de zéro",
|
||||
"templates_card_title": "Mesurez l'expérience de vos clients",
|
||||
"this_month": "Ce mois-ci",
|
||||
"this_quarter": "Ce trimestre",
|
||||
"this_week": "Cette semaine",
|
||||
"today": "Aujourd'hui"
|
||||
},
|
||||
"formbricks_logo": "Logo Formbricks",
|
||||
"integrations": {
|
||||
"activepieces_integration_description": "Connectez instantanément Formbricks avec des applications populaires pour automatiser les tâches sans coder.",
|
||||
@@ -789,6 +757,7 @@
|
||||
"no_api_keys_yet": "Vous n'avez pas encore de clés API.",
|
||||
"no_env_permissions_found": "Aucune autorisation d'environnement trouvée",
|
||||
"organization_access": "Accès à l'organisation",
|
||||
"organization_access_description": "Sélectionnez les privilèges de lecture ou d'écriture pour les ressources de l'organisation.",
|
||||
"permissions": "Permissions",
|
||||
"project_access": "Accès au projet",
|
||||
"secret": "Secret",
|
||||
@@ -1064,7 +1033,6 @@
|
||||
"website_surveys": "Sondages de site web"
|
||||
},
|
||||
"enterprise": {
|
||||
"ai": "Analyse IA",
|
||||
"audit_logs": "Journaux d'audit",
|
||||
"coming_soon": "À venir bientôt",
|
||||
"contacts_and_segments": "Gestion des contacts et des segments",
|
||||
@@ -1102,13 +1070,7 @@
|
||||
"eliminate_branding_with_whitelabel": "Éliminez la marque Formbricks et activez des options de personnalisation supplémentaires.",
|
||||
"email_customization_preview_email_heading": "Salut {userName}",
|
||||
"email_customization_preview_email_text": "Cette est une prévisualisation d'e-mail pour vous montrer quel logo sera rendu dans les e-mails.",
|
||||
"enable_formbricks_ai": "Activer Formbricks IA",
|
||||
"error_deleting_organization_please_try_again": "Erreur lors de la suppression de l'organisation. Veuillez réessayer.",
|
||||
"formbricks_ai": "Formbricks IA",
|
||||
"formbricks_ai_description": "Obtenez des insights personnalisés à partir de vos réponses au sondage avec Formbricks AI.",
|
||||
"formbricks_ai_disable_success_message": "Formbricks AI désactivé avec succès.",
|
||||
"formbricks_ai_enable_success_message": "Formbricks AI activé avec succès.",
|
||||
"formbricks_ai_privacy_policy_text": "En activant Formbricks AI, vous acceptez les mises à jour",
|
||||
"from_your_organization": "de votre organisation",
|
||||
"invitation_sent_once_more": "Invitation envoyée une fois de plus.",
|
||||
"invite_deleted_successfully": "Invitation supprimée avec succès",
|
||||
@@ -1331,6 +1293,14 @@
|
||||
"card_shadow_color": "Couleur de l'ombre de la carte",
|
||||
"card_styling": "Style de carte",
|
||||
"casual": "Décontracté",
|
||||
"caution_edit_duplicate": "Dupliquer et modifier",
|
||||
"caution_edit_published_survey": "Modifier un sondage publié ?",
|
||||
"caution_explanation_all_data_as_download": "Toutes les données, y compris les réponses passées, sont disponibles en téléchargement.",
|
||||
"caution_explanation_intro": "Nous comprenons que vous souhaitiez encore apporter des modifications. Voici ce qui se passe si vous le faites : ",
|
||||
"caution_explanation_new_responses_separated": "Les nouvelles réponses sont collectées séparément.",
|
||||
"caution_explanation_only_new_responses_in_summary": "Seules les nouvelles réponses apparaissent dans le résumé de l'enquête.",
|
||||
"caution_explanation_responses_are_safe": "Les réponses existantes restent en sécurité.",
|
||||
"caution_recommendation": "Modifier votre enquête peut entraîner des incohérences dans le résumé de l'enquête. Nous vous recommandons de dupliquer l'enquête à la place.",
|
||||
"caution_text": "Les changements entraîneront des incohérences.",
|
||||
"centered_modal_overlay_color": "Couleur de superposition modale centrée",
|
||||
"change_anyway": "Changer de toute façon",
|
||||
@@ -1356,6 +1326,7 @@
|
||||
"close_survey_on_date": "Clôturer l'enquête à la date",
|
||||
"close_survey_on_response_limit": "Fermer l'enquête sur la limite de réponse",
|
||||
"color": "Couleur",
|
||||
"column_used_in_logic_error": "Cette colonne est utilisée dans la logique de la question {questionIndex}. Veuillez d'abord la supprimer de la logique.",
|
||||
"columns": "Colonnes",
|
||||
"company": "Société",
|
||||
"company_logo": "Logo de l'entreprise",
|
||||
@@ -1454,9 +1425,6 @@
|
||||
"follow_ups_new": "Nouveau suivi",
|
||||
"follow_ups_upgrade_button_text": "Passez à la version supérieure pour activer les relances",
|
||||
"form_styling": "Style de formulaire",
|
||||
"formbricks_ai_description": "Décrivez votre enquête et laissez l'IA de Formbricks créer l'enquête pour vous.",
|
||||
"formbricks_ai_generate": "Générer",
|
||||
"formbricks_ai_prompt_placeholder": "Saisissez les informations de l'enquête (par exemple, les sujets clés à aborder)",
|
||||
"formbricks_sdk_is_not_connected": "Le SDK Formbricks n'est pas connecté",
|
||||
"four_points": "4 points",
|
||||
"heading": "En-tête",
|
||||
@@ -1485,10 +1453,13 @@
|
||||
"invalid_youtube_url": "URL YouTube invalide",
|
||||
"is_accepted": "C'est accepté",
|
||||
"is_after": "est après",
|
||||
"is_any_of": "Est l'un des",
|
||||
"is_before": "Est avant",
|
||||
"is_booked": "Est réservé",
|
||||
"is_clicked": "Est cliqué",
|
||||
"is_completely_submitted": "Est complètement soumis",
|
||||
"is_empty": "Est vide",
|
||||
"is_not_empty": "N'est pas vide",
|
||||
"is_not_set": "N'est pas défini",
|
||||
"is_partially_submitted": "Est partiellement soumis",
|
||||
"is_set": "Est défini",
|
||||
@@ -1520,6 +1491,7 @@
|
||||
"no_hidden_fields_yet_add_first_one_below": "Aucun champ caché pour le moment. Ajoutez le premier ci-dessous.",
|
||||
"no_images_found_for": "Aucune image trouvée pour ''{query}\"",
|
||||
"no_languages_found_add_first_one_to_get_started": "Aucune langue trouvée. Ajoutez la première pour commencer.",
|
||||
"no_option_found": "Aucune option trouvée",
|
||||
"no_variables_yet_add_first_one_below": "Aucune variable pour le moment. Ajoutez la première ci-dessous.",
|
||||
"number": "Numéro",
|
||||
"once_set_the_default_language_for_this_survey_can_only_be_changed_by_disabling_the_multi_language_option_and_deleting_all_translations": "Une fois défini, la langue par défaut de cette enquête ne peut être changée qu'en désactivant l'option multilingue et en supprimant toutes les traductions.",
|
||||
@@ -1571,6 +1543,7 @@
|
||||
"response_limits_redirections_and_more": "Limites de réponse, redirections et plus.",
|
||||
"response_options": "Options de réponse",
|
||||
"roundness": "Rondité",
|
||||
"row_used_in_logic_error": "Cette ligne est utilisée dans la logique de la question {questionIndex}. Veuillez d'abord la supprimer de la logique.",
|
||||
"rows": "Lignes",
|
||||
"save_and_close": "Enregistrer et fermer",
|
||||
"scale": "Échelle",
|
||||
@@ -1596,6 +1569,7 @@
|
||||
"simple": "Simple",
|
||||
"single_use_survey_links": "Liens d'enquête à usage unique",
|
||||
"single_use_survey_links_description": "Autoriser uniquement 1 réponse par lien d'enquête.",
|
||||
"six_points": "6 points",
|
||||
"skip_button_label": "Étiquette du bouton Ignorer",
|
||||
"smiley": "Sourire",
|
||||
"star": "Étoile",
|
||||
@@ -1740,11 +1714,6 @@
|
||||
"embed_on_website": "Incorporer sur le site web",
|
||||
"embed_pop_up_survey_title": "Comment intégrer une enquête pop-up sur votre site web",
|
||||
"embed_survey": "Intégrer l'enquête",
|
||||
"enable_ai_insights_banner_button": "Activer les insights",
|
||||
"enable_ai_insights_banner_description": "Vous pouvez activer la nouvelle fonctionnalité d'aperçus pour l'enquête afin d'obtenir des aperçus basés sur l'IA pour vos réponses en texte libre.",
|
||||
"enable_ai_insights_banner_success": "Génération d'analyses pour cette enquête. Veuillez revenir dans quelques minutes.",
|
||||
"enable_ai_insights_banner_title": "Prêt à tester les insights de l'IA ?",
|
||||
"enable_ai_insights_banner_tooltip": "Veuillez nous contacter à hola@formbricks.com pour générer des insights pour cette enquête.",
|
||||
"failed_to_copy_link": "Échec de la copie du lien",
|
||||
"filter_added_successfully": "Filtre ajouté avec succès",
|
||||
"filter_updated_successfully": "Filtre mis à jour avec succès",
|
||||
@@ -1766,7 +1735,6 @@
|
||||
"impressions_tooltip": "Nombre de fois que l'enquête a été consultée.",
|
||||
"includes_all": "Comprend tous",
|
||||
"includes_either": "Comprend soit",
|
||||
"insights_disabled": "Insights désactivés",
|
||||
"install_widget": "Installer le widget Formbricks",
|
||||
"is_equal_to": "Est égal à",
|
||||
"is_less_than": "est inférieur à",
|
||||
@@ -1973,7 +1941,6 @@
|
||||
"alignment_and_engagement_survey_question_1_upper_label": "Compréhension complète",
|
||||
"alignment_and_engagement_survey_question_2_headline": "Je sens que mes valeurs s'alignent avec la mission et la culture de l'entreprise.",
|
||||
"alignment_and_engagement_survey_question_2_lower_label": "Non aligné",
|
||||
"alignment_and_engagement_survey_question_2_upper_label": "Complètement aligné",
|
||||
"alignment_and_engagement_survey_question_3_headline": "Je collabore efficacement avec mon équipe pour atteindre nos objectifs.",
|
||||
"alignment_and_engagement_survey_question_3_lower_label": "Mauvaise collaboration",
|
||||
"alignment_and_engagement_survey_question_3_upper_label": "Excellente collaboration",
|
||||
@@ -1983,7 +1950,6 @@
|
||||
"book_interview": "Réserver un entretien",
|
||||
"build_product_roadmap_description": "Identifiez la chose UNIQUE que vos utilisateurs désirent le plus et construisez-la.",
|
||||
"build_product_roadmap_name": "Élaborer la feuille de route du produit",
|
||||
"build_product_roadmap_name_with_project_name": "Entrée de feuille de route $[projectName]",
|
||||
"build_product_roadmap_question_1_headline": "Dans quelle mesure êtes-vous satisfait des fonctionnalités et de l'ergonomie de $[projectName] ?",
|
||||
"build_product_roadmap_question_1_lower_label": "Pas du tout satisfait",
|
||||
"build_product_roadmap_question_1_upper_label": "Extrêmement satisfait",
|
||||
@@ -2166,7 +2132,6 @@
|
||||
"csat_question_7_choice_3": "Quelque peu réactif",
|
||||
"csat_question_7_choice_4": "Pas si réactif",
|
||||
"csat_question_7_choice_5": "Pas du tout réactif",
|
||||
"csat_question_7_choice_6": "Non applicable",
|
||||
"csat_question_7_headline": "Dans quelle mesure avons-nous été réactifs à vos questions concernant nos services ?",
|
||||
"csat_question_7_subheader": "Veuillez en sélectionner un :",
|
||||
"csat_question_8_choice_1": "Ceci est mon premier achat",
|
||||
@@ -2174,7 +2139,6 @@
|
||||
"csat_question_8_choice_3": "Six mois à un an",
|
||||
"csat_question_8_choice_4": "1 - 2 ans",
|
||||
"csat_question_8_choice_5": "3 ans ou plus",
|
||||
"csat_question_8_choice_6": "Je n'ai pas encore effectué d'achat.",
|
||||
"csat_question_8_headline": "Depuis combien de temps êtes-vous client de $[projectName] ?",
|
||||
"csat_question_8_subheader": "Veuillez en sélectionner un :",
|
||||
"csat_question_9_choice_1": "Extrêmement probable",
|
||||
@@ -2389,7 +2353,6 @@
|
||||
"identify_sign_up_barriers_question_9_dismiss_button_label": "Passer pour l'instant",
|
||||
"identify_sign_up_barriers_question_9_headline": "Merci ! Voici votre code : SIGNUPNOW10",
|
||||
"identify_sign_up_barriers_question_9_html": "<p class=\"fb-editor-paragraph\" dir=\"ltr\"><span>Merci beaucoup d'avoir pris le temps de partager vos retours \uD83D\uDE4F</span></p>",
|
||||
"identify_sign_up_barriers_with_project_name": "Barrières d'inscription $[projectName]",
|
||||
"identify_upsell_opportunities_description": "Découvrez combien de temps votre produit fait gagner à vos utilisateurs. Utilisez-le pour vendre davantage.",
|
||||
"identify_upsell_opportunities_name": "Identifier les opportunités de vente additionnelle",
|
||||
"identify_upsell_opportunities_question_1_choice_1": "Moins d'une heure",
|
||||
@@ -2642,7 +2605,6 @@
|
||||
"product_market_fit_superhuman_question_3_choice_3": "Chef de produit",
|
||||
"product_market_fit_superhuman_question_3_choice_4": "Propriétaire de produit",
|
||||
"product_market_fit_superhuman_question_3_choice_5": "Ingénieur logiciel",
|
||||
"product_market_fit_superhuman_question_3_headline": "Quel est votre rôle ?",
|
||||
"product_market_fit_superhuman_question_3_subheader": "Veuillez sélectionner l'une des options suivantes :",
|
||||
"product_market_fit_superhuman_question_4_headline": "Quel type de personnes pensez-vous bénéficierait le plus de $[projectName] ?",
|
||||
"product_market_fit_superhuman_question_5_headline": "Quel est le principal avantage que vous tirez de $[projectName] ?",
|
||||
@@ -2664,7 +2626,6 @@
|
||||
"professional_development_survey_description": "Évaluer la satisfaction des employés concernant les opportunités de croissance et de développement professionnel.",
|
||||
"professional_development_survey_name": "Sondage sur le développement professionnel",
|
||||
"professional_development_survey_question_1_choice_1": "Oui",
|
||||
"professional_development_survey_question_1_choice_2": "Non",
|
||||
"professional_development_survey_question_1_headline": "Êtes-vous intéressé par des activités de développement professionnel ?",
|
||||
"professional_development_survey_question_2_choice_1": "Événements de réseautage",
|
||||
"professional_development_survey_question_2_choice_2": "Conférences ou séminaires",
|
||||
@@ -2754,7 +2715,6 @@
|
||||
"site_abandonment_survey_question_6_choice_3": "Plus de variété de produits",
|
||||
"site_abandonment_survey_question_6_choice_4": "Conception de site améliorée",
|
||||
"site_abandonment_survey_question_6_choice_5": "Plus d'avis clients",
|
||||
"site_abandonment_survey_question_6_choice_6": "Autre",
|
||||
"site_abandonment_survey_question_6_headline": "Quelles améliorations vous inciteraient à rester plus longtemps sur notre site ?",
|
||||
"site_abandonment_survey_question_6_subheader": "Veuillez sélectionner tout ce qui s'applique :",
|
||||
"site_abandonment_survey_question_7_headline": "Souhaitez-vous recevoir des mises à jour sur les nouveaux produits et les promotions ?",
|
||||
@@ -209,7 +209,6 @@
|
||||
"in_progress": "Em andamento",
|
||||
"inactive_surveys": "Pesquisas inativas",
|
||||
"input_type": "Tipo de entrada",
|
||||
"insights": "Percepções",
|
||||
"integration": "integração",
|
||||
"integrations": "Integrações",
|
||||
"invalid_date": "Data inválida",
|
||||
@@ -246,8 +245,6 @@
|
||||
"move_up": "Subir",
|
||||
"multiple_languages": "Vários idiomas",
|
||||
"name": "Nome",
|
||||
"negative": "Negativo",
|
||||
"neutral": "Neutro",
|
||||
"new": "Novo",
|
||||
"new_survey": "Nova Pesquisa",
|
||||
"new_version_available": "Formbricks {version} chegou. Atualize agora!",
|
||||
@@ -289,11 +286,9 @@
|
||||
"please_select_at_least_one_survey": "Por favor, selecione pelo menos uma pesquisa",
|
||||
"please_select_at_least_one_trigger": "Por favor, selecione pelo menos um gatilho",
|
||||
"please_upgrade_your_plan": "Por favor, atualize seu plano.",
|
||||
"positive": "Positivo",
|
||||
"preview": "Prévia",
|
||||
"preview_survey": "Prévia da Pesquisa",
|
||||
"privacy": "Política de Privacidade",
|
||||
"privacy_policy": "Política de Privacidade",
|
||||
"product_manager": "Gerente de Produto",
|
||||
"profile": "Perfil",
|
||||
"project": "Projeto",
|
||||
@@ -616,33 +611,6 @@
|
||||
"upload_contacts_modal_preview": "Aqui está uma prévia dos seus dados.",
|
||||
"upload_contacts_modal_upload_btn": "Fazer upload de contatos"
|
||||
},
|
||||
"experience": {
|
||||
"all": "tudo",
|
||||
"all_time": "Todo o tempo",
|
||||
"analysed_feedbacks": "Feedbacks Analisados",
|
||||
"category": "Categoria",
|
||||
"category_updated_successfully": "Categoria atualizada com sucesso!",
|
||||
"complaint": "Reclamação",
|
||||
"did_you_find_this_insight_helpful": "Você achou essa dica útil?",
|
||||
"failed_to_update_category": "Falha ao atualizar categoria",
|
||||
"feature_request": "Pedido de Recurso",
|
||||
"good_afternoon": "\uD83C\uDF24️ Boa tarde",
|
||||
"good_evening": "\uD83C\uDF19 Boa noite",
|
||||
"good_morning": "☀️ Bom dia",
|
||||
"insights_description": "Todos os insights gerados a partir das respostas de todas as suas pesquisas",
|
||||
"insights_for_project": "Insights para {projectName}",
|
||||
"new_responses": "Novas Respostas",
|
||||
"no_insights_for_this_filter": "Sem insights para este filtro",
|
||||
"no_insights_found": "Não foram encontrados insights. Colete mais respostas de pesquisa ou ative insights para suas pesquisas existentes para começar.",
|
||||
"praise": "elogio",
|
||||
"sentiment_score": "Pontuação de Sentimento",
|
||||
"templates_card_description": "Escolha um template ou comece do zero",
|
||||
"templates_card_title": "Meça a experiência do seu cliente",
|
||||
"this_month": "Este mês",
|
||||
"this_quarter": "Esse trimestre",
|
||||
"this_week": "Essa semana",
|
||||
"today": "Hoje"
|
||||
},
|
||||
"formbricks_logo": "Logo da Formbricks",
|
||||
"integrations": {
|
||||
"activepieces_integration_description": "Conecte o Formbricks instantaneamente com aplicativos populares para automatizar tarefas sem codificação.",
|
||||
@@ -1065,7 +1033,6 @@
|
||||
"website_surveys": "Pesquisas de Site"
|
||||
},
|
||||
"enterprise": {
|
||||
"ai": "Análise de IA",
|
||||
"audit_logs": "Registros de Auditoria",
|
||||
"coming_soon": "Em breve",
|
||||
"contacts_and_segments": "Gerenciamento de contatos e segmentos",
|
||||
@@ -1103,13 +1070,7 @@
|
||||
"eliminate_branding_with_whitelabel": "Elimine a marca Formbricks e ative opções adicionais de personalização de marca branca.",
|
||||
"email_customization_preview_email_heading": "Oi {userName}",
|
||||
"email_customization_preview_email_text": "Esta é uma pré-visualização de e-mail para mostrar qual logo será renderizado nos e-mails.",
|
||||
"enable_formbricks_ai": "Ativar Formbricks IA",
|
||||
"error_deleting_organization_please_try_again": "Erro ao deletar a organização. Por favor, tente novamente.",
|
||||
"formbricks_ai": "Formbricks IA",
|
||||
"formbricks_ai_description": "Obtenha insights personalizados das suas respostas de pesquisa com o Formbricks AI",
|
||||
"formbricks_ai_disable_success_message": "Formbricks AI desativado com sucesso.",
|
||||
"formbricks_ai_enable_success_message": "Formbricks AI ativado com sucesso.",
|
||||
"formbricks_ai_privacy_policy_text": "Ao ativar o Formbricks AI, você concorda com a versão atualizada",
|
||||
"from_your_organization": "da sua organização",
|
||||
"invitation_sent_once_more": "Convite enviado de novo.",
|
||||
"invite_deleted_successfully": "Convite deletado com sucesso",
|
||||
@@ -1332,6 +1293,14 @@
|
||||
"card_shadow_color": "cor da sombra do cartão",
|
||||
"card_styling": "Estilização de Cartão",
|
||||
"casual": "Casual",
|
||||
"caution_edit_duplicate": "Duplicar e editar",
|
||||
"caution_edit_published_survey": "Editar uma pesquisa publicada?",
|
||||
"caution_explanation_all_data_as_download": "Todos os dados, incluindo respostas anteriores, estão disponíveis para download.",
|
||||
"caution_explanation_intro": "Entendemos que você ainda pode querer fazer alterações. Aqui está o que acontece se você fizer:",
|
||||
"caution_explanation_new_responses_separated": "Novas respostas são coletadas separadamente.",
|
||||
"caution_explanation_only_new_responses_in_summary": "Apenas novas respostas aparecem no resumo da pesquisa.",
|
||||
"caution_explanation_responses_are_safe": "As respostas existentes permanecem seguras.",
|
||||
"caution_recommendation": "Editar sua pesquisa pode causar inconsistências de dados no resumo da pesquisa. Recomendamos duplicar a pesquisa em vez disso.",
|
||||
"caution_text": "Mudanças vão levar a inconsistências",
|
||||
"centered_modal_overlay_color": "cor de sobreposição modal centralizada",
|
||||
"change_anyway": "Mudar mesmo assim",
|
||||
@@ -1357,6 +1326,7 @@
|
||||
"close_survey_on_date": "Fechar pesquisa na data",
|
||||
"close_survey_on_response_limit": "Fechar pesquisa ao atingir limite de respostas",
|
||||
"color": "cor",
|
||||
"column_used_in_logic_error": "Esta coluna é usada na lógica da pergunta {questionIndex}. Por favor, remova-a da lógica primeiro.",
|
||||
"columns": "colunas",
|
||||
"company": "empresa",
|
||||
"company_logo": "Logo da empresa",
|
||||
@@ -1455,9 +1425,6 @@
|
||||
"follow_ups_new": "Novo acompanhamento",
|
||||
"follow_ups_upgrade_button_text": "Atualize para habilitar os Acompanhamentos",
|
||||
"form_styling": "Estilização de Formulários",
|
||||
"formbricks_ai_description": "Descreva sua pesquisa e deixe a Formbricks AI criar a pesquisa pra você",
|
||||
"formbricks_ai_generate": "gerar",
|
||||
"formbricks_ai_prompt_placeholder": "Insira as informações da pesquisa (ex.: tópicos principais a serem abordados)",
|
||||
"formbricks_sdk_is_not_connected": "O SDK do Formbricks não está conectado",
|
||||
"four_points": "4 pontos",
|
||||
"heading": "Título",
|
||||
@@ -1486,10 +1453,13 @@
|
||||
"invalid_youtube_url": "URL do YouTube inválida",
|
||||
"is_accepted": "Está aceito",
|
||||
"is_after": "é depois",
|
||||
"is_any_of": "É qualquer um de",
|
||||
"is_before": "é antes",
|
||||
"is_booked": "Tá reservado",
|
||||
"is_clicked": "É clicado",
|
||||
"is_completely_submitted": "Está completamente submetido",
|
||||
"is_empty": "Está vazio",
|
||||
"is_not_empty": "Não está vazio",
|
||||
"is_not_set": "Não está definido",
|
||||
"is_partially_submitted": "Parcialmente enviado",
|
||||
"is_set": "Está definido",
|
||||
@@ -1521,6 +1491,7 @@
|
||||
"no_hidden_fields_yet_add_first_one_below": "Ainda não há campos ocultos. Adicione o primeiro abaixo.",
|
||||
"no_images_found_for": "Nenhuma imagem encontrada para ''{query}\"",
|
||||
"no_languages_found_add_first_one_to_get_started": "Nenhum idioma encontrado. Adicione o primeiro para começar.",
|
||||
"no_option_found": "Nenhuma opção encontrada",
|
||||
"no_variables_yet_add_first_one_below": "Ainda não há variáveis. Adicione a primeira abaixo.",
|
||||
"number": "Número",
|
||||
"once_set_the_default_language_for_this_survey_can_only_be_changed_by_disabling_the_multi_language_option_and_deleting_all_translations": "Depois de definido, o idioma padrão desta pesquisa só pode ser alterado desativando a opção de vários idiomas e excluindo todas as traduções.",
|
||||
@@ -1572,6 +1543,7 @@
|
||||
"response_limits_redirections_and_more": "Limites de resposta, redirecionamentos e mais.",
|
||||
"response_options": "Opções de Resposta",
|
||||
"roundness": "redondeza",
|
||||
"row_used_in_logic_error": "Esta linha é usada na lógica da pergunta {questionIndex}. Por favor, remova-a da lógica primeiro.",
|
||||
"rows": "linhas",
|
||||
"save_and_close": "Salvar e Fechar",
|
||||
"scale": "escala",
|
||||
@@ -1597,6 +1569,7 @@
|
||||
"simple": "Simples",
|
||||
"single_use_survey_links": "Links de pesquisa de uso único",
|
||||
"single_use_survey_links_description": "Permitir apenas 1 resposta por link da pesquisa.",
|
||||
"six_points": "6 pontos",
|
||||
"skip_button_label": "Botão de Pular",
|
||||
"smiley": "Sorridente",
|
||||
"star": "Estrela",
|
||||
@@ -1741,11 +1714,6 @@
|
||||
"embed_on_website": "Incorporar no site",
|
||||
"embed_pop_up_survey_title": "Como incorporar uma pesquisa pop-up no seu site",
|
||||
"embed_survey": "Incorporar pesquisa",
|
||||
"enable_ai_insights_banner_button": "Ativar insights",
|
||||
"enable_ai_insights_banner_description": "Você pode ativar o novo recurso de insights para a pesquisa e obter insights baseados em IA para suas respostas em texto aberto.",
|
||||
"enable_ai_insights_banner_success": "Gerando insights para essa pesquisa. Por favor, volte em alguns minutos.",
|
||||
"enable_ai_insights_banner_title": "Pronto pra testar as ideias da IA?",
|
||||
"enable_ai_insights_banner_tooltip": "Por favor, entre em contato conosco pelo e-mail hola@formbricks.com para gerar insights para esta pesquisa",
|
||||
"failed_to_copy_link": "Falha ao copiar link",
|
||||
"filter_added_successfully": "Filtro adicionado com sucesso",
|
||||
"filter_updated_successfully": "Filtro atualizado com sucesso",
|
||||
@@ -1767,7 +1735,6 @@
|
||||
"impressions_tooltip": "Número de vezes que a pesquisa foi visualizada.",
|
||||
"includes_all": "Inclui tudo",
|
||||
"includes_either": "Inclui ou",
|
||||
"insights_disabled": "Insights desativados",
|
||||
"install_widget": "Instalar Widget do Formbricks",
|
||||
"is_equal_to": "É igual a",
|
||||
"is_less_than": "É menor que",
|
||||
@@ -1974,7 +1941,6 @@
|
||||
"alignment_and_engagement_survey_question_1_upper_label": "Entendimento completo",
|
||||
"alignment_and_engagement_survey_question_2_headline": "Sinto que meus valores estão alinhados com a missão e cultura da empresa.",
|
||||
"alignment_and_engagement_survey_question_2_lower_label": "Nenhum alinhamento",
|
||||
"alignment_and_engagement_survey_question_2_upper_label": "Totalmente alinhado",
|
||||
"alignment_and_engagement_survey_question_3_headline": "Eu trabalho efetivamente com minha equipe para atingir nossos objetivos.",
|
||||
"alignment_and_engagement_survey_question_3_lower_label": "Colaboração ruim",
|
||||
"alignment_and_engagement_survey_question_3_upper_label": "Colaboração excelente",
|
||||
@@ -1984,7 +1950,6 @@
|
||||
"book_interview": "Marcar entrevista",
|
||||
"build_product_roadmap_description": "Identifique a ÚNICA coisa que seus usuários mais querem e construa isso.",
|
||||
"build_product_roadmap_name": "Construir Roteiro do Produto",
|
||||
"build_product_roadmap_name_with_project_name": "Entrada do Roadmap do $[projectName]",
|
||||
"build_product_roadmap_question_1_headline": "Quão satisfeito(a) você está com os recursos e funcionalidades do $[projectName]?",
|
||||
"build_product_roadmap_question_1_lower_label": "Nada satisfeito",
|
||||
"build_product_roadmap_question_1_upper_label": "Super satisfeito",
|
||||
@@ -2167,7 +2132,6 @@
|
||||
"csat_question_7_choice_3": "Meio responsivo",
|
||||
"csat_question_7_choice_4": "Não tão responsivo",
|
||||
"csat_question_7_choice_5": "Nada responsivo",
|
||||
"csat_question_7_choice_6": "Não se aplica",
|
||||
"csat_question_7_headline": "Quão rápido temos respondido suas perguntas sobre nossos serviços?",
|
||||
"csat_question_7_subheader": "Por favor, escolha uma:",
|
||||
"csat_question_8_choice_1": "Essa é minha primeira compra",
|
||||
@@ -2175,7 +2139,6 @@
|
||||
"csat_question_8_choice_3": "De seis meses a um ano",
|
||||
"csat_question_8_choice_4": "1 - 2 anos",
|
||||
"csat_question_8_choice_5": "3 ou mais anos",
|
||||
"csat_question_8_choice_6": "Ainda não fiz uma compra",
|
||||
"csat_question_8_headline": "Há quanto tempo você é cliente do $[projectName]?",
|
||||
"csat_question_8_subheader": "Por favor, escolha uma:",
|
||||
"csat_question_9_choice_1": "Muito provável",
|
||||
@@ -2390,7 +2353,6 @@
|
||||
"identify_sign_up_barriers_question_9_dismiss_button_label": "Pular por enquanto",
|
||||
"identify_sign_up_barriers_question_9_headline": "Valeu! Aqui está seu código: SIGNUPNOW10",
|
||||
"identify_sign_up_barriers_question_9_html": "Valeu demais por tirar um tempinho pra compartilhar seu feedback \uD83D\uDE4F",
|
||||
"identify_sign_up_barriers_with_project_name": "Barreiras de Cadastro do $[projectName]",
|
||||
"identify_upsell_opportunities_description": "Descubra quanto tempo seu produto economiza para o usuário. Use isso para fazer upsell.",
|
||||
"identify_upsell_opportunities_name": "Identificar Oportunidades de Upsell",
|
||||
"identify_upsell_opportunities_question_1_choice_1": "Menos de 1 hora",
|
||||
@@ -2643,7 +2605,6 @@
|
||||
"product_market_fit_superhuman_question_3_choice_3": "Gerente de Produto",
|
||||
"product_market_fit_superhuman_question_3_choice_4": "Dono do Produto",
|
||||
"product_market_fit_superhuman_question_3_choice_5": "Engenheiro de Software",
|
||||
"product_market_fit_superhuman_question_3_headline": "Qual é a sua função?",
|
||||
"product_market_fit_superhuman_question_3_subheader": "Por favor, escolha uma das opções a seguir:",
|
||||
"product_market_fit_superhuman_question_4_headline": "Que tipo de pessoas você acha que mais se beneficiariam do $[projectName]?",
|
||||
"product_market_fit_superhuman_question_5_headline": "Qual é o principal benefício que você recebe do $[projectName]?",
|
||||
@@ -2665,7 +2626,6 @@
|
||||
"professional_development_survey_description": "Avalie a satisfação dos funcionários com oportunidades de desenvolvimento profissional.",
|
||||
"professional_development_survey_name": "Avaliação de Desenvolvimento Profissional",
|
||||
"professional_development_survey_question_1_choice_1": "Sim",
|
||||
"professional_development_survey_question_1_choice_2": "Não",
|
||||
"professional_development_survey_question_1_headline": "Você está interessado em atividades de desenvolvimento profissional?",
|
||||
"professional_development_survey_question_2_choice_1": "Eventos de networking",
|
||||
"professional_development_survey_question_2_choice_2": "Conferencias ou seminários",
|
||||
@@ -2755,7 +2715,6 @@
|
||||
"site_abandonment_survey_question_6_choice_3": "Mais variedade de produtos",
|
||||
"site_abandonment_survey_question_6_choice_4": "Design do site melhorado",
|
||||
"site_abandonment_survey_question_6_choice_5": "Mais avaliações de clientes",
|
||||
"site_abandonment_survey_question_6_choice_6": "outro",
|
||||
"site_abandonment_survey_question_6_headline": "Quais melhorias fariam você ficar mais tempo no nosso site?",
|
||||
"site_abandonment_survey_question_6_subheader": "Por favor, selecione todas as opções que se aplicam:",
|
||||
"site_abandonment_survey_question_7_headline": "Você gostaria de receber atualizações sobre novos produtos e promoções?",
|
||||
@@ -209,7 +209,6 @@
|
||||
"in_progress": "Em Progresso",
|
||||
"inactive_surveys": "Inquéritos inativos",
|
||||
"input_type": "Tipo de entrada",
|
||||
"insights": "Informações",
|
||||
"integration": "integração",
|
||||
"integrations": "Integrações",
|
||||
"invalid_date": "Data inválida",
|
||||
@@ -246,8 +245,6 @@
|
||||
"move_up": "Mover para cima",
|
||||
"multiple_languages": "Várias línguas",
|
||||
"name": "Nome",
|
||||
"negative": "Negativo",
|
||||
"neutral": "Neutro",
|
||||
"new": "Novo",
|
||||
"new_survey": "Novo inquérito",
|
||||
"new_version_available": "Formbricks {version} está aqui. Atualize agora!",
|
||||
@@ -289,11 +286,9 @@
|
||||
"please_select_at_least_one_survey": "Por favor, selecione pelo menos um inquérito",
|
||||
"please_select_at_least_one_trigger": "Por favor, selecione pelo menos um gatilho",
|
||||
"please_upgrade_your_plan": "Por favor, atualize o seu plano.",
|
||||
"positive": "Positivo",
|
||||
"preview": "Pré-visualização",
|
||||
"preview_survey": "Pré-visualização do inquérito",
|
||||
"privacy": "Política de Privacidade",
|
||||
"privacy_policy": "Política de Privacidade",
|
||||
"product_manager": "Gestor de Produto",
|
||||
"profile": "Perfil",
|
||||
"project": "Projeto",
|
||||
@@ -616,33 +611,6 @@
|
||||
"upload_contacts_modal_preview": "Aqui está uma pré-visualização dos seus dados.",
|
||||
"upload_contacts_modal_upload_btn": "Carregar contactos"
|
||||
},
|
||||
"experience": {
|
||||
"all": "Todos",
|
||||
"all_time": "Todo o tempo",
|
||||
"analysed_feedbacks": "Respostas de Texto Livre Analisadas",
|
||||
"category": "Categoria",
|
||||
"category_updated_successfully": "Categoria atualizada com sucesso!",
|
||||
"complaint": "Queixa",
|
||||
"did_you_find_this_insight_helpful": "Achou esta informação útil?",
|
||||
"failed_to_update_category": "Falha ao atualizar a categoria",
|
||||
"feature_request": "Pedido",
|
||||
"good_afternoon": "\uD83C\uDF24️ Boa tarde",
|
||||
"good_evening": "\uD83C\uDF19 Boa noite",
|
||||
"good_morning": "☀️ Bom dia",
|
||||
"insights_description": "Todos os insights gerados a partir das respostas de todos os seus inquéritos",
|
||||
"insights_for_project": "Informações sobre {projectName}",
|
||||
"new_responses": "Respostas",
|
||||
"no_insights_for_this_filter": "Sem informações para este filtro",
|
||||
"no_insights_found": "Não foram encontradas informações. Recolha mais respostas ao inquérito ou ative informações para os seus inquéritos existentes para começar.",
|
||||
"praise": "Elogio",
|
||||
"sentiment_score": "Pontuação de Sentimento",
|
||||
"templates_card_description": "Escolha um modelo ou comece do zero",
|
||||
"templates_card_title": "Meça a experiência do seu cliente",
|
||||
"this_month": "Este mês",
|
||||
"this_quarter": "Este trimestre",
|
||||
"this_week": "Esta semana",
|
||||
"today": "Hoje"
|
||||
},
|
||||
"formbricks_logo": "Logotipo do Formbricks",
|
||||
"integrations": {
|
||||
"activepieces_integration_description": "Conecte instantaneamente o Formbricks com apps populares para automatizar tarefas sem codificação.",
|
||||
@@ -1065,7 +1033,6 @@
|
||||
"website_surveys": "Inquéritos do Website"
|
||||
},
|
||||
"enterprise": {
|
||||
"ai": "Análise de IA",
|
||||
"audit_logs": "Registos de Auditoria",
|
||||
"coming_soon": "Em breve",
|
||||
"contacts_and_segments": "Gestão de contactos e segmentos",
|
||||
@@ -1103,13 +1070,7 @@
|
||||
"eliminate_branding_with_whitelabel": "Elimine a marca Formbricks e ative opções adicionais de personalização de marca branca.",
|
||||
"email_customization_preview_email_heading": "Olá {userName}",
|
||||
"email_customization_preview_email_text": "Esta é uma pré-visualização de email para mostrar qual logotipo será exibido nos emails.",
|
||||
"enable_formbricks_ai": "Ativar Formbricks IA",
|
||||
"error_deleting_organization_please_try_again": "Erro ao eliminar a organização. Por favor, tente novamente.",
|
||||
"formbricks_ai": "Formbricks IA",
|
||||
"formbricks_ai_description": "Obtenha informações personalizadas das suas respostas aos inquéritos com o Formbricks IA",
|
||||
"formbricks_ai_disable_success_message": "Formbricks AI desativado com sucesso.",
|
||||
"formbricks_ai_enable_success_message": "Formbricks IA ativado com sucesso.",
|
||||
"formbricks_ai_privacy_policy_text": "Ao ativar o Formbricks AI, você concorda com a atualização",
|
||||
"from_your_organization": "da sua organização",
|
||||
"invitation_sent_once_more": "Convite enviado mais uma vez.",
|
||||
"invite_deleted_successfully": "Convite eliminado com sucesso",
|
||||
@@ -1332,6 +1293,14 @@
|
||||
"card_shadow_color": "Cor da sombra do cartão",
|
||||
"card_styling": "Estilo do cartão",
|
||||
"casual": "Casual",
|
||||
"caution_edit_duplicate": "Duplicar e editar",
|
||||
"caution_edit_published_survey": "Editar um inquérito publicado?",
|
||||
"caution_explanation_all_data_as_download": "Todos os dados, incluindo respostas anteriores, estão disponíveis para download.",
|
||||
"caution_explanation_intro": "Entendemos que ainda pode querer fazer alterações. Eis o que acontece se o fizer:",
|
||||
"caution_explanation_new_responses_separated": "As novas respostas são recolhidas separadamente.",
|
||||
"caution_explanation_only_new_responses_in_summary": "Apenas novas respostas aparecem no resumo do inquérito.",
|
||||
"caution_explanation_responses_are_safe": "As respostas existentes permanecem seguras.",
|
||||
"caution_recommendation": "Editar o seu inquérito pode causar inconsistências de dados no resumo do inquérito. Recomendamos duplicar o inquérito em vez disso.",
|
||||
"caution_text": "As alterações levarão a inconsistências",
|
||||
"centered_modal_overlay_color": "Cor da sobreposição modal centralizada",
|
||||
"change_anyway": "Alterar mesmo assim",
|
||||
@@ -1357,6 +1326,7 @@
|
||||
"close_survey_on_date": "Encerrar inquérito na data",
|
||||
"close_survey_on_response_limit": "Fechar inquérito no limite de respostas",
|
||||
"color": "Cor",
|
||||
"column_used_in_logic_error": "Esta coluna é usada na lógica da pergunta {questionIndex}. Por favor, remova-a da lógica primeiro.",
|
||||
"columns": "Colunas",
|
||||
"company": "Empresa",
|
||||
"company_logo": "Logotipo da empresa",
|
||||
@@ -1455,9 +1425,6 @@
|
||||
"follow_ups_new": "Novo acompanhamento",
|
||||
"follow_ups_upgrade_button_text": "Atualize para ativar os acompanhamentos",
|
||||
"form_styling": "Estilo do formulário",
|
||||
"formbricks_ai_description": "Descreva o seu inquérito e deixe a Formbricks AI criar o inquérito para si",
|
||||
"formbricks_ai_generate": "Gerar",
|
||||
"formbricks_ai_prompt_placeholder": "Introduza as informações do inquérito (por exemplo, tópicos principais a abordar)",
|
||||
"formbricks_sdk_is_not_connected": "O SDK do Formbricks não está conectado",
|
||||
"four_points": "4 pontos",
|
||||
"heading": "Cabeçalho",
|
||||
@@ -1486,10 +1453,13 @@
|
||||
"invalid_youtube_url": "URL do YouTube inválido",
|
||||
"is_accepted": "É aceite",
|
||||
"is_after": "É depois",
|
||||
"is_any_of": "É qualquer um de",
|
||||
"is_before": "É antes",
|
||||
"is_booked": "Está reservado",
|
||||
"is_clicked": "É clicado",
|
||||
"is_completely_submitted": "Está completamente submetido",
|
||||
"is_empty": "Está vazio",
|
||||
"is_not_empty": "Não está vazio",
|
||||
"is_not_set": "Não está definido",
|
||||
"is_partially_submitted": "Está parcialmente submetido",
|
||||
"is_set": "Está definido",
|
||||
@@ -1521,6 +1491,7 @@
|
||||
"no_hidden_fields_yet_add_first_one_below": "Ainda não há campos ocultos. Adicione o primeiro abaixo.",
|
||||
"no_images_found_for": "Não foram encontradas imagens para ''{query}\"",
|
||||
"no_languages_found_add_first_one_to_get_started": "Nenhuma língua encontrada. Adicione a primeira para começar.",
|
||||
"no_option_found": "Nenhuma opção encontrada",
|
||||
"no_variables_yet_add_first_one_below": "Ainda não há variáveis. Adicione a primeira abaixo.",
|
||||
"number": "Número",
|
||||
"once_set_the_default_language_for_this_survey_can_only_be_changed_by_disabling_the_multi_language_option_and_deleting_all_translations": "Depois de definido, o idioma padrão desta pesquisa só pode ser alterado desativando a opção de vários idiomas e eliminando todas as traduções.",
|
||||
@@ -1572,6 +1543,7 @@
|
||||
"response_limits_redirections_and_more": "Limites de resposta, redirecionamentos e mais.",
|
||||
"response_options": "Opções de Resposta",
|
||||
"roundness": "Arredondamento",
|
||||
"row_used_in_logic_error": "Esta linha é usada na lógica da pergunta {questionIndex}. Por favor, remova-a da lógica primeiro.",
|
||||
"rows": "Linhas",
|
||||
"save_and_close": "Guardar e Fechar",
|
||||
"scale": "Escala",
|
||||
@@ -1597,6 +1569,7 @@
|
||||
"simple": "Simples",
|
||||
"single_use_survey_links": "Links de inquérito de uso único",
|
||||
"single_use_survey_links_description": "Permitir apenas 1 resposta por link de inquérito.",
|
||||
"six_points": "6 pontos",
|
||||
"skip_button_label": "Rótulo do botão Ignorar",
|
||||
"smiley": "Sorridente",
|
||||
"star": "Estrela",
|
||||
@@ -1741,11 +1714,6 @@
|
||||
"embed_on_website": "Incorporar no site",
|
||||
"embed_pop_up_survey_title": "Como incorporar um questionário pop-up no seu site",
|
||||
"embed_survey": "Incorporar inquérito",
|
||||
"enable_ai_insights_banner_button": "Ativar insights",
|
||||
"enable_ai_insights_banner_description": "Pode ativar a nova funcionalidade de insights para o inquérito para obter insights baseados em IA para as suas respostas de texto aberto.",
|
||||
"enable_ai_insights_banner_success": "A gerar insights para este inquérito. Por favor, volte a verificar dentro de alguns minutos.",
|
||||
"enable_ai_insights_banner_title": "Pronto para testar as perceções de IA?",
|
||||
"enable_ai_insights_banner_tooltip": "Por favor, contacte-nos em hola@formbricks.com para gerar insights para este inquérito",
|
||||
"failed_to_copy_link": "Falha ao copiar link",
|
||||
"filter_added_successfully": "Filtro adicionado com sucesso",
|
||||
"filter_updated_successfully": "Filtro atualizado com sucesso",
|
||||
@@ -1767,7 +1735,6 @@
|
||||
"impressions_tooltip": "Número de vezes que o inquérito foi visualizado.",
|
||||
"includes_all": "Inclui tudo",
|
||||
"includes_either": "Inclui qualquer um",
|
||||
"insights_disabled": "Informações desativadas",
|
||||
"install_widget": "Instalar Widget Formbricks",
|
||||
"is_equal_to": "É igual a",
|
||||
"is_less_than": "É menos que",
|
||||
@@ -1974,7 +1941,6 @@
|
||||
"alignment_and_engagement_survey_question_1_upper_label": "Compreensão completa",
|
||||
"alignment_and_engagement_survey_question_2_headline": "Sinto que os meus valores estão alinhados com a missão e a cultura da empresa.",
|
||||
"alignment_and_engagement_survey_question_2_lower_label": "Não alinhado",
|
||||
"alignment_and_engagement_survey_question_2_upper_label": "Completamente alinhado",
|
||||
"alignment_and_engagement_survey_question_3_headline": "Colaboro eficazmente com a minha equipa para alcançar os nossos objetivos.",
|
||||
"alignment_and_engagement_survey_question_3_lower_label": "Colaboração fraca",
|
||||
"alignment_and_engagement_survey_question_3_upper_label": "Excelente colaboração",
|
||||
@@ -1984,7 +1950,6 @@
|
||||
"book_interview": "Agendar entrevista",
|
||||
"build_product_roadmap_description": "Identifique a ÚNICA coisa que os seus utilizadores mais querem e construa-a.",
|
||||
"build_product_roadmap_name": "Construir Roteiro do Produto",
|
||||
"build_product_roadmap_name_with_project_name": "Contributo para o Roteiro de $[projectName]",
|
||||
"build_product_roadmap_question_1_headline": "Quão satisfeito está com as funcionalidades e características de $[projectName]?",
|
||||
"build_product_roadmap_question_1_lower_label": "Nada satisfeito",
|
||||
"build_product_roadmap_question_1_upper_label": "Extremamente satisfeito",
|
||||
@@ -2167,7 +2132,6 @@
|
||||
"csat_question_7_choice_3": "Um pouco responsivo",
|
||||
"csat_question_7_choice_4": "Não tão responsivo",
|
||||
"csat_question_7_choice_5": "Nada responsivo",
|
||||
"csat_question_7_choice_6": "Não aplicável",
|
||||
"csat_question_7_headline": "Quão responsivos temos sido às suas perguntas sobre os nossos serviços?",
|
||||
"csat_question_7_subheader": "Por favor, selecione um:",
|
||||
"csat_question_8_choice_1": "Esta é a minha primeira compra",
|
||||
@@ -2175,7 +2139,6 @@
|
||||
"csat_question_8_choice_3": "Seis meses a um ano",
|
||||
"csat_question_8_choice_4": "1 - 2 anos",
|
||||
"csat_question_8_choice_5": "3 ou mais anos",
|
||||
"csat_question_8_choice_6": "Ainda não fiz uma compra",
|
||||
"csat_question_8_headline": "Há quanto tempo é cliente de $[projectName]?",
|
||||
"csat_question_8_subheader": "Por favor, selecione um:",
|
||||
"csat_question_9_choice_1": "Extremamente provável",
|
||||
@@ -2390,7 +2353,6 @@
|
||||
"identify_sign_up_barriers_question_9_dismiss_button_label": "Saltar por agora",
|
||||
"identify_sign_up_barriers_question_9_headline": "Obrigado! Aqui está o seu código: SIGNUPNOW10",
|
||||
"identify_sign_up_barriers_question_9_html": "<p class=\"fb-editor-paragraph\" dir=\"ltr\"><span>Muito obrigado por dedicar tempo a partilhar feedback \uD83D\uDE4F</span></p>",
|
||||
"identify_sign_up_barriers_with_project_name": "Barreiras de Inscrição do $[projectName]",
|
||||
"identify_upsell_opportunities_description": "Descubra quanto tempo o seu produto poupa ao seu utilizador. Use isso para vender mais.",
|
||||
"identify_upsell_opportunities_name": "Identificar Oportunidades de Venda Adicional",
|
||||
"identify_upsell_opportunities_question_1_choice_1": "Menos de 1 hora",
|
||||
@@ -2643,7 +2605,6 @@
|
||||
"product_market_fit_superhuman_question_3_choice_3": "Gestor de Produto",
|
||||
"product_market_fit_superhuman_question_3_choice_4": "Proprietário do Produto",
|
||||
"product_market_fit_superhuman_question_3_choice_5": "Engenheiro de Software",
|
||||
"product_market_fit_superhuman_question_3_headline": "Qual é o seu papel?",
|
||||
"product_market_fit_superhuman_question_3_subheader": "Por favor, selecione uma das seguintes opções:",
|
||||
"product_market_fit_superhuman_question_4_headline": "Que tipo de pessoas acha que mais beneficiariam de $[projectName]?",
|
||||
"product_market_fit_superhuman_question_5_headline": "Qual é o principal benefício que recebe de $[projectName]?",
|
||||
@@ -2665,7 +2626,6 @@
|
||||
"professional_development_survey_description": "Avaliar a satisfação dos funcionários com as oportunidades de crescimento e desenvolvimento profissional.",
|
||||
"professional_development_survey_name": "Inquérito de Desenvolvimento Profissional",
|
||||
"professional_development_survey_question_1_choice_1": "Sim",
|
||||
"professional_development_survey_question_1_choice_2": "Não",
|
||||
"professional_development_survey_question_1_headline": "Está interessado em atividades de desenvolvimento profissional?",
|
||||
"professional_development_survey_question_2_choice_1": "Eventos de networking",
|
||||
"professional_development_survey_question_2_choice_2": "Conferências ou seminários",
|
||||
@@ -2755,7 +2715,6 @@
|
||||
"site_abandonment_survey_question_6_choice_3": "Mais variedade de produtos",
|
||||
"site_abandonment_survey_question_6_choice_4": "Design do site melhorado",
|
||||
"site_abandonment_survey_question_6_choice_5": "Mais avaliações de clientes",
|
||||
"site_abandonment_survey_question_6_choice_6": "Outro",
|
||||
"site_abandonment_survey_question_6_headline": "Que melhorias o incentivariam a permanecer mais tempo no nosso site?",
|
||||
"site_abandonment_survey_question_6_subheader": "Por favor, selecione todas as opções aplicáveis:",
|
||||
"site_abandonment_survey_question_7_headline": "Gostaria de receber atualizações sobre novos produtos e promoções?",
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user