feat: integrate formbricks for team disband action (#13362)

* feat: integrate formmbricks for team disband action

* fix: attribute typing & duplicate action

* fix: track action uniformly across repo

* fix: move action tracking on success of team disband mutation

* fix: yarn lock file

* feat: bump formbricks/js to latest version

---------

Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-02-07 04:14:26 -03:00
1 parent 0990549e7f
commit 8469c91973
13 files changed
+92 -10

No files matched your search

+2 -2
View File
@@ -137,8 +137,8 @@ NEXT_PUBLIC_SENDGRID_SENDER_NAME=
NEXT_PUBLIC_SENTRY_DSN=
# Formbricks Experience Management Integration
FORMBRICKS_HOST_URL=https://app.formbricks.com
FORMBRICKS_ENVIRONMENT_ID=
NEXT_PUBLIC_FORMBRICKS_HOST_URL=https://app.formbricks.com
NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID=
FORMBRICKS_FEEDBACK_SURVEY_ID=
# AvatarAPI
@@ -1,5 +1,6 @@
import { useState } from "react";
import { trackFormbricksAction } from "@calcom/lib/formbricks-client";
import type { RouterOutputs } from "@calcom/trpc/react";
import { trpc } from "@calcom/trpc/react";
import { showToast } from "@calcom/ui";
@@ -27,6 +28,7 @@ export default function OtherTeamList(props: Props) {
const deleteTeamMutation = trpc.viewer.organizations.deleteTeam.useMutation({
async onSuccess() {
await utils.viewer.organizations.listOtherTeams.invalidate();
trackFormbricksAction("team_disbanded");
},
async onError(err) {
showToast(err.message, "error");
@@ -11,6 +11,7 @@ import { z } from "zod";
import { IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
import { trackFormbricksAction } from "@calcom/lib/formbricks-client";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
import { md } from "@calcom/lib/markdownIt";
@@ -126,6 +127,7 @@ const OtherTeamProfileView = () => {
await utils.viewer.organizations.listOtherTeams.invalidate();
showToast(t("your_team_disbanded_successfully"), "success");
router.push(`${WEBAPP_URL}/teams`);
trackFormbricksAction("team_disbanded");
},
});
@@ -324,7 +326,9 @@ const OtherTeamProfileView = () => {
variety="danger"
title={t("disband_team")}
confirmBtnText={t("confirm_disband_team")}
onConfirm={deleteTeam}>
onConfirm={() => {
deleteTeam();
}}>
{t("disband_team_confirmation_message")}
</ConfirmationDialogContent>
</Dialog>
@@ -1,5 +1,6 @@
import { useState } from "react";
import { trackFormbricksAction } from "@calcom/lib/formbricks-client";
import type { MembershipRole } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc/react";
import { showToast } from "@calcom/ui";
@@ -36,6 +37,7 @@ export default function TeamInviteList(props: Props) {
await utils.viewer.teams.list.invalidate();
await utils.viewer.teams.get.invalidate();
await utils.viewer.organizations.listMembers.invalidate();
trackFormbricksAction("team_disbanded");
},
async onError(err) {
showToast(err.message, "error");
@@ -1,5 +1,6 @@
import { useState } from "react";
import { trackFormbricksAction } from "@calcom/lib/formbricks-client";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { RouterOutputs } from "@calcom/trpc/react";
import { trpc } from "@calcom/trpc/react";
@@ -32,6 +33,7 @@ export default function TeamList(props: Props) {
async onSuccess() {
await utils.viewer.teams.list.invalidate();
await utils.viewer.teams.hasTeamPlan.invalidate();
trackFormbricksAction("team_disbanded");
},
async onError(err) {
showToast(err.message, "error");
@@ -12,6 +12,7 @@ import { z } from "zod";
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
import { IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
import { trackFormbricksAction } from "@calcom/lib/formbricks-client";
import { getTeamUrlSync } from "@calcom/lib/getBookerUrl/client";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
@@ -124,6 +125,7 @@ const ProfileView = () => {
await utils.viewer.teams.list.invalidate();
showToast(t("your_team_disbanded_successfully"), "success");
router.push(`${WEBAPP_URL}/teams`);
trackFormbricksAction("team_disbanded");
},
});
@@ -217,7 +219,9 @@ const ProfileView = () => {
variety="danger"
title={t("disband_team")}
confirmBtnText={t("confirm_disband_team")}
onConfirm={deleteTeam}>
onConfirm={() => {
deleteTeam();
}}>
{t("disband_team_confirmation_message")}
</ConfirmationDialogContent>
</Dialog>
+3
View File
@@ -44,6 +44,7 @@ import {
TOP_BANNER_HEIGHT,
ENABLE_PROFILE_SWITCHER,
} from "@calcom/lib/constants";
import { useFormbricks } from "@calcom/lib/formbricks-client";
import getBrandColours from "@calcom/lib/getBrandColours";
import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl";
import { useLocale } from "@calcom/lib/hooks/useLocale";
@@ -237,6 +238,8 @@ const Layout = (props: LayoutProps) => {
return (activeBanners?.length ?? 0) * TOP_BANNER_HEIGHT;
}, [banners]);
useFormbricks();
return (
<>
{!props.withoutSeo && (
+56
View File
@@ -0,0 +1,56 @@
import formbricks from "@formbricks/js";
import { useSession } from "next-auth/react";
import { useEffect } from "react";
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
export const initFormbricks = ({
userId,
attributes,
}: {
userId: string;
attributes: { [key: string]: string | null | undefined };
}) => {
const filteredAttributes: Record<string, string | number> = {};
Object.entries(attributes).forEach(([key, value]) => {
if (value !== null && value !== undefined) {
filteredAttributes[key] = value;
}
});
if (process.env.NEXT_PUBLIC_FORMBRICKS_HOST_URL && process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID) {
formbricks.init({
environmentId: process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID,
apiHost: process.env.NEXT_PUBLIC_FORMBRICKS_HOST_URL,
debug: process.env.NODE_ENV === "development",
userId,
attributes: filteredAttributes,
});
}
};
export const trackFormbricksAction = (eventName: string, properties: Record<string, string> = {}) => {
if (process.env.NEXT_PUBLIC_FORMBRICKS_HOST_URL && process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID) {
formbricks.track(eventName, properties);
}
};
export const useFormbricks = () => {
const { data: user, isLoading } = useMeQuery();
const { data: session, status } = useSession();
useEffect(() => {
if (!isLoading && user && session) {
initFormbricks({
userId: user.id.toString(),
attributes: {
name: user?.name,
email: user.email,
username: user?.username,
belongsToActiveTeam: session.user.belongsToActiveTeam?.toString(),
isOrganizationAdmin: user.organization?.isOrgAdmin?.toString(),
},
});
}
}, [isLoading, user, status, session]);
};
+3 -3
View File
@@ -10,11 +10,11 @@ enum Rating {
}
export const sendFeedbackFormbricks = async (userId: number, feedback: Feedback) => {
if (!process.env.FORMBRICKS_HOST_URL || !process.env.FORMBRICKS_ENVIRONMENT_ID)
if (!process.env.NEXT_PUBLIC_FORMBRICKS_HOST_URL || !process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID)
throw new Error("Missing FORMBRICKS_HOST_URL or FORMBRICKS_ENVIRONMENT_ID env variable");
const api = new FormbricksAPI({
apiHost: process.env.FORMBRICKS_HOST_URL,
environmentId: process.env.FORMBRICKS_ENVIRONMENT_ID,
apiHost: process.env.NEXT_PUBLIC_FORMBRICKS_HOST_URL,
environmentId: process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID,
});
if (process.env.FORMBRICKS_FEEDBACK_SURVEY_ID) {
const formbricksUserId = userId.toString();
+1
View File
@@ -15,6 +15,7 @@
"@calcom/config": "*",
"@calcom/dayjs": "*",
"@formbricks/api": "^1.1.0",
"@formbricks/js": "^1.5.0",
"@sendgrid/client": "^7.7.0",
"@vercel/og": "^0.5.0",
"bcryptjs": "^2.4.3",
@@ -31,7 +31,7 @@ export const submitFeedbackHandler = async ({ ctx, input }: SubmitFeedbackOption
comment: comment,
},
});
if (process.env.FORMBRICKS_HOST_URL && process.env.FORMBRICKS_ENVIRONMENT_ID)
if (process.env.NEXT_PUBLIC_FORMBRICKS_HOST_URL && process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID)
sendFeedbackFormbricks(ctx.user.id, feedback);
if (process.env.SEND_FEEDBACK_EMAIL && comment) sendFeedbackEmail(feedback);
+2 -2
View File
@@ -259,8 +259,6 @@
"EMAIL_SERVER_USER",
"EMAIL_SERVER",
"EXCHANGE_DEFAULT_EWS_URL",
"FORMBRICKS_HOST_URL",
"FORMBRICKS_ENVIRONMENT_ID",
"FORMBRICKS_FEEDBACK_SURVEY_ID",
"AVATARAPI_USERNAME",
"AVATARAPI_PASSWORD",
@@ -291,6 +289,8 @@
"NEXT_PUBLIC_DEBUG",
"NEXT_PUBLIC_DISABLE_SIGNUP",
"NEXT_PUBLIC_EMBED_LIB_URL",
"NEXT_PUBLIC_FORMBRICKS_HOST_URL",
"NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID",
"NEXT_PUBLIC_HOSTED_CAL_FEATURES",
"NEXT_PUBLIC_MINUTES_TO_BOOK",
"NEXT_PUBLIC_SENDER_ID",
+8
View File
@@ -4229,6 +4229,7 @@ __metadata:
"@calcom/types": "*"
"@faker-js/faker": ^7.3.0
"@formbricks/api": ^1.1.0
"@formbricks/js": ^1.5.0
"@sendgrid/client": ^7.7.0
"@vercel/og": ^0.5.0
bcryptjs: ^2.4.3
@@ -6307,6 +6308,13 @@ __metadata:
languageName: node
linkType: hard
"@formbricks/js@npm:^1.5.0":
version: 1.5.0
resolution: "@formbricks/js@npm:1.5.0"
checksum: b9ba81484f205888f6db81b48b0e5178458b4de8fa3dd76a6f95378656d739204adab502356181fce08fcb65a3b324047ffeb977d8bf556b3e95f652b67aee4d
languageName: node
linkType: hard
"@formkit/auto-animate@npm:1.0.0-beta.5":
version: 1.0.0-beta.5
resolution: "@formkit/auto-animate@npm:1.0.0-beta.5"