Skip to content

Commit

Permalink
Merge branch 'main' into chore/bump-yarn-lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
emrysal authored Dec 28, 2024
2 parents 51702be + 3f0a671 commit 44a38a0
Show file tree
Hide file tree
Showing 44 changed files with 220 additions and 149 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ PLAIN_API_URL=https://api.plain.com/v1
PLAIN_HMAC_SECRET_KEY=
PLAIN_CHAT_ID=
PLAIN_CHAT_HMAC_SECRET_KEY=
NEXT_PUBLIC_PLAIN_CHAT_EXCLUDED_PATHS=

# Zendesk Config
NEXT_PUBLIC_ZENDESK_KEY=
Expand Down
Empty file added .yarn/versions/6e890e70.yml
Empty file.
280 changes: 150 additions & 130 deletions apps/web/lib/plain/plainChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useSession } from "next-auth/react";
import { usePathname, useSearchParams } from "next/navigation";
import Script from "next/script";
import { useEffect, useState } from "react";
import { useEffect, useState, useCallback, useMemo } from "react";

declare global {
interface Window {
Expand Down Expand Up @@ -75,157 +75,177 @@ const PlainChat = () => {
const pathname = usePathname();
const searchParams = useSearchParams();

const isAppDomain = typeof window !== "undefined" && window.location.hostname === "app.cal.com";
const shouldOpenPlain = pathname === "/event-types" && searchParams?.has("openPlain");
const userEmail = session?.user?.email;

useEffect(() => {
if (!isAppDomain) return;
const isAppDomain = useMemo(() => {
const restrictedPaths = process.env.NEXT_PUBLIC_PLAIN_CHAT_EXCLUDED_PATHS?.split(",") || [];
return (
typeof window !== "undefined" &&
window.location.origin === process.env.NEXT_PUBLIC_WEBAPP_URL &&
!restrictedPaths.some((path) => pathname?.startsWith(path.trim()))
);
}, [pathname]);

const checkScreenSize = () => {
setIsSmallScreen(window.innerWidth < 768);
};
const checkScreenSize = useCallback(() => {
if (typeof window === "undefined") return;

checkScreenSize();
window.addEventListener("resize", checkScreenSize);
const isSmall = window.innerWidth < 768;
setIsSmallScreen(isSmall);

const initConfig = async () => {
if (!session?.user?.email) return;
if (isSmall && window.Plain) {
const plainElement = document.querySelector("#plain-container");
plainElement?.remove();
window.Plain = undefined;
} else if (!isSmall && window.Plain === undefined) {
window.plainScriptLoaded?.();
}
}, []);

try {
const response = await fetch("/api/plain-hash", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
const initConfig = useCallback(async () => {
if (!userEmail) return;

if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to generate hash: ${errorText}`);
}
try {
const response = await fetch("/api/plain-hash", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});

const data = await response.json();
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to generate hash: ${errorText}`);
}

if (!data.hash || !data.email || !data.appId) {
throw new Error("Missing required fields in API response");
}
const data = await response.json();

if (!data.hash || !data.email || !data.appId) {
throw new Error("Missing required fields in API response");
}

const plainChatConfig: PlainChatConfig = {
appId: data.appId,
customerDetails: {
email: data.email,
shortName: data.shortName,
fullName: data.fullName,
emailHash: data.hash,
chatAvatarUrl: data.chatAvatarUrl,
const plainChatConfig: PlainChatConfig = {
appId: data.appId,
customerDetails: {
email: data.email,
shortName: data.shortName,
fullName: data.fullName,
emailHash: data.hash,
chatAvatarUrl: data.chatAvatarUrl,
},
links: [
{
icon: "book",
text: "Documentation",
url: "https://cal.com/docs",
},
links: [
{
icon: "book",
text: "Documentation",
url: "https://cal.com/docs",
},
{
icon: "chat",
text: "Ask the community",
url: "https://github.com/calcom/cal.com/discussions",
},
],
chatButtons: [
{
icon: "chat",
text: "Ask a question",
type: "primary",
},
{
icon: "bulb",
text: "Send feedback",
type: "default",
},
{
icon: "error",
text: "Report an issue",
type: "default",
form: {
fields: [
{
type: "dropdown",
placeholder: "Select severity...",
options: [
{
icon: "support",
text: "I'm unable to use the app",
threadDetails: {
severity: "critical",
issueType: "critical",
labelTypeIds: ["lt_01JFJWNWAC464N8DZ6YE71YJRF"],
priority: "u",
},
{
icon: "chat",
text: "Ask the community",
url: "https://github.com/calcom/cal.com/discussions",
},
],
chatButtons: [
{
icon: "chat",
text: "Ask a question",
type: "primary",
},
{
icon: "bulb",
text: "Send feedback",
type: "default",
},
{
icon: "error",
text: "Report an issue",
type: "default",
form: {
fields: [
{
type: "dropdown",
placeholder: "Select severity...",
options: [
{
icon: "support",
text: "I'm unable to use the app",
threadDetails: {
severity: "critical",
issueType: "critical",
labelTypeIds: ["lt_01JFJWNWAC464N8DZ6YE71YJRF"],
priority: "u",
},
{
icon: "error",
text: "Major functionality degraded",
threadDetails: {
severity: "major",
issueType: "major",
labelTypeIds: ["lt_01JFJWP3KECF1YQES6XF212RFW"],
priority: "h",
},
},
{
icon: "error",
text: "Major functionality degraded",
threadDetails: {
severity: "major",
issueType: "major",
labelTypeIds: ["lt_01JFJWP3KECF1YQES6XF212RFW"],
priority: "h",
},
{
icon: "bug",
text: "Minor annoyance",
threadDetails: {
severity: "minor",
issueType: "minor",
labelTypeIds: ["lt_01JFJWPC8ADW0PK28JHMJR6NSS"],
priority: "l",
},
},
{
icon: "bug",
text: "Minor annoyance",
threadDetails: {
severity: "minor",
issueType: "minor",
labelTypeIds: ["lt_01JFJWPC8ADW0PK28JHMJR6NSS"],
priority: "l",
},
],
},
],
},
},
],
},
],
},
],
entryPoint: {
type: "chat",
},
hideBranding: true,
theme: "auto",
style: {
brandColor: "#FFFFFF",
launcherBackgroundColor: "#262626",
launcherIconColor: "#FFFFFF",
},
position: {
bottom: "20px",
right: "20px",
},
};
],
entryPoint: {
type: "chat",
},
hideBranding: true,
theme: "auto",
style: {
brandColor: "#FFFFFF",
launcherBackgroundColor: "#262626",
launcherIconColor: "#FFFFFF",
},
position: {
bottom: "20px",
right: "20px",
},
};

if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
window.__PLAIN_CONFIG__ = plainChatConfig;
}
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
window.__PLAIN_CONFIG__ = plainChatConfig;
}

setConfig(plainChatConfig);
setConfig(plainChatConfig);

if (pathname === "/event-types" && searchParams?.has("openPlain")) {
const timer = setTimeout(() => {
if (window.Plain) {
window.Plain.open();
}
}, 100);
return () => clearTimeout(timer);
}
} catch (error) {
console.error("Failed to initialize Plain Chat:", error);
if (shouldOpenPlain) {
const timer = setTimeout(() => {
if (window.Plain) {
window.Plain.open();
}
}, 100);
return () => clearTimeout(timer);
}
};
} catch (error) {
console.error("Failed to initialize Plain Chat:", error);
}
}, [userEmail, shouldOpenPlain]);

useEffect(() => {
if (!isAppDomain) return;

checkScreenSize();
window.addEventListener("resize", checkScreenSize);
initConfig();

return () => window.removeEventListener("resize", checkScreenSize);
}, [session, pathname, searchParams, isAppDomain]);
}, [isAppDomain, checkScreenSize, initConfig, userEmail]);

const plainChatScript = `
window.plainScriptLoaded = function() {
Expand All @@ -239,7 +259,7 @@ const PlainChat = () => {
}
`;

if (!isAppDomain || isSmallScreen || !config) return null;
if (!isAppDomain || isSmallScreen || !config || typeof window === "undefined") return null;

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calcom/web",
"version": "4.8.9",
"version": "4.8.10",
"private": true,
"scripts": {
"analyze": "ANALYZE=true next build",
Expand Down
5 changes: 3 additions & 2 deletions apps/web/public/static/locales/ar/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2216,8 +2216,8 @@
"org_no_teams_yet": "هذه المنظمة ليس لديها فرق بعد",
"org_no_teams_yet_description": "إذا كنت مسؤول، تأكد من إنشاء فرق لعرضها هنا.",
"set_up": "الإعداد",
"my_profile": "الملف الشخصي",
"my_settings": "الإعدادات",
"my_profile": "ملفي الشخصي",
"my_settings": "إعداداتي",
"crm": "CRM",
"messaging": "المراسلة",
"sender_id_info": "الاسم أو الرقم الظاهر على أنه مرسل الرسالة النصية القصيرة (بعض البلدان لا تسمح بمعرفات المرسل الأبجدية الرقمية)",
Expand Down Expand Up @@ -2811,6 +2811,7 @@
"salesforce_owner_name_to_change": "اسم المالك المراد تغييره",
"no_filter_set": "لم يتم تعيين أي تصفية",
"booking_dry_run_successful": "تم إجراء المحاكاة التجريبية للحجز بنجاح",
"booking_dry_run_successful_description": "تم إكمال التشغيل التجريبي بنجاح.",
"dont_have_access_this_page": "ليس لديك صلاحية الوصول إلى هذه الصفحة",
"you_need_admin_or_owner_privileges_to_access": "لرؤية هذه الصفحة أو التفاعل معها، يجب أن تكون لديك صلاحيات المدير أو المالك",
"field_type": "نوع الحقل",
Expand Down
5 changes: 3 additions & 2 deletions apps/web/public/static/locales/az/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2216,8 +2216,8 @@
"org_no_teams_yet": "Bu təşkilatda hələ komanda yoxdur",
"org_no_teams_yet_description": "Əgər siz administratorsunuzsa, burada göstərmək üçün komandalar yaratdığınızdan əmin olun.",
"set_up": "Quraşdır",
"my_profile": "Profilim",
"my_settings": "Ayarlarım",
"my_profile": "Mənim profilim",
"my_settings": "Mənim tənzimləmələrim",
"crm": "CRM",
"messaging": "Mesajlaşma",
"sender_id_info": "SMS göndərən kimi göstərilən ad və ya nömrə (bəzi ölkələrdə alfasayısal göndərən ID-lərinə icazə verilmir)",
Expand Down Expand Up @@ -2811,6 +2811,7 @@
"salesforce_owner_name_to_change": "Dəyişdiriləcək sahibin adı",
"no_filter_set": "Filtr təyin edilməyib",
"booking_dry_run_successful": "Rezervasiya test yoxlaması uğurlu oldu",
"booking_dry_run_successful_description": "Test yoxlaması uğurla başa çatdı.",
"dont_have_access_this_page": "Bu səhifəyə girişiniz yoxdur",
"you_need_admin_or_owner_privileges_to_access": "Bu səhifəni görmək və ya onunla qarşılıqlı əlaqədə olmaq üçün admin və ya sahib imtiyazlarına malik olmalısınız",
"field_type": "Sahə növü",
Expand Down
1 change: 1 addition & 0 deletions apps/web/public/static/locales/bg/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,7 @@
"salesforce_owner_name_to_change": "Име на собственик за промяна",
"no_filter_set": "Няма зададен филтър",
"booking_dry_run_successful": "Тестовото резервиране е успешно",
"booking_dry_run_successful_description": "Тестовото изпълнение завърши успешно.",
"dont_have_access_this_page": "Нямате достъп до тази страница",
"you_need_admin_or_owner_privileges_to_access": "За да видите или взаимодействате с тази страница, трябва да имате администраторски права или да сте собственик",
"field_type": "Тип на полето",
Expand Down
1 change: 1 addition & 0 deletions apps/web/public/static/locales/ca/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,7 @@
"salesforce_owner_name_to_change": "Nom del propietari a canviar",
"no_filter_set": "Cap filtre establert",
"booking_dry_run_successful": "La prova de reserva s'ha realitzat correctament",
"booking_dry_run_successful_description": "La prova de funcionament s'ha completat correctament.",
"dont_have_access_this_page": "No tens accés a aquesta pàgina",
"you_need_admin_or_owner_privileges_to_access": "Per veure o interactuar amb aquesta pàgina, has de tenir privilegis d'administrador o propietari",
"field_type": "Tipus de camp",
Expand Down
Loading

0 comments on commit 44a38a0

Please sign in to comment.