@telia-ace/knowledge-widget-bot-provider 0.0.18-next.1 → 0.0.18-next.3
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/contact-method-list.369194cf.js +127 -0
- package/dist/contact-method-list.369194cf.js.map +1 -0
- package/dist/contact-method.49203d93.js +132 -0
- package/dist/{contact-method.6ba724b7.js.map → contact-method.49203d93.js.map} +1 -1
- package/dist/{index.9c7696ef.js → index.94fbbd75.js} +112 -109
- package/dist/index.94fbbd75.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/utils.d.ts +2 -2
- package/package.json +5 -5
- package/dist/contact-method-list.0f9b85c9.js +0 -124
- package/dist/contact-method-list.0f9b85c9.js.map +0 -1
- package/dist/contact-method.6ba724b7.js +0 -131
- package/dist/index.9c7696ef.js.map +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var k = Object.defineProperty, z = Object.defineProperties;
|
|
2
|
+
var I = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var x = Object.getOwnPropertySymbols;
|
|
4
|
+
var L = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var M = (t, e, n) => e in t ? k(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, l = (t, e) => {
|
|
6
|
+
for (var n in e || (e = {}))
|
|
7
|
+
L.call(e, n) && M(t, n, e[n]);
|
|
8
|
+
if (x)
|
|
9
|
+
for (var n of x(e))
|
|
10
|
+
j.call(e, n) && M(t, n, e[n]);
|
|
11
|
+
return t;
|
|
12
|
+
}, E = (t, e) => z(t, I(e));
|
|
13
|
+
var $ = (t, e, n) => new Promise((p, s) => {
|
|
14
|
+
var m = (o) => {
|
|
15
|
+
try {
|
|
16
|
+
r(n.next(o));
|
|
17
|
+
} catch (i) {
|
|
18
|
+
s(i);
|
|
19
|
+
}
|
|
20
|
+
}, u = (o) => {
|
|
21
|
+
try {
|
|
22
|
+
r(n.throw(o));
|
|
23
|
+
} catch (i) {
|
|
24
|
+
s(i);
|
|
25
|
+
}
|
|
26
|
+
}, r = (o) => o.done ? p(o.value) : Promise.resolve(o.value).then(m, u);
|
|
27
|
+
r((n = n.apply(t, e)).next());
|
|
28
|
+
});
|
|
29
|
+
import y from "@emotion/styled";
|
|
30
|
+
import { ContactList as v, ContactMethod as w } from "@telia-ace/knowledge-widget-adapters";
|
|
31
|
+
import { useDispatch as A, useContainer as K } from "@telia-ace/knowledge-widget-ui";
|
|
32
|
+
import h, { useState as b, useEffect as P } from "react";
|
|
33
|
+
import R from "./contact-method.49203d93.js";
|
|
34
|
+
import "@telia-ace/knowledge-data-client";
|
|
35
|
+
import "@telia-ace/widget-forms";
|
|
36
|
+
import "./index.94fbbd75.js";
|
|
37
|
+
import "@telia-ace/widget-conversation";
|
|
38
|
+
import "@telia-ace/widget-services";
|
|
39
|
+
import "@telia-ace/widget-utilities";
|
|
40
|
+
const Y = ({ actions: t, entryId: e, groupId: n }) => {
|
|
41
|
+
const p = A(), s = K(), [m, u] = b([]), [r, o] = b([]);
|
|
42
|
+
return P(() => {
|
|
43
|
+
s.getAsync("contactMethods").then((i) => {
|
|
44
|
+
if (!i)
|
|
45
|
+
return;
|
|
46
|
+
const f = t.map((d) => $(void 0, null, function* () {
|
|
47
|
+
var g;
|
|
48
|
+
if (!((g = d.data) != null && g.clientName))
|
|
49
|
+
return null;
|
|
50
|
+
const c = yield i.handleAdapters(d.data);
|
|
51
|
+
return E(l(l({}, c), d.data), {
|
|
52
|
+
description: d.data.description ? d.data.description : c.description,
|
|
53
|
+
onClick: (C, a) => {
|
|
54
|
+
if (typeof c.onClick == "function" && c.onClick(C, a), !C.defaultPrevented)
|
|
55
|
+
if (a.inline && !a.expanded)
|
|
56
|
+
o([...r, a.id]);
|
|
57
|
+
else {
|
|
58
|
+
const { events: S } = s.get("$widget");
|
|
59
|
+
S.dispatch("provider:open-contact-method", {
|
|
60
|
+
entryId: e,
|
|
61
|
+
contactMethod: a,
|
|
62
|
+
actionKey: d.actionKey
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}));
|
|
68
|
+
Promise.all(f).then((d) => {
|
|
69
|
+
u(d.filter((c) => !!c));
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}, [t, s, e, r]), m.length ? /* @__PURE__ */ h.createElement(
|
|
73
|
+
D,
|
|
74
|
+
{
|
|
75
|
+
contactMethods: m,
|
|
76
|
+
dispatch: p,
|
|
77
|
+
itemRenderer: (i, f) => (r.includes(i.id) || i.expanded) && i.inline ? /* @__PURE__ */ h.createElement(
|
|
78
|
+
G,
|
|
79
|
+
{
|
|
80
|
+
contactMethodId: i.id,
|
|
81
|
+
groupId: n,
|
|
82
|
+
guideId: i.body.guideId
|
|
83
|
+
}
|
|
84
|
+
) : /* @__PURE__ */ h.createElement(N, l(l({}, i), f))
|
|
85
|
+
}
|
|
86
|
+
) : null;
|
|
87
|
+
}, D = y(v)`
|
|
88
|
+
> ul > li {
|
|
89
|
+
a {
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
outline-offset: -2px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&:not(:last-child) {
|
|
96
|
+
${(t) => t.theme.border && `border-bottom: ${t.theme.border};`}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
`, G = y(R)`
|
|
100
|
+
i {
|
|
101
|
+
margin: 0 ${(t) => {
|
|
102
|
+
var e;
|
|
103
|
+
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
104
|
+
}} 0 0;
|
|
105
|
+
display: flex;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
align-items: center;
|
|
108
|
+
}
|
|
109
|
+
`, N = y(w)`
|
|
110
|
+
padding: ${(t) => {
|
|
111
|
+
var e;
|
|
112
|
+
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
113
|
+
}};
|
|
114
|
+
i {
|
|
115
|
+
margin: 0 ${(t) => {
|
|
116
|
+
var e;
|
|
117
|
+
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
118
|
+
}} 0 0;
|
|
119
|
+
display: flex;
|
|
120
|
+
justify-content: center;
|
|
121
|
+
align-items: center;
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
export {
|
|
125
|
+
Y as default
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=contact-method-list.369194cf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contact-method-list.369194cf.js","sources":["../src/ui/contact-method-list.tsx"],"sourcesContent":["import styled from '@emotion/styled';\nimport {\n ContactList,\n ContactMethod as GenericContactMethod,\n ContactMethodType,\n} from '@telia-ace/knowledge-widget-adapters';\nimport { useContainer, useDispatch } from '@telia-ace/knowledge-widget-ui';\nimport React, { useEffect, useState } from 'react';\nimport { ActionItem } from '../types';\nimport ContactMethod from './contact-method';\n\ntype Props = {\n actions: ActionItem[];\n contactMethodIds?: string[];\n entryId: string;\n groupId: string;\n};\nconst ContactMethodList: React.FC<Props> = ({ actions, entryId, groupId }) => {\n const dispatch = useDispatch();\n const container = useContainer();\n const [items, setItems] = useState<any[]>([]);\n const [expanded, setExpanded] = useState<string[]>([]);\n\n useEffect(() => {\n container.getAsync('contactMethods').then((platform: any) => {\n if (!platform) {\n return;\n }\n const promises = actions.map(async (action) => {\n if (!action.data?.clientName) {\n return null;\n }\n const cm = await platform.handleAdapters(action.data);\n\n return {\n ...cm,\n ...action.data,\n description: action.data.description ? action.data.description : cm.description,\n onClick: (event: React.MouseEvent, data: ContactMethodType) => {\n if (typeof cm.onClick === 'function') {\n cm.onClick(event, data);\n }\n\n if (event.defaultPrevented) {\n return;\n }\n if (data.inline && !data.expanded) {\n setExpanded([...expanded, data.id]);\n } else {\n const { events } = container.get('$widget');\n events.dispatch('provider:open-contact-method', {\n entryId,\n contactMethod: data,\n actionKey: action.actionKey,\n });\n }\n },\n };\n });\n\n Promise.all(promises).then((result) => {\n setItems(result.filter((i) => !!i));\n });\n });\n }, [actions, container, entryId, expanded]);\n\n if (!items.length) {\n return null;\n }\n\n return (\n <StyledContactList\n contactMethods={items}\n dispatch={dispatch}\n itemRenderer={(cm: any, props: any) => {\n const isExpanded = expanded.includes(cm.id) || cm.expanded;\n if (isExpanded && cm.inline) {\n return (\n <StyledContactMethod\n contactMethodId={cm.id}\n groupId={groupId}\n guideId={cm.body.guideId}\n />\n );\n }\n return <StyledGenericContactMethod {...cm} {...props} />;\n }}\n />\n );\n};\n\nexport default ContactMethodList;\n\nconst StyledContactList = styled(ContactList)`\n > ul > li {\n a {\n display: flex;\n align-items: center;\n outline-offset: -2px;\n }\n\n &:not(:last-child) {\n ${(p) => p.theme.border && `border-bottom: ${p.theme.border};`}\n }\n }\n`;\n\nconst StyledContactMethod = styled(ContactMethod)`\n i {\n margin: 0 ${(p) => p.theme.sizes?.medium} 0 0;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n`;\nconst StyledGenericContactMethod = styled(GenericContactMethod)`\n padding: ${(p) => p.theme.sizes?.medium};\n i {\n margin: 0 ${(p) => p.theme.sizes?.medium} 0 0;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n`;\n"],"names":["ContactMethodList","actions","entryId","groupId","dispatch","useDispatch","container","useContainer","items","setItems","useState","expanded","setExpanded","useEffect","platform","promises","action","__async","_a","cm","__spreadProps","__spreadValues","event","data","events","result","i","React","StyledContactList","props","StyledContactMethod","StyledGenericContactMethod","styled","ContactList","p","ContactMethod","GenericContactMethod"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,IAAqC,CAAC,EAAE,SAAAC,GAAS,SAAAC,GAAS,SAAAC,QAAc;AAC1E,QAAMC,IAAWC,KACXC,IAAYC,KACZ,CAACC,GAAOC,CAAQ,IAAIC,EAAgB,CAAE,CAAA,GACtC,CAACC,GAAUC,CAAW,IAAIF,EAAmB,CAAE,C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,EAAG,EAAE,KAAKA,EAAG,aAChCA,EAAG,SAEb,gBAAAQ,EAAA;AAAA,QAACG;AAAA,QAAA;AAAA,UACG,iBAAiBX,EAAG;AAAA,UACpB,SAAAhB;AAAA,UACA,SAASgB,EAAG,KAAK;AAAA,QAAA;AAAA,MAAA,IAIrB,gBAAAQ,EAAA,cAAAI,GAAAV,IAAA,IAA+BF,IAAQU,EAAO;AAAA,IAC1D;AAAA,EAAA,IAnBG;AAsBf,GAIMD,IAAoBI,EAAOC,CAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAS9B,CAACC,MAAMA,EAAE,MAAM,UAAU,kBAAkBA,EAAE,MAAM;AAAA;AAAA;AAAA,GAK3DJ,IAAsBE,EAAOG,CAAa;AAAA;AAAA,oBAE5B,CAACD,MAAM;;AAAA,UAAAhB,IAAAgB,EAAE,MAAM,UAAR,gBAAAhB,EAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAMpCa,IAA6BC,EAAOI,CAAoB;AAAA,eAC/C,CAACF,MAAM;;AAAA,UAAAhB,IAAAgB,EAAE,MAAM,UAAR,gBAAAhB,EAAe;AAAA;AAAA;AAAA,oBAEjB,CAACgB,MAAM;;AAAA,UAAAhB,IAAAgB,EAAE,MAAM,UAAR,gBAAAhB,EAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var T = Object.defineProperty, _ = Object.defineProperties;
|
|
2
|
+
var k = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var R = Object.getOwnPropertySymbols;
|
|
4
|
+
var G = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var x = (e, t, r) => t in e ? T(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, a = (e, t) => {
|
|
6
|
+
for (var r in t || (t = {}))
|
|
7
|
+
G.call(t, r) && x(e, r, t[r]);
|
|
8
|
+
if (R)
|
|
9
|
+
for (var r of R(t))
|
|
10
|
+
I.call(t, r) && x(e, r, t[r]);
|
|
11
|
+
return e;
|
|
12
|
+
}, s = (e, t) => _(e, k(t));
|
|
13
|
+
var p = (e, t, r) => new Promise((h, o) => {
|
|
14
|
+
var d = (n) => {
|
|
15
|
+
try {
|
|
16
|
+
y(r.next(n));
|
|
17
|
+
} catch (u) {
|
|
18
|
+
o(u);
|
|
19
|
+
}
|
|
20
|
+
}, c = (n) => {
|
|
21
|
+
try {
|
|
22
|
+
y(r.throw(n));
|
|
23
|
+
} catch (u) {
|
|
24
|
+
o(u);
|
|
25
|
+
}
|
|
26
|
+
}, y = (n) => n.done ? h(n.value) : Promise.resolve(n.value).then(d, c);
|
|
27
|
+
y((r = r.apply(e, t)).next());
|
|
28
|
+
});
|
|
29
|
+
import V from "@emotion/styled";
|
|
30
|
+
import { DataClient as j, DataType as q } from "@telia-ace/knowledge-data-client";
|
|
31
|
+
import { ContactMethod as H } from "@telia-ace/knowledge-widget-adapters";
|
|
32
|
+
import { useContainer as J, useDispatch as K, useConversation as L } from "@telia-ace/knowledge-widget-ui";
|
|
33
|
+
import { FormBuilder as N } from "@telia-ace/widget-forms";
|
|
34
|
+
import O, { useState as P, useRef as Q, useEffect as z, useCallback as U } from "react";
|
|
35
|
+
import { u as A } from "./index.94fbbd75.js";
|
|
36
|
+
import "@telia-ace/widget-conversation";
|
|
37
|
+
import "@telia-ace/widget-services";
|
|
38
|
+
import "@telia-ace/widget-utilities";
|
|
39
|
+
const mt = ({ contactMethodId: e, guideId: t, groupId: r, className: h }) => {
|
|
40
|
+
var g, E, S;
|
|
41
|
+
const [o, d] = P(), c = J(), y = K(), n = Q(!0), u = L();
|
|
42
|
+
z(() => {
|
|
43
|
+
const { events: l } = c.get("$widget"), $ = l.subscribe("bot-provider:form-submitted", (C, m) => p(void 0, null, function* () {
|
|
44
|
+
var D;
|
|
45
|
+
if (((D = m.form.meta) == null ? void 0 : D.groupId) !== r || m.id !== o.id)
|
|
46
|
+
return;
|
|
47
|
+
u && (m.form.meta || (m.form.meta = {}), m.form.meta.conversation = u);
|
|
48
|
+
const v = yield c.getAsync("contactMethods"), i = s(a({}, o), {
|
|
49
|
+
body: s(a({}, o.body), {
|
|
50
|
+
form: m.form
|
|
51
|
+
})
|
|
52
|
+
}), { errors: b, valid: M, errorTypes: X } = yield v.validate(i);
|
|
53
|
+
if (!M) {
|
|
54
|
+
const F = new N(o.body.form);
|
|
55
|
+
d(void 0), F.setValidationErrors(b), i.body = s(a({}, i.body), {
|
|
56
|
+
form: F.get()
|
|
57
|
+
}), d(a({}, i));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const B = yield v.submit(i);
|
|
61
|
+
i.confirmation = B, d(i);
|
|
62
|
+
})), f = l.subscribe("bot-provider:evaluate", (C, m) => p(void 0, null, function* () {
|
|
63
|
+
if (m.id != e)
|
|
64
|
+
return;
|
|
65
|
+
const i = yield (yield c.getAsync("contactMethods")).evaluate(o);
|
|
66
|
+
let b = s(a({}, o), {
|
|
67
|
+
body: s(a({}, o.body), {
|
|
68
|
+
form: i
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
const M = A(b, {
|
|
72
|
+
submit: "Submit",
|
|
73
|
+
errors: {},
|
|
74
|
+
meta: { groupId: r }
|
|
75
|
+
});
|
|
76
|
+
b = s(a({}, b), {
|
|
77
|
+
body: M
|
|
78
|
+
}), d(b);
|
|
79
|
+
}));
|
|
80
|
+
return () => {
|
|
81
|
+
$(), f();
|
|
82
|
+
};
|
|
83
|
+
}, [c, o, d, u]);
|
|
84
|
+
const w = U(
|
|
85
|
+
(l) => p(void 0, null, function* () {
|
|
86
|
+
const f = yield (yield j.getInstance(c)).fetch(q.ContactMethod, {
|
|
87
|
+
contactMethodId: l,
|
|
88
|
+
guideId: t
|
|
89
|
+
}), C = A(f, {
|
|
90
|
+
submit: "Submit",
|
|
91
|
+
errors: {},
|
|
92
|
+
meta: { groupId: r }
|
|
93
|
+
});
|
|
94
|
+
if (f.body = C, f.body.guideId = t, !n.current)
|
|
95
|
+
return null;
|
|
96
|
+
d(f);
|
|
97
|
+
}),
|
|
98
|
+
[n]
|
|
99
|
+
);
|
|
100
|
+
return z(() => (w(e), () => {
|
|
101
|
+
n.current = !1;
|
|
102
|
+
}), [e, w]), o ? /* @__PURE__ */ O.createElement(
|
|
103
|
+
W,
|
|
104
|
+
s(a({}, o), {
|
|
105
|
+
body: s(a({}, o.body), {
|
|
106
|
+
form: o.body.form ? s(a({}, o.body.form), {
|
|
107
|
+
data: (g = o.body.form) == null ? void 0 : g.data,
|
|
108
|
+
layout: a({}, o.body.form.layout),
|
|
109
|
+
meta: (E = o.body.form) == null ? void 0 : E.meta,
|
|
110
|
+
schema: (S = o.body.form) == null ? void 0 : S.schema
|
|
111
|
+
}) : void 0,
|
|
112
|
+
guideId: o.body.guideId
|
|
113
|
+
}),
|
|
114
|
+
inline: !0,
|
|
115
|
+
expanded: !0,
|
|
116
|
+
dispatch: y,
|
|
117
|
+
className: h
|
|
118
|
+
})
|
|
119
|
+
) : null;
|
|
120
|
+
}, W = V(H)`
|
|
121
|
+
padding: ${(e) => {
|
|
122
|
+
var t;
|
|
123
|
+
return (t = e.theme.sizes) == null ? void 0 : t.normal;
|
|
124
|
+
}} ${(e) => {
|
|
125
|
+
var t;
|
|
126
|
+
return (t = e.theme.sizes) == null ? void 0 : t.medium;
|
|
127
|
+
}};
|
|
128
|
+
`;
|
|
129
|
+
export {
|
|
130
|
+
mt as default
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=contact-method.49203d93.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contact-method.
|
|
1
|
+
{"version":3,"file":"contact-method.49203d93.js","sources":["../src/ui/contact-method.tsx"],"sourcesContent":["import styled from '@emotion/styled';\nimport { DataClient, DataType } from '@telia-ace/knowledge-data-client';\nimport {\n ContactMethod as GenericContactMethod,\n ContactMethodPlatform,\n} from '@telia-ace/knowledge-widget-adapters';\nimport { useContainer, useConversation, useDispatch } from '@telia-ace/knowledge-widget-ui';\nimport { FormBuilder } from '@telia-ace/widget-forms';\nimport { Widget } from '@webprovisions/platform';\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { updateForm } from '../utils';\n\ntype Props = {\n contactMethodId: string;\n groupId: string;\n guideId?: string;\n className?: string;\n};\nconst ContactMethod: React.FC<Props> = ({ contactMethodId, guideId, groupId, className }) => {\n const [contactMethod, setContactMethod] = useState<any>();\n const container = useContainer();\n const dispatch = useDispatch();\n const mountedRef = useRef<boolean>(true);\n const currentConversation = useConversation();\n\n useEffect(() => {\n const { events } = container.get('$widget') as Widget;\n\n const unsubscribe = events.subscribe('bot-provider:form-submitted', async (_, data) => {\n // making sure that this is the form that is submitted\n if (data.form.meta?.groupId !== groupId || data.id !== contactMethod.id) {\n return;\n }\n\n if (currentConversation) {\n if (!data.form.meta) {\n data.form.meta = {};\n }\n\n data.form.meta.conversation = currentConversation;\n }\n\n const platform = (await container.getAsync('contactMethods')) as ContactMethodPlatform;\n\n const updatedMethod = {\n ...contactMethod,\n body: {\n ...contactMethod.body,\n form: data.form,\n },\n };\n\n const { errors, valid, errorTypes } = await platform.validate(updatedMethod);\n\n if (!valid) {\n const builder = new FormBuilder(contactMethod.body.form);\n setContactMethod(undefined);\n\n builder.setValidationErrors(errors);\n\n updatedMethod.body = {\n ...updatedMethod.body,\n form: builder.get(),\n };\n\n setContactMethod({ ...updatedMethod });\n return;\n }\n\n const result = await platform.submit(updatedMethod);\n\n updatedMethod.confirmation = result;\n setContactMethod(updatedMethod);\n });\n\n const unsubscribeEvaluate = events.subscribe('bot-provider:evaluate', async (_, data) => {\n if (data.id != contactMethodId) {\n return;\n }\n\n const platform = (await container.getAsync('contactMethods')) as ContactMethodPlatform;\n\n const updatedForm = await platform.evaluate(contactMethod);\n\n let updatedMethod = {\n ...contactMethod,\n body: {\n ...contactMethod.body,\n form: updatedForm,\n },\n };\n\n const updatedBody = updateForm(updatedMethod, {\n submit: 'Submit',\n errors: {},\n meta: { groupId },\n });\n\n updatedMethod = {\n ...updatedMethod,\n body: updatedBody,\n };\n\n setContactMethod(updatedMethod);\n });\n\n return () => {\n unsubscribe();\n unsubscribeEvaluate();\n };\n }, [container, contactMethod, setContactMethod, currentConversation]);\n\n const fetchContactMethod = useCallback(\n async (id: string) => {\n const dataClient = await DataClient.getInstance(container);\n\n const cm = await dataClient.fetch(DataType.ContactMethod, {\n contactMethodId: id,\n guideId,\n });\n\n const body = updateForm(cm, {\n submit: 'Submit',\n errors: {},\n meta: { groupId },\n });\n cm.body = body;\n cm.body.guideId = guideId;\n\n if (!mountedRef.current) {\n return null;\n }\n setContactMethod(cm);\n },\n [mountedRef]\n );\n\n useEffect(() => {\n fetchContactMethod(contactMethodId);\n return () => {\n mountedRef.current = false; // clean up\n };\n }, [contactMethodId, fetchContactMethod]);\n\n if (!contactMethod) {\n return null;\n }\n return (\n <StyledGenericContactMethod\n {...contactMethod}\n body={{\n ...contactMethod.body,\n form: contactMethod.body.form\n ? {\n ...contactMethod.body.form,\n data: contactMethod.body.form?.data,\n layout: { ...contactMethod.body.form.layout },\n meta: contactMethod.body.form?.meta,\n schema: contactMethod.body.form?.schema,\n }\n : undefined,\n guideId: contactMethod.body.guideId,\n }}\n inline={true}\n expanded={true}\n dispatch={dispatch}\n className={className}\n />\n );\n};\n\nexport default ContactMethod;\n\nconst StyledGenericContactMethod = styled(GenericContactMethod)`\n padding: ${(p) => p.theme.sizes?.normal} ${(p) => p.theme.sizes?.medium};\n`;\n"],"names":["ContactMethod","contactMethodId","guideId","groupId","className","contactMethod","setContactMethod","useState","container","useContainer","dispatch","useDispatch","mountedRef","useRef","currentConversation","useConversation","useEffect","events","unsubscribe","_","data","__async","_a","platform","updatedMethod","__spreadProps","__spreadValues","errors","valid","errorTypes","builder","FormBuilder","result","unsubscribeEvaluate","updatedForm","updatedBody","updateForm","fetchContactMethod","useCallback","id","cm","DataClient","DataType","body","React","StyledGen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