@greatapps/common 1.1.193 → 1.1.195
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.
- package/dist/components/embeds/CrispEmbed.mjs +4 -12
- package/dist/components/embeds/CrispEmbed.mjs.map +1 -1
- package/dist/components/embeds/FrillEmbed.mjs +7 -11
- package/dist/components/embeds/FrillEmbed.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/embeds/CrispEmbed.tsx +4 -13
- package/src/components/embeds/FrillEmbed.tsx +7 -12
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
-
import { usePathname } from "next/navigation";
|
|
4
3
|
import { useAuth } from "../../providers/auth.provider";
|
|
5
4
|
import { useWhitelabel } from "../../providers/whitelabel.provider";
|
|
6
5
|
import { useActiveSubscription } from "../../modules/subscriptions/hooks/find-active-subscription.hook";
|
|
@@ -8,27 +7,20 @@ const V4_WHITELABEL_ID = 367568;
|
|
|
8
7
|
const CRISP_WEBSITE_ID = "3339a3ec-b4c6-4aac-8b86-45668fb7655c";
|
|
9
8
|
const CRISP_SCRIPT_URL = "https://client.crisp.chat/l.js";
|
|
10
9
|
const CRISP_LOAD_DELAY = 800;
|
|
11
|
-
const EXCLUDED_ROUTES = [
|
|
12
|
-
"/login",
|
|
13
|
-
"/forgot-password",
|
|
14
|
-
"/register"
|
|
15
|
-
];
|
|
16
10
|
function openCrispHelpdesk() {
|
|
17
11
|
if (typeof window !== "undefined" && window.$crisp) {
|
|
18
12
|
window.$crisp.push(["do", "helpdesk:search"]);
|
|
19
13
|
}
|
|
20
14
|
}
|
|
21
15
|
function CrispEmbed() {
|
|
22
|
-
const pathname = usePathname();
|
|
23
16
|
const { user, account } = useAuth();
|
|
24
17
|
const { whitelabel } = useWhitelabel();
|
|
25
18
|
const { data: subscriptionData } = useActiveSubscription();
|
|
26
19
|
const scriptLoadedRef = useRef(false);
|
|
27
20
|
const subscription = subscriptionData?.data?.[0] ?? null;
|
|
28
|
-
const isExcluded = EXCLUDED_ROUTES.some((route) => pathname.startsWith(route));
|
|
29
21
|
const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
|
|
30
22
|
useEffect(() => {
|
|
31
|
-
if (
|
|
23
|
+
if (!user || scriptLoadedRef.current) return;
|
|
32
24
|
const win = window;
|
|
33
25
|
win.$crisp = [];
|
|
34
26
|
win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
|
|
@@ -41,10 +33,10 @@ function CrispEmbed() {
|
|
|
41
33
|
scriptLoadedRef.current = true;
|
|
42
34
|
}, CRISP_LOAD_DELAY);
|
|
43
35
|
return () => clearTimeout(timeout);
|
|
44
|
-
}, [user
|
|
36
|
+
}, [user]);
|
|
45
37
|
useEffect(() => {
|
|
46
38
|
const $crisp = window.$crisp;
|
|
47
|
-
if (
|
|
39
|
+
if (!user || !$crisp) return;
|
|
48
40
|
$crisp.push(["set", "user:email", user.email]);
|
|
49
41
|
$crisp.push(["set", "user:nickname", `${user.name} ${user.last_name}`.trim()]);
|
|
50
42
|
$crisp.push(["set", "user:company", account?.name ?? ""]);
|
|
@@ -62,7 +54,7 @@ function CrispEmbed() {
|
|
|
62
54
|
$crisp.push(["set", "session:data", [[["Plano", planName]]]]);
|
|
63
55
|
$crisp.push(["set", "session:data", [[["Usuario", user.profile]]]]);
|
|
64
56
|
}
|
|
65
|
-
}, [user, account,
|
|
57
|
+
}, [user, account, isV4, subscription?.plan_name]);
|
|
66
58
|
return null;
|
|
67
59
|
}
|
|
68
60
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/embeds/CrispEmbed.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport {
|
|
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;AAElB,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,EAAE,MAAM,QAAQ,IAAI,QAAQ;AAClC,QAAM,EAAE,WAAW,IAAI,cAAc;AACrC,QAAM,EAAE,MAAM,iBAAiB,IAAI,sBAAsB;AACzD,QAAM,kBAAkB,OAAO,KAAK;AAEpC,QAAM,eAAe,kBAAkB,OAAO,CAAC,KAAK;AACpD,QAAM,OAAO,YAAY,OAAO;AAGhC,YAAU,MAAM;AACd,QAAI,CAAC,QAAQ,gBAAgB,QAAS;AAEtC,UAAM,MAAM;AACZ,QAAI,SAAS,CAAC;AACd,QAAI,mBAAmB;AAEvB,UAAM,UAAU,WAAW,MAAM;AAC/B,UAAI,SAAS,cAAc,eAAe,gBAAgB,IAAI,EAAG;AACjE,YAAM,IAAI,SAAS,cAAc,QAAQ;AACzC,QAAE,MAAM;AACR,QAAE,QAAQ;AACV,eAAS,KAAK,YAAY,CAAC;AAC3B,sBAAgB,UAAU;AAAA,IAC5B,GAAG,gBAAgB;AAEnB,WAAO,MAAM,aAAa,OAAO;AAAA,EACnC,GAAG,CAAC,IAAI,CAAC;AAGT,YAAU,MAA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ef } from "react";
|
|
3
|
-
import { usePathname } from "next/navigation";
|
|
4
3
|
import { useAuth } from "../../providers/auth.provider";
|
|
5
4
|
import { useWhitelabel } from "../../providers/whitelabel.provider";
|
|
6
5
|
import { useActiveSubscription } from "../../modules/subscriptions/hooks/find-active-subscription.hook";
|
|
7
6
|
const V4_WHITELABEL_ID = 367568;
|
|
8
7
|
const FRILL_SCRIPT_URL = "https://widget.frill.co/v2/container.js";
|
|
9
8
|
const FRILL_KEY = "2f77f232-a120-438e-8ef6-01912ffd1b99";
|
|
10
|
-
const EXCLUDED_ROUTES = [
|
|
11
|
-
"/login",
|
|
12
|
-
"/forgot-password",
|
|
13
|
-
"/register"
|
|
14
|
-
];
|
|
15
9
|
const SURVEYS = [{ key: "7f59dbf6-b665-458a-80e2-778de47efe1c" }];
|
|
16
10
|
const WIDGETS = [
|
|
17
11
|
{ key: "4a5ba13b-1150-49fe-aa15-f9a2da0ba909" },
|
|
@@ -53,16 +47,14 @@ function loadFrillScript() {
|
|
|
53
47
|
anchor?.parentNode?.insertBefore(script, anchor);
|
|
54
48
|
}
|
|
55
49
|
function FrillEmbed() {
|
|
56
|
-
const pathname = usePathname();
|
|
57
50
|
const { user } = useAuth();
|
|
58
51
|
const { whitelabel } = useWhitelabel();
|
|
59
52
|
const { data: subscriptionData } = useActiveSubscription();
|
|
60
53
|
const containerRef = useRef(null);
|
|
61
54
|
const subscription = subscriptionData?.data?.[0] ?? null;
|
|
62
|
-
const isExcluded = EXCLUDED_ROUTES.some((route) => pathname.startsWith(route));
|
|
63
55
|
const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
|
|
64
56
|
useEffect(() => {
|
|
65
|
-
if (
|
|
57
|
+
if (!user) return;
|
|
66
58
|
initFrillLoader();
|
|
67
59
|
if (document.readyState === "complete" || document.readyState === "interactive") {
|
|
68
60
|
loadFrillScript();
|
|
@@ -81,14 +73,18 @@ function FrillEmbed() {
|
|
|
81
73
|
config.widgets = WIDGETS;
|
|
82
74
|
}
|
|
83
75
|
const win = window;
|
|
84
|
-
|
|
76
|
+
const containerPromise = win.Frill("container", config);
|
|
85
77
|
win.Frill("identify", userData);
|
|
78
|
+
containerPromise.then((widget) => {
|
|
79
|
+
containerRef.current = widget;
|
|
80
|
+
}).catch(() => {
|
|
81
|
+
});
|
|
86
82
|
return () => {
|
|
87
83
|
containerRef.current?.destroy();
|
|
88
84
|
containerRef.current = null;
|
|
89
85
|
document.removeEventListener("DOMContentLoaded", loadFrillScript);
|
|
90
86
|
};
|
|
91
|
-
}, [user,
|
|
87
|
+
}, [user, isV4, subscription?.plan_name]);
|
|
92
88
|
return null;
|
|
93
89
|
}
|
|
94
90
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/embeds/FrillEmbed.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/embeds/FrillEmbed.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 FRILL_SCRIPT_URL = 'https://widget.frill.co/v2/container.js';\nconst FRILL_KEY = '2f77f232-a120-438e-8ef6-01912ffd1b99';\n\nconst SURVEYS = [{ key: '7f59dbf6-b665-458a-80e2-778de47efe1c' }];\nconst WIDGETS = [\n { key: '4a5ba13b-1150-49fe-aa15-f9a2da0ba909' },\n { key: '720c0912-e6a4-495c-835e-3ff1f59d6dfc' },\n];\n\nfunction initFrillLoader() {\n const win = window as any;\n if (win.Frill) return;\n\n let counter = 0;\n const queue: Record<number, any> = {};\n\n win.Frill = function (action: string, params: any) {\n let instance: any;\n const id = counter++;\n const promise: any = new Promise((resolve, reject) => {\n queue[id] = {\n params: [action, params],\n resolve: (f: any) => {\n instance = f;\n resolve(f);\n },\n reject,\n };\n });\n promise.destroy = () => {\n delete queue[id];\n instance?.destroy();\n };\n return promise;\n };\n win.Frill.q = queue;\n}\n\nfunction loadFrillScript() {\n if (document.querySelector(`script[src=\"${FRILL_SCRIPT_URL}\"]`)) return;\n const anchor = document.getElementsByTagName('script')[0];\n const script = document.createElement('script');\n script.type = 'text/javascript';\n script.async = true;\n script.src = FRILL_SCRIPT_URL;\n anchor?.parentNode?.insertBefore(script, anchor);\n}\n\nexport function FrillEmbed() {\n const { user } = useAuth();\n const { whitelabel } = useWhitelabel();\n const { data: subscriptionData } = useActiveSubscription();\n const containerRef = useRef<any>(null);\n\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isV4 = whitelabel?.id === V4_WHITELABEL_ID;\n\n useEffect(() => {\n if (!user) return;\n\n initFrillLoader();\n\n if (document.readyState === 'complete' || document.readyState === 'interactive') {\n loadFrillScript();\n } else {\n document.addEventListener('DOMContentLoaded', loadFrillScript);\n }\n\n const userData = {\n id: String(user.id),\n email: user.email,\n name: `${user.name} ${user.last_name}`.trim(),\n attributes: isV4\n ? { company: 'V4' }\n : { profile: user.profile, plan: subscription?.plan_name ?? '' },\n };\n\n const config: Record<string, any> = { key: FRILL_KEY, user: userData };\n if (!isV4) {\n config.surveys = SURVEYS;\n config.widgets = WIDGETS;\n }\n\n const win = window as any;\n const containerPromise = win.Frill('container', config);\n win.Frill('identify', userData);\n\n containerPromise.then((widget: any) => {\n containerRef.current = widget;\n }).catch(() => {});\n\n return () => {\n containerRef.current?.destroy();\n containerRef.current = null;\n document.removeEventListener('DOMContentLoaded', loadFrillScript);\n };\n }, [user, 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,YAAY;AAElB,MAAM,UAAU,CAAC,EAAE,KAAK,u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Ae;AAC/E,sBAAgB;AAAA,IAClB,OAAO;AACL,eAAS,iBAAiB,oBAAoB,eAAe;AAAA,IAC/D;AAEA,UAAM,WAAW;AAAA,MACf,IAAI,OAAO,KAAK,EAAE;AAAA,MAClB,OAAO,KAAK;AAAA,MACZ,MAAM,GAAG,KAAK,IAAI,IAAI,KAAK,SAAS,GAAG,KAAK;AAAA,MAC5C,YAAY,OACR,EAAE,SAAS,KAAK,IAChB,EAAE,SAAS,KAAK,SAAS,MAAM,cAAc,aAAa,GAAG;AAAA,IACnE;AAEA,UAAM,SAA8B,EAAE,KAAK,WAAW,MAAM,SAAS;AACrE,QAAI,CAAC,MAAM;AACT,aAAO,UAAU;AACjB,aAAO,UAAU;AAAA,IACnB;AAEA,UAAM,MAAM;AACZ,UAAM,mBAAmB,IAAI,MAAM,aAAa,MAAM;AACtD,QAAI,MAAM,YAAY,QAAQ;AAE9B,qBAAiB,KAAK,CAAC,WAAgB;AACrC,mBAAa,UAAU;AAAA,IACzB,CAAC,EAAE,MAAM,MAAM;AAAA,IAAC,CAAC;AAEjB,WAAO,MAAM;AACX,mBAAa,SAAS,QAAQ;AAC9B,mBAAa,UAAU;AACvB,eAAS,oBAAoB,oBAAoB,eAAe;AAAA,IAClE;AAAA,EACF,GAAG,CAAC,MAAM,MAAM,cAAc,SAAS,CAAC;AAExC,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
|
-
import { usePathname } from 'next/navigation';
|
|
5
4
|
import { useAuth } from '../../providers/auth.provider';
|
|
6
5
|
import { useWhitelabel } from '../../providers/whitelabel.provider';
|
|
7
6
|
import { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';
|
|
@@ -12,12 +11,6 @@ const CRISP_WEBSITE_ID = '3339a3ec-b4c6-4aac-8b86-45668fb7655c';
|
|
|
12
11
|
const CRISP_SCRIPT_URL = 'https://client.crisp.chat/l.js';
|
|
13
12
|
const CRISP_LOAD_DELAY = 800;
|
|
14
13
|
|
|
15
|
-
const EXCLUDED_ROUTES = [
|
|
16
|
-
'/login',
|
|
17
|
-
'/forgot-password',
|
|
18
|
-
'/register',
|
|
19
|
-
];
|
|
20
|
-
|
|
21
14
|
export function openCrispHelpdesk() {
|
|
22
15
|
if (typeof window !== 'undefined' && (window as any).$crisp) {
|
|
23
16
|
(window as any).$crisp.push(['do', 'helpdesk:search']);
|
|
@@ -25,19 +18,17 @@ export function openCrispHelpdesk() {
|
|
|
25
18
|
}
|
|
26
19
|
|
|
27
20
|
export function CrispEmbed() {
|
|
28
|
-
const pathname = usePathname();
|
|
29
21
|
const { user, account } = useAuth();
|
|
30
22
|
const { whitelabel } = useWhitelabel();
|
|
31
23
|
const { data: subscriptionData } = useActiveSubscription();
|
|
32
24
|
const scriptLoadedRef = useRef(false);
|
|
33
25
|
|
|
34
26
|
const subscription = subscriptionData?.data?.[0] ?? null;
|
|
35
|
-
const isExcluded = EXCLUDED_ROUTES.some((route) => pathname.startsWith(route));
|
|
36
27
|
const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
|
|
37
28
|
|
|
38
29
|
// Load Crisp script (once, with 800ms delay)
|
|
39
30
|
useEffect(() => {
|
|
40
|
-
if (
|
|
31
|
+
if (!user || scriptLoadedRef.current) return;
|
|
41
32
|
|
|
42
33
|
const win = window as any;
|
|
43
34
|
win.$crisp = [];
|
|
@@ -53,12 +44,12 @@ export function CrispEmbed() {
|
|
|
53
44
|
}, CRISP_LOAD_DELAY);
|
|
54
45
|
|
|
55
46
|
return () => clearTimeout(timeout);
|
|
56
|
-
}, [user
|
|
47
|
+
}, [user]);
|
|
57
48
|
|
|
58
49
|
// Identify user
|
|
59
50
|
useEffect(() => {
|
|
60
51
|
const $crisp = (window as any).$crisp;
|
|
61
|
-
if (
|
|
52
|
+
if (!user || !$crisp) return;
|
|
62
53
|
|
|
63
54
|
$crisp.push(['set', 'user:email', user.email]);
|
|
64
55
|
$crisp.push(['set', 'user:nickname', `${user.name} ${user.last_name}`.trim()]);
|
|
@@ -79,7 +70,7 @@ export function CrispEmbed() {
|
|
|
79
70
|
$crisp.push(['set', 'session:data', [[['Plano', planName]]]]);
|
|
80
71
|
$crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);
|
|
81
72
|
}
|
|
82
|
-
}, [user, account,
|
|
73
|
+
}, [user, account, isV4, subscription?.plan_name]);
|
|
83
74
|
|
|
84
75
|
return null;
|
|
85
76
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
|
-
import { usePathname } from 'next/navigation';
|
|
5
4
|
import { useAuth } from '../../providers/auth.provider';
|
|
6
5
|
import { useWhitelabel } from '../../providers/whitelabel.provider';
|
|
7
6
|
import { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';
|
|
@@ -11,12 +10,6 @@ const V4_WHITELABEL_ID = 367568;
|
|
|
11
10
|
const FRILL_SCRIPT_URL = 'https://widget.frill.co/v2/container.js';
|
|
12
11
|
const FRILL_KEY = '2f77f232-a120-438e-8ef6-01912ffd1b99';
|
|
13
12
|
|
|
14
|
-
const EXCLUDED_ROUTES = [
|
|
15
|
-
'/login',
|
|
16
|
-
'/forgot-password',
|
|
17
|
-
'/register',
|
|
18
|
-
];
|
|
19
|
-
|
|
20
13
|
const SURVEYS = [{ key: '7f59dbf6-b665-458a-80e2-778de47efe1c' }];
|
|
21
14
|
const WIDGETS = [
|
|
22
15
|
{ key: '4a5ba13b-1150-49fe-aa15-f9a2da0ba909' },
|
|
@@ -63,18 +56,16 @@ function loadFrillScript() {
|
|
|
63
56
|
}
|
|
64
57
|
|
|
65
58
|
export function FrillEmbed() {
|
|
66
|
-
const pathname = usePathname();
|
|
67
59
|
const { user } = useAuth();
|
|
68
60
|
const { whitelabel } = useWhitelabel();
|
|
69
61
|
const { data: subscriptionData } = useActiveSubscription();
|
|
70
62
|
const containerRef = useRef<any>(null);
|
|
71
63
|
|
|
72
64
|
const subscription = subscriptionData?.data?.[0] ?? null;
|
|
73
|
-
const isExcluded = EXCLUDED_ROUTES.some((route) => pathname.startsWith(route));
|
|
74
65
|
const isV4 = whitelabel?.id === V4_WHITELABEL_ID;
|
|
75
66
|
|
|
76
67
|
useEffect(() => {
|
|
77
|
-
if (
|
|
68
|
+
if (!user) return;
|
|
78
69
|
|
|
79
70
|
initFrillLoader();
|
|
80
71
|
|
|
@@ -100,15 +91,19 @@ export function FrillEmbed() {
|
|
|
100
91
|
}
|
|
101
92
|
|
|
102
93
|
const win = window as any;
|
|
103
|
-
|
|
94
|
+
const containerPromise = win.Frill('container', config);
|
|
104
95
|
win.Frill('identify', userData);
|
|
105
96
|
|
|
97
|
+
containerPromise.then((widget: any) => {
|
|
98
|
+
containerRef.current = widget;
|
|
99
|
+
}).catch(() => {});
|
|
100
|
+
|
|
106
101
|
return () => {
|
|
107
102
|
containerRef.current?.destroy();
|
|
108
103
|
containerRef.current = null;
|
|
109
104
|
document.removeEventListener('DOMContentLoaded', loadFrillScript);
|
|
110
105
|
};
|
|
111
|
-
}, [user,
|
|
106
|
+
}, [user, isV4, subscription?.plan_name]);
|
|
112
107
|
|
|
113
108
|
return null;
|
|
114
109
|
}
|