feat: implement tiered Intercom chat system replacing Plain (#23285)
* feat: implement tiered Intercom chat system replacing Plain - Add TieredIntercomChat component with customer tier detection - Add IntercomContactForm for free users using Intercom API - Add /api/intercom-conversation endpoint for free user support - Update UserDropdown to use tiered chat logic - Replace Plain chat with Intercom in app providers - Remove all Plain chat components and related files - Use useHasPaidPlan hook for customer tier detection Paying customers see Intercom widget, free users see contact form that creates conversations via Intercom API. Co-Authored-By: [email protected] <[email protected]> * fix: add missing environment variables to turbo.json globalEnv - Add NEXT_PUBLIC_WEBAPP_URL, NEXT_PUBLIC_WEBSITE_URL, NEXT_PUBLIC_STRIPE_PUBLIC_KEY - Add NEXT_PUBLIC_IS_E2E, NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE_MONTHLY - Add NEXT_PUBLIC_BOOKER_NUMBER_OF_DAYS_TO_LOAD, NEXT_PUBLIC_STRIPE_CREDITS_PRICE_ID - Resolves turbo/no-undeclared-env-vars ESLint errors blocking commits Co-Authored-By: [email protected] <[email protected]> * fix: resolve linting errors in platform examples base package - Fix prettier/prettier formatting (quotes and comma) - Add underscore prefix to unused variables - Resolves CI failure in @calcom/base#lint check Co-Authored-By: [email protected] <[email protected]> * remove plain usage * placement fixes * fix: pop closing immediately issue * stuff * proper error and additional user info * add key to .env.example and remove unused plain route * fix conversation route * refactor intercom dynamic provider * code rabbit fixes * feat: introduce tiered support feature flag * fix: type check * Apply suggestion from @coderabbitai[bot] Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Amit Sharma <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
36 files changed
+635
-2208
No files matched your search
@@ -0,0 +1,195 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState, useCallback } from "react";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { Label, TextArea } from "@calcom/ui/components/form";
|
||||
import { Icon } from "@calcom/ui/components/icon";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@calcom/ui/components/popover";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Support?: {
|
||||
open: () => void;
|
||||
shouldShowTriggerButton: (showTrigger: boolean) => void;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const IntercomContactForm = () => {
|
||||
const { t } = useLocale();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [isSubmitted, setIsSubmitted] = useState(false);
|
||||
const [message, setMessage] = useState("");
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [showTrigger, setShowTrigger] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined" && !window.Support) {
|
||||
window.Support = {
|
||||
open: () => {
|
||||
setIsOpen(true);
|
||||
},
|
||||
shouldShowTriggerButton: (showTrigger) => {
|
||||
setShowTrigger(showTrigger);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (typeof window !== "undefined" && window.Support) {
|
||||
delete window.Support;
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
const onSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/support/conversation", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ message }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.error || "Failed to send message");
|
||||
}
|
||||
|
||||
showToast(t("success"), "success");
|
||||
setIsSubmitting(false);
|
||||
setIsSubmitted(true);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : t("something_went_wrong");
|
||||
showToast(message, "error");
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const contentRef = useCallback(
|
||||
(node: HTMLDivElement | null) => {
|
||||
if (!node) return;
|
||||
|
||||
const isSmall = window.innerWidth < 768;
|
||||
|
||||
if (isSmall) {
|
||||
setShowTrigger(false);
|
||||
}
|
||||
|
||||
const wrapper = node.parentElement;
|
||||
if (wrapper?.hasAttribute("data-radix-popper-content-wrapper")) {
|
||||
if (!showTrigger) {
|
||||
wrapper.style.left = "auto";
|
||||
wrapper.style.right = "0px";
|
||||
wrapper.style.bottom = "5rem";
|
||||
wrapper.style.top = "auto";
|
||||
} else {
|
||||
wrapper.style.left = "0px";
|
||||
wrapper.style.right = "auto";
|
||||
wrapper.style.bottom = "auto";
|
||||
wrapper.style.top = "0px";
|
||||
}
|
||||
}
|
||||
},
|
||||
[showTrigger]
|
||||
);
|
||||
|
||||
const resetForm = () => {
|
||||
setIsSubmitted(false);
|
||||
setMessage("");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="fixed bottom-[1rem] right-[1rem] z-50 [&_[data-radix-popper-content-wrapper]]:!bottom-[1rem]">
|
||||
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
||||
<PopoverTrigger
|
||||
asChild
|
||||
className={classNames("enabled:hover:bg-subtle bg-subtle shadow-none", !showTrigger && "!hidden")}>
|
||||
<Button
|
||||
onClick={() => setIsOpen(true)}
|
||||
className="bg-subtle text-emphasis flex h-12 w-12 items-center justify-center rounded-full border-none">
|
||||
<Icon name="message-circle" className="h-6 w-6" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
|
||||
<PopoverContent
|
||||
ref={contentRef}
|
||||
style={{ maxWidth: "450px", maxHeight: "650px" }}
|
||||
className={classNames(
|
||||
"!bg-muted no-scrollbar mb-2 w-screen overflow-hidden overflow-y-scroll px-6 py-4 md:w-[450px]",
|
||||
showTrigger ? "mr-8" : "mr-0"
|
||||
)}>
|
||||
<div className="flex w-full justify-between">
|
||||
<p className="mb-5 text-lg font-semibold">{t("contact_support")}</p>
|
||||
<Button
|
||||
color="minimal"
|
||||
variant="button"
|
||||
StartIcon="x"
|
||||
size="sm"
|
||||
onClick={() => setIsOpen(false)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{isSubmitted ? (
|
||||
<div className="py-4 text-center">
|
||||
<h4 className="mb-2 text-lg font-medium ">{t("message_sent")}</h4>
|
||||
<p className="text-subtle mb-4 text-sm">{t("support_message_sent_description")}</p>
|
||||
<Button color="primary" className="my-2" onClick={resetForm} variant="button" size="base">
|
||||
{t("send_another_message")}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={onSubmit} className="flex flex-col gap-4">
|
||||
<div>
|
||||
<Label htmlFor="message">{t("describe_the_issue")}</Label>
|
||||
<TextArea
|
||||
id="message"
|
||||
name="message"
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
placeholder={t("support_message_placeholder")}
|
||||
required
|
||||
rows={4}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex w-full items-center">
|
||||
<Button
|
||||
color="secondary"
|
||||
variant="button"
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="w-full">
|
||||
<div className="flex w-full justify-center">
|
||||
{isSubmitting ? (
|
||||
<div className="flex items-center">
|
||||
<Icon name="loader" className="mr-2 h-4 w-4 animate-spin rounded-full" />
|
||||
{t("sending")}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Icon name="send" className="mr-2 h-4 w-4" />
|
||||
{t("send_message")}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,142 @@
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
|
||||
export interface Contact extends CreateContact {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface CreateContact {
|
||||
type: "contact" | "lead";
|
||||
external_id: string;
|
||||
email: string;
|
||||
name: string;
|
||||
custom_attributes?: object;
|
||||
}
|
||||
|
||||
interface IntercomResponse<T> {
|
||||
data?: T;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
interface CreateConversation {
|
||||
from: {
|
||||
type: string;
|
||||
id: string;
|
||||
};
|
||||
body: string;
|
||||
}
|
||||
|
||||
const INTERCOM_API_ENDPOINT = "https://api.intercom.io";
|
||||
const INTERCOM_API_TOKEN = process.env.INTERCOM_API_TOKEN;
|
||||
export const intercom = {
|
||||
async getContactByEmail(email: string): Promise<IntercomResponse<Contact | null>> {
|
||||
try {
|
||||
const res = await fetch(`${INTERCOM_API_ENDPOINT}/contacts/search`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
query: {
|
||||
operator: "AND",
|
||||
value: [
|
||||
{
|
||||
field: "email",
|
||||
operator: "=",
|
||||
value: email,
|
||||
},
|
||||
],
|
||||
},
|
||||
pagination: {
|
||||
per_page: 1,
|
||||
},
|
||||
}),
|
||||
headers: {
|
||||
Authorization: `Bearer ${INTERCOM_API_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const body = await res.json();
|
||||
return {
|
||||
error: body?.errors[0]?.message,
|
||||
};
|
||||
}
|
||||
|
||||
const { data } = (await res.json()) as { type: string; data: Contact[] };
|
||||
|
||||
if (data.length === 0) {
|
||||
return {
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
data: data[0],
|
||||
};
|
||||
} catch (err) {
|
||||
console.error(`Unexpected error while fetching contact data from email: ${safeStringify(err)}`);
|
||||
return {
|
||||
error: "Unexpected error while fetching contact data from email",
|
||||
};
|
||||
}
|
||||
},
|
||||
async createContact(data: CreateContact): Promise<IntercomResponse<Contact>> {
|
||||
try {
|
||||
const res = await fetch(`${INTERCOM_API_ENDPOINT}/contacts`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${INTERCOM_API_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const data = await res.json();
|
||||
console.error(`Error creating contact from email ${data.email}: `, safeStringify(data));
|
||||
return {
|
||||
error: data?.errors[0]?.message ?? "Error creating contact from email",
|
||||
};
|
||||
}
|
||||
|
||||
const contact = (await res.json()) as Contact;
|
||||
return {
|
||||
data: contact,
|
||||
};
|
||||
} catch (err) {
|
||||
console.error(`Unexpected error while creating contact from email: ${safeStringify(err)}`);
|
||||
return {
|
||||
error: "Unexpected error while creating contact from email",
|
||||
};
|
||||
}
|
||||
},
|
||||
async createConversation({ from, body }: CreateConversation): Promise<IntercomResponse<boolean>> {
|
||||
try {
|
||||
const response = await fetch(`https://api.intercom.io/conversations`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${INTERCOM_API_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
from,
|
||||
body,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
console.error("Intercom API error:", safeStringify(errorData));
|
||||
return {
|
||||
error: `Intercom Err: ${errorData?.errors?.[0].message ?? "Error creating conversation"}`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
data: true,
|
||||
};
|
||||
} catch (err) {
|
||||
console.error(`Unexpected error while creating conversation from email: ${safeStringify(err)}`);
|
||||
return {
|
||||
error: "Unexpected error while creating contact from email",
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1,8 +1,61 @@
|
||||
import { FC } from "react";
|
||||
"use client";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useEffect, type FC } from "react";
|
||||
import { IntercomProvider } from "react-use-intercom";
|
||||
|
||||
const Provider: FC<{ children: React.ReactNode }> = ({ children }) => (
|
||||
<IntercomProvider appId={process.env.NEXT_PUBLIC_INTERCOM_APP_ID || ""}>{children}</IntercomProvider>
|
||||
);
|
||||
import { useBootIntercom } from "@calcom/ee/support/lib/intercom/useIntercom";
|
||||
import { IntercomContactForm } from "@calcom/features/ee/support/components/IntercomContactForm";
|
||||
import { useFlagMap } from "@calcom/features/flags/context/provider";
|
||||
import useHasPaidPlan from "@calcom/lib/hooks/useHasPaidPlan";
|
||||
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Support?: {
|
||||
open: () => void;
|
||||
shouldShowTriggerButton: (showTrigger: boolean) => void;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function IntercomBootstrap() {
|
||||
useBootIntercom();
|
||||
return null;
|
||||
}
|
||||
|
||||
const Provider: FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const { hasPaidPlan } = useHasPaidPlan();
|
||||
const isMobile = useMediaQuery("(max-width: 768px)");
|
||||
const flagMap = useFlagMap();
|
||||
|
||||
useEffect(() => {
|
||||
if (window.Support) {
|
||||
window.Support.shouldShowTriggerButton(!isMobile);
|
||||
}
|
||||
}, [isMobile]);
|
||||
|
||||
const pathname = usePathname();
|
||||
const isOnboardingPage = pathname?.startsWith("/getting-started");
|
||||
|
||||
if (isOnboardingPage) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
if (flagMap["tiered-support-chat"] && !hasPaidPlan) {
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
<IntercomContactForm />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<IntercomProvider appId={process.env.NEXT_PUBLIC_INTERCOM_APP_ID || ""}>
|
||||
<IntercomBootstrap />
|
||||
{children}
|
||||
</IntercomProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default Provider;
|
||||
@@ -2,7 +2,7 @@ import dynamic from "next/dynamic";
|
||||
import { Fragment } from "react";
|
||||
|
||||
const DynamicIntercomProvider = process.env.NEXT_PUBLIC_INTERCOM_APP_ID
|
||||
? dynamic(() => import("./provider"))
|
||||
? dynamic(() => import("./provider"), { ssr: false })
|
||||
: Fragment;
|
||||
|
||||
export default DynamicIntercomProvider;
|
||||
@@ -1,12 +1,15 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { noop } from "lodash";
|
||||
import { useEffect } from "react";
|
||||
import type { IntercomBootProps, IntercomProps } from "react-use-intercom";
|
||||
import { useIntercom as useIntercomLib } from "react-use-intercom";
|
||||
import { z } from "zod";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { useFlagMap } from "@calcom/features/flags/context/provider";
|
||||
import { WEBAPP_URL, WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import { useHasTeamPlan, useHasPaidPlan } from "@calcom/lib/hooks/useHasPaidPlan";
|
||||
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
|
||||
import { localStorage } from "@calcom/lib/webstorage";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
@@ -17,14 +20,18 @@ const useIntercomHook = isInterComEnabled
|
||||
? useIntercomLib
|
||||
: () => {
|
||||
return {
|
||||
boot: noop,
|
||||
// eslint-disable-next-line
|
||||
boot: (_props: IntercomBootProps) => {},
|
||||
show: noop,
|
||||
shutdown: noop,
|
||||
// eslint-disable-next-line
|
||||
update: (_props: Partial<IntercomProps>) => {},
|
||||
};
|
||||
};
|
||||
|
||||
export const useIntercom = () => {
|
||||
const hookData = useIntercomHook();
|
||||
const isMobile = useMediaQuery("(max-width: 768px)");
|
||||
const { data } = trpc.viewer.me.get.useQuery();
|
||||
const { data: statsData } = trpc.viewer.me.myStats.useQuery(undefined, {
|
||||
trpc: {
|
||||
@@ -39,8 +46,7 @@ export const useIntercom = () => {
|
||||
const boot = async () => {
|
||||
if (!data || !statsData) return;
|
||||
let userHash;
|
||||
|
||||
const req = await fetch(`/api/intercom-hash`);
|
||||
const req = await fetch(`/api/support/hash`);
|
||||
const res = await req.json();
|
||||
if (res?.hash) {
|
||||
userHash = res.hash;
|
||||
@@ -52,6 +58,7 @@ export const useIntercom = () => {
|
||||
...(data && data?.id && { userId: data.id }),
|
||||
createdAt: String(dayjs(data?.createdDate).unix()),
|
||||
...(userHash && { userHash }),
|
||||
hideDefaultLauncher: isMobile,
|
||||
customAttributes: {
|
||||
//keys should be snake cased
|
||||
user_name: data?.username,
|
||||
@@ -83,7 +90,7 @@ export const useIntercom = () => {
|
||||
const open = async () => {
|
||||
let userHash;
|
||||
|
||||
const req = await fetch(`/api/intercom-hash`);
|
||||
const req = await fetch(`/api/support/hash`);
|
||||
const res = await req.json();
|
||||
if (res?.hash) {
|
||||
userHash = res.hash;
|
||||
@@ -95,6 +102,7 @@ export const useIntercom = () => {
|
||||
...(data && data?.id && { userId: data.id }),
|
||||
createdAt: String(dayjs(data?.createdDate).unix()),
|
||||
...(userHash && { userHash }),
|
||||
hideDefaultLauncher: isMobile,
|
||||
customAttributes: {
|
||||
//keys should be snake cased
|
||||
user_name: data?.username,
|
||||
@@ -126,9 +134,22 @@ export const useIntercom = () => {
|
||||
return { ...hookData, open, boot };
|
||||
};
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Support?: {
|
||||
open: () => void;
|
||||
shouldShowTriggerButton: (showTrigger: boolean) => void;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const useBootIntercom = () => {
|
||||
const { boot } = useIntercom();
|
||||
const { hasPaidPlan } = useHasPaidPlan();
|
||||
const flagMap = useFlagMap();
|
||||
const { boot, open, update } = useIntercom();
|
||||
|
||||
const { data: user } = trpc.viewer.me.get.useQuery();
|
||||
const isTieredSupportEnabled = flagMap["tiered-support-chat"];
|
||||
const { data: statsData } = trpc.viewer.me.myStats.useQuery(undefined, {
|
||||
trpc: {
|
||||
context: {
|
||||
@@ -139,12 +160,28 @@ export const useBootIntercom = () => {
|
||||
useEffect(() => {
|
||||
// not using useMediaQuery as it toggles between true and false
|
||||
const showIntercom = localStorage.getItem("showIntercom");
|
||||
if (!isInterComEnabled || showIntercom === "false" || window.innerWidth <= 768 || !user || !statsData)
|
||||
if (
|
||||
!isInterComEnabled ||
|
||||
showIntercom === "false" ||
|
||||
!user ||
|
||||
!statsData ||
|
||||
(!hasPaidPlan && isTieredSupportEnabled)
|
||||
)
|
||||
return;
|
||||
|
||||
boot();
|
||||
if (typeof window !== "undefined" && !window.Support) {
|
||||
window.Support = {
|
||||
open,
|
||||
shouldShowTriggerButton: (showTrigger: boolean) => {
|
||||
update({
|
||||
hideDefaultLauncher: !showTrigger,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [user, statsData]);
|
||||
}, [user, statsData, hasPaidPlan, isTieredSupportEnabled]);
|
||||
};
|
||||
|
||||
export default useIntercom;
|
||||
@@ -25,6 +25,7 @@ export type AppFlags = {
|
||||
"restriction-schedule": boolean;
|
||||
"team-booking-page-cache": boolean;
|
||||
"cal-ai-voice-agents": boolean;
|
||||
"tiered-support-chat": boolean;
|
||||
};
|
||||
|
||||
export type TeamFeatures = Record<keyof AppFlags, boolean>;
|
||||
@@ -24,6 +24,7 @@ const initialData: AppFlags = {
|
||||
"restriction-schedule": false,
|
||||
"team-booking-page-cache": false,
|
||||
"cal-ai-voice-agents": false,
|
||||
"tiered-support-chat": false,
|
||||
};
|
||||
|
||||
if (process.env.NEXT_PUBLIC_IS_E2E) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { signOut } from "next-auth/react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import type { MouseEvent } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { ROADMAP, DESKTOP_APP_LINK } from "@calcom/lib/constants";
|
||||
@@ -24,10 +25,9 @@ import FreshChatProvider from "../../ee/support/lib/freshchat/FreshChatProvider"
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Plain?: {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
init: (config: any) => void;
|
||||
Support?: {
|
||||
open: () => void;
|
||||
shouldShowTriggerButton: (showTrigger: boolean) => void;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ export function UserDropdown({ small }: UserDropdownProps) {
|
||||
const { data: user, isPending } = useMeQuery();
|
||||
const pathname = usePathname();
|
||||
const isPlatformPages = pathname?.startsWith("/settings/platform");
|
||||
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
@@ -55,22 +56,25 @@ export function UserDropdown({ small }: UserDropdownProps) {
|
||||
});
|
||||
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const [openSupportAfterClose, setOpenSupportAfterClose] = useState(false);
|
||||
|
||||
const handleHelpClick = (e?: React.MouseEvent) => {
|
||||
const handleHelpClick = (e?: MouseEvent) => {
|
||||
e?.preventDefault();
|
||||
e?.stopPropagation();
|
||||
|
||||
setOpenSupportAfterClose(true);
|
||||
setMenuOpen(false);
|
||||
|
||||
// Defer to next frame to avoid the originating click closing the dialog
|
||||
requestAnimationFrame(() => {
|
||||
// double RAF is extra-safe if your dropdown unmounts with a transition
|
||||
requestAnimationFrame(() => {
|
||||
if (window.Plain) window.Plain.open();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!menuOpen && openSupportAfterClose) {
|
||||
setTimeout(() => {
|
||||
window.Support?.open();
|
||||
}, 0);
|
||||
setOpenSupportAfterClose(false);
|
||||
}
|
||||
}, [menuOpen, openSupportAfterClose]);
|
||||
|
||||
// Prevent rendering dropdown if user isn't available.
|
||||
// We don't want to show nameless user.
|
||||
if (!user && !isPending) {
|
||||
|
||||
Reference in new issue
Block a user