@greatapps/common 1.1.571 → 1.1.572

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,6 +61,34 @@ function CrispEmbed() {
61
61
  const subscription = subscriptionData?.data?.[0] ?? null;
62
62
  const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
63
63
  const shouldLoadCrisp = isV4 || isGreat;
64
+ useEffect(() => {
65
+ if (!user || !shouldLoadCrisp || scriptLoadedRef.current) return;
66
+ try {
67
+ const win = window;
68
+ if (!win.$crisp) {
69
+ win.$crisp = [];
70
+ win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
71
+ win.$crisp.push(["config", "container:index", [100]]);
72
+ }
73
+ if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) {
74
+ scriptLoadedRef.current = true;
75
+ return;
76
+ }
77
+ const timeout = setTimeout(() => {
78
+ try {
79
+ if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
80
+ const s = document.createElement("script");
81
+ s.src = CRISP_SCRIPT_URL;
82
+ s.async = true;
83
+ document.head.appendChild(s);
84
+ scriptLoadedRef.current = true;
85
+ } catch {
86
+ }
87
+ }, CRISP_LOAD_DELAY);
88
+ return () => clearTimeout(timeout);
89
+ } catch {
90
+ }
91
+ }, [user, shouldLoadCrisp]);
64
92
  useEffect(() => {
65
93
  try {
66
94
  if (!user || !shouldLoadCrisp || !window?.$crisp) return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/embeds/CrispEmbed.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAuth } from '../../providers/auth.provider';\nimport { useIsDefaultWhitelabel, useWhitelabel } from '../../providers/whitelabel.provider';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\n\nconst V4_WHITELABEL_ID = 367568;\n\nconst PROFILE_LABELS: Record<string, string> = {\n owner: 'Proprietário',\n admin: 'Administrador',\n editor: 'Colaborador',\n viewer: 'Visualizador',\n};\n\nconst CRISP_WEBSITE_ID = '3339a3ec-b4c6-4aac-8b86-45668fb7655c';\nconst CRISP_SCRIPT_URL = 'https://client.crisp.chat/l.js';\nconst CRISP_LOAD_DELAY = 800;\n\n// ── Crisp helpers ──────────────────────────────────────────────\n\nfunction safeCrispPush(args: unknown[]) {\n try {\n const $crisp = (window as any)?.$crisp;\n if ($crisp) $crisp.push(args);\n } catch {}\n}\n\nfunction crispDo(action: string) {\n safeCrispPush(['do', action]);\n}\n\nfunction crispSegment(segment: string) {\n safeCrispPush(['set', 'session:segments', [[segment]]]);\n}\n\nfunction crispSessionData(key: string, value: string) {\n safeCrispPush(['set', 'session:data', [[[key, value]]]]);\n}\n\n// ── Public API ─────────────────────────────────────────────────\n\nexport function openCrispHelpdesk() {\n crispDo('helpdesk:search');\n}\n\nexport function hideCrisp() {\n crispDo('chat:hide');\n}\n\nexport function showCrisp() {\n crispDo('chat:show');\n}\n\nexport function updateCrispUser(data: {\n email?: string;\n name?: string;\n lastName?: string;\n company?: string;\n ddi?: string;\n phone?: string;\n photo?: string;\n}) {\n try {\n if (data.email) safeCrispPush(['set', 'user:email', data.email]);\n\n const fullName = `${data.name ?? ''} ${data.lastName ?? ''}`.trim();\n if (fullName) safeCrispPush(['set', 'user:nickname', fullName]);\n\n if (data.company) safeCrispPush(['set', 'user:company', data.company]);\n\n const phone = `${data.ddi ?? ''}${data.phone ?? ''}`.trim();\n if (phone) safeCrispPush(['set', 'user:phone', phone]);\n\n if (data.photo?.startsWith('http')) {\n safeCrispPush(['set', 'user:avatar', data.photo]);\n }\n } catch {}\n}\n\n// ── Component ──────────────────────────────────────────────────\n\nexport function CrispEmbed() {\n const { user, account } = useAuth();\n const { whitelabel } = useWhitelabel();\n const { data: subscriptionData } = useActiveSubscription();\n const scriptLoadedRef = useRef(false);\n\n const isGreat = useIsDefaultWhitelabel();\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n const shouldLoadCrisp = isV4 || isGreat;\n\n // Load Crisp script (once, with 800ms delay)\n // useEffect(() => {\n // if (!user || !shouldLoadCrisp || scriptLoadedRef.current) return;\n\n // try {\n // const win = window as any;\n\n // if (!win.$crisp) {\n // win.$crisp = [];\n // win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;\n // win.$crisp.push(['config', 'container:index', [100]]);\n // }\n\n // if (document.querySelector(`script[src=\"${CRISP_SCRIPT_URL}\"]`)) {\n // scriptLoadedRef.current = true;\n // return;\n // }\n\n // const timeout = setTimeout(() => {\n // try {\n // if (document.querySelector(`script[src=\"${CRISP_SCRIPT_URL}\"]`)) return;\n // const s = document.createElement('script');\n // s.src = CRISP_SCRIPT_URL;\n // s.async = true;\n // document.head.appendChild(s);\n // scriptLoadedRef.current = true;\n // } catch {}\n // }, CRISP_LOAD_DELAY);\n\n // return () => clearTimeout(timeout);\n // } catch {}\n // }, [user, shouldLoadCrisp]);\n\n // Identify user\n useEffect(() => {\n try {\n if (!user || !shouldLoadCrisp || !(window as any)?.$crisp) return;\n\n updateCrispUser({\n email: user.email,\n name: user.name,\n lastName: user.last_name,\n company: account?.name,\n ddi: user.ddi,\n phone: user.phone,\n photo: user.photo ?? undefined,\n });\n\n if (isV4) {\n crispSegment('company_v4');\n crispSessionData('Company', 'V4');\n } else {\n const planName = subscription?.plan_name ?? '';\n const profileLabel = PROFILE_LABELS[user.profile ?? ''] ?? user.profile ?? '';\n if (planName) crispSegment(`plano_${planName}`);\n if (profileLabel) crispSegment(`usuario_${profileLabel}`);\n if (planName) crispSessionData('Plano', planName);\n if (profileLabel) crispSessionData('Usuario', profileLabel);\n }\n } catch {}\n }, [user, account, isV4, shouldLoadCrisp, subscription?.plan_name]);\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAClC,SAAS,eAAe;AACxB,SAAS,wBAAwB,qBAAqB;AACtD,SAAS,6BAA6B;AAEtC,MAAM,mBAAmB;AAEzB,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useRef } from 'react';\nimport { useAuth } from '../../providers/auth.provider';\nimport { useIsDefaultWhitelabel, useWhitelabel } from '../../providers/whitelabel.provider';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\n\nconst V4_WHITELABEL_ID = 367568;\n\nconst PROFILE_LABELS: Record<string, string> = {\n owner: 'Proprietário',\n admin: 'Administrador',\n editor: 'Colaborador',\n viewer: 'Visualizador',\n};\n\nconst CRISP_WEBSITE_ID = '3339a3ec-b4c6-4aac-8b86-45668fb7655c';\nconst CRISP_SCRIPT_URL = 'https://client.crisp.chat/l.js';\nconst CRISP_LOAD_DELAY = 800;\n\n// ── Crisp helpers ──────────────────────────────────────────────\n\nfunction safeCrispPush(args: unknown[]) {\n try {\n const $crisp = (window as any)?.$crisp;\n if ($crisp) $crisp.push(args);\n } catch {}\n}\n\nfunction crispDo(action: string) {\n safeCrispPush(['do', action]);\n}\n\nfunction crispSegment(segment: string) {\n safeCrispPush(['set', 'session:segments', [[segment]]]);\n}\n\nfunction crispSessionData(key: string, value: string) {\n safeCrispPush(['set', 'session:data', [[[key, value]]]]);\n}\n\n// ── Public API ─────────────────────────────────────────────────\n\nexport function openCrispHelpdesk() {\n crispDo('helpdesk:search');\n}\n\nexport function hideCrisp() {\n crispDo('chat:hide');\n}\n\nexport function showCrisp() {\n crispDo('chat:show');\n}\n\nexport function updateCrispUser(data: {\n email?: string;\n name?: string;\n lastName?: string;\n company?: string;\n ddi?: string;\n phone?: string;\n photo?: string;\n}) {\n try {\n if (data.email) safeCrispPush(['set', 'user:email', data.email]);\n\n const fullName = `${data.name ?? ''} ${data.lastName ?? ''}`.trim();\n if (fullName) safeCrispPush(['set', 'user:nickname', fullName]);\n\n if (data.company) safeCrispPush(['set', 'user:company', data.company]);\n\n const phone = `${data.ddi ?? ''}${data.phone ?? ''}`.trim();\n if (phone) safeCrispPush(['set', 'user:phone', phone]);\n\n if (data.photo?.startsWith('http')) {\n safeCrispPush(['set', 'user:avatar', data.photo]);\n }\n } catch {}\n}\n\n// ── Component ──────────────────────────────────────────────────\n\nexport function CrispEmbed() {\n const { user, account } = useAuth();\n const { whitelabel } = useWhitelabel();\n const { data: subscriptionData } = useActiveSubscription();\n const scriptLoadedRef = useRef(false);\n\n const isGreat = useIsDefaultWhitelabel();\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n const shouldLoadCrisp = isV4 || isGreat;\n\n // Load Crisp script (once, with 800ms delay)\n useEffect(() => {\n if (!user || !shouldLoadCrisp || scriptLoadedRef.current) return;\n\n try {\n const win = window as any;\n\n if (!win.$crisp) {\n win.$crisp = [];\n win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;\n win.$crisp.push(['config', 'container:index', [100]]);\n }\n\n if (document.querySelector(`script[src=\"${CRISP_SCRIPT_URL}\"]`)) {\n scriptLoadedRef.current = true;\n return;\n }\n\n const timeout = setTimeout(() => {\n try {\n if (document.querySelector(`script[src=\"${CRISP_SCRIPT_URL}\"]`)) return;\n const s = document.createElement('script');\n s.src = CRISP_SCRIPT_URL;\n s.async = true;\n document.head.appendChild(s);\n scriptLoadedRef.current = true;\n } catch {}\n }, CRISP_LOAD_DELAY);\n\n return () => clearTimeout(timeout);\n } catch {}\n }, [user, shouldLoadCrisp]);\n\n // Identify user\n useEffect(() => {\n try {\n if (!user || !shouldLoadCrisp || !(window as any)?.$crisp) return;\n\n updateCrispUser({\n email: user.email,\n name: user.name,\n lastName: user.last_name,\n company: account?.name,\n ddi: user.ddi,\n phone: user.phone,\n photo: user.photo ?? undefined,\n });\n\n if (isV4) {\n crispSegment('company_v4');\n crispSessionData('Company', 'V4');\n } else {\n const planName = subscription?.plan_name ?? '';\n const profileLabel = PROFILE_LABELS[user.profile ?? ''] ?? user.profile ?? '';\n if (planName) crispSegment(`plano_${planName}`);\n if (profileLabel) crispSegment(`usuario_${profileLabel}`);\n if (planName) crispSessionData('Plano', planName);\n if (profileLabel) crispSessionData('Usuario', prof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,MAAM,aAAa,OAAO;AAAA,IACnC,QAAQ;AAAA,IAAC;AAAA,EACX,GAAG,CAAC,MAAM,eAAe,CAAC;AAG1B,YAAU,MAAM;AACd,QAAI;AACF,UAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAE,QAAgB,OAAQ;AAE3D,sBAAgB;AAAA,QACd,OAAO,KAAK;AAAA,QACZ,MAAM,KAAK;AAAA,QACX,UAAU,KAAK;AAAA,QACf,SAAS,SAAS;AAAA,QAClB,KAAK,KAAK;AAAA,QACV,OAAO,KAAK;AAAA,QACZ,OAAO,KAAK,SAAS;AAAA,MACvB,CAAC;AAED,UAAI,MAAM;AACR,qBAAa,YAAY;AACzB,yBAAiB,WAAW,IAAI;AAAA,MAClC,OAAO;AACL,cAAM,WAAW,cAAc,aAAa;AAC5C,cAAM,eAAe,eAAe,KAAK,WAAW,EAAE,KAAK,KAAK,WAAW;AAC3E,YAAI,SAAU,cAAa,SAAS,QAAQ,EAAE;AAC9C,YAAI,aAAc,cAAa,WAAW,YAAY,EAAE;AACxD,YAAI,SAAU,kBAAiB,SAAS,QAAQ;AAChD,YAAI,aAAc,kBAAiB,WAAW,YAAY;AAAA,MAC5D;AAAA,IACF,QAAQ;AAAA,IAAC;AAAA,EACX,GAAG,CAAC,MAAM,SAAS,MAAM,iBAAiB,cAAc,SAAS,CAAC;AAElE,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.571",
3
+ "version": "1.1.572",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
@@ -93,37 +93,37 @@ export function CrispEmbed() {
93
93
  const shouldLoadCrisp = isV4 || isGreat;
94
94
 
95
95
  // Load Crisp script (once, with 800ms delay)
96
- // useEffect(() => {
97
- // if (!user || !shouldLoadCrisp || scriptLoadedRef.current) return;
98
-
99
- // try {
100
- // const win = window as any;
101
-
102
- // if (!win.$crisp) {
103
- // win.$crisp = [];
104
- // win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
105
- // win.$crisp.push(['config', 'container:index', [100]]);
106
- // }
107
-
108
- // if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) {
109
- // scriptLoadedRef.current = true;
110
- // return;
111
- // }
112
-
113
- // const timeout = setTimeout(() => {
114
- // try {
115
- // if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
116
- // const s = document.createElement('script');
117
- // s.src = CRISP_SCRIPT_URL;
118
- // s.async = true;
119
- // document.head.appendChild(s);
120
- // scriptLoadedRef.current = true;
121
- // } catch {}
122
- // }, CRISP_LOAD_DELAY);
123
-
124
- // return () => clearTimeout(timeout);
125
- // } catch {}
126
- // }, [user, shouldLoadCrisp]);
96
+ useEffect(() => {
97
+ if (!user || !shouldLoadCrisp || scriptLoadedRef.current) return;
98
+
99
+ try {
100
+ const win = window as any;
101
+
102
+ if (!win.$crisp) {
103
+ win.$crisp = [];
104
+ win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
105
+ win.$crisp.push(['config', 'container:index', [100]]);
106
+ }
107
+
108
+ if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) {
109
+ scriptLoadedRef.current = true;
110
+ return;
111
+ }
112
+
113
+ const timeout = setTimeout(() => {
114
+ try {
115
+ if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
116
+ const s = document.createElement('script');
117
+ s.src = CRISP_SCRIPT_URL;
118
+ s.async = true;
119
+ document.head.appendChild(s);
120
+ scriptLoadedRef.current = true;
121
+ } catch {}
122
+ }, CRISP_LOAD_DELAY);
123
+
124
+ return () => clearTimeout(timeout);
125
+ } catch {}
126
+ }, [user, shouldLoadCrisp]);
127
127
 
128
128
  // Identify user
129
129
  useEffect(() => {