@greatapps/common 1.1.194 → 1.1.196
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 +16 -9
- package/dist/components/embeds/CrispEmbed.mjs.map +1 -1
- package/dist/components/embeds/FrillEmbed.mjs +11 -5
- package/dist/components/embeds/FrillEmbed.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/embeds/CrispEmbed.tsx +19 -9
- package/src/components/embeds/FrillEmbed.tsx +14 -8
|
@@ -24,6 +24,11 @@ function CrispEmbed() {
|
|
|
24
24
|
const win = window;
|
|
25
25
|
win.$crisp = [];
|
|
26
26
|
win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
|
|
27
|
+
win.CRISP_RUNTIME_CONFIG = {
|
|
28
|
+
lock: {
|
|
29
|
+
"container-index": 498
|
|
30
|
+
}
|
|
31
|
+
};
|
|
27
32
|
const timeout = setTimeout(() => {
|
|
28
33
|
if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
|
|
29
34
|
const s = document.createElement("script");
|
|
@@ -37,11 +42,13 @@ function CrispEmbed() {
|
|
|
37
42
|
useEffect(() => {
|
|
38
43
|
const $crisp = window.$crisp;
|
|
39
44
|
if (!user || !$crisp) return;
|
|
40
|
-
$crisp.push(["set", "user:email", user.email]);
|
|
41
|
-
|
|
42
|
-
$crisp.push(["set", "user:
|
|
43
|
-
$crisp.push(["set", "user:
|
|
44
|
-
|
|
45
|
+
if (user.email) $crisp.push(["set", "user:email", user.email]);
|
|
46
|
+
const fullName = `${user.name ?? ""} ${user.last_name ?? ""}`.trim();
|
|
47
|
+
if (fullName) $crisp.push(["set", "user:nickname", fullName]);
|
|
48
|
+
if (account?.name) $crisp.push(["set", "user:company", account.name]);
|
|
49
|
+
const phone = `${user.ddi ?? ""}${user.phone ?? ""}`.trim();
|
|
50
|
+
if (phone) $crisp.push(["set", "user:phone", phone]);
|
|
51
|
+
if (user.photo && user.photo.startsWith("http")) {
|
|
45
52
|
$crisp.push(["set", "user:avatar", user.photo]);
|
|
46
53
|
}
|
|
47
54
|
if (isV4) {
|
|
@@ -49,10 +56,10 @@ function CrispEmbed() {
|
|
|
49
56
|
$crisp.push(["set", "session:data", [[["Company", "V4"]]]]);
|
|
50
57
|
} else {
|
|
51
58
|
const planName = subscription?.plan_name ?? "";
|
|
52
|
-
$crisp.push(["set", "session:segments", [[`plano_${planName}`]]]);
|
|
53
|
-
$crisp.push(["set", "session:segments", [[`usuario_${user.profile}`]]]);
|
|
54
|
-
$crisp.push(["set", "session:data", [[["Plano", planName]]]]);
|
|
55
|
-
$crisp.push(["set", "session:data", [[["Usuario", user.profile]]]]);
|
|
59
|
+
if (planName) $crisp.push(["set", "session:segments", [[`plano_${planName}`]]]);
|
|
60
|
+
if (user.profile) $crisp.push(["set", "session:segments", [[`usuario_${user.profile}`]]]);
|
|
61
|
+
if (planName) $crisp.push(["set", "session:data", [[["Plano", planName]]]]);
|
|
62
|
+
if (user.profile) $crisp.push(["set", "session:data", [[["Usuario", user.profile]]]]);
|
|
56
63
|
}
|
|
57
64
|
}, [user, account, isV4, subscription?.plan_name]);
|
|
58
65
|
return null;
|
|
@@ -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
|
|
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 win.CRISP_RUNTIME_CONFIG = {\n lock: {\n 'container-index': 498,\n },\n };\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 if (user.email) $crisp.push(['set', 'user:email', user.email]);\n\n const fullName = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();\n if (fullName) $crisp.push(['set', 'user:nickname', fullName]);\n\n if (account?.name) $crisp.push(['set', 'user:company', account.name]);\n\n const phone = `${user.ddi ?? ''}${user.phone ?? ''}`.trim();\n if (phone) $crisp.push(['set', 'user:phone', phone]);\n\n if (user.photo && user.photo.startsWith('http')) {\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 if (planName) $crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);\n if (user.profile) $crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);\n if (planName) $crisp.push(['set', 'session:data', [[['Plano', planName]]]]);\n if (user.profile) $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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.addEventListener("DOMContentLoaded", loadFrillScript);
|
|
63
63
|
}
|
|
64
64
|
const userData = {
|
|
65
|
-
id: String(user.id)
|
|
66
|
-
email: user.email,
|
|
67
|
-
name: `${user.name} ${user.last_name}`.trim(),
|
|
68
|
-
attributes: isV4 ? { company: "V4" } : { profile: user.profile, plan: subscription?.plan_name ?? "" }
|
|
65
|
+
id: String(user.id ?? "")
|
|
69
66
|
};
|
|
67
|
+
if (user.email) userData.email = user.email;
|
|
68
|
+
if (user.name || user.last_name) {
|
|
69
|
+
userData.name = `${user.name ?? ""} ${user.last_name ?? ""}`.trim();
|
|
70
|
+
}
|
|
71
|
+
userData.attributes = isV4 ? { company: "V4" } : { profile: user.profile ?? "", plan: subscription?.plan_name ?? "" };
|
|
70
72
|
const config = { key: FRILL_KEY, user: userData };
|
|
71
73
|
if (!isV4) {
|
|
72
74
|
config.surveys = SURVEYS;
|
|
73
75
|
config.widgets = WIDGETS;
|
|
74
76
|
}
|
|
75
77
|
const win = window;
|
|
76
|
-
|
|
78
|
+
const containerPromise = win.Frill("container", config);
|
|
77
79
|
win.Frill("identify", userData);
|
|
80
|
+
containerPromise.then((widget) => {
|
|
81
|
+
containerRef.current = widget;
|
|
82
|
+
}).catch(() => {
|
|
83
|
+
});
|
|
78
84
|
return () => {
|
|
79
85
|
containerRef.current?.destroy();
|
|
80
86
|
containerRef.current = null;
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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: Record<string, any> = {\n id: String(user.id ?? ''),\n };\n if (user.email) userData.email = user.email;\n if (user.name || user.last_name) {\n userData.name = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();\n }\n userData.attributes = isV4\n ? { company: 'V4' }\n : { profile: user.profile ?? '', plan: subscription?.plan_name ?? '' };\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,uCAAuC,CAAC;AAChE,MAAM,UAAU;AAAA,EACd,EAAE,KAAK,uCAAuC;AAAA,EAC9C,EAAE,KAAK,uCAAuC;AAChD;AAEA,SAAS,kBAAkB;AACzB,QAAM,MAAM;AACZ,MAAI,IAAI,MAAO;AAEf,MAAI,UAAU;AACd,QAAM,QAA6B,CAAC;AAEpC,MAAI,QAAQ,SAAU,QAAgB,QAAa;AACjD,QAAI;AACJ,UAAM,KAAK;AACX,UAAM,UAAe,IAAI,QAAQ,CAAC,SAAS,WAAW;AACpD,YAAM,EAAE,IAAI;AAAA,QACV,QAAQ,CAAC,QAAQ,MAAM;AAAA,QACvB,SAAS,CAAC,MAAW;AACnB,qBAAW;AACX,kBAAQ,CAAC;AAAA,QACX;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AACD,YAAQ,UAAU,MAAM;AACtB,aAAO,MAAM,EAAE;AACf,gBAAU,QAAQ;AAAA,IACpB;AACA,WAAO;AAAA,EACT;AACA,MAAI,MAAM,IAAI;AAChB;AAEA,SAAS,kBAAkB;AACzB,MAAI,SAAS,cAAc,eAAe,gBAAgB,IAAI,EAAG;AACjE,QAAM,SAAS,SAAS,qBAAqB,QAAQ,EA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A,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
|
@@ -33,6 +33,11 @@ export function CrispEmbed() {
|
|
|
33
33
|
const win = window as any;
|
|
34
34
|
win.$crisp = [];
|
|
35
35
|
win.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
|
|
36
|
+
win.CRISP_RUNTIME_CONFIG = {
|
|
37
|
+
lock: {
|
|
38
|
+
'container-index': 498,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
36
41
|
|
|
37
42
|
const timeout = setTimeout(() => {
|
|
38
43
|
if (document.querySelector(`script[src="${CRISP_SCRIPT_URL}"]`)) return;
|
|
@@ -51,12 +56,17 @@ export function CrispEmbed() {
|
|
|
51
56
|
const $crisp = (window as any).$crisp;
|
|
52
57
|
if (!user || !$crisp) return;
|
|
53
58
|
|
|
54
|
-
$crisp.push(['set', 'user:email', user.email]);
|
|
55
|
-
$crisp.push(['set', 'user:nickname', `${user.name} ${user.last_name}`.trim()]);
|
|
56
|
-
$crisp.push(['set', 'user:company', account?.name ?? '']);
|
|
57
|
-
$crisp.push(['set', 'user:phone', `${user.ddi}${user.phone}`]);
|
|
59
|
+
if (user.email) $crisp.push(['set', 'user:email', user.email]);
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
const fullName = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();
|
|
62
|
+
if (fullName) $crisp.push(['set', 'user:nickname', fullName]);
|
|
63
|
+
|
|
64
|
+
if (account?.name) $crisp.push(['set', 'user:company', account.name]);
|
|
65
|
+
|
|
66
|
+
const phone = `${user.ddi ?? ''}${user.phone ?? ''}`.trim();
|
|
67
|
+
if (phone) $crisp.push(['set', 'user:phone', phone]);
|
|
68
|
+
|
|
69
|
+
if (user.photo && user.photo.startsWith('http')) {
|
|
60
70
|
$crisp.push(['set', 'user:avatar', user.photo]);
|
|
61
71
|
}
|
|
62
72
|
|
|
@@ -65,10 +75,10 @@ export function CrispEmbed() {
|
|
|
65
75
|
$crisp.push(['set', 'session:data', [[['Company', 'V4']]]]);
|
|
66
76
|
} else {
|
|
67
77
|
const planName = subscription?.plan_name ?? '';
|
|
68
|
-
$crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);
|
|
69
|
-
$crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);
|
|
70
|
-
$crisp.push(['set', 'session:data', [[['Plano', planName]]]]);
|
|
71
|
-
$crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);
|
|
78
|
+
if (planName) $crisp.push(['set', 'session:segments', [[`plano_${planName}`]]]);
|
|
79
|
+
if (user.profile) $crisp.push(['set', 'session:segments', [[`usuario_${user.profile}`]]]);
|
|
80
|
+
if (planName) $crisp.push(['set', 'session:data', [[['Plano', planName]]]]);
|
|
81
|
+
if (user.profile) $crisp.push(['set', 'session:data', [[['Usuario', user.profile]]]]);
|
|
72
82
|
}
|
|
73
83
|
}, [user, account, isV4, subscription?.plan_name]);
|
|
74
84
|
|
|
@@ -75,14 +75,16 @@ export function FrillEmbed() {
|
|
|
75
75
|
document.addEventListener('DOMContentLoaded', loadFrillScript);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
const userData = {
|
|
79
|
-
id: String(user.id),
|
|
80
|
-
email: user.email,
|
|
81
|
-
name: `${user.name} ${user.last_name}`.trim(),
|
|
82
|
-
attributes: isV4
|
|
83
|
-
? { company: 'V4' }
|
|
84
|
-
: { profile: user.profile, plan: subscription?.plan_name ?? '' },
|
|
78
|
+
const userData: Record<string, any> = {
|
|
79
|
+
id: String(user.id ?? ''),
|
|
85
80
|
};
|
|
81
|
+
if (user.email) userData.email = user.email;
|
|
82
|
+
if (user.name || user.last_name) {
|
|
83
|
+
userData.name = `${user.name ?? ''} ${user.last_name ?? ''}`.trim();
|
|
84
|
+
}
|
|
85
|
+
userData.attributes = isV4
|
|
86
|
+
? { company: 'V4' }
|
|
87
|
+
: { profile: user.profile ?? '', plan: subscription?.plan_name ?? '' };
|
|
86
88
|
|
|
87
89
|
const config: Record<string, any> = { key: FRILL_KEY, user: userData };
|
|
88
90
|
if (!isV4) {
|
|
@@ -91,9 +93,13 @@ export function FrillEmbed() {
|
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
const win = window as any;
|
|
94
|
-
|
|
96
|
+
const containerPromise = win.Frill('container', config);
|
|
95
97
|
win.Frill('identify', userData);
|
|
96
98
|
|
|
99
|
+
containerPromise.then((widget: any) => {
|
|
100
|
+
containerRef.current = widget;
|
|
101
|
+
}).catch(() => {});
|
|
102
|
+
|
|
97
103
|
return () => {
|
|
98
104
|
containerRef.current?.destroy();
|
|
99
105
|
containerRef.current = null;
|