Compare commits

...

28 Commits

Author SHA1 Message Date
Matti Nannt
78d8a0604f chore: update npm dependencies, update version numbers (#1853) 2024-01-04 14:08:10 +00:00
Anjy Gupta
e05cfaba5f feat: added survey response sharing feature (#1469)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
Co-authored-by: Johannes <johannes@formbricks.com>
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
2024-01-03 15:33:52 +00:00
Dhruwang Jariwala
0d74921233 fix: reload Verify email page (#1851)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2024-01-03 14:23:57 +00:00
Dhruwang Jariwala
60c7713aa0 feat: automatic next button label updation (#1848)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2024-01-03 14:11:06 +00:00
Zayd Krunz
c62f041819 style: Basic refactoring, a little tooltip fix, and some small language changes (#1850)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2024-01-03 10:30:14 +00:00
Zayd Krunz
7782196822 fix: Update webhook test endpoint to conform to standard webhooks (#1849) 2024-01-03 10:24:29 +00:00
Zayd Krunz
f964319ddb style: Fix typo in docs (#1842) 2024-01-02 11:57:56 +00:00
Anshuman Pandey
e0c17407e3 fix: ignore NEXT_NOT_FOUND error on sentry (#1837) 2024-01-02 11:42:47 +00:00
Dhruwang Jariwala
7f25bbc008 feat: adds confirm password field to password reset (#1845) 2024-01-02 11:40:55 +00:00
Johannes
ae530d710b fix: tweak above the fold wording (#1839) 2023-12-29 00:46:10 +00:00
Dhruwang Jariwala
08bdc7208e fix: updated cleanHtml script (#1836) 2023-12-29 00:26:27 +00:00
Dhruwang Jariwala
224ba2ea22 fix: delayed survey saving (#1838) 2023-12-29 00:10:19 +00:00
Johannes
8a4ceae38c fix: object fit for logo on welcome card (#1835)
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
2023-12-28 06:43:28 +00:00
Dhruwang Jariwala
d91e1cc7ea fix: background image issue (#1829)
Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
2023-12-28 01:27:24 +00:00
Johannes
8896cbcd87 fix: tweak rating UI after fix (#1834) 2023-12-27 18:57:17 +00:00
Dhruwang Jariwala
5e1822c9e6 fix: rating question alignment (#1833) 2023-12-27 18:06:37 +00:00
Elie Steinbock
1b69560e50 docs: Add Inbox Zero as an OSS friend (#1615)
Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
2023-12-27 02:41:14 +00:00
Dhruwang Jariwala
b28a4e72d8 fix: logic jump issues (#1830) 2023-12-27 02:29:29 +00:00
Sushant
8694c371af fix: make template page keyboard accessible (#1828) 2023-12-26 01:57:42 +00:00
Dhruwang Jariwala
359da760f7 fix: scaling issues (#1825)
Co-authored-by: review-agent-prime[bot] <147289438+review-agent-prime[bot]@users.noreply.github.com>
2023-12-24 12:43:49 +00:00
Matti Nannt
044080fee9 chore: increase batch size of weekly summary team calls (#1827) 2023-12-23 18:49:14 +00:00
Olasunkanmi Balogun
8a7d498a26 chore: add feeback app contest article (#1818)
Co-authored-by: Johannes <johannes@formbricks.com>
Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
2023-12-22 22:20:27 +00:00
Johannes
82f916d86b fix: PIN survey caused faulty layout due to background (#1826) 2023-12-22 21:39:16 +00:00
Shubham Palriwala
6ac48a26bb fix: revalidate invite cache even if email delivery fails (#1823) 2023-12-22 12:30:40 +00:00
Shubham Palriwala
ab22c0297e feat: role management is only allowed on paid inAppSurveys plan (#1824) 2023-12-22 12:30:03 +00:00
Dhruwang Jariwala
1ce02edc1b fix: other option (#1821) 2023-12-22 11:59:34 +00:00
Matti Nannt
d36de1e54f fix: remove comments in env files (#1817) 2023-12-21 15:39:30 +00:00
Matti Nannt
15c91b798d chore: add user properties to posthog integration (#1814) 2023-12-21 13:58:55 +00:00
109 changed files with 4390 additions and 1839 deletions

View File

@@ -1,4 +1,3 @@
/*
########################################################################
# ------------ MANDATORY (CHANGE ACCORDING TO YOUR SETUP) ------------#
########################################################################
@@ -138,5 +137,3 @@ ENTERPRISE_LICENSE_KEY=
# set to 1 to skip onboarding for new users
# ONBOARDING_DISABLED=1
*/

View File

@@ -218,7 +218,7 @@ This set of API can be used to
<CodeGroup title="Request" tag="DELETE" label="/api/v1/client/responses/<response-id>">
```bash {{ title: 'cURL' }}
curl -X DELETE https://app.formbricks.com/api/v1/management/resposnes/<response-id> \
curl -X DELETE https://app.formbricks.com/api/v1/management/responses/<response-id> \
--header 'x-api-key: <your-api-key>'
```

View File

@@ -6,7 +6,7 @@ import FlixbusLogo from "@/images/clients/flixbus-white.svg";
import NILogoDark from "@/images/clients/niLogoDark.svg";
import NILogoLight from "@/images/clients/niLogoWhite.svg";
import AnimationFallback from "@/public/animations/opensource-xm-platform-formbricks-fallback.png";
import { ChevronRightIcon } from "@heroicons/react/24/outline";
import { ShieldCheckIcon, StarIcon } from "@heroicons/react/24/outline";
import { usePlausible } from "next-plausible";
import Image from "next/image";
import { useRouter } from "next/router";
@@ -21,26 +21,31 @@ export const Hero: React.FC = ({}) => {
return (
<div className="relative">
<div className="px-4 pb-20 pt-16 text-center sm:px-6 lg:px-8 lg:pb-32 lg:pt-20">
<a
href="https://formbricks.com/github"
target="_blank"
className="border-brand-dark xs:text-sm animate-bounce rounded-full border px-4 py-1.5 text-xs text-slate-500 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-slate-800">
We&apos;re Open Source - Star us on GitHub
<ChevronRightIcon className="mb-1 ml-1 inline h-4 w-4 text-slate-300" />
</a>
<div className="xs:text-sm flex items-center justify-center space-x-4 divide-x-2 text-xs text-slate-600">
<p>
<ShieldCheckIcon className="mb-1 inline h-4 w-4" /> Privacy-first
</p>
<a href="https://formbricks.com/github" target="_blank" className="hover:text-slate-800">
<StarIcon className="mb-1 ml-3 mr-1 inline h-4 w-4" />
Star us on GitHub
</a>
</div>
<h1 className="mt-10 text-3xl font-bold tracking-tight text-slate-800 sm:text-4xl md:text-5xl dark:text-slate-200">
<span className="xl:inline">Privacy-first Experience Management</span>
<span className="xl:inline">
Turn customer insights
<br />
into irresistible experiences
</span>
</h1>
<p className="xs:max-w-none mx-auto mt-3 max-w-xs text-base text-slate-500 sm:text-lg md:mt-5 md:text-xl dark:text-slate-400">
Turn customer insights into irresistible experiences {" "}
<span className="decoration-brand-dark underline underline-offset-4">all privacy-first.</span>
<p className="xs:max-w-none mx-auto mt-3 max-w-xs text-balance text-base text-slate-500 sm:text-lg md:mt-5 md:text-xl dark:text-slate-400">
Formbricks is an Experience Management Suite built on the largest open source survey stack
worldwide. Gracefully gather feedback at every step of the customer journey to{" "}
<span className="decoration-brand-dark underline underline-offset-4">
know what your customers need.
</span>
</p>
<div className="mx-auto mt-5 max-w-2xl items-center px-4 sm:flex sm:justify-center md:mt-6 md:space-x-8 md:px-0">
<p className="hidden whitespace-nowrap pt-3 text-xs text-slate-400 md:block dark:text-slate-500">
Trusted by
</p>
<div className="grid grid-cols-4 items-center gap-6 pt-2 md:gap-8">
<Image
src={FlixbusLogo}
@@ -86,22 +91,22 @@ export const Hero: React.FC = ({}) => {
/>
</div>
</div>
<div className="hidden pt-10 md:block">
<div className="hidden pt-14 md:block">
<Button
variant="highlight"
className="mr-3 px-6"
onClick={() => {
router.push("https://app.formbricks.com/auth/signup");
plausible("Hero_CTA_CreateSurvey");
plausible("Hero_CTA_GetStartedItsFree");
}}>
Get started
Get Started, it&apos;s Free
</Button>
<Button
variant="secondary"
className="px-6"
onClick={() => {
router.push("https://formbricks.com/github");
/* plausible("Hero_CTA_LaunchDemo"); */
plausible("Hero_CTA_ViewGitHub");
}}>
View Code on GitHub
</Button>

View File

@@ -1,4 +1,5 @@
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
import AuthorOla from "@/images/blog/ola-content-writer.png";
import Image from "next/image";
interface AuthorBoxProps {
@@ -6,14 +7,15 @@ interface AuthorBoxProps {
title: string;
date: string;
duration: string;
author: string;
}
export default function AuthorBox({ name, title, date, duration }: AuthorBoxProps) {
export default function AuthorBox({ name, title, date, duration, author }: AuthorBoxProps) {
return (
<div className="mb-8 flex items-center space-x-4 rounded-lg border border-slate-200 bg-slate-100 px-6 py-3 dark:border-slate-700 dark:bg-slate-800">
<Image
className="m-0 rounded-full"
src={AuthorJohannes}
src={author === "Johannes" ? AuthorJohannes : AuthorOla}
alt={name}
width={45}
height={45}

View File

@@ -280,9 +280,9 @@ export default function Header() {
Pricing
</Link>
<Link
href="/concierge"
href="/community"
className="text-sm font-medium text-slate-400 hover:text-slate-700 lg:text-base dark:hover:text-slate-300">
Concierge
Community
</Link>
<Link
href="/docs"
@@ -331,7 +331,7 @@ export default function Header() {
router.push("https://app.formbricks.com");
plausible("NavBar_CTA_Login");
}}>
Go to app
Get started
</Button>
</div>
</div>
@@ -391,7 +391,7 @@ export default function Header() {
<hr className="mx-20 my-6 opacity-25" />
</div>
)}
<Link href="/concierge">Concierge</Link>
<Link href="/community">Community</Link>
<Link href="/pricing">Pricing</Link>
<Link href="/docs">Docs</Link>
<Link href="/blog">Blog</Link>

View File

@@ -60,7 +60,7 @@ export default function LayoutMdx({ meta, children }: Props) {
)}
</header>
)}
<Prose className="prose-h2:text-2xl prose-h2:mt-4 prose-p:text-base prose-p:mb-4 prose-h3:text-xl prose-a:text-slate-900 prose-a:hover:text-slate-900 prose-a:text-decoration-brand prose-a:not-italic ">
<Prose className="prose-h2:text-2xl prose-li:text-base prose-h2:mt-4 prose-p:text-base prose-p:mb-4 prose-h3:text-xl prose-a:text-slate-900 prose-a:hover:text-slate-900 prose-a:text-decoration-brand prose-a:not-italic ">
{children}
</Prose>
</article>

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View File

@@ -38,8 +38,8 @@ export function cleanHtml(str: string): string {
function isPossiblyDangerous(name: string, value: string): boolean {
let val = value.replace(/\s+/g, "").toLowerCase();
if (
["src", "href", "xlink:href"].includes(name) &&
(val.includes("javascript:") || val.includes("data:"))
["src", "href", "xlink:href", "srcdoc"].includes(name) &&
(val.includes("javascript:") || val.includes("data:") || val.includes("<script>"))
) {
return true;
}
@@ -57,10 +57,14 @@ export function cleanHtml(str: string): string {
// Loop through each attribute
// If it's dangerous, remove it
let atts = elem.attributes;
for (let i = 0; i < atts.length; i++) {
for (let i = atts.length - 1; i >= 0; i--) {
let { name, value } = atts[i];
if (!isPossiblyDangerous(name, value)) continue;
elem.removeAttribute(name);
if (isPossiblyDangerous(name, value)) {
elem.removeAttribute(name);
} else if (name === "srcdoc") {
// Recursively sanitize srcdoc content
elem.setAttribute(name, cleanHtml(value));
}
}
}

View File

@@ -92,6 +92,12 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
"HTMX is a dependency-free JavaScript library that allows you to access AJAX, CSS Transitions, WebSockets, and Server Sent Events directly in HTML.",
href: "https://htmx.org",
},
{
name: "Inbox Zero",
description:
"Inbox Zero makes it easy to clean up your inbox and reach inbox zero fast. It provides bulk newsletter unsubscribe, cold email blocking, email analytics, and AI automations.",
href: "https://getinboxzero.com",
},
{
name: "Infisical",
description:

View File

@@ -0,0 +1,254 @@
import AuthorBox from "@/components/shared/AuthorBox";
import LayoutMdx from "@/components/shared/LayoutMdx";
import AuthorOla from "@/images/blog/ola-content-writer.png";
import Image from "next/image";
import Appcues from "./best-feedback-app-2024-appcues-feedback-app.png";
import Header from "./best-feedback-app-2024-free-in-app-header-image.webp";
import Formbricks from "./formbricks-best-open-source-feedback-app.png";
import InAppFeedback from "./in-app-feedback-tool-editor-open-source.webp";
import Pendo from "./pendo-best-digital-experience-feedback-app.png";
import Qualaroo from "./qualaroo-best-user-feedback-software.png";
import Survicate from "./survicate-best-survey-feedback-app.png";
import Userpilot from "./userpilot-best-feedback-in-app-tool.png";
export const meta = {
title: "Feedback App Contest: 6 Candidates, 1 Winner (and how to use it)",
description:
"We looked at the best in app feedback tools 2024 and found a clear winner. Gather feedback in your app for free with Formbricks.",
date: "2023-12-21",
publishedTime: "2023-12-21T12:00:00",
authors: ["Olasunkanmi Balogun"],
section: "Feedback Apps",
tags: ["Feedback Apps", "Formbricks", "Userpilot", "Pendo", "Appcues", "Survicate", "Qualaroo"],
};
<Image src={Header} alt="Gather in app feedback for free with these 6 tools." className="w-full rounded-lg" />
<AuthorBox
name="Olasunkanmi Balogun"
title="Content Writer"
date="December 21st, 2023"
duration="15"
author={"Ola"}
/>
_Only when you understand your users and customers will they come back and tell others about your service. AI makes it easier and easier to crank out code, but are you building the right thing?_
Only your users and customers can tell you.
## Whats in-app feedback, and why is it 6x better?
In-app feedback is a method of collecting feedback from users while they are using the app. Instead of redirecting users to external platforms or surveys, in-app feedback methods enable users to share their thoughts seamlessly.
“Why is it better?” you ask. Well, first of all, in-app surveys have a 6x higher response rate than emailed-out surveys. So to get the same amount of insight, you have to bother a lot fewer people. Orrr from the same number of people, you can harvest a LOT more insights.
Additionally, you get feedback directly when a user experiences your app, instead of pinging them hours later when they are in a completely different context. So in-app feedback gives you **more insights of higher quality while having to ask less often**.
<Image
src={InAppFeedback}
alt="Open Source and free: Formbricks is the new kid on the block."
className="w-full rounded-lg"
/>
### How to gather in-app feedback
Depending on the tools you use, you can collect in-app feedback through the following methods:
- **Chatbots**: Chatbots can be used to collect feedback conversationally and provide real-time support to users.
- **Embedded forms**: Embedded forms can be used to collect feedback on specific pages or workflows within the app. The huge advantage is that they seamlessly integrate into the existing UI, avoiding survey fatigue completely.
- **Feedback widget**: Feedback widgets are a valuable tool for app developers and website owners who want to gather user insights and improve their products or services. They are small snippets of code installed on the entire website.
### Picking the right in-app feedback tool
Here are some of the things to look for in an in-app feedback tool. According to these 7 criteria, we will rate the 6 tools we found most useful:
1. **Pre-segmentation & Targeting 🎯**
You want to avoid asking everyone the same questions. The ability to target specific segments differs widely.
2. **Native Look & Feel 😍**
Youve spent a lot of time crafting that UX and you likely dont wanna ruin it with a popup survey. Am I right?
3. **Insights Assistance** 🧠
Here we look at to what extent the tool helps you get the insights you need and how to share them with the right people in your team.
4. **Integrations with third-party tools 🧩**
How well can you implement the tool in your existing product stack?
5. **Extensibility 🛠️**
Wanna do more? We look at how much you can customize and extend each of the tools.
6. **Pricing 💸**
How expensive is it and is it worth it?
7. **Privacy and Compliance 🔒**
Can you use it with full GDPR, CCPA, or even HIPAA compliance?
The next section will explore 6 of the best tools to gather user feedback and rate them on the criteria listed above
## Meet the contenders: The best tools to gather user feedback
Among the plethora of tools available in todays market, this section will guide you through a curated selection of top contenders in the world of user feedback collection tools. Each is designed to empower you with the knowledge to refine your products and elevate user satisfaction.
### 1. Formbricks
<Image
src={Formbricks}
alt="Formbricks is a free and open source survey software for in app micro surveys. Ask any user segment at any point in the user journey."
className="w-full rounded-lg"
/>
[Formbricks](http://formbricks.com/) is an open-source micro-survey solution designed to gather specific user feedback at the perfect moment in their journey. It allows you to create and deploy targeted surveys within your app without disrupting the user experience.
Formbricks boasts a user-friendly interface, making it easy for both technical and non-technical users to create and deploy micro-surveys. The no-code editor removes the need for coding knowledge, while the intuitive design guides you through the process. Being the only open-source feedback app out there, privacy-focused users will love this!
| Score | Details |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 🎯🎯🎯🎯 | **Pre-segmentation & Targeting:** Pre-segmentation and targeting of user segments with Formbricks is almost complete. You can send user attributes and user events to Formbricks and build segments based on that. In the next few weeks, the Formbricks team will ship [Advanced Targeting](https://github.com/formbricks/formbricks/pull/758). It gives you granular control to target any group of users even down to individual users. |
| 😍😍😍😍 | **Native Look & Feel:** Formbricks supports several means of styling the survey to match the existing UI. You can change the main color of the survey and in which corner it appears. As an engineer, you can add a stylesheet to change every element in the survey. The team is currently working on a UI to make this possible with no code as well. In the medium term, Formbricks will provide an open-source SDK to embed surveys inline, instead of having them pop over. This depth of embedding is only possible due to Formbricks open-source approach. |
| 🧠🧠🧠 | **Insights Assistance:** Formbricks provides base analytics with a few insightful add-ons like the Drop Off Analyzer and measuring time to completion for each question. The Formbricks team is scoping out AI-supported insight generation as well as custom dashboards for Q1 2024. |
| 🧩🧩🧩🧩 | **Integrations with third-party tools:** Formbricks packs direct integrations into Google Sheets, Airtable, Zapier, and Make.com. Currently in progress are a Notion and a Slack integration. With webhooks or platforms like Zapier, you can send your data exactly where you need it! |
| 🛠️🛠️🛠️🛠️🛠️ | **Extensibility:** Formbricks is the only open source solution out there. Their open approach allows you to build anything on top, below, or around it that you need - your imagination is the limit. |
| <p className="whitespace-nowrap"> 💸💸💸💸💸 </p> | **Pricing:** Formbricks is completely free to get started with, you dont even need a credit card. If you want to unlock advanced user targeting, multi-language forms, and role management, you can add your credit card and still have a free contingent of 250 responses per month. After that, you are charged $0.15 per submission - super fair! |
| 🔒🔒🔒🔒🔒 | **Privacy and Compliance:** Formbricks Cloud is hosted in Germany with full GDPR as well as CCPA compliance. Since Formbricks is easily self-hostable, keeping full control over your data is smooth. At this point, Formbricks does not yet provide HIPAA or SOC-2 compliance, but it is on the roadmap for 2024. |
**Overall**, Formbricks is a very promising solution that packs a lot of useful features and gets better by the day. The open-source approach guarantees maximum data ownership and control. Worth checking out!
Lets have a look at Userpilot!
### 2. Userpilot
<Image
src={Userpilot}
alt="Userpilot helps product teams deliver personalized in-app experiences to increase growth metrics at every stage of the user journey."
className="w-full rounded-lg"
/>
Userpilot empowers you to engage and understand your users like never before. Through its comprehensive suite of features, Userpilot helps you gather valuable feedback, personalize the user experience, and ultimately increase growth metrics.
With Userpilot, you can get started quickly with ready-made templates for common use cases.
| Score | Details |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p className="whitespace-nowrap">🎯🎯🎯🎯🎯</p> | **Pre-segmentation & Targeting:** Userpilot's pre-segmentation and targeting capabilities empower you to create personalized user experiences based on shared characteristics that resonate with your audience. You can segment your users based on user attributes, customer behaviors, customer preferences, and lead scoring. |
| 😍😍😍 | **Native Look & Feel:** When you create a flow with Userpilot, you also have full control over the theme of the flow. The theme controls different general appearance aspects such as fonts, background colors, and buttons. However, it always feels “added” instead of being a native part of the experience. |
| 🧠🧠🧠🧠 | **Insights Assistance:** Userpilot offers quite a range of insights on its own. You can get insights into product usage data, user engagement data, and user sentiment data. You can also analyze your product data with third-party integrations. |
| 🧩🧩🧩🧩🧩 | **Integrations with third-party tools:** You can use Userpilot with other apps in your stack. You can integrate with tools like Segment, Amplitude, Google Analytics, Google Tag Manager, Heap, Intercom, Kissmetrics, and Mixpanel. |
| 🛠️🛠️🛠️ | **Extensibility:** The extensibility is fairly limited. Userpilot does not support custom integrations or other more advanced forms of customizability. |
| 💸💸💸 | **Pricing:** Userpilot comes at a starting price of $249 / month going up to $499 if you want advanced targeting or GDPR-compliant hosting in the EU. Even though it packs a lot of great features, it seems somewhat pricey over the long run. |
| 🔒🔒 | **Privacy and Compliance:** Userpilot cannot be self-hosted. The GDPR-compliant EU cloud is only available in the $500/month plan. If you need SOC-2, you have to go with the Enterprise plan. |
**Overall**, Userpilot empowers data-driven decisions and continuous improvement, helping you to increase user engagement and reduce churn. Userpilot offers a free plan to determine if the high price point is justified.
Next up: Pendo 👇
### 3. Pendo
<Image
src={Pendo}
alt="Pendo improves the apps you build, buy, and sell so you can deliver better customer and employee experiences."
className="w-full rounded-lg"
/>
Pendo does a lot more than gathering feedback (product analytics, in-app guides, roadmaps). Once you have implemented it, you can run NPS surveys to measure your users' satisfaction with your application and gather actionable insights for driving app success. Its comprehensive suite of tools helps you understand user behavior, collect valuable feedback, and optimize your app for maximum impact.
| Score | Details |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p className="whitespace-nowrap">🎯🎯🎯🎯🎯</p> | **Pre-segmentation & Targeting:** Since Pendo packs analytics, you get to leverage the same events and segments youre using to analyze your cohorts. With Pendo, you can also divide your user base by behavioral, demographic, or customer attributes. The granular segmentation lets you run the NPS survey with users who experienced the true value of your product. |
| 😍😍😍 | **Native Look & Feel:** Pendo enables you to style your user-facing UI by setting the formatting and layouts your team can use to communicate with the user base. This helps you keep in line with your brand identity. While the styling capabilities are comprehensive, you won't be able to get a 100% native look & feel of your user-facing components. |
| 🧠🧠🧠 | **Insights Assistance:** Pendo provides analytics tools that enable you to evaluate product usage and visualize users paths. The analytics are informative and easily accessible. If needed, you can also combine Pendo with other third-party tools for a deeper analysis. |
| 🧩🧩🧩🧩🧩 | **Integrations with third-party tools:** You can connect Pendo to other apps in your stack for data integration and data syncing. You can also integrate with CRMs like Salesforce. Given all these integrations you should be able to embed Pendo nicely in your current product stack. |
| 🛠️🛠️🛠️ | **Extensibility:** Pendo does not support customization or custom integration well. There is a Developer Center where you can get the most information you need to build your own integration. |
| 💸💸💸 | **Pricing:** Pendo only provides pricing information on request. Different sources shared different estimations but it seems to start somewhere around $6000 / year. |
| 🔒🔒🔒🔒🔒 | **Privacy and Compliance:** Pendo cannot be used on-premise, so the data resides within the Pendo Cloud. It comes with GDPR, CCPA, SOC-2, and HIPAA compliance if required - thats great! |
**Overall**, Pendo stands out as a powerful and customizable platform, empowering you to create exceptional user experiences, gather valuable insights, and optimize your app for success.
Lets have a look at Appcues now ⬇️
### 4. Appcues
<Image
src={Appcues}
alt="Appcues helps you personalize in-app experiences that meet your customers where and when they need it most."
className="w-full rounded-lg"
/>
Appcues is a versatile user onboarding and engagement platform that offers a seamless experience for both users and developers. It provides a comprehensive toolkit that offers a way to streamline the journey from onboarding to feedback collection, providing valuable insights to refine your app. While it lets you run NPS surveys.
| Score | Details |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 🎯🎯🎯🎯 | **Pre-segmentation & Targeting:** Appcues enables you to target specific segments with the experiences with the flows or NPS surveys you have created. You can segment your experiences based on new users, including or excluding a subset of users. |
| 😍😍😍 | **Native Look & Feel:** Appcues is somewhat versatile in customizations. However, even after adding your brand color, the user-facing components will always look like Appcues. It feels bolted on top of your app instead of being a native part of it. |
| <p className="whitespace-nowrap">🧠🧠🧠🧠</p> | **Insights Assistance:** Appcues lets you track key product events to better understand user behavior, all with data visualizations—no coding needed. The insights dashboard is fairly comprehensive giving you a good insight into what's happening. |
| 🧩🧩🧩🧩 | **Integrations with third-party tools:** You can send data exactly where you need it with third-party integrations which include Fullstory, Google Analytics, Logrocket, and Mixpanel among others. |
| 🛠️🛠️🛠️ | **Extensibility:** Appcues offers some APIs for basic integrations, but they might not provide the level of control and flexibility required for more complex integrations or custom workflows. This can be frustrating for developers who need to work around API limitations to achieve desired functionality. |
| 💸💸 | **Pricing:** Appcues pricing starts at $249/month for smaller apps (2.500 users) jumping to $10.500/year for the Growth plan (only yearly plan available). In the Growth plan, you get access to the majority of the really cool features. Surveying in mobile apps (iOS and Android) always costs an additional premium. |
| 🔒🔒🔒 | **Privacy and Compliance:** Appcues cannot be used on-premise, so the data resides within the Appcues Cloud. It comes with GDPR and CCPA compliance and requires additional work on the customer side for HIPAA compliance. |
**Overall**, Appcues empowers you to design personalized tooltips, tours, and modals to guide users, highlight key features, and enhance their initial journey. It can be used to gather feedback in-app but it isnt built for that.
The next one has a great value for money: Survicate 💰
### 5. Survicate
<Image
src={Survicate}
alt="Survicate lets you create engaging surveys with ease."
className="w-full rounded-lg"
/>
Survicate is a powerful feedback and survey tool designed for simplicity. Users can effortlessly create and deploy surveys through an intuitive interface, with features like drag-and-drop survey builders and customizable templates. Survicate powers email, link, website, and mobile app survey.
| Score | Details |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 🎯🎯🎯 | **Pre-segmentation & Targeting:** Survicate tracks behavior in a very useful and product-agnostic way. This means that you can perform quite granular segmentation without having to set up tracking for custom events or actions. While this significantly shortens the setup time, you might not reach the exact segment you want with Survicate's built-in targeting. |
| 😍😍😍😍 | **Native Look & Feel:** Survicate enables you to design your surveys quite flexibly. You can change colors, fonts and even add custom CSS to get exactly the look and feel you are looking for. |
| 🧠🧠🧠🧠🧠 | **Insights Assistance:** Survicate has a powerful analytics dashboard. They offer custom visualizations like Word Cloud for question types where it makes sense to display one. Overall, the insights section offers a lot of depth - our favorite in this comparison 👑 |
| 🧩🧩🧩🧩🧩 | **Integrations with third-party tools:** Survicate supports a significant amount of integrations. They offer two-way sync with all relevant customer data platforms as well as one-click integrations with most other common productivity and marketing tools. |
| 🛠️🛠️ | **Extensibility:** Like most proprietary software, Survicate is not really extensible nor customizable. They offer data export via API but that's about it. |
| <p className="whitespace-nowrap">💸💸💸💸💸</p> | **Pricing:** Survicate has great value for money. You get most of the standalone survey products for $50/month. However, this does not include website or mobile app surveys, which start at $112/month for 1000 responses. Anything above is on request. |
| 🔒🔒 | **Privacy and Compliance:** As a European company, Survicate is fully GDPR compliant. There is no information about CCPA and it is not HIPAA compliant, as per their support page. Since self-hosting is not an option, Survicate cannot be used by a relevant segment of users. |
**Overall**, Survicate offers a lot of feature depth. Having been around for over 10 years, the team keeps shipping! It comes at a fair price and is versatile enough to cover most surveying use cases. The only downside is a lack of compliance support so big companies won't be able to use it.
### 6. Qualaroo
<Image
src={Qualaroo}
alt="Qualaroo simplifies the process of collecting user feedback with surveys"
className="w-full rounded-lg"
/>
Qualaroo empowers you to gather valuable user feedback through targeted "Nudges" that appear at key moments on your website. This unobtrusive approach minimizes user disruption while effectively capturing feedback that drives user experience improvements and product success.
| Score | Details |
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 🎯🎯🎯🎯 | **Pre-segmentation & Targeting:** Qualaroo offers various pre-segmentation methods to help you target your surveys and gather the most relevant feedback from specific user segments. These methods include user attributes and website activity like click and scroll depth, page targeting, and exit intent among others. |
| 😍😍 | **Native Look & Feel:** Qualaroo provides you with an option to style your nudges - whether light or dark palettes. While they offer a range of options, the surveys tend to look added to the UI. |
| 🧠🧠🧠🧠 | **Insights Assistance:** Qualaroo analytics and insights help you view detailed reports on survey responses, including answer choices, open-ended feedback, and sentiment analysis. You can also segment responses by user demographics, website activity, and other criteria to gain deeper insights into specific user groups. They also incorporate some AI to shorten the time to insight. |
| 🧩🧩🧩🧩 | **Integrations with third-party tools:** Qualaroo integrates with various third-party tools including Slack and Zapier. |
| 🛠️ | **Extensibility:** Since its internal workings are not readily accessible (as its not open-sourced), developers are limited in their ability to augment the platform's core functionality and tailor it to specific needs. Qualaroo does not provide APIs for developers to build on top of it. |
| 💸💸💸 | **Pricing:** Qualaroo is pretty cheap for small amounts of responses. You can access the complete product for $19.99 with 100 responses/month. If you need more, you need to reach out to their sales team. |
| <p className="whitespace-nowrap">🔒🔒🔒🔒</p> | **Privacy and Compliance:** Qualaroo cannot be self-hosted, so the data resides within the US-based cloud. The privacy compliance information is not super comprehensive, but it seems that Qualaroo supports GDPR, CCPA, and even HIPAA compliance. |
**Overall**, Qualaroo is a somewhat dated but solid solution to run surveys on public websites.
<div className="hidden sm:block">
Now that we've explored the key features and functionalities of each app, let's take a step back and see how they compare in a side-by-side format:
| Features | Formbricks | Userpilot | Pendo | Appcues | Survicate | Qualaroo |
| --------------------------------- | ---------- | --------- | ----- | ------- | --------- | -------- |
| Pre-segmentation and targeting 🎯 | 🟡🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟡 |
| Native look and feel 😍 | 🟢 | 🟡 | 🟡 | 🟡 | 🟢 | 🔴 |
| Insights 🧠 | 🟡🟢 | 🟢 | 🟢 | 🟡 | 🟢 | 🟢 |
| Integrations 🧩 | 🟡 | 🟢 | 🟢 | 🟢 | 🟢 | 🟡 |
| Extensibility 🛠️ | 🟢 | 🟡 | 🟡 | 🔴 | 🔴 | 🔴 |
| Pricing 💸 | 🟢 | 🟡 | 🟡 | 🔴 | 🟢 | 🟡 |
| Privacy 🔒 | 🟢 | 🟡 | 🟢 | 🟡 | 🔴 | 🟡 |
</div>
# Whos the winner here? 🤓
Its a tough race and it depends on what youre looking for. If youre all about gathering feedback from many different sources and channels, **Survicate is your best shot.** Its a complete survey tool allowing pretty much any survey use case and it comes at a very fair price. The only downside is privacy compliance.
If **extensibility, data privacy,** and pricing are high on your list, **give Formbricks a squeeze**. The team built out an impressive amount of surveying functionality for apps, websites, emails, and link surveys in less than a year. Being the only open source solution available, its definitely worth considering.
[Try Formbricks](https://app.formbricks.com/auth/signup) today - it's free! Measure your user or customer experience without limits.
export default ({ children }) => <LayoutMdx meta={meta}>{children}</LayoutMdx>;

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

View File

@@ -1,6 +1,7 @@
import Image from "next/image";
import LayoutMdx from "@/components/shared/LayoutMdx";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
import Formbricks from "./open-source-survey-software-free-2023-formbricks-typeform-alternative.png";
import Typebot from "./typebot-open-source-free-conversational-form-builder-survey-software-opensource.jpg";
import LimeSurvey from "./free-survey-tool-limesurvey-open-source-software-opensource.png";
@@ -19,7 +20,7 @@ export const meta = {
tags: ["Open Source Surveys", "Formbricks", "Typeform", "SurveyJS", "Typebot", "OpnForm", "LimeSurvey"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" author={"Johannes"} />
_Most open source projects get abandoned after a while. But these 5 open source survey tools are still alive and kicking in 2023._

View File

@@ -2,7 +2,7 @@ import Image from "next/image";
import LayoutMdx from "@/components/shared/LayoutMdx";
import { Callout } from "@/components/shared/Callout";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
import TweetPeer from "./peer-tweet-typeform-open-source.png";
import SnoopForms from "./snoopforms-open-source-typeform-alternative.png";
import TwitterResult from "./twitter-results-PMF-cal.png";
@@ -22,7 +22,7 @@ export const meta = {
tags: ["Open Source", "Experience Management", "Formbricks"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" author={"Johannes"}/>
_A lot has happened since Matti and I had a chat about open-source surveys in May last year. The release of Formbricks v1.0 is a perfect opportunity to look back on how it all started._

View File

@@ -1,7 +1,7 @@
import Image from "next/image";
import LayoutMdx from "@/components/shared/LayoutMdx";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
import EmailGIF from "./email-embed.gif";
import FigmaMock from "./figma-mock.webp";
import PiyushPR from "./pr-merged.webp";
@@ -17,7 +17,7 @@ export const meta = {
tags: ["Open Source Surveys", "Open Source Design", "Design", "Community Design"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="October 11th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="October 11th, 2023" duration="4" author={"Johannes"} />
<p className="text-lg font-semibold">We are super excited to share the first end-to-end feature built by the community: From request, over design to code implementation ✅</p>

View File

@@ -6,6 +6,7 @@ import Mail from "./github-accelerator-selection-mail.png";
import Teams from "./github-accelerator-2022-teams.png";
import NewsletterSignup from "@/components/shared/NewsletterSignup";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
export const meta = {
title: "Our GitHub Accelerator Experience 👀",
@@ -18,7 +19,7 @@ export const meta = {
tags: ["GitHub Accelerator", "Open-Source", "Startup"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" author={"Johannes"} />
_We were among the first 20 teams ever to run through the Open-Source Accelerator by Github. Read about our experience and if we would do it again:_

View File

@@ -3,7 +3,7 @@ import LayoutMdx from "@/components/shared/LayoutMdx";
import TitleImage from "./formbricks-sponsored-by-github-accelerator-2023.webp";
import NewsletterSignup from "@/components/shared/NewsletterSignup";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
export const meta = {
title: "Formbricks Joins GitHub Accelerator's Inaugural Cohort 💃",
description:
@@ -15,7 +15,7 @@ export const meta = {
tags: ["GitHub Accelerator", "Open-Source"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" author={"Johannes"}/>
_We're getting ready to take our open-source experience management platform to new heights, thanks to being part of the first-ever GitHub Accelerator program!_

View File

@@ -5,7 +5,7 @@ import HeaderImage from "./create-a-new-survey-with-formbricks.png";
import GitpodImage from "./setup-formbricks-via-gitpod.png";
import PackagesFolderImage from "./formbricks-packages-folder.png";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
export const meta = {
title: "Join the FormTribe 🔥",
description: "Here is everything you need to know about joining the Formbricks community",
@@ -16,7 +16,7 @@ export const meta = {
tags: ["Open-Source", "No-Code", "Formbricks", "Geting started", "Welcome guide"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="October 1st, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="October 1st, 2023" duration="4" author={"Johannes"}/>
<Image src={HeaderImage} alt="Title Image" className="w-full rounded-lg" />

View File

@@ -5,6 +5,7 @@ import WhyWeDoIt from "./why-we-do-it.png";
import EverythinEverywhereAllAtOnce from "./everything_everywhere_all_at_once.png";
import ResponsiveEmbed from "react-responsive-embed";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
export const meta = {
title: "Open source forms will save the world.",
@@ -16,7 +17,7 @@ export const meta = {
tags: ["Open Source", "Survey Tool", "Forms"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" author={"Johannes"} />
<Image src={RobinHoodMeme} alt="Robin Hood Meme" className="rounded-lg w-full" />

View File

@@ -10,6 +10,7 @@ import TypeformValue from "./typeform-value-prop.png";
import ResponsiveEmbed from "react-responsive-embed";
import { Callout } from "@/components/shared/Callout";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
export const meta = {
title: "Why Qualtrics beats Typeform, especially Open-Source",
@@ -22,7 +23,7 @@ export const meta = {
tags: ["Open Source", "Experience Management", "Typeform", "Qualtrics"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" author={"Johannes"} />
<Image src={Wrestling} alt="Why we do it" className="rounded-lg w-full" />

View File

@@ -2,6 +2,7 @@ import Image from "next/image";
import LayoutMdx from "@/components/shared/LayoutMdx";
import AuthorBox from "@/components/shared/AuthorBox";
import Preseed from "./preseed-header.webp";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
export const meta = {
title: "We raised Pre-Seed Funding 💸",
@@ -22,7 +23,7 @@ export const meta = {
_Were delighted to announce that Formbricks successfully acquired pre-seed funding in May 2023._
<AuthorBox name="Johannes" title="Co-Founder" date="November 1st, 2023" duration="2" />
<AuthorBox name="Johannes" title="Co-Founder" date="November 1st, 2023" duration="2" author={"Johannes"}/>
The Formbricks pre-seed round was led by [OSS Capital](https://oss.capital/portfolio) with participation of Peer Richelsen, co-founder at [Cal.com](http://Cal.com), as well as other angel investors.

View File

@@ -3,6 +3,7 @@ import LayoutMdx from "@/components/shared/LayoutMdx";
import HeaderImage from "./formbricks-logo-header-open-source-form-infrastructure.svg";
import HeroAnimation from "../../../components/shared/HeroAnimation.tsx";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
export const meta = {
title: "snoopForms → Formbricks 🎉",
@@ -14,7 +15,7 @@ export const meta = {
tags: ["Formbricks", "snoopForms", "Open Source"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" author={"Johannes"} />
<Image src={HeaderImage} alt="Formbricks - Open Source Forms and Surveys" className="rounded-lg w-full" />

View File

@@ -7,6 +7,7 @@ import HeaderImage from "./formbricks-logo.svg";
import ProprietaryDependence from "./propietary-dependence.jpeg";
import ResponsiveEmbed from "react-responsive-embed";
import AuthorBox from "@/components/shared/AuthorBox";
import AuthorJohannes from "@/images/blog/johannes-co-founder-formbricks-small.jpg";
export const meta = {
title: "Why Open-Source + No-Code is the Future of Enterprise & Goverment Software",
@@ -19,7 +20,7 @@ export const meta = {
tags: ["Open-Source", "No-Code", "Enterprise", "Government"],
};
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" />
<AuthorBox name="Johannes" title="Co-Founder" date="April 7th, 2023" duration="4" author={"Johannes"}/>
<Image src={TitleImage} alt="Title Image" className="rounded-lg w-full" />

View File

@@ -17,19 +17,19 @@
},
"devDependencies": {
"@formbricks/tsconfig": "workspace:*",
"@storybook/addon-essentials": "^7.6.4",
"@storybook/addon-interactions": "^7.6.4",
"@storybook/addon-links": "^7.6.4",
"@storybook/addon-essentials": "^7.6.7",
"@storybook/addon-interactions": "^7.6.7",
"@storybook/addon-links": "^7.6.7",
"@storybook/addon-onboarding": "^1.0.10",
"@storybook/blocks": "^7.6.4",
"@storybook/react": "^7.6.4",
"@storybook/react-vite": "^7.6.4",
"@storybook/blocks": "^7.6.7",
"@storybook/react": "^7.6.7",
"@storybook/react-vite": "^7.6.7",
"@storybook/testing-library": "^0.2.2",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"@vitejs/plugin-react": "^4.2.1",
"esbuild": "^0.19.9",
"esbuild": "^0.19.11",
"tsup": "^8.0.1",
"vite": "^5.0.8"
"vite": "^5.0.10"
}
}

View File

@@ -13,7 +13,7 @@ export default function PosthogIdentify({ session }: { session: Session }) {
useEffect(() => {
if (posthogEnabled && session.user && posthog) {
posthog.identify(session.user.id);
posthog.identify(session.user.id, { name: session.user.name, email: session.user.email });
}
}, [session, posthog]);

View File

@@ -7,7 +7,7 @@ export const testEndpoint = async (url: string) => {
const response = await fetch(url, {
method: "POST",
body: JSON.stringify({
formbricks: "test endpoint",
event: "testEndpoint",
}),
headers: {
"Content-Type": "application/json",

View File

@@ -93,6 +93,10 @@ export default function PricingTableComponent({
};
const coreAndWebAppSurveyFeatures = [
{
title: "Remove Formbricks Branding",
comingSoon: false,
},
{
title: "Team Roles",
comingSoon: false,

View File

@@ -1,6 +1,9 @@
import { getServerSession } from "next-auth";
import { getIsEnterpriseEdition } from "@formbricks/ee/lib/service";
import {
getRemoveInAppBrandingPermission,
getRemoveLinkBrandingPermission,
} from "@formbricks/ee/lib/service";
import { authOptions } from "@formbricks/lib/authOptions";
import { DEFAULT_BRAND_COLOR, IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
import { getMembershipByUserIdTeamId } from "@formbricks/lib/membership/service";
@@ -33,12 +36,8 @@ export default async function ProfileSettingsPage({ params }: { params: { enviro
throw new Error("Team not found");
}
const isEnterpriseEdition = await getIsEnterpriseEdition();
const canRemoveLinkBranding =
team.billing.features.linkSurvey.status !== "inactive" || !IS_FORMBRICKS_CLOUD;
const canRemoveInAppBranding =
team.billing.features.inAppSurvey.status !== "inactive" || isEnterpriseEdition;
const canRemoveInAppBranding = getRemoveInAppBrandingPermission(team);
const canRemoveLinkBranding = getRemoveLinkBrandingPermission(team);
const currentUserMembership = await getMembershipByUserIdTeamId(session?.user.id, team.id);
const { isDeveloper, isViewer } = getAccessFlags(currentUserMembership?.role);

View File

@@ -19,10 +19,19 @@ interface MemberModalProps {
open: boolean;
setOpen: (v: boolean) => void;
onSubmit: (data: { name: string; email: string; role: MembershipRole }) => void;
isEnterpriseEdition: boolean;
canDoRoleManagement: boolean;
isFormbricksCloud: boolean;
environmentId: string;
}
export default function AddMemberModal({ open, setOpen, onSubmit, isEnterpriseEdition }: MemberModalProps) {
export default function AddMemberModal({
open,
setOpen,
onSubmit,
canDoRoleManagement,
isFormbricksCloud,
environmentId,
}: MemberModalProps) {
const { register, getValues, handleSubmit, reset, control } = useForm<{
name: string;
email: string;
@@ -47,11 +56,25 @@ export default function AddMemberModal({ open, setOpen, onSubmit, isEnterpriseEd
</div>
</div>
</div>
{!isEnterpriseEdition && (
<div className="mx-6 mt-2">
<UpgradePlanNotice message="Upgrade to an Enterprise License to manage access roles for your team" />
</div>
)}
{!canDoRoleManagement &&
(isFormbricksCloud ? (
<div className="mx-6 mt-2">
<UpgradePlanNotice
message="To manage access roles for your team"
url={`/environments/${environmentId}/settings/billing`}
textForUrl="Upgrade to the App Surveys plan."
/>
</div>
) : (
<div className="mx-6 mt-2">
<UpgradePlanNotice
message="To manage access roles for your team,"
url="mailto:hola@formbricks.com"
textForUrl="get a self-hosted license (free to get started)."
/>
</div>
))}
<form onSubmit={handleSubmit(submitEventClass)}>
<div className="flex justify-between rounded-lg p-6">
<div className="w-full space-y-4">
@@ -66,7 +89,7 @@ export default function AddMemberModal({ open, setOpen, onSubmit, isEnterpriseEd
<Label>Email Adress</Label>
<Input type="email" placeholder="hans@wurst.com" {...register("email", { required: true })} />
</div>
{isEnterpriseEdition && <AddMemberRole control={control} />}
{canDoRoleManagement && <AddMemberRole control={control} />}
</div>
</div>
<div className="flex justify-end border-t border-slate-200 p-6">

View File

@@ -1,7 +1,7 @@
import MembersInfo from "@/app/(app)/environments/[environmentId]/settings/members/components/EditMemberships/MembersInfo";
import React from "react";
import { getIsEnterpriseEdition } from "@formbricks/ee/lib/service";
import { getRoleManagementPermission } from "@formbricks/ee/lib/service";
import { getInvitesByTeamId } from "@formbricks/lib/invite/service";
import { getMembersByTeamId } from "@formbricks/lib/membership/service";
import { TMembership } from "@formbricks/types/memberships";
@@ -24,7 +24,8 @@ export async function EditMemberships({
const currentUserRole = membership?.role;
const isUserAdminOrOwner = membership?.role === "admin" || membership?.role === "owner";
const isEnterpriseEdition = await getIsEnterpriseEdition();
const canDoRoleManagement = getRoleManagementPermission(team);
return (
<div>
<div className="rounded-lg border border-slate-200">
@@ -32,7 +33,7 @@ export async function EditMemberships({
<div className="col-span-2"></div>
<div className="col-span-5">Fullname</div>
<div className="col-span-5">Email</div>
{isEnterpriseEdition && <div className="col-span-3">Role</div>}
{canDoRoleManagement && <div className="col-span-3">Role</div>}
<div className="col-span-5"></div>
</div>
@@ -44,7 +45,7 @@ export async function EditMemberships({
members={members ?? []}
isUserAdminOrOwner={isUserAdminOrOwner}
currentUserRole={currentUserRole}
isEnterpriseEdition={isEnterpriseEdition}
canDoRoleManagement={canDoRoleManagement}
/>
)}
</div>

View File

@@ -16,7 +16,7 @@ type MembersInfoProps = {
isUserAdminOrOwner: boolean;
currentUserId: string;
currentUserRole: TMembershipRole;
isEnterpriseEdition: boolean;
canDoRoleManagement: boolean;
};
// Type guard to check if member is an invitee
@@ -31,7 +31,7 @@ const MembersInfo = async ({
members,
currentUserId,
currentUserRole,
isEnterpriseEdition,
canDoRoleManagement,
}: MembersInfoProps) => {
const allMembers = [...members, ...invites];
@@ -56,7 +56,7 @@ const MembersInfo = async ({
</div>
<div className="ph-no-capture col-span-3 flex flex-col items-start justify-center break-all">
{isEnterpriseEdition && allMembers?.length > 0 && (
{canDoRoleManagement && allMembers?.length > 0 && (
<EditMembershipRole
isAdminOrOwner={isUserAdminOrOwner}
memberRole={member.role}

View File

@@ -21,7 +21,9 @@ type TeamActionsProps = {
isLeaveTeamDisabled: boolean;
team: TTeam;
isInviteDisabled: boolean;
isEnterpriseEdition: boolean;
canDoRoleManagement: boolean;
isFormbricksCloud: boolean;
environmentId: string;
};
export default function TeamActions({
@@ -30,7 +32,9 @@ export default function TeamActions({
team,
isLeaveTeamDisabled,
isInviteDisabled,
isEnterpriseEdition,
canDoRoleManagement,
isFormbricksCloud,
environmentId,
}: TeamActionsProps) {
const router = useRouter();
const [isLeaveTeamModalOpen, setLeaveTeamModalOpen] = useState(false);
@@ -94,7 +98,9 @@ export default function TeamActions({
open={isAddMemberModalOpen}
setOpen={setAddMemberModalOpen}
onSubmit={handleAddMember}
isEnterpriseEdition={isEnterpriseEdition}
canDoRoleManagement={canDoRoleManagement}
isFormbricksCloud={isFormbricksCloud}
environmentId={environmentId}
/>
<CustomDialog

View File

@@ -2,9 +2,9 @@ import TeamActions from "@/app/(app)/environments/[environmentId]/settings/membe
import { getServerSession } from "next-auth";
import { Suspense } from "react";
import { getIsEnterpriseEdition } from "@formbricks/ee/lib/service";
import { getRoleManagementPermission } from "@formbricks/ee/lib/service";
import { authOptions } from "@formbricks/lib/authOptions";
import { INVITE_DISABLED } from "@formbricks/lib/constants";
import { INVITE_DISABLED, IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
import { getMembershipByUserIdTeamId, getMembershipsByUserId } from "@formbricks/lib/membership/service";
import { getAccessFlags } from "@formbricks/lib/membership/utils";
import { getTeamByEnvironmentId } from "@formbricks/lib/team/service";
@@ -44,9 +44,6 @@ const MembersLoading = () => (
export default async function MembersSettingsPage({ params }: { params: { environmentId: string } }) {
const session = await getServerSession(authOptions);
const isEnterpriseEdition = await getIsEnterpriseEdition();
if (!session) {
throw new Error("Unauthenticated");
}
@@ -55,6 +52,7 @@ export default async function MembersSettingsPage({ params }: { params: { enviro
if (!team) {
throw new Error("Team not found");
}
const canDoRoleManagement = getRoleManagementPermission(team);
const currentUserMembership = await getMembershipByUserIdTeamId(session?.user.id, team.id);
const { isOwner, isAdmin } = getAccessFlags(currentUserMembership?.role);
@@ -77,7 +75,9 @@ export default async function MembersSettingsPage({ params }: { params: { enviro
role={currentUserRole}
isLeaveTeamDisabled={isLeaveTeamDisabled}
isInviteDisabled={INVITE_DISABLED}
isEnterpriseEdition={isEnterpriseEdition}
canDoRoleManagement={canDoRoleManagement}
isFormbricksCloud={IS_FORMBRICKS_CLOUD}
environmentId={params.environmentId}
/>
)}

View File

@@ -2,12 +2,14 @@
import { getEmailTemplateHtml } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/emailTemplate";
import { generateSurveySingleUseId } from "@/app/lib/singleUseSurveys";
import { customAlphabet } from "nanoid";
import { getServerSession } from "next-auth";
import { authOptions } from "@formbricks/lib/authOptions";
import { sendEmbedSurveyPreviewEmail } from "@formbricks/lib/emails/emails";
import { canUserAccessSurvey } from "@formbricks/lib/survey/auth";
import { AuthenticationError, AuthorizationError } from "@formbricks/types/errors";
import { getSurvey, updateSurvey } from "@formbricks/lib/survey/service";
import { AuthenticationError, AuthorizationError, ResourceNotFoundError } from "@formbricks/types/errors";
type TSendEmailActionArgs = {
to: string;
@@ -35,6 +37,58 @@ export const sendEmailAction = async ({ html, subject, to }: TSendEmailActionArg
return await sendEmbedSurveyPreviewEmail(to, subject, html);
};
export async function generateResultShareUrlAction(surveyId: string): Promise<string> {
const session = await getServerSession(authOptions);
if (!session) throw new AuthorizationError("Not authorized");
const hasUserSurveyAccess = await canUserAccessSurvey(session.user.id, surveyId);
if (!hasUserSurveyAccess) throw new AuthorizationError("Not authorized");
const survey = await getSurvey(surveyId);
if (!survey?.id) {
throw new ResourceNotFoundError("Survey", surveyId);
}
const resultShareKey = customAlphabet(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
20
)();
await updateSurvey({ ...survey, resultShareKey });
return resultShareKey;
}
export async function getResultShareUrlAction(surveyId: string): Promise<string | null> {
const session = await getServerSession(authOptions);
if (!session) throw new AuthorizationError("Not authorized");
const hasUserSurveyAccess = await canUserAccessSurvey(session.user.id, surveyId);
if (!hasUserSurveyAccess) throw new AuthorizationError("Not authorized");
const survey = await getSurvey(surveyId);
if (!survey?.id) {
throw new ResourceNotFoundError("Survey", surveyId);
}
return survey.resultShareKey;
}
export async function deleteResultShareUrlAction(surveyId: string): Promise<void> {
const session = await getServerSession(authOptions);
if (!session) throw new AuthorizationError("Not authorized");
const hasUserSurveyAccess = await canUserAccessSurvey(session.user.id, surveyId);
if (!hasUserSurveyAccess) throw new AuthorizationError("Not authorized");
const survey = await getSurvey(surveyId);
if (!survey?.id) {
throw new ResourceNotFoundError("Survey", surveyId);
}
await updateSurvey({ ...survey, resultShareKey: null });
}
export const getEmailHtmlAction = async (surveyId: string) => {
const session = await getServerSession(authOptions);
if (!session) throw new AuthorizationError("Not authorized");

View File

@@ -1,17 +1,30 @@
"use client";
import { ShareIcon } from "@heroicons/react/24/outline";
import clsx from "clsx";
import {
deleteResultShareUrlAction,
generateResultShareUrlAction,
getResultShareUrlAction,
} from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/actions";
import { LinkIcon } from "@heroicons/react/24/outline";
import { DownloadIcon } from "lucide-react";
import { useState } from "react";
import { useEffect } from "react";
import toast from "react-hot-toast";
import { TProduct } from "@formbricks/types/product";
import { TSurvey } from "@formbricks/types/surveys";
import { TUser } from "@formbricks/types/user";
import { Button } from "@formbricks/ui/Button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@formbricks/ui/DropdownMenu";
import ShareEmbedSurvey from "./ShareEmbedSurvey";
import ShareSurveyResults from "./ShareSurveyResults";
interface LinkSurveyShareButtonProps {
interface SurveyShareButtonProps {
survey: TSurvey;
className?: string;
webAppUrl: string;
@@ -19,28 +32,83 @@ interface LinkSurveyShareButtonProps {
user: TUser;
}
export default function LinkSurveyShareButton({
survey,
className,
webAppUrl,
product,
user,
}: LinkSurveyShareButtonProps) {
export default function SurveyShareButton({ survey, webAppUrl, product, user }: SurveyShareButtonProps) {
const [showLinkModal, setShowLinkModal] = useState(false);
const [showResultsLinkModal, setShowResultsLinkModal] = useState(false);
const [showPublishModal, setShowPublishModal] = useState(false);
const [surveyUrl, setSurveyUrl] = useState("");
const handlePublish = async () => {
const key = await generateResultShareUrlAction(survey.id);
setSurveyUrl(webAppUrl + "/share/" + key);
setShowPublishModal(true);
};
const handleUnpublish = () => {
deleteResultShareUrlAction(survey.id)
.then(() => {
toast.success("Survey Unpublished successfully");
setShowPublishModal(false);
setShowLinkModal(false);
})
.catch((error) => {
toast.error(`Error: ${error.message}`);
});
};
useEffect(() => {
async function fetchSharingKey() {
const sharingKey = await getResultShareUrlAction(survey.id);
if (sharingKey) {
setSurveyUrl(webAppUrl + "/share/" + sharingKey);
setShowPublishModal(true);
}
}
fetchSharingKey();
}, [survey.id, webAppUrl]);
useEffect(() => {
if (showResultsLinkModal) {
setShowLinkModal(false);
}
}, [showResultsLinkModal]);
return (
<>
<Button
variant="secondary"
className={clsx(
"border border-slate-300 bg-white px-2 hover:bg-slate-100 focus:bg-slate-100 lg:px-6",
className
)}
onClick={() => {
setShowLinkModal(true);
}}>
<ShareIcon className="h-5 w-5" />
</Button>
<DropdownMenu>
<DropdownMenuTrigger
asChild
className="focus:bg-muted cursor-pointer border border-slate-300 outline-none">
<div className="min-w-auto h-auto rounded-md border bg-white p-3 sm:flex sm:min-w-[7rem] sm:px-6 sm:py-3">
<div className="hidden w-full items-center justify-between sm:flex">
<span className="text-sm text-slate-700"> Share</span>
<LinkIcon className="h-4 w-4" />
</div>
<DownloadIcon className="block h-4 sm:hidden" />
</div>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
{survey.type === "link" && (
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
setShowLinkModal(true);
}}>
<p className="text-slate-700">Share Survey</p>
</DropdownMenuItem>
)}
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
setShowResultsLinkModal(true);
}}>
<p className="text-slate-700">Publish Results</p>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
{showLinkModal && (
<ShareEmbedSurvey
survey={survey}
@@ -51,6 +119,16 @@ export default function LinkSurveyShareButton({
user={user}
/>
)}
{showResultsLinkModal && (
<ShareSurveyResults
open={showResultsLinkModal}
setOpen={setShowResultsLinkModal}
surveyUrl={surveyUrl}
handlePublish={handlePublish}
handleUnpublish={handleUnpublish}
showPublishModal={showPublishModal}
/>
)}
</>
);
}

View File

@@ -0,0 +1,108 @@
"use client";
import { CheckCircleIcon, GlobeEuropeAfricaIcon } from "@heroicons/react/24/solid";
import { Clipboard } from "lucide-react";
import { toast } from "react-hot-toast";
import { Button } from "@formbricks/ui/Button";
import { Dialog, DialogContent } from "@formbricks/ui/Dialog";
interface ShareEmbedSurveyProps {
open: boolean;
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
handlePublish: () => void;
handleUnpublish: () => void;
showPublishModal: boolean;
surveyUrl: string;
}
export default function ShareSurveyResults({
open,
setOpen,
handlePublish,
handleUnpublish,
showPublishModal,
surveyUrl,
}: ShareEmbedSurveyProps) {
return (
<Dialog
open={open}
onOpenChange={(open) => {
setOpen(open);
}}>
{showPublishModal && surveyUrl ? (
<DialogContent className="bottom-0 flex h-[95%] w-full cursor-pointer flex-col gap-0 overflow-hidden rounded-2xl bg-white p-0 sm:max-w-none lg:bottom-auto lg:h-auto lg:w-[40%]">
<div className="no-scrollbar mt-4 flex grow flex-col items-center justify-center overflow-x-hidden overflow-y-scroll">
<CheckCircleIcon className="mt-4 h-20 w-20 text-slate-300" />
<div className="mt-6 px-4 py-3 text-lg font-medium text-slate-600 lg:px-6 lg:py-3">
Your survey results are public on the web.
</div>
<div className="text-md px-4 py-3 text-slate-500 lg:px-6 lg:py-0">
Your survey results are shared with anyone who has the link.
</div>
<div className="text-md mb-6 px-4 py-3 text-slate-500 lg:px-6 lg:py-0">
The results will not be indexed by search engines.
</div>
<div className="flex gap-2">
<div className="relative grow overflow-auto rounded-lg border border-slate-300 bg-white px-3 py-2 text-slate-800">
<span
style={{
wordBreak: "break-all",
}}>
{surveyUrl}
</span>
</div>
<Button
variant="secondary"
size="sm"
title="Copy survey link to clipboard"
aria-label="Copy survey link to clipboard"
onClick={() => {
navigator.clipboard.writeText(surveyUrl);
toast.success("URL copied to clipboard!");
}}>
<Clipboard />
</Button>
</div>
<div className="my-6 flex gap-2">
<Button
type="submit"
variant="secondary"
className=" text-center"
onClick={() => handleUnpublish()}>
Unpublish
</Button>
<Button variant="darkCTA" className=" text-center" href={surveyUrl} target="_blank">
View Site
</Button>
</div>
</div>
</DialogContent>
) : (
<DialogContent className="bottom-0 flex h-[95%] w-full flex-col gap-0 overflow-hidden rounded-2xl bg-white p-0 sm:max-w-none lg:bottom-auto lg:h-auto lg:w-[40%]">
<div className="no-scrollbar mt-4 flex grow flex-col items-center justify-center overflow-x-hidden overflow-y-scroll">
<GlobeEuropeAfricaIcon className="mt-4 h-20 w-20 text-slate-300" />
<div className=" mt-6 px-4 py-3 text-lg font-medium text-slate-600 lg:px-6 lg:py-3">
Publish Results to web
</div>
<div className="text-md px-4 py-3 text-slate-500 lg:px-6 lg:py-0">
Your survey results are shared with anyone who has the link.
</div>
<div className=" text-md px-4 py-3 text-slate-500 lg:px-6 lg:py-0">
The results will not be indexed by search engines.
</div>
<Button
type="submit"
variant="darkCTA"
className="my-8 h-full text-center"
onClick={() => handlePublish()}>
Publish to web
</Button>
</div>
</DialogContent>
)}
</Dialog>
);
}

View File

@@ -80,29 +80,29 @@ export default function SummaryMetadata({
<div className="mb-4">
<div className="flex flex-col-reverse gap-y-2 lg:grid lg:grid-cols-3 lg:gap-x-2">
<div className="grid grid-cols-2 gap-4 md:grid-cols-5 md:gap-x-2 lg:col-span-2">
<div className="flex flex-col justify-between space-y-2 rounded-lg border border-slate-200 bg-white p-4 shadow-sm">
<p className="text-sm text-slate-600">Displays</p>
<p className="text-2xl font-bold text-slate-800">
{displayCount === 0 ? <span>-</span> : displayCount}
</p>
</div>
<StatCard
label="Displays"
percentage={null}
value={displayCount === 0 ? <span>-</span> : displayCount}
tooltipText="Number of times the survey has been viewed."
/>
<StatCard
label="Starts"
percentage={`${Math.round((totalResponses / displayCount) * 100)}%`}
value={totalResponses === 0 ? <span>-</span> : totalResponses}
tooltipText="People who started the survey."
tooltipText="Number of times the survey has been started."
/>
<StatCard
label="Responses"
percentage={`${Math.round((completedResponsesCount / displayCount) * 100)}%`}
value={responses.length === 0 ? <span>-</span> : completedResponsesCount}
tooltipText="People who completed the survey."
tooltipText="Number of times the survey has been completed."
/>
<StatCard
label="Drop Offs"
percentage={`${Math.round(((totalResponses - completedResponsesCount) / totalResponses) * 100)}%`}
value={responses.length === 0 ? <span>-</span> : totalResponses - completedResponsesCount}
tooltipText="People who started but not completed the survey."
tooltipText="Number of times the survey has been started but not completed."
/>
<StatCard
label="Time to Complete"

View File

@@ -1,6 +1,6 @@
"use client";
import LinkSurveyShareButton from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/LinkModalButton";
import SurveyShareButton from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/LinkModalButton";
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 { updateSurveyAction } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/actions";
@@ -14,6 +14,7 @@ import { TMembershipRole } from "@formbricks/types/memberships";
import { TProduct } from "@formbricks/types/product";
import { TSurvey } from "@formbricks/types/surveys";
import { TUser } from "@formbricks/types/user";
import { Badge } from "@formbricks/ui/Badge";
import { Button } from "@formbricks/ui/Button";
import {
DropdownMenu,
@@ -53,16 +54,18 @@ const SummaryHeader = ({
const closeOnDate = survey.closeOnDate ? new Date(survey.closeOnDate) : null;
const isStatusChangeDisabled = (isCloseOnDateEnabled && closeOnDate && closeOnDate < new Date()) ?? false;
const { isViewer } = getAccessFlags(membershipRole);
return (
<div className="mb-11 mt-6 flex flex-wrap items-center justify-between">
<div>
<p className="text-3xl font-bold text-slate-800">{survey.name}</p>
<div className="flex gap-4">
<p className="text-3xl font-bold text-slate-800">{survey.name}</p>
{survey.resultShareKey && <Badge text="Public Results" type="success" size="normal"></Badge>}
</div>
<span className="text-base font-extralight text-slate-600">{product.name}</span>
</div>
<div className="hidden justify-end gap-x-1.5 sm:flex">
{survey.type === "link" && (
<LinkSurveyShareButton survey={survey} webAppUrl={webAppUrl} product={product} user={user} />
)}
<SurveyShareButton survey={survey} webAppUrl={webAppUrl} product={product} user={user} />
{!isViewer &&
(environment?.widgetSetupCompleted || survey.type === "link") &&
survey?.status !== "draft" ? (
@@ -88,7 +91,7 @@ const SummaryHeader = ({
<DropdownMenuContent align="end" className="p-2">
{survey.type === "link" && (
<>
<LinkSurveyShareButton
<SurveyShareButton
className="flex w-full justify-center p-1"
survey={survey}
webAppUrl={webAppUrl}

View File

@@ -109,6 +109,7 @@ export default function EditWelcomeCard({
updateSurvey({ fileUrl: url[0] });
}}
fileUrl={localSurvey?.welcomeCard?.fileUrl}
imageFit="contain"
/>
</div>
<div className="mt-3">

View File

@@ -281,13 +281,16 @@ export default function LogicEditor({
<SelectValue placeholder="Select match type" />
</SelectTrigger>
<SelectContent className="w-full bg-slate-50 text-slate-700 2xl:w-96">
{logicConditions[logic.condition].values?.map((value) => (
<SelectItem key={value} value={value} title={value}>
<div className="w-full">
<p className="line-clamp-1 w-40 text-left 2xl:w-80">{value}</p>
</div>
</SelectItem>
))}
{logicConditions[logic.condition].values?.map((value) => {
if (!value) return;
return (
<SelectItem key={value} value={value} title={value}>
<div className="w-full">
<p className="line-clamp-1 w-40 text-left 2xl:w-80">{value}</p>
</div>
</SelectItem>
);
})}
</SelectContent>
</Select>
) : (
@@ -339,7 +342,7 @@ export default function LogicEditor({
(question, idx) =>
idx !== questionIdx && (
<SelectItem key={question.id} value={question.id} title={question.headline}>
<div className="w-32">
<div className="max-w-[6rem]">
<p className="truncate text-left">{question.headline}</p>
</div>
</SelectItem>

View File

@@ -99,6 +99,14 @@ export default function QuestionCard({
const open = activeQuestionId === question.id;
const [openAdvanced, setOpenAdvanced] = useState(question.logic && question.logic.length > 0);
const updateEmptyNextButtonLabels = (labelValue: string) => {
localSurvey.questions.forEach((q, index) => {
if (!q.buttonLabel || q.buttonLabel?.trim() === "") {
updateQuestion(index, { buttonLabel: labelValue });
}
});
};
return (
<Draggable draggableId={question.id} index={questionIdx}>
{(provided) => (
@@ -298,7 +306,7 @@ export default function QuestionCard({
question.type !== TSurveyQuestionType.CTA ? (
<div className="mt-4 flex space-x-2">
<div className="w-full">
<Label htmlFor="buttonLabel">Button Label</Label>
<Label htmlFor="buttonLabel">&quot;Next&quot; Button Label</Label>
<div className="mt-2">
<Input
id="buttonLabel"
@@ -307,9 +315,11 @@ export default function QuestionCard({
maxLength={48}
placeholder={lastQuestion ? "Finish" : "Next"}
onChange={(e) => {
if (e.target.value.trim() == "") e.target.value = "";
updateQuestion(questionIdx, { buttonLabel: e.target.value });
}}
onBlur={(e) => {
updateEmptyNextButtonLabels(e.target.value);
}}
/>
</div>
</div>

View File

@@ -241,7 +241,6 @@ export default function SurveyMenuBar({
try {
await updateSurveyAction({ ...strippedSurvey });
router.refresh();
setIsSurveySaving(false);
toast.success("Changes saved.");
if (shouldNavigateBack) {
@@ -252,7 +251,6 @@ export default function SurveyMenuBar({
} else {
router.push(`/environments/${environment.id}/surveys`);
}
router.refresh();
}
} catch (e) {
console.error(e);

View File

@@ -19,16 +19,52 @@ export default function Modal({
}) {
const [show, setShow] = useState(false);
const modalRef = useRef<HTMLDivElement | null>(null);
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
const calculateScaling = () => {
const scaleValue = (() => {
if (windowWidth > 1600) return "1";
else if (windowWidth > 1200) return ".9";
else if (windowWidth > 900) return ".8";
return "0.7";
})();
const getPlacementClass = (() => {
switch (placement) {
case "bottomLeft":
return "bottom left";
case "bottomRight":
return "bottom right";
case "topLeft":
return "top left";
case "topRight":
return "top right";
default:
return "";
}
})();
return {
transform: `scale(${scaleValue})`,
"transform-origin": getPlacementClass,
};
};
const scalingClasses = calculateScaling();
useEffect(() => {
const handleResize = () => setWindowWidth(window.innerWidth);
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);
const highlightBorderColorStyle = useMemo(() => {
if (!highlightBorderColor)
return {
overflow: "visible",
overflow: "auto",
};
return {
border: `2px solid ${highlightBorderColor}`,
overflow: "visible",
overflow: "auto",
};
}, [highlightBorderColor]);
@@ -58,7 +94,7 @@ export default function Modal({
<div aria-live="assertive" className="relative h-full w-full overflow-visible bg-slate-300">
<div
ref={modalRef}
style={highlightBorderColorStyle}
style={{ ...highlightBorderColorStyle, ...scalingClasses }}
className={cn(
"no-scrollbar pointer-events-auto absolute h-fit max-h-[90%] w-full max-w-sm overflow-y-auto rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5 transition-all duration-500 ease-in-out ",
previewMode === "desktop" ? getPlacementStyle(placement) : "max-w-full",

View File

@@ -111,8 +111,8 @@ export default function TemplateList({
className={cn(
selectedFilter === category
? " bg-slate-800 font-semibold text-white"
: " bg-white text-slate-700 hover:bg-slate-100",
"mt-2 rounded border border-slate-800 px-2 py-1 text-xs transition-all duration-150 "
: " bg-white text-slate-700 hover:bg-slate-100 focus:scale-105 focus:bg-slate-100 focus:outline-none focus:ring-0",
"mt-2 rounded border border-slate-800 px-2 py-1 text-xs transition-all duration-150"
)}>
{category}
{category === RECOMMENDED_CATEGORY_NAME && <SparklesIcon className="ml-1 inline h-5 w-5" />}
@@ -153,7 +153,7 @@ export default function TemplateList({
? [...filteredTemplates, testTemplate]
: filteredTemplates
).map((template: TTemplate) => (
<div
<button
onClick={() => {
const newTemplate = replacePresetPlaceholders(template, product);
onTemplateClick(newTemplate);
@@ -184,9 +184,9 @@ export default function TemplateList({
{template.preset.questions.some((question) => question.logic && question.logic.length > 0) && (
<TooltipProvider delayDuration={80}>
<Tooltip>
<TooltipTrigger>
<TooltipTrigger tabIndex={-1}>
<div>
<SplitIcon className="ml-1.5 h-5 w-5 rounded border border-slate-300 bg-slate-50 p-0.5 text-slate-400" />
<SplitIcon className="ml-1.5 h-5 w-5 rounded border border-slate-300 bg-slate-50 p-0.5 text-slate-400" />
</div>
</TooltipTrigger>
<TooltipContent>This survey uses branching logic.</TooltipContent>
@@ -197,16 +197,18 @@ export default function TemplateList({
<h3 className="text-md mb-1 mt-3 text-left font-bold text-slate-700">{template.name}</h3>
<p className="text-left text-xs text-slate-600">{template.description}</p>
{activeTemplate?.name === template.name && (
<Button
variant="darkCTA"
className="mt-6 px-6 py-3"
disabled={activeTemplate === null}
loading={loading}
onClick={() => addSurvey(activeTemplate)}>
Use this template
</Button>
<div className="flex justify-start">
<Button
variant="darkCTA"
className="mt-6 px-6 py-3"
disabled={activeTemplate === null}
loading={loading}
onClick={() => addSurvey(activeTemplate)}>
Use this template
</Button>
</div>
)}
</div>
</button>
))}
</div>
</main>

View File

@@ -2528,4 +2528,5 @@ export const minimalSurvey: TSurvey = {
productOverwrites: null,
singleUse: null,
styling: null,
resultShareKey: null,
};

View File

@@ -1,6 +1,6 @@
import FormbricksClient from "@/app/(app)/components/FormbricksClient";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
// import { redirect } from "next/navigation";
import { Suspense } from "react";
import { authOptions } from "@formbricks/lib/authOptions";
@@ -11,9 +11,9 @@ import PosthogIdentify from "./components/PosthogIdentify";
export default async function AppLayout({ children }) {
const session = await getServerSession(authOptions);
if (!session) {
return redirect(`/auth/login`);
}
// if (!session) {
// return redirect(`/auth/login`);
// }
return (
<>
@@ -23,8 +23,13 @@ export default async function AppLayout({ children }) {
</Suspense>
<PHProvider>
<>
<PosthogIdentify session={session} />
<FormbricksClient session={session} />
{session ? (
<>
<PosthogIdentify session={session} />
<FormbricksClient session={session} />
</>
) : null}
{children}
</>
</PHProvider>

View File

@@ -0,0 +1,60 @@
import { cn } from "@formbricks/lib/cn";
import { PresentationChartLineIcon, InboxStackIcon } from "@heroicons/react/24/solid";
import Link from "next/link";
import revalidateSurveyIdPath from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/actions";
interface SurveyResultsTabProps {
activeId: string;
environmentId: string;
surveyId: string;
sharingKey: string;
}
export default function SurveyResultsTab({
activeId,
environmentId,
surveyId,
sharingKey,
}: SurveyResultsTabProps) {
const tabs = [
{
id: "summary",
label: "Summary",
icon: <PresentationChartLineIcon />,
href: `/share/${sharingKey}/summary?referer=true`,
},
{
id: "responses",
label: "Responses",
icon: <InboxStackIcon />,
href: `/share/${sharingKey}/responses?referer=true`,
},
];
return (
<div>
<div className="mb-7 h-14 w-full border-b">
<nav className="flex h-full items-center space-x-4 justify-self-center" aria-label="Tabs">
{tabs.map((tab) => (
<Link
key={tab.id}
onClick={() => {
revalidateSurveyIdPath(environmentId, surveyId);
}}
href={tab.href}
className={cn(
tab.id === activeId
? " border-brand-dark text-brand-dark border-b-2 font-semibold"
: "text-slate-500 hover:text-slate-700",
"flex h-full items-center px-3 text-sm font-medium"
)}
aria-current={tab.id === activeId ? "page" : undefined}>
{tab.icon && <div className="mr-2 h-5 w-5">{tab.icon}</div>}
{tab.label}
</Link>
))}
</nav>
</div>
</div>
);
}

View File

@@ -0,0 +1,38 @@
"use server";
import { createTag } from "@formbricks/lib/tag/service";
import { addTagToRespone, deleteTagOnResponse } from "@formbricks/lib/tagOnResponse/service";
import { hasUserEnvironmentAccess } from "@formbricks/lib/environment/auth";
import { authOptions } from "@formbricks/lib/authOptions";
import { getServerSession } from "next-auth";
import { AuthorizationError } from "@formbricks/types/errors";
import { canUserAccessTagOnResponse } from "@formbricks/lib/tagOnResponse/auth";
export const createTagAction = async (environmentId: string, tagName: string) => {
const session = await getServerSession(authOptions);
if (!session) throw new AuthorizationError("Not authorized");
const isAuthorized = await hasUserEnvironmentAccess(session.user.id, environmentId);
if (!isAuthorized) throw new AuthorizationError("Not authorized");
return await createTag(environmentId, tagName);
};
export const createTagToResponeAction = async (responseId: string, tagId: string) => {
const session = await getServerSession(authOptions);
if (!session) throw new AuthorizationError("Not authorized");
const isAuthorized = await canUserAccessTagOnResponse(session.user.id, tagId, responseId);
if (!isAuthorized) throw new AuthorizationError("Not authorized");
return await addTagToRespone(responseId, tagId);
};
export const deleteTagOnResponseAction = async (responseId: string, tagId: string) => {
const session = await getServerSession(authOptions);
if (!session) throw new AuthorizationError("Not authorized");
const isAuthorized = await canUserAccessTagOnResponse(session.user.id, tagId, responseId);
if (!isAuthorized) throw new AuthorizationError("Not authorized");
return await deleteTagOnResponse(responseId, tagId);
};

View File

@@ -0,0 +1,119 @@
"use client";
import { PlusIcon } from "@heroicons/react/24/solid";
import clsx from "clsx";
import { Maximize2Icon, Minimize2Icon } from "lucide-react";
import { useEffect, useMemo, useRef } from "react";
import { cn } from "@formbricks/lib/cn";
import { timeSince } from "@formbricks/lib/time";
import { TResponseNote } from "@formbricks/types/responses";
interface ResponseNotesProps {
responseId: string;
notes: TResponseNote[];
isOpen: boolean;
setIsOpen: (isOpen: boolean) => void;
}
export default function ResponseNotes({ notes, isOpen, setIsOpen }: ResponseNotesProps) {
const divRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (divRef.current) {
divRef.current.scrollTop = divRef.current.scrollHeight;
}
}, [notes]);
const unresolvedNotes = useMemo(() => notes.filter((note) => !note.isResolved), [notes]);
return (
<div
className={clsx(
"absolute w-1/4 rounded-lg border border-slate-200 shadow-sm transition-all",
!isOpen && unresolvedNotes.length && "group/hint cursor-pointer bg-white hover:-right-3",
!isOpen && !unresolvedNotes.length && "cursor-pointer bg-slate-50",
isOpen
? "-right-5 top-0 h-5/6 max-h-[600px] w-1/4 bg-white"
: unresolvedNotes.length
? "right-0 top-[8.33%] h-5/6 max-h-[600px] w-1/12"
: "right-[120px] top-[8.333%] h-5/6 max-h-[600px] w-1/12 group-hover:right-[0]"
)}
onClick={() => {
if (!isOpen) setIsOpen(true);
}}>
{!isOpen ? (
<div className="flex h-full flex-col">
<div
className={clsx(
"space-y-2 rounded-t-lg px-2 pb-2 pt-2",
unresolvedNotes.length ? "flex h-12 items-center justify-end bg-amber-50" : "bg-slate-200"
)}>
{!unresolvedNotes.length ? (
<div className="flex items-center justify-end">
<div className="group flex items-center">
<h3 className="float-left ml-4 pb-1 text-sm text-slate-600">Note</h3>
</div>
</div>
) : (
<div className="float-left mr-1.5">
<Maximize2Icon className="h-4 w-4 text-amber-500 hover:text-amber-600 group-hover/hint:scale-110" />
</div>
)}
</div>
{!unresolvedNotes.length ? (
<div className="flex flex-1 items-center justify-end pr-3">
<span>
<PlusIcon className=" h-5 w-5 text-slate-400" />
</span>
</div>
) : null}
</div>
) : (
<div className="relative flex h-full flex-col">
<div className="rounded-t-lg bg-amber-50 px-4 pb-3 pt-4">
<div className="flex items-center justify-between">
<div className="group flex items-center">
<h3 className="pb-1 text-sm text-amber-500">Note</h3>
</div>
<button
className="h-6 w-6 cursor-pointer"
onClick={() => {
setIsOpen(!isOpen);
}}>
<Minimize2Icon className="h-5 w-5 text-amber-500 hover:text-amber-600" />
</button>
</div>
</div>
<div className="flex-1 overflow-auto px-4 pt-2" ref={divRef}>
{unresolvedNotes.map((note) => (
<div className="group/notetext mb-3" key={note.id}>
<span className="block font-semibold text-slate-700">
{note.user.name}
<time
className="ml-2 text-xs font-normal text-slate-500"
dateTime={timeSince(note.updatedAt.toISOString())}>
{timeSince(note.updatedAt.toISOString())}
</time>
{note.isEdited && (
<span className="ml-1 text-[12px] font-normal text-slate-500">{"(edited)"}</span>
)}
</span>
<div className="flex items-center">
<span className="block text-slate-700">{note.text}</span>
</div>
</div>
))}
</div>
<div className={cn("h-[120px] transition-all duration-300")}>
<div
className={clsx(
"absolute bottom-0 w-full px-3 pb-3",
!unresolvedNotes.length && "absolute bottom-0"
)}></div>
</div>
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,82 @@
"use client";
import { useResponseFilter } from "@/app/(app)/environments/[environmentId]/components/ResponseFilterContext";
import CustomFilter from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/CustomFilter";
import SurveyResultsTabs from "@/app/(app)/share/[sharingKey]/(analysis)/components/SurveyResultsTabs";
import ResponseTimeline from "@/app/(app)/share/[sharingKey]/(analysis)/responses/components/ResponseTimeline";
import SummaryHeader from "@/app/(app)/share/[sharingKey]/components/SummaryHeader";
import { getFilterResponses } from "@/app/lib/surveys/surveys";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo } from "react";
import { TEnvironment } from "@formbricks/types/environment";
import { TProduct } from "@formbricks/types/product";
import { TResponse } from "@formbricks/types/responses";
import { TSurvey } from "@formbricks/types/surveys";
import { TTag } from "@formbricks/types/tags";
import ContentWrapper from "@formbricks/ui/ContentWrapper";
interface ResponsePageProps {
environment: TEnvironment;
survey: TSurvey;
surveyId: string;
responses: TResponse[];
webAppUrl: string;
product: TProduct;
sharingKey: string;
environmentTags: TTag[];
responsesPerPage: number;
}
const ResponsePage = ({
environment,
survey,
surveyId,
responses,
product,
sharingKey,
environmentTags,
responsesPerPage,
}: ResponsePageProps) => {
const { selectedFilter, dateRange, resetState } = useResponseFilter();
const searchParams = useSearchParams();
useEffect(() => {
if (!searchParams?.get("referer")) {
resetState();
}
}, [searchParams]);
// get the filtered array when the selected filter value changes
const filterResponses: TResponse[] = useMemo(() => {
return getFilterResponses(responses, selectedFilter, survey, dateRange);
}, [selectedFilter, responses, survey, dateRange]);
return (
<ContentWrapper>
<SummaryHeader survey={survey} product={product} />
<CustomFilter
environmentTags={environmentTags}
responses={filterResponses}
survey={survey}
totalResponses={responses}
/>
<SurveyResultsTabs
activeId="responses"
environmentId={environment.id}
surveyId={surveyId}
sharingKey={sharingKey}
/>
<ResponseTimeline
environment={environment}
surveyId={surveyId}
responses={filterResponses}
survey={survey}
environmentTags={environmentTags}
responsesPerPage={responsesPerPage}
/>
</ContentWrapper>
);
};
export default ResponsePage;

View File

@@ -0,0 +1,91 @@
"use client";
import EmptyInAppSurveys from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/components/EmptyInAppSurveys";
import { useEffect, useRef, useState } from "react";
import { TEnvironment } from "@formbricks/types/environment";
import { TResponse } from "@formbricks/types/responses";
import { TSurvey } from "@formbricks/types/surveys";
import { TTag } from "@formbricks/types/tags";
import EmptySpaceFiller from "@formbricks/ui/EmptySpaceFiller";
import SingleResponseCard from "@formbricks/ui/SingleResponseCard";
interface ResponseTimelineProps {
environment: TEnvironment;
surveyId: string;
responses: TResponse[];
survey: TSurvey;
environmentTags: TTag[];
responsesPerPage: number;
}
export default function ResponseTimeline({
environment,
responses,
survey,
environmentTags,
responsesPerPage,
}: ResponseTimelineProps) {
const [displayedResponses, setDisplayedResponses] = useState<TResponse[]>([]);
const loadingRef = useRef(null);
useEffect(() => {
setDisplayedResponses(responses.slice(0, responsesPerPage));
}, [responses]);
useEffect(() => {
const observer = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting) {
setDisplayedResponses((prevResponses) => [
...prevResponses,
...responses.slice(prevResponses.length, prevResponses.length + responsesPerPage),
]);
}
},
{ threshold: 0.8 }
);
if (loadingRef.current) {
observer.observe(loadingRef.current);
}
return () => {
if (loadingRef.current) {
observer.unobserve(loadingRef.current);
}
};
}, [responses]);
return (
<div className="space-y-4">
{survey.type === "web" && displayedResponses.length === 0 && !environment.widgetSetupCompleted ? (
<EmptyInAppSurveys environment={environment} />
) : displayedResponses.length === 0 ? (
<EmptySpaceFiller
type="response"
environment={environment}
noWidgetRequired={survey.type === "link"}
/>
) : (
<div>
{displayedResponses.map((response) => {
return (
<div key={response.id}>
<SingleResponseCard
survey={survey}
response={response}
environmentTags={environmentTags}
pageType="response"
environment={environment}
user={undefined}
/>
</div>
);
})}
<div ref={loadingRef}></div>
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,57 @@
import { getAnalysisData } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/data";
import ResponsePage from "@/app/(app)/share/[sharingKey]/(analysis)/responses/components/ResponsePage";
import { getResultShareUrlSurveyAction } from "@/app/(app)/share/[sharingKey]/action";
import { notFound } from "next/navigation";
import { RESPONSES_PER_PAGE, REVALIDATION_INTERVAL, WEBAPP_URL } from "@formbricks/lib/constants";
import { getEnvironment } from "@formbricks/lib/environment/service";
import { getProductByEnvironmentId } from "@formbricks/lib/product/service";
import { getSurvey } from "@formbricks/lib/survey/service";
import { getTagsByEnvironmentId } from "@formbricks/lib/tag/service";
export const revalidate = REVALIDATION_INTERVAL;
export default async function Page({ params }) {
const surveyId = await getResultShareUrlSurveyAction(params.sharingKey);
if (!surveyId) {
return notFound();
}
const survey = await getSurvey(surveyId);
if (!survey) {
throw new Error("Survey not found");
}
const [{ responses }, environment] = await Promise.all([
getAnalysisData(survey.id, survey.environmentId),
getEnvironment(survey.environmentId),
]);
if (!environment) {
throw new Error("Environment not found");
}
const product = await getProductByEnvironmentId(environment.id);
if (!product) {
throw new Error("Product not found");
}
const tags = await getTagsByEnvironmentId(environment.id);
return (
<>
<ResponsePage
environment={environment}
responses={responses}
survey={survey}
surveyId={params.surveyId}
webAppUrl={WEBAPP_URL}
product={product}
sharingKey={params.sharingKey}
environmentTags={tags}
responsesPerPage={RESPONSES_PER_PAGE}
/>
</>
);
}

View File

@@ -0,0 +1,92 @@
"use client";
import { useResponseFilter } from "@/app/(app)/environments/[environmentId]/components/ResponseFilterContext";
import SummaryDropOffs from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryDropOffs";
import SummaryList from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryList";
import SummaryMetadata from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryMetadata";
import CustomFilter from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/CustomFilter";
import SurveyResultsTabs from "@/app/(app)/share/[sharingKey]/(analysis)/components/SurveyResultsTabs";
import SummaryHeader from "@/app/(app)/share/[sharingKey]/components/SummaryHeader";
import { getFilterResponses } from "@/app/lib/surveys/surveys";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useState } from "react";
import { TEnvironment } from "@formbricks/types/environment";
import { TProduct } from "@formbricks/types/product";
import { TResponse } from "@formbricks/types/responses";
import { TSurvey } from "@formbricks/types/surveys";
import { TTag } from "@formbricks/types/tags";
import ContentWrapper from "@formbricks/ui/ContentWrapper";
interface SummaryPageProps {
environment: TEnvironment;
survey: TSurvey;
surveyId: string;
responses: TResponse[];
product: TProduct;
sharingKey: string;
environmentTags: TTag[];
displayCount: number;
responsesPerPage: number;
}
const SummaryPage = ({
environment,
survey,
surveyId,
responses,
product,
sharingKey,
environmentTags,
displayCount,
responsesPerPage: openTextResponsesPerPage,
}: SummaryPageProps) => {
const { selectedFilter, dateRange, resetState } = useResponseFilter();
const [showDropOffs, setShowDropOffs] = useState<boolean>(false);
const searchParams = useSearchParams();
useEffect(() => {
if (!searchParams?.get("referer")) {
resetState();
}
}, [searchParams]);
// get the filtered array when the selected filter value changes
const filterResponses: TResponse[] = useMemo(() => {
return getFilterResponses(responses, selectedFilter, survey, dateRange);
}, [selectedFilter, responses, survey, dateRange]);
return (
<ContentWrapper>
<SummaryHeader survey={survey} product={product} />
<CustomFilter
environmentTags={environmentTags}
responses={filterResponses}
survey={survey}
totalResponses={responses}
/>
<SurveyResultsTabs
activeId="summary"
environmentId={environment.id}
surveyId={surveyId}
sharingKey={sharingKey}
/>
<SummaryMetadata
responses={filterResponses}
survey={survey}
displayCount={displayCount}
showDropOffs={showDropOffs}
setShowDropOffs={setShowDropOffs}
/>
{showDropOffs && <SummaryDropOffs survey={survey} responses={responses} displayCount={displayCount} />}
<SummaryList
responses={filterResponses}
survey={survey}
environment={environment}
responsesPerPage={openTextResponsesPerPage}
/>
</ContentWrapper>
);
};
export default SummaryPage;

View File

@@ -0,0 +1,58 @@
import { getAnalysisData } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/data";
import SummaryPage from "@/app/(app)/share/[sharingKey]/(analysis)/summary/components/SummaryPage";
import { getResultShareUrlSurveyAction } from "@/app/(app)/share/[sharingKey]/action";
import { notFound } from "next/navigation";
import { REVALIDATION_INTERVAL, TEXT_RESPONSES_PER_PAGE } from "@formbricks/lib/constants";
import { getEnvironment } from "@formbricks/lib/environment/service";
import { getProductByEnvironmentId } from "@formbricks/lib/product/service";
import { getSurvey } from "@formbricks/lib/survey/service";
import { getTagsByEnvironmentId } from "@formbricks/lib/tag/service";
export const revalidate = REVALIDATION_INTERVAL;
export default async function Page({ params }) {
const surveyId = await getResultShareUrlSurveyAction(params.sharingKey);
if (!surveyId) {
return notFound();
}
const survey = await getSurvey(surveyId);
if (!survey) {
throw new Error("Survey not found");
}
const [{ responses, displayCount }, environment] = await Promise.all([
getAnalysisData(survey.id, survey.environmentId),
getEnvironment(survey.environmentId),
]);
if (!environment) {
throw new Error("Environment not found");
}
const product = await getProductByEnvironmentId(environment.id);
if (!product) {
throw new Error("Product not found");
}
const tags = await getTagsByEnvironmentId(environment.id);
return (
<>
<SummaryPage
environment={environment}
responses={responses}
survey={survey}
sharingKey={params.sharingKey}
surveyId={survey.id}
product={product}
environmentTags={tags}
displayCount={displayCount}
responsesPerPage={TEXT_RESPONSES_PER_PAGE}
/>
</>
);
}

View File

@@ -0,0 +1,7 @@
"use server";
import { getSurveyByResultShareKey } from "@formbricks/lib/survey/service";
export async function getResultShareUrlSurveyAction(key: string): Promise<string | null> {
return getSurveyByResultShareKey(key);
}

View File

@@ -0,0 +1,472 @@
"use client";
import {
DateRange,
useResponseFilter,
} from "@/app/(app)/environments/[environmentId]/components/ResponseFilterContext";
import ResponseFilter from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/components/ResponseFilter";
import { fetchFile } from "@/app/lib/fetchFile";
import { generateQuestionAndFilterOptions, getTodayDate } from "@/app/lib/surveys/surveys";
import { createId } from "@paralleldrive/cuid2";
import { differenceInDays, format, subDays } from "date-fns";
import { ChevronDown, ChevronUp, DownloadIcon } from "lucide-react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import toast from "react-hot-toast";
import { getTodaysDateFormatted } from "@formbricks/lib/time";
import useClickOutside from "@formbricks/lib/useClickOutside";
import { TResponse } from "@formbricks/types/responses";
import { TSurvey } from "@formbricks/types/surveys";
import { TTag } from "@formbricks/types/tags";
import { Calendar } from "@formbricks/ui/Calendar";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@formbricks/ui/DropdownMenu";
enum DateSelected {
FROM = "from",
TO = "to",
}
enum FilterDownload {
ALL = "all",
FILTER = "filter",
}
enum FilterDropDownLabels {
ALL_TIME = "All time",
LAST_7_DAYS = "Last 7 days",
LAST_30_DAYS = "Last 30 days",
CUSTOM_RANGE = "Custom range...",
}
interface CustomFilterProps {
environmentTags: TTag[];
survey: TSurvey;
responses: TResponse[];
totalResponses: TResponse[];
}
const getDifferenceOfDays = (from, to) => {
const days = differenceInDays(to, from);
if (days === 7) {
return FilterDropDownLabels.LAST_7_DAYS;
} else if (days === 30) {
return FilterDropDownLabels.LAST_30_DAYS;
} else {
return FilterDropDownLabels.CUSTOM_RANGE;
}
};
const CustomFilter = ({ environmentTags, responses, survey, totalResponses }: CustomFilterProps) => {
const { setSelectedOptions, dateRange, setDateRange } = useResponseFilter();
const [filterRange, setFilterRange] = useState<FilterDropDownLabels>(
dateRange.from && dateRange.to
? getDifferenceOfDays(dateRange.from, dateRange.to)
: FilterDropDownLabels.ALL_TIME
);
const [selectingDate, setSelectingDate] = useState<DateSelected>(DateSelected.FROM);
const [isDatePickerOpen, setIsDatePickerOpen] = useState<boolean>(false);
const [isFilterDropDownOpen, setIsFilterDropDownOpen] = useState<boolean>(false);
const [isDownloadDropDownOpen, setIsDownloadDropDownOpen] = useState<boolean>(false);
const [hoveredRange, setHoveredRange] = useState<DateRange | null>(null);
// when the page loads we get total responses and iterate over the responses and questions, tags and attributes to create the filter options
useEffect(() => {
const { questionFilterOptions, questionOptions } = generateQuestionAndFilterOptions(
survey,
totalResponses,
environmentTags
);
setSelectedOptions({ questionFilterOptions, questionOptions });
}, [totalResponses, survey, setSelectedOptions, environmentTags]);
const datePickerRef = useRef<HTMLDivElement>(null);
const getMatchQandA = (responses: TResponse[], survey: TSurvey) => {
if (survey && responses) {
// Create a mapping of question IDs to their headlines
const questionIdToHeadline = {};
survey.questions.forEach((question) => {
questionIdToHeadline[question.id] = question.headline;
});
// Replace question IDs with question headlines in response data
const updatedResponses = responses.map((response) => {
const updatedResponse: Array<{
id: string;
question: string;
answer: string;
type: string;
scale?: "number" | "star" | "smiley";
range?: number;
}> = []; // Specify the type of updatedData
// iterate over survey questions and build the updated response
for (const question of survey.questions) {
const answer = response.data[question.id];
if (answer) {
updatedResponse.push({
id: createId(),
question: question.headline,
type: question.type,
scale: question.scale,
range: question.range,
answer: answer as string,
});
}
}
return { ...response, responses: updatedResponse };
});
const updatedResponsesWithTags = updatedResponses.map((response) => ({
...response,
tags: response.tags?.map((tag) => tag),
}));
return updatedResponsesWithTags;
}
return [];
};
const downloadFileName = useMemo(() => {
if (survey) {
const formattedDateString = getTodaysDateFormatted("_");
return `${survey.name.split(" ").join("_")}_responses_${formattedDateString}`.toLocaleLowerCase();
}
return "my_survey_responses";
}, [survey]);
function extracMetadataKeys(obj, parentKey = "") {
let keys: string[] = [];
for (let key in obj) {
if (typeof obj[key] === "object" && obj[key] !== null) {
keys = keys.concat(extracMetadataKeys(obj[key], parentKey + key + " - "));
} else {
keys.push(parentKey + key);
}
}
return keys;
}
const downloadResponses = useCallback(
async (filter: FilterDownload, filetype: "csv" | "xlsx") => {
const downloadResponse = filter === FilterDownload.ALL ? totalResponses : responses;
const questionNames = survey.questions?.map((question) => question.headline);
const hiddenFieldIds = survey.hiddenFields.fieldIds;
const hiddenFieldResponse = {};
let metaDataFields = extracMetadataKeys(downloadResponse[0].meta);
const userAttributes = ["Init Attribute 1", "Init Attribute 2"];
const matchQandA = getMatchQandA(downloadResponse, survey);
const jsonData = matchQandA.map((response) => {
const basicInfo = {
"Response ID": response.id,
Timestamp: response.createdAt,
Finished: response.finished,
"Survey ID": response.surveyId,
"Formbricks User ID": response.person?.id ?? "",
};
const metaDataKeys = extracMetadataKeys(response.meta);
let metaData = {};
metaDataKeys.forEach((key) => {
if (!metaDataFields.includes(key)) metaDataFields.push(key);
if (response.meta) {
if (key.includes("-")) {
const nestedKeyArray = key.split("-");
metaData[key] = response.meta[nestedKeyArray[0].trim()][nestedKeyArray[1].trim()] ?? "";
} else {
metaData[key] = response.meta[key] ?? "";
}
}
});
const personAttributes = response.personAttributes;
if (hiddenFieldIds && hiddenFieldIds.length > 0) {
hiddenFieldIds.forEach((hiddenFieldId) => {
hiddenFieldResponse[hiddenFieldId] = response.data[hiddenFieldId] ?? "";
});
}
const fileResponse = { ...basicInfo, ...metaData, ...personAttributes, ...hiddenFieldResponse };
// Map each question name to its corresponding answer
questionNames.forEach((questionName: string) => {
const matchingQuestion = response.responses.find((question) => question.question === questionName);
let transformedAnswer = "";
if (matchingQuestion) {
const answer = matchingQuestion.answer;
if (Array.isArray(answer)) {
transformedAnswer = answer.join("; ");
} else {
transformedAnswer = answer;
}
}
fileResponse[questionName] = matchingQuestion ? transformedAnswer : "";
});
return fileResponse;
});
// Fields which will be used as column headers in the file
const fields = [
"Response ID",
"Timestamp",
"Finished",
"Survey ID",
"Formbricks User ID",
...metaDataFields,
...questionNames,
...(hiddenFieldIds ?? []),
...(survey.type === "web" ? userAttributes : []),
];
let response;
try {
response = await fetchFile(
{
json: jsonData,
fields,
fileName: downloadFileName,
},
filetype
);
} catch (err) {
toast.error(`Error downloading ${filetype === "csv" ? "CSV" : "Excel"}`);
return;
}
let blob: Blob;
if (filetype === "csv") {
blob = new Blob([response.fileResponse], { type: "text/csv;charset=utf-8;" });
} else if (filetype === "xlsx") {
const binaryString = atob(response["fileResponse"]);
const byteArray = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
byteArray[i] = binaryString.charCodeAt(i);
}
blob = new Blob([byteArray], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
} else {
throw new Error(`Unsupported filetype: ${filetype}`);
}
const downloadUrl = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = downloadUrl;
link.download = `${downloadFileName}.${filetype}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(downloadUrl);
},
[downloadFileName, responses, totalResponses, survey]
);
const handleDateHoveredChange = (date: Date) => {
if (selectingDate === DateSelected.FROM) {
const startOfRange = new Date(date);
startOfRange.setHours(0, 0, 0, 0); // Set to the start of the selected day
// Check if the selected date is after the current 'to' date
if (startOfRange > dateRange?.to!) {
return;
} else {
setHoveredRange({ from: startOfRange, to: dateRange.to });
}
} else {
const endOfRange = new Date(date);
endOfRange.setHours(23, 59, 59, 999); // Set to the end of the selected day
// Check if the selected date is before the current 'from' date
if (endOfRange < dateRange?.from!) {
return;
} else {
setHoveredRange({ from: dateRange.from, to: endOfRange });
}
}
};
const handleDateChange = (date: Date) => {
if (selectingDate === DateSelected.FROM) {
const startOfRange = new Date(date);
startOfRange.setHours(0, 0, 0, 0); // Set to the start of the selected day
// Check if the selected date is after the current 'to' date
if (startOfRange > dateRange?.to!) {
const nextDay = new Date(startOfRange);
nextDay.setDate(nextDay.getDate() + 1);
nextDay.setHours(23, 59, 59, 999);
setDateRange({ from: startOfRange, to: nextDay });
} else {
setDateRange((prevData) => ({ from: startOfRange, to: prevData.to }));
}
setSelectingDate(DateSelected.TO);
} else {
const endOfRange = new Date(date);
endOfRange.setHours(23, 59, 59, 999); // Set to the end of the selected day
// Check if the selected date is before the current 'from' date
if (endOfRange < dateRange?.from!) {
const previousDay = new Date(endOfRange);
previousDay.setDate(previousDay.getDate() - 1);
previousDay.setHours(0, 0, 0, 0); // Set to the start of the selected day
setDateRange({ from: previousDay, to: endOfRange });
} else {
setDateRange((prevData) => ({ from: prevData?.from, to: endOfRange }));
}
setIsDatePickerOpen(false);
setSelectingDate(DateSelected.FROM);
}
};
const handleDatePickerClose = () => {
setIsDatePickerOpen(false);
setSelectingDate(DateSelected.FROM);
};
useClickOutside(datePickerRef, () => handleDatePickerClose());
return (
<>
<div className="relative mb-12 flex justify-between">
<div className="flex justify-stretch gap-x-1.5">
<ResponseFilter />
<DropdownMenu
onOpenChange={(value) => {
value && handleDatePickerClose();
setIsFilterDropDownOpen(value);
}}>
<DropdownMenuTrigger>
<div className="flex h-auto min-w-[8rem] items-center justify-between rounded-md border bg-white p-3 sm:min-w-[11rem] sm:px-6 sm:py-3">
<span className="text-sm text-slate-700">
{filterRange === FilterDropDownLabels.CUSTOM_RANGE
? `${dateRange?.from ? format(dateRange?.from, "dd LLL") : "Select first date"} - ${
dateRange?.to ? format(dateRange.to, "dd LLL") : "Select last date"
}`
: filterRange}
</span>
{isFilterDropDownOpen ? (
<ChevronUp className="ml-2 h-4 w-4 opacity-50" />
) : (
<ChevronDown className="ml-2 h-4 w-4 opacity-50" />
)}
</div>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
setFilterRange(FilterDropDownLabels.ALL_TIME);
setDateRange({ from: undefined, to: getTodayDate() });
}}>
<p className="text-slate-700">All time</p>
</DropdownMenuItem>
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
setFilterRange(FilterDropDownLabels.LAST_7_DAYS);
setDateRange({ from: subDays(new Date(), 7), to: getTodayDate() });
}}>
<p className="text-slate-700">Last 7 days</p>
</DropdownMenuItem>
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
setFilterRange(FilterDropDownLabels.LAST_30_DAYS);
setDateRange({ from: subDays(new Date(), 30), to: getTodayDate() });
}}>
<p className="text-slate-700">Last 30 days</p>
</DropdownMenuItem>
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
setIsDatePickerOpen(true);
setFilterRange(FilterDropDownLabels.CUSTOM_RANGE);
setSelectingDate(DateSelected.FROM);
}}>
<p className="text-sm text-slate-700 hover:ring-0">Custom range...</p>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<DropdownMenu
onOpenChange={(value) => {
value && handleDatePickerClose();
setIsDownloadDropDownOpen(value);
}}>
<DropdownMenuTrigger asChild className="focus:bg-muted cursor-pointer outline-none">
<div className="min-w-auto h-auto rounded-md border bg-white p-3 sm:flex sm:min-w-[11rem] sm:px-6 sm:py-3">
<div className="hidden w-full items-center justify-between sm:flex">
<span className="text-sm text-slate-700">Download</span>
{isDownloadDropDownOpen ? (
<ChevronUp className="ml-2 h-4 w-4 opacity-50" />
) : (
<ChevronDown className="ml-2 h-4 w-4 opacity-50" />
)}
</div>
<DownloadIcon className="block h-4 sm:hidden" />
</div>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
downloadResponses(FilterDownload.ALL, "csv");
}}>
<p className="text-slate-700">All responses (CSV)</p>
</DropdownMenuItem>
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
downloadResponses(FilterDownload.ALL, "xlsx");
}}>
<p className="text-slate-700">All responses (Excel)</p>
</DropdownMenuItem>
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
downloadResponses(FilterDownload.FILTER, "csv");
}}>
<p className="text-slate-700">Current selection (CSV)</p>
</DropdownMenuItem>
<DropdownMenuItem
className="hover:ring-0"
onClick={() => {
downloadResponses(FilterDownload.FILTER, "xlsx");
}}>
<p className="text-slate-700">Current selection (Excel)</p>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
{isDatePickerOpen && (
<div ref={datePickerRef} className="absolute top-full z-50 my-2 rounded-md border bg-white">
<Calendar
initialFocus
mode="range"
defaultMonth={dateRange?.from}
selected={hoveredRange ? hoveredRange : dateRange}
numberOfMonths={2}
onDayClick={(date) => handleDateChange(date)}
onDayMouseEnter={handleDateHoveredChange}
onDayMouseLeave={() => setHoveredRange(null)}
classNames={{
day_today: "hover:bg-slate-200 bg-white",
}}
/>
</div>
)}
</div>
</>
);
};
export default CustomFilter;

View File

@@ -0,0 +1,21 @@
"use client";
import { TProduct } from "@formbricks/types/product";
import { TSurvey } from "@formbricks/types/surveys";
interface SummaryHeaderProps {
survey: TSurvey;
product: TProduct;
}
const SummaryHeader = ({ survey, product }: SummaryHeaderProps) => {
return (
<div className="mb-11 mt-6 flex flex-wrap items-center justify-between">
<div>
<p className="text-3xl font-bold text-slate-800">{survey.name}</p>
<span className="text-base font-extralight text-slate-600">{product.name}</span>
</div>
</div>
);
};
export default SummaryHeader;

View File

@@ -0,0 +1,14 @@
import { ResponseFilterProvider } from "@/app/(app)/environments/[environmentId]/components/ResponseFilterContext";
import { Metadata } from "next";
export const metadata: Metadata = {
robots: { index: false, follow: false },
};
export default async function EnvironmentLayout({ children }) {
return (
<div className="flex-1">
<ResponseFilterProvider>{children}</ResponseFilterProvider>
</div>
);
}

View File

@@ -0,0 +1,20 @@
import Link from "next/link";
import { Button } from "@formbricks/ui/Button";
export default function NotFound() {
return (
<>
<div className="mx-auto flex h-full max-w-xl flex-col items-center justify-center py-16 text-center">
<p className="text-sm font-semibold text-zinc-900 dark:text-white">404</p>
<h1 className="mt-2 text-2xl font-bold text-zinc-900 dark:text-white">Page not found</h1>
<p className="mt-2 text-base text-zinc-600 dark:text-zinc-400">
Sorry, we couldnt find the responses sharing ID youre looking for.
</p>
<Link href={"/"}>
<Button className="mt-8">Back to home</Button>
</Link>
</div>
</>
);
}

View File

@@ -0,0 +1,5 @@
import { redirect } from "next/navigation";
export default function EnvironmentPage({ params }) {
return redirect(`/share/${params.sharingKey}/summary`);
}

View File

@@ -5,6 +5,7 @@ import { resetPassword } from "@/app/lib/users/users";
import { XCircleIcon } from "@heroicons/react/24/solid";
import { useRouter, useSearchParams } from "next/navigation";
import { useState } from "react";
import { toast } from "react-hot-toast";
import { Button } from "@formbricks/ui/Button";
import { PasswordInput } from "@formbricks/ui/PasswordInput";
@@ -14,11 +15,16 @@ export const ResetPasswordForm = () => {
const router = useRouter();
const [error, setError] = useState<string>("");
const [password, setPassword] = useState<string | null>(null);
const [confirmPassword, setConfirmPassword] = useState<string | null>(null);
const [isValid, setIsValid] = useState(false);
const [loading, setLoading] = useState<boolean>(false);
const handleSubmit = async (e) => {
e.preventDefault();
if (password !== confirmPassword) {
toast.error("Passwords do not match");
return;
}
setLoading(true);
const token = searchParams?.get("token");
try {
@@ -51,23 +57,39 @@ export const ResetPasswordForm = () => {
</div>
)}
<form onSubmit={handleSubmit} className="space-y-6">
<div>
<label htmlFor="email" className="block text-sm font-medium text-slate-800">
New password
</label>
<div className="mt-1">
<div className="space-y-4">
<div>
<label htmlFor="email" className="block text-sm font-medium text-slate-800">
New password
</label>
<PasswordInput
id="password"
name="password"
value={password ? password : ""}
value={password ?? ""}
onChange={(e) => setPassword(e.target.value)}
autoComplete="current-password"
placeholder="*******"
required
className="focus:border-brand focus:ring-brand block w-full rounded-md border-slate-300 shadow-sm sm:text-sm"
className="focus:border-brand focus:ring-brand mt-2 block w-full rounded-md border-slate-300 shadow-sm sm:text-sm"
/>
<IsPasswordValid password={password} setIsValid={setIsValid} />
</div>
<div>
<label htmlFor="email" className="block text-sm font-medium text-slate-800">
Confirm password
</label>
<PasswordInput
id="confirmPassword"
name="confirmPassword"
value={confirmPassword ?? ""}
onChange={(e) => setConfirmPassword(e.target.value)}
autoComplete="current-password"
placeholder="*******"
required
className="focus:border-brand focus:ring-brand mt-2 block w-full rounded-md border-slate-300 shadow-sm sm:text-sm"
/>
</div>
<IsPasswordValid password={password} setIsValid={setIsValid} />
</div>
<div>

View File

@@ -1,5 +1,6 @@
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
import { Toaster } from "react-hot-toast";
import { authOptions } from "@formbricks/lib/authOptions";
@@ -9,10 +10,13 @@ export default async function AuthLayout({ children }: { children: React.ReactNo
redirect(`/`);
}
return (
<div className="min-h-screen bg-slate-50">
<div className="isolate bg-white">
<div className="bg-gradient-radial flex min-h-screen from-slate-200 to-slate-50">{children}</div>
<>
<Toaster />
<div className="min-h-screen bg-slate-50">
<div className="isolate bg-white">
<div className="bg-gradient-radial flex min-h-screen from-slate-200 to-slate-50">{children}</div>
</div>
</div>
</div>
</>
);
}

View File

@@ -1,6 +1,7 @@
"use client";
import { resendVerificationEmail } from "@/app/lib/users/users";
import { useEffect } from "react";
import toast from "react-hot-toast";
import { Button } from "@formbricks/ui/Button";
@@ -10,6 +11,20 @@ interface RequestEmailVerificationProps {
}
export const RequestVerificationEmail = ({ email }: RequestEmailVerificationProps) => {
useEffect(() => {
const handleVisibilityChange = () => {
if (document.visibilityState === "visible") {
location.reload();
}
};
document.addEventListener("visibilitychange", handleVisibilityChange);
return () => {
document.removeEventListener("visibilitychange", handleVisibilityChange);
};
}, []);
const requestVerificationEmail = async () => {
try {
if (!email) throw new Error("No email provided");
@@ -19,6 +34,7 @@ export const RequestVerificationEmail = ({ email }: RequestEmailVerificationProp
toast.error(`Error: ${e.message}`);
}
};
return (
<>
<Button variant="secondary" onClick={requestVerificationEmail} className="w-full justify-center">

View File

@@ -8,7 +8,7 @@ import { CRON_SECRET } from "@formbricks/lib/constants";
import { sendNoLiveSurveyNotificationEmail, sendWeeklySummaryNotificationEmail } from "./email";
import { EnvironmentData, NotificationResponse, ProductData, Survey, SurveyResponse } from "./types";
const BATCH_SIZE = 10;
const BATCH_SIZE = 500;
export async function POST(): Promise<NextResponse> {
// Check authentication

View File

@@ -13,7 +13,7 @@ export const metadata: Metadata = {
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body className="flex h-screen flex-col bg-slate-50">{children}</body>
<body className="flex h-screen flex-col">{children}</body>
</html>
);
}

View File

@@ -148,6 +148,76 @@ export const generateQuestionAndFilterOptions = (
return { questionOptions: [...questionOptions], questionFilterOptions: [...questionFilterOptions] };
};
export const generateQuestionAndFilterOptionsForResponseSharing = (
survey: TSurvey,
responses: TResponse[]
): {
questionOptions: QuestionOptions[];
questionFilterOptions: QuestionFilterOptions[];
} => {
let questionOptions: any = [];
let questionFilterOptions: any = [];
let questionsOptions: any = [];
survey.questions.forEach((q) => {
if (Object.keys(conditionOptions).includes(q.type)) {
questionsOptions.push({
label: q.headline,
questionType: q.type,
type: OptionsType.QUESTIONS,
id: q.id,
});
}
});
questionOptions = [...questionOptions, { header: OptionsType.QUESTIONS, option: questionsOptions }];
survey.questions.forEach((q) => {
if (Object.keys(conditionOptions).includes(q.type)) {
if (
q.type === TSurveyQuestionType.MultipleChoiceMulti ||
q.type === TSurveyQuestionType.MultipleChoiceSingle
) {
questionFilterOptions.push({
type: q.type,
filterOptions: conditionOptions[q.type],
filterComboBoxOptions: q?.choices ? q?.choices?.map((c) => c?.label) : [""],
id: q.id,
});
} else {
questionFilterOptions.push({
type: q.type,
filterOptions: conditionOptions[q.type],
filterComboBoxOptions: filterOptions[q.type],
id: q.id,
});
}
}
});
const attributes = getPersonAttributes(responses);
if (attributes) {
questionOptions = [
...questionOptions,
{
header: OptionsType.ATTRIBUTES,
option: Object.keys(attributes).map((a) => {
return { label: a, type: OptionsType.ATTRIBUTES, id: a };
}),
},
];
Object.keys(attributes).forEach((a) => {
questionFilterOptions.push({
type: "Attributes",
filterOptions: conditionOptions.userAttributes,
filterComboBoxOptions: attributes[a],
id: a,
});
});
}
return { questionOptions: [...questionOptions], questionFilterOptions: [...questionFilterOptions] };
};
// get the filtered responses
export const getFilterResponses = (
responses: TResponse[],

View File

@@ -1,6 +1,11 @@
import rateLimit from "@/app/middleware/rateLimit";
import { CLIENT_SIDE_API_RATE_LIMIT, LOGIN_RATE_LIMIT, SIGNUP_RATE_LIMIT } from "@formbricks/lib/constants";
import {
CLIENT_SIDE_API_RATE_LIMIT,
LOGIN_RATE_LIMIT,
SHARE_RATE_LIMIT,
SIGNUP_RATE_LIMIT,
} from "@formbricks/lib/constants";
export const signUpLimiter = rateLimit({
interval: SIGNUP_RATE_LIMIT.interval,
@@ -14,3 +19,8 @@ export const clientSideApiEndpointsLimiter = rateLimit({
interval: CLIENT_SIDE_API_RATE_LIMIT.interval,
allowedPerInterval: CLIENT_SIDE_API_RATE_LIMIT.allowedPerInterval,
});
export const shareUrlLimiter = rateLimit({
interval: SHARE_RATE_LIMIT.interval,
allowedPerInterval: SHARE_RATE_LIMIT.allowedPerInterval,
});

View File

@@ -8,3 +8,8 @@ export const clientSideApiRoute = (url: string): boolean => {
const regex = /^\/api\/v\d+\/client\//;
return regex.test(url);
};
export const shareUrlRoute = (url: string): boolean => {
const regex = /\/share\/[A-Za-z0-9]+\/(summary|responses)/;
return regex.test(url);
};

View File

@@ -1,12 +1,12 @@
import Link from "next/link";
import { IMPRINT_URL, PRIVACY_URL } from "@formbricks/lib/constants";
interface LegalFooterProps {
bgColor?: string | null;
IMPRINT_URL?: string;
PRIVACY_URL?: string;
}
export default function LegalFooter({ bgColor }: LegalFooterProps) {
export default function LegalFooter({ bgColor, IMPRINT_URL, PRIVACY_URL }: LegalFooterProps) {
if (!IMPRINT_URL && !PRIVACY_URL) return null;
return (

View File

@@ -1,7 +1,9 @@
"use client";
import { validateSurveyPinAction } from "@/app/s/[surveyId]/actions";
import LegalFooter from "@/app/s/[surveyId]/components/LegalFooter";
import LinkSurvey from "@/app/s/[surveyId]/components/LinkSurvey";
import { MediaBackground } from "@/app/s/[surveyId]/components/MediaBackground";
import { TSurveyPinValidationResponseError } from "@/app/s/[surveyId]/types";
import type { NextPage } from "next";
import { useCallback, useEffect, useState } from "react";
@@ -21,6 +23,8 @@ interface LinkSurveyPinScreenProps {
singleUseId?: string;
singleUseResponse?: TResponse;
webAppUrl: string;
IMPRINT_URL?: string;
PRIVACY_URL?: string;
}
const LinkSurveyPinScreen: NextPage<LinkSurveyPinScreenProps> = (props) => {
@@ -33,6 +37,8 @@ const LinkSurveyPinScreen: NextPage<LinkSurveyPinScreenProps> = (props) => {
prefillAnswer,
singleUseId,
singleUseResponse,
IMPRINT_URL,
PRIVACY_URL,
} = props;
const [localPinEntry, setLocalPinEntry] = useState<string>("");
@@ -101,16 +107,25 @@ const LinkSurveyPinScreen: NextPage<LinkSurveyPinScreenProps> = (props) => {
}
return (
<LinkSurvey
survey={survey}
product={product}
userId={userId}
emailVerificationStatus={emailVerificationStatus}
prefillAnswer={prefillAnswer}
singleUseId={singleUseId}
singleUseResponse={singleUseResponse}
webAppUrl={webAppUrl}
/>
<div>
<MediaBackground survey={survey}>
<LinkSurvey
survey={survey}
product={product}
userId={userId}
emailVerificationStatus={emailVerificationStatus}
prefillAnswer={prefillAnswer}
singleUseId={singleUseId}
singleUseResponse={singleUseResponse}
webAppUrl={webAppUrl}
/>
</MediaBackground>
<LegalFooter
bgColor={survey.styling?.background?.bg || "#ffff"}
IMPRINT_URL={IMPRINT_URL}
PRIVACY_URL={PRIVACY_URL}
/>
</div>
);
};

View File

@@ -8,6 +8,7 @@ import { checkValidity } from "@/app/s/[surveyId]/lib/prefilling";
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { IMPRINT_URL, PRIVACY_URL } from "@formbricks/lib/constants";
import { WEBAPP_URL } from "@formbricks/lib/constants";
import { createPerson, getPersonByUserId } from "@formbricks/lib/person/service";
import { getProductByEnvironmentId } from "@formbricks/lib/product/service";
@@ -181,6 +182,8 @@ export default async function LinkSurveyPage({ params, searchParams }: LinkSurve
singleUseId={isSingleUseSurvey ? singleUseId : undefined}
singleUseResponse={singleUseResponse ? singleUseResponse : undefined}
webAppUrl={WEBAPP_URL}
IMPRINT_URL={IMPRINT_URL}
PRIVACY_URL={PRIVACY_URL}
/>
);
}
@@ -200,7 +203,11 @@ export default async function LinkSurveyPage({ params, searchParams }: LinkSurve
responseCount={survey.welcomeCard.showResponseCount ? responseCount : undefined}
/>
</MediaBackground>
<LegalFooter bgColor={survey.styling?.background?.bg || "#ffff"} />
<LegalFooter
bgColor={survey.styling?.background?.bg || "#ffff"}
IMPRINT_URL={IMPRINT_URL}
PRIVACY_URL={PRIVACY_URL}
/>
</div>
) : null;
}

View File

@@ -1,5 +1,15 @@
import { clientSideApiEndpointsLimiter, loginLimiter, signUpLimiter } from "@/app/middleware/bucket";
import { clientSideApiRoute, loginRoute, signupRoute } from "@/app/middleware/endpointValidator";
import {
clientSideApiEndpointsLimiter,
loginLimiter,
shareUrlLimiter,
signUpLimiter,
} from "@/app/middleware/bucket";
import {
clientSideApiRoute,
loginRoute,
shareUrlRoute,
signupRoute,
} from "@/app/middleware/endpointValidator";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
@@ -23,6 +33,8 @@ export async function middleware(request: NextRequest) {
await signUpLimiter.check(ip);
} else if (clientSideApiRoute(request.nextUrl.pathname)) {
await clientSideApiEndpointsLimiter.check(ip);
} else if (shareUrlRoute(request.nextUrl.pathname)) {
await shareUrlLimiter.check(ip);
}
return res;
} catch (_e) {
@@ -41,5 +53,6 @@ export const config = {
"/api/(.*)/client/:path*",
"/api/v1/js/actions",
"/api/v1/client/storage",
"/share/(.*)/:path",
],
};

View File

@@ -1,6 +1,6 @@
{
"name": "@formbricks/web",
"version": "1.4.0",
"version": "1.4.1",
"private": true,
"scripts": {
"clean": "rimraf .turbo node_modules .next",
@@ -26,20 +26,20 @@
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@react-email/components": "^0.0.12",
"@sentry/nextjs": "^7.90.0",
"@vercel/og": "^0.6.1",
"@sentry/nextjs": "^7.91.0",
"@vercel/og": "^0.6.2",
"bcryptjs": "^2.4.3",
"dotenv": "^16.3.1",
"encoding": "^0.1.13",
"framer-motion": "10.16.16",
"framer-motion": "10.17.4",
"googleapis": "^129.0.0",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"lru-cache": "^10.1.0",
"lucide-react": "^0.299.0",
"lucide-react": "^0.303.0",
"mime": "^4.0.1",
"next": "14.0.4",
"nodemailer": "^6.9.7",
"nodemailer": "^6.9.8",
"otplib": "^12.0.1",
"posthog-js": "^1.96.1",
"prismjs": "^1.29.0",

View File

@@ -26,4 +26,14 @@ Sentry.init({
blockAllMedia: true,
}),
],
beforeSend(event, hint) {
const error = hint.originalException as Error;
// @ts-expect-error
if (error && error.digest === "NEXT_NOT_FOUND") {
return null;
}
return event;
},
});

View File

@@ -11,4 +11,14 @@ Sentry.init({
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
beforeSend(event, hint) {
const error = hint.originalException as Error;
// @ts-expect-error
if (error && error.digest === "NEXT_NOT_FOUND") {
return null;
}
return event;
},
});

View File

@@ -1,8 +1,5 @@
version: "3.3"
# If you already have a local .env then please run this using
# docker compose --env-file /dev/null up
# This should be the same as below if you are running via docker compose up
x-webapp-url: &webapp_url http://localhost:3000

View File

@@ -10,7 +10,7 @@
"schema": "packages/database/schema.prisma"
},
"scripts": {
"clean": "turbo run clean && rimraf node_modules .turbo coverage",
"clean": "turbo run clean && rimraf node_modules .turbo coverage out",
"build": "turbo run build",
"post-install": "turbo run post-install",
"db:migrate:dev": "turbo run db:migrate:dev",

View File

@@ -37,6 +37,6 @@
"eslint-config-turbo": "latest",
"terser": "^5.26.0",
"vite": "^5.0.10",
"vite-plugin-dts": "^3.6.4"
"vite-plugin-dts": "^3.7.0"
}
}

View File

@@ -0,0 +1,11 @@
/*
Warnings:
- A unique constraint covering the columns `[resultShareKey]` on the table `Survey` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "Survey" ADD COLUMN "resultShareKey" TEXT;
-- CreateIndex
CREATE UNIQUE INDEX "Survey_resultShareKey_key" ON "Survey"("resultShareKey");

View File

@@ -299,6 +299,7 @@ model Survey {
/// [SurveyVerifyEmail]
verifyEmail Json?
pin String?
resultShareKey String? @unique
@@index([environmentId])
}

View File

@@ -1,17 +1,29 @@
import "server-only";
import { unstable_cache } from "next/cache";
import { ENTERPRISE_LICENSE_KEY, IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
import { TTeam } from "@formbricks/types/teams";
import { ENTERPRISE_LICENSE_KEY } from "@formbricks/lib/constants";
export const getIsEnterpriseEdition = (): boolean => {
if (ENTERPRISE_LICENSE_KEY) {
return ENTERPRISE_LICENSE_KEY.length > 0;
}
return false;
};
export const getIsEnterpriseEdition = () =>
unstable_cache(
async () => {
if (ENTERPRISE_LICENSE_KEY) {
return ENTERPRISE_LICENSE_KEY?.length > 0;
}
return false;
},
["getIsEnterpriseEdition"],
{ revalidate: 60 * 60 * 24 }
)();
export const getRemoveInAppBrandingPermission = (team: TTeam): boolean => {
if (IS_FORMBRICKS_CLOUD) return team.billing.features.inAppSurvey.status !== "inactive";
else if (!IS_FORMBRICKS_CLOUD) return getIsEnterpriseEdition();
else return false;
};
export const getRemoveLinkBrandingPermission = (team: TTeam): boolean => {
if (IS_FORMBRICKS_CLOUD) return team.billing.features.linkSurvey.status !== "inactive";
else if (!IS_FORMBRICKS_CLOUD) return true;
else return false;
};
export const getRoleManagementPermission = (team: TTeam): boolean => {
if (IS_FORMBRICKS_CLOUD) return team.billing.features.inAppSurvey.status !== "inactive";
else if (!IS_FORMBRICKS_CLOUD) return getIsEnterpriseEdition();
else return false;
};

View File

@@ -18,6 +18,6 @@
},
"dependencies": {
"@formbricks/lib": "workspace:*",
"stripe": "^14.9.0"
"stripe": "^14.10.0"
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "@formbricks/js",
"license": "MIT",
"version": "1.4.0",
"version": "1.4.1",
"description": "Formbricks-js allows you to connect your app to Formbricks, display surveys and trigger events.",
"homepage": "https://formbricks.com",
"repository": {
@@ -39,8 +39,8 @@
},
"author": "Formbricks <hola@formbricks.com>",
"devDependencies": {
"@babel/core": "^7.23.6",
"@babel/preset-env": "^7.23.6",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.7",
"@babel/preset-typescript": "^7.23.3",
"@formbricks/api": "workspace:*",
"@formbricks/lib": "workspace:*",
@@ -48,8 +48,8 @@
"@formbricks/tsconfig": "workspace:*",
"@formbricks/types": "workspace:*",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"babel-jest": "^29.7.0",
"cross-env": "^7.0.3",
"isomorphic-fetch": "^3.0.0",
@@ -58,7 +58,7 @@
"jest-fetch-mock": "^3.0.3",
"terser": "^5.26.0",
"vite": "^5.0.10",
"vite-plugin-dts": "^3.6.4",
"vite-plugin-dts": "^3.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "latest"
},

View File

@@ -38,8 +38,8 @@ export function cleanHtml(str: string): string {
function isPossiblyDangerous(name: string, value: string): boolean {
let val = value.replace(/\s+/g, "").toLowerCase();
if (
["src", "href", "xlink:href"].includes(name) &&
(val.includes("javascript:") || val.includes("data:"))
["src", "href", "xlink:href", "srcdoc"].includes(name) &&
(val.includes("javascript:") || val.includes("data:") || val.includes("<script>"))
) {
return true;
}
@@ -57,10 +57,14 @@ export function cleanHtml(str: string): string {
// Loop through each attribute
// If it's dangerous, remove it
let atts = elem.attributes;
for (let i = 0; i < atts.length; i++) {
for (let i = atts.length - 1; i >= 0; i--) {
let { name, value } = atts[i];
if (!isPossiblyDangerous(name, value)) continue;
elem.removeAttribute(name);
if (isPossiblyDangerous(name, value)) {
elem.removeAttribute(name);
} else if (name === "srcdoc") {
// Recursively sanitize srcdoc content
elem.setAttribute(name, cleanHtml(value));
}
}
}

View File

@@ -123,6 +123,10 @@ export const CLIENT_SIDE_API_RATE_LIMIT = {
interval: 10 * 15 * 1000, // 15 minutes
allowedPerInterval: 60,
};
export const SHARE_RATE_LIMIT = {
interval: 60 * 60 * 1000, // 60 minutes
allowedPerInterval: 30,
};
// Enterprise License constant
export const ENTERPRISE_LICENSE_KEY = env.ENTERPRISE_LICENSE_KEY;

View File

@@ -234,12 +234,11 @@ export const inviteUser = async ({
},
});
await sendInviteMemberEmail(invite.id, email, currentUserName, name);
inviteCache.revalidate({
id: invite.id,
teamId: invite.teamId,
});
await sendInviteMemberEmail(invite.id, email, currentUserName, name);
return invite;
};

View File

@@ -14,25 +14,25 @@
"test": "jest -ci --coverage --no-cache"
},
"dependencies": {
"@aws-sdk/s3-presigned-post": "3.478.0",
"@aws-sdk/client-s3": "3.478.0",
"@aws-sdk/s3-request-presigner": "3.478.0",
"@aws-sdk/s3-presigned-post": "3.485.0",
"@aws-sdk/client-s3": "3.485.0",
"@aws-sdk/s3-request-presigner": "3.485.0",
"@t3-oss/env-nextjs": "^0.7.1",
"mime": "4.0.1",
"@formbricks/api": "*",
"@formbricks/database": "*",
"@formbricks/types": "*",
"@paralleldrive/cuid2": "^2.2.2",
"aws-crt": "^1.20.0",
"date-fns": "^3.0.4",
"aws-crt": "^1.20.1",
"date-fns": "^3.0.6",
"jsonwebtoken": "^9.0.2",
"markdown-it": "^14.0.0",
"nanoid": "^5.0.4",
"next-auth": "^4.24.5",
"nodemailer": "^6.9.7",
"posthog-node": "^3.2.1",
"nodemailer": "^6.9.8",
"posthog-node": "^3.3.0",
"server-only": "^0.0.1",
"tailwind-merge": "^2.1.0"
"tailwind-merge": "^2.2.0"
},
"devDependencies": {
"@formbricks/tsconfig": "*",

View File

@@ -49,6 +49,7 @@ export const selectSurvey = {
surveyClosedMessage: true,
singleUse: true,
pin: true,
resultShareKey: true,
triggers: {
select: {
actionClass: {
@@ -686,3 +687,25 @@ export const getSyncSurveys = async (environmentId: string, person: TPerson): Pr
)();
return surveys.map((survey) => formatDateFields(survey, ZSurvey));
};
export const getSurveyByResultShareKey = async (resultShareKey: string): Promise<string | null> => {
try {
const survey = await prisma.survey.findFirst({
where: {
resultShareKey,
},
});
if (!survey) {
return null;
}
return survey.id;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError(error.message);
}
throw error;
}
};

View File

@@ -1,5 +1,5 @@
import { formatDistance } from "date-fns";
import intlFormat from "date-fns/intlFormat";
import { intlFormat } from "date-fns";
export const convertDateString = (dateString: string) => {
if (!dateString) {

View File

@@ -9,6 +9,6 @@
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"prettier": "^3.1.1",
"prettier-plugin-tailwindcss": "^0.5.9"
"prettier-plugin-tailwindcss": "^0.5.10"
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "@formbricks/surveys",
"license": "MIT",
"version": "1.4.0",
"version": "1.4.1",
"description": "Formbricks-surveys is a helper library to embed surveys into your application",
"homepage": "https://formbricks.com",
"repository": {
@@ -36,7 +36,7 @@
"@formbricks/lib": "workspace:*",
"@formbricks/tsconfig": "workspace:*",
"@formbricks/types": "workspace:*",
"@preact/preset-vite": "^2.7.0",
"@preact/preset-vite": "^2.8.1",
"autoprefixer": "^10.4.16",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "latest",
@@ -46,8 +46,8 @@
"tailwindcss": "^3.4.0",
"terser": "^5.26.0",
"vite": "^5.0.10",
"vite-plugin-dts": "^3.6.4",
"vite-tsconfig-paths": "^4.2.2",
"vite-plugin-dts": "^3.7.0",
"vite-tsconfig-paths": "^4.2.3",
"serve": "14.2.1",
"concurrently": "8.2.2",
"@calcom/embed-snippet": "1.1.2"

View File

@@ -3,7 +3,7 @@ import { FunctionComponent } from "preact";
export const TiredFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -64,7 +64,7 @@ export const TiredFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>>
export const WearyFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -125,7 +125,7 @@ export const WearyFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>>
export const PerseveringFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -195,7 +195,7 @@ export const PerseveringFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElem
export const FrowningFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -225,7 +225,7 @@ export const FrowningFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement
export const ConfusedFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -254,7 +254,7 @@ export const ConfusedFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement
export const NeutralFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -287,7 +287,7 @@ export const NeutralFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>
export const SlightlySmilingFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -319,7 +319,7 @@ export const SmilingFaceWithSmilingEyes: FunctionComponent<JSX.HTMLAttributes<SV
props
) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -365,7 +365,7 @@ export const GrinningFaceWithSmilingEyes: FunctionComponent<JSX.HTMLAttributes<S
props
) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -417,7 +417,7 @@ export const GrinningFaceWithSmilingEyes: FunctionComponent<JSX.HTMLAttributes<S
export const GrinningSquintingFace: FunctionComponent<JSX.HTMLAttributes<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}>
<g id="line">
<circle
cx="36"
@@ -469,5 +469,5 @@ export const GrinningSquintingFace: FunctionComponent<JSX.HTMLAttributes<SVGCirc
};
export let icons = [
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}></svg>,
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={48} height={48}></svg>,
];

View File

@@ -42,17 +42,20 @@ export default function MultipleChoiceMultiQuestion({
() => question.choices.filter((choice) => choice.id !== "other").map((item) => item.label),
[question]
);
const [otherSelected, setOtherSelected] = useState<boolean>(false);
const [otherSelected, setOtherSelected] = useState(
!!value &&
((Array.isArray(value) ? value : [value]) as string[]).some((item) => {
return getChoicesWithoutOtherLabels().includes(item) === false;
})
); // check if the value contains any string which is not in `choicesWithoutOther`, if it is there, it must be other value which make the initial value true
const [otherValue, setOtherValue] = useState(
(Array.isArray(value) && value.filter((v) => !question.choices.find((c) => c.label === v))[0]) || ""
); // initially set to the first value that is not in choices
const [otherValue, setOtherValue] = useState("");
useEffect(() => {
setOtherSelected(
!!value &&
((Array.isArray(value) ? value : [value]) as string[]).some((item) => {
return getChoicesWithoutOtherLabels().includes(item) === false;
})
);
setOtherValue(
(Array.isArray(value) && value.filter((v) => !question.choices.find((c) => c.label === v))[0]) || ""
);
}, [question.id]);
const questionChoices = useMemo(() => {
if (!question.choices) {
@@ -65,6 +68,10 @@ export default function MultipleChoiceMultiQuestion({
return choicesWithoutOther;
}, [question.choices, question.shuffleOption]);
const questionChoiceLabels = questionChoices.map((questionChoice) => {
return questionChoice.label;
});
const otherOption = useMemo(
() => question.choices.find((choice) => choice.id === "other"),
[question.choices]
@@ -79,8 +86,16 @@ export default function MultipleChoiceMultiQuestion({
}, [otherSelected]);
const addItem = (item: string) => {
const isOtherValue = !questionChoiceLabels.includes(item);
if (Array.isArray(value)) {
return onChange({ [question.id]: [...value, item] });
if (isOtherValue) {
const newValue = value.filter((v) => {
return questionChoiceLabels.includes(v);
});
return onChange({ [question.id]: [...newValue, item] });
} else {
return onChange({ [question.id]: [...value, item] });
}
}
return onChange({ [question.id]: [item] }); // if not array, make it an array
};

View File

@@ -38,9 +38,7 @@ export default function MultipleChoiceSingleQuestion({
useTtc(question.id, ttc, setTtc, startTime, setStartTime);
const [otherSelected, setOtherSelected] = useState(
!!value && !question.choices.find((c) => c.label === value)
); // initially set to true if value is not in choices
const [otherSelected, setOtherSelected] = useState(false);
const questionChoices = useMemo(() => {
if (!question.choices) {
@@ -58,6 +56,10 @@ export default function MultipleChoiceSingleQuestion({
[question.choices]
);
useEffect(() => {
setOtherSelected(!!value && !question.choices.find((c) => c.label === value));
}, [question.id]);
const otherSpecify = useRef<HTMLInputElement | null>(null);
useEffect(() => {

Some files were not shown because too many files have changed in this diff Show More