* 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: peer@cal.com <peer@cal.com> * 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: peer@cal.com <peer@cal.com> * 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: peer@cal.com <peer@cal.com> * 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 <74371312+Amit91848@users.noreply.github.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
196 lines
6.2 KiB
TypeScript
196 lines
6.2 KiB
TypeScript
"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>
|
|
);
|
|
};
|