@greatapps/common 1.1.191 → 1.1.193
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
+
import { usePathname } from "next/navigation";
|
|
3
4
|
import { useAuth } from "../../providers/auth.provider";
|
|
4
5
|
import { useWhitelabel } from "../../providers/whitelabel.provider";
|
|
5
6
|
import { useActiveSubscription } from "../../modules/subscriptions/hooks/find-active-subscription.hook";
|
|
@@ -7,20 +8,27 @@ const V4_WHITELABEL_ID = 367568;
|
|
|
7
8
|
const CRISP_WEBSITE_ID = "3339a3ec-b4c6-4aac-8b86-45668fb7655c";
|
|
8
9
|
const CRISP_SCRIPT_URL = "https://client.crisp.chat/l.js";
|
|
9
10
|
const CRISP_LOAD_DELAY = 800;
|
|
11
|
+
const EXCLUDED_ROUTES = [
|
|
12
|
+
"/login",
|
|
13
|
+
"/forgot-password",
|
|
14
|
+
"/register"
|
|
15
|
+
];
|
|
10
16
|
function openCrispHelpdesk() {
|
|
11
17
|
if (typeof window !== "undefined" && window.$crisp) {
|
|
12
18
|
window.$crisp.push(["do", "helpdesk:search"]);
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
function CrispEmbed() {
|
|
22
|
+
const pathname = usePathname();
|
|
16
23
|
const { user, account } = useAuth();
|
|
17
24
|
const { whitelabel } = useWhitelabel();
|
|
18
25
|
const { data: subscriptionData } = useActiveSubscription();
|
|
19
26
|
const scriptLoadedRef = useRef(false);
|
|
20
27
|
const subscription = subscriptionData?.data?.[0] ?? null;
|
|
28
|
+
const isExcluded = EXCLUDED_ROUTES.some((route) => pathname.startsWith(route));
|
|
21
29
|
const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
|
|
22
30
|
useEffect(() => {
|
|
23
|
-
if (!user || scriptLoadedRef.current) return;
|
|
31
|
+
if (isExcluded || !user || scriptLoadedRef.current) return;
|
|
24
32
|
const win = window;
|
|
25
33
|
win.$crisp = [];
|
|
26
34
|
win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
|
|
@@ -33,10 +41,10 @@ function CrispEmbed() {
|
|
|
33
41
|
scriptLoadedRef.current = true;
|
|
34
42
|
}, CRISP_LOAD_DELAY);
|
|
35
43
|
return () => clearTimeout(timeout);
|
|
36
|
-
}, [user]);
|
|
44
|
+
}, [user, isExcluded]);
|
|
37
45
|
useEffect(() => {
|
|
38
46
|
const $crisp = window.$crisp;
|
|
39
|
-
if (!user || !$crisp) return;
|
|
47
|
+
if (isExcluded || !user || !$crisp) return;
|
|
40
48
|
$crisp.push(["set", "user:email", user.email]);
|
|
41
49
|
$crisp.push(["set", "user:nickname", `${user.name} ${user.last_name}`.trim()]);
|
|
42
50
|
$crisp.push(["set", "user:company", account?.name ?? ""]);
|
|
@@ -54,7 +62,7 @@ function CrispEmbed() {
|
|
|
54
62
|
$crisp.push(["set", "session:data", [[["Plano", planName]]]]);
|
|
55
63
|
$crisp.push(["set", "session:data", [[["Usuario", user.profile]]]]);
|
|
56
64
|
}
|
|
57
|
-
}, [user, account, isV4, subscription?.plan_name]);
|
|
65
|
+
}, [user, account, isExcluded, isV4, subscription?.plan_name]);
|
|
58
66
|
return null;
|
|
59
67
|
}
|
|
60
68
|
export {
|
|
@@ -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 { useWhitelabel } from '../../providers/whitelabel.provider';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\n\nconst V4_WHITELABEL_ID = 367568;\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\nexport function openCrispHelpdesk() {\n if (typeof window !== 'undefined' && (window as any).$crisp) {\n (window as any).$crisp.push(['do', 'helpdesk:search']);\n }\n}\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 subscription = subscriptionData?.data?.[0] ?? null;\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n\n // Load Crisp script (once, with 800ms delay)\n useEffect(() => {\n if (!user || scriptLoadedRef.current) return;\n\n const win = window as any;\n win.$crisp = [];\n win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;\n\n const timeout = setTimeout(() => {\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 }, CRISP_LOAD_DELAY);\n\n return () => clearTimeout(timeout);\n }, [user]);\n\n // Identify user\n useEffect(() => {\n const $crisp = (window as any).$crisp;\n if (!user || !$crisp) return;\n\n $crisp.push(['set', 'user:email', user.email]);\n $crisp.push(['set', 'user:nickname', `${user.name} ${user.last_name}`.trim()]);\n $crisp.push(['set', 'user:company', account?.name ?? '']);\n $crisp.push(['set', 'user:phone', `${user.ddi}${user.phone}`]);\n\n if (user.photo) {\n $crisp.push(['set', 'user:avatar', user.photo]);\n }\n\n if (isV4) {\n $crisp.push(['set', 'session:segments', [['company_v4']]]);\n $crisp.push(['set', 'session:data', [[['Company', 'V4']]]]);\n } else {\n const planName = subscription?.plan_name ?? '';\n $crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);\n $crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);\n $crisp.push(['set', 'session:data', [[['Plano', planName]]]]);\n $crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);\n }\n }, [user, account, isV4, subscription?.plan_name]);\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAClC,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../../src/components/embeds/CrispEmbed.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { usePathname } from 'next/navigation';\nimport { useAuth } from '../../providers/auth.provider';\nimport { useWhitelabel } from '../../providers/whitelabel.provider';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\n\nconst V4_WHITELABEL_ID = 367568;\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\nconst EXCLUDED_ROUTES = [\n '/login',\n '/forgot-password',\n '/register',\n];\n\nexport function openCrispHelpdesk() {\n if (typeof window !== 'undefined' && (window as any).$crisp) {\n (window as any).$crisp.push(['do', 'helpdesk:search']);\n }\n}\n\nexport function CrispEmbed() {\n const pathname = usePathname();\n const { user, account } = useAuth();\n const { whitelabel } = useWhitelabel();\n const { data: subscriptionData } = useActiveSubscription();\n const scriptLoadedRef = useRef(false);\n\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isExcluded = EXCLUDED_ROUTES.some((route) => pathname.startsWith(route));\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n\n // Load Crisp script (once, with 800ms delay)\n useEffect(() => {\n if (isExcluded || !user || scriptLoadedRef.current) return;\n\n const win = window as any;\n win.$crisp = [];\n win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;\n\n const timeout = setTimeout(() => {\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 }, CRISP_LOAD_DELAY);\n\n return () => clearTimeout(timeout);\n }, [user, isExcluded]);\n\n // Identify user\n useEffect(() => {\n const $crisp = (window as any).$crisp;\n if (isExcluded || !user || !$crisp) return;\n\n $crisp.push(['set', 'user:email', user.email]);\n $crisp.push(['set', 'user:nickname', `${user.name} ${user.last_name}`.trim()]);\n $crisp.push(['set', 'user:company', account?.name ?? '']);\n $crisp.push(['set', 'user:phone', `${user.ddi}${user.phone}`]);\n\n if (user.photo) {\n $crisp.push(['set', 'user:avatar', user.photo]);\n }\n\n if (isV4) {\n $crisp.push(['set', 'session:segments', [['company_v4']]]);\n $crisp.push(['set', 'session:data', [[['Company', 'V4']]]]);\n } else {\n const planName = subscription?.plan_name ?? '';\n $crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);\n $crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);\n $crisp.push(['set', 'session:data', [[['Plano', planName]]]]);\n $crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);\n }\n }, [user, account, isExcluded, isV4, subscription?.plan_name]);\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAClC,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AAEzB,MAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,oBAAoB;AAClC,MAAI,OAAO,WAAW,eAAgB,OAAe,QAAQ;AAC3D,IAAC,OAAe,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAC;AAAA,EACvD;AACF;AAEO,SAAS,aAAa;AAC3B,QAAM,WAAW,YAAY;AAC7B,QAAM,EAAE,MAAM,QAAQ,IAAI,QAAQ;AAClC,QAAM,EAAE,WAAW,IAAI,cAAc;AACrC,QAAM,EAAE,MAAM,iBA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AO,gBAAgB,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC;AAAA,IAC5D,OAAO;AACL,YAAM,WAAW,cAAc,aAAa;AAC5C,aAAO,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,CAAC,CAAC;AAChE,aAAO,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC,WAAW,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC;AACtE,aAAO,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC5D,aAAO,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAAA,IACpE;AAAA,EACF,GAAG,CAAC,MAAM,SAAS,YAAY,MAAM,cAAc,SAAS,CAAC;AAE7D,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greatapps/common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.193",
|
|
4
4
|
"description": "Shared library for GreatApps frontend applications",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@greatapps/cache": "^2.0.1",
|
|
35
|
-
"@greatapps/common": "^1.1.138",
|
|
36
35
|
"@radix-ui/react-accordion": "^1.2.12",
|
|
37
36
|
"@radix-ui/react-checkbox": "^1.3.3",
|
|
38
37
|
"@radix-ui/react-popover": "^1.1.15",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { usePathname } from 'next/navigation';
|
|
4
5
|
import { useAuth } from '../../providers/auth.provider';
|
|
5
6
|
import { useWhitelabel } from '../../providers/whitelabel.provider';
|
|
6
7
|
import { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';
|
|
@@ -11,6 +12,12 @@ const CRISP_WEBSITE_ID = '3339a3ec-b4c6-4aac-8b86-45668fb7655c';
|
|
|
11
12
|
const CRISP_SCRIPT_URL = 'https://client.crisp.chat/l.js';
|
|
12
13
|
const CRISP_LOAD_DELAY = 800;
|
|
13
14
|
|
|
15
|
+
const EXCLUDED_ROUTES = [
|
|
16
|
+
'/login',
|
|
17
|
+
'/forgot-password',
|
|
18
|
+
'/register',
|
|
19
|
+
];
|
|
20
|
+
|
|
14
21
|
export function openCrispHelpdesk() {
|
|
15
22
|
if (typeof window !== 'undefined' && (window as any).$crisp) {
|
|
16
23
|
(window as any).$crisp.push(['do', 'helpdesk:search']);
|
|
@@ -18,17 +25,19 @@ export function openCrispHelpdesk() {
|
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
export function CrispEmbed() {
|
|
28
|
+
const pathname = usePathname();
|
|
21
29
|
const { user, account } = useAuth();
|
|
22
30
|
const { whitelabel } = useWhitelabel();
|
|
23
31
|
const { data: subscriptionData } = useActiveSubscription();
|
|
24
32
|
const scriptLoadedRef = useRef(false);
|
|
25
33
|
|
|
26
34
|
const subscription = subscriptionData?.data?.[0] ?? null;
|
|
35
|
+
const isExcluded = EXCLUDED_ROUTES.some((route) => pathname.startsWith(route));
|
|
27
36
|
const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
|
|
28
37
|
|
|
29
38
|
// Load Crisp script (once, with 800ms delay)
|
|
30
39
|
useEffect(() => {
|
|
31
|
-
if (!user || scriptLoadedRef.current) return;
|
|
40
|
+
if (isExcluded || !user || scriptLoadedRef.current) return;
|
|
32
41
|
|
|
33
42
|
const win = window as any;
|
|
34
43
|
win.$crisp = [];
|
|
@@ -44,12 +53,12 @@ export function CrispEmbed() {
|
|
|
44
53
|
}, CRISP_LOAD_DELAY);
|
|
45
54
|
|
|
46
55
|
return () => clearTimeout(timeout);
|
|
47
|
-
}, [user]);
|
|
56
|
+
}, [user, isExcluded]);
|
|
48
57
|
|
|
49
58
|
// Identify user
|
|
50
59
|
useEffect(() => {
|
|
51
60
|
const $crisp = (window as any).$crisp;
|
|
52
|
-
if (!user || !$crisp) return;
|
|
61
|
+
if (isExcluded || !user || !$crisp) return;
|
|
53
62
|
|
|
54
63
|
$crisp.push(['set', 'user:email', user.email]);
|
|
55
64
|
$crisp.push(['set', 'user:nickname', `${user.name} ${user.last_name}`.trim()]);
|
|
@@ -70,7 +79,7 @@ export function CrispEmbed() {
|
|
|
70
79
|
$crisp.push(['set', 'session:data', [[['Plano', planName]]]]);
|
|
71
80
|
$crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);
|
|
72
81
|
}
|
|
73
|
-
}, [user, account, isV4, subscription?.plan_name]);
|
|
82
|
+
}, [user, account, isExcluded, isV4, subscription?.plan_name]);
|
|
74
83
|
|
|
75
84
|
return null;
|
|
76
85
|
}
|