@bigbinary/neeto-assist-frontend 0.0.0-stage → 1.0.1
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/README.md +243 -2
- package/app/javascript/src/translations/ar.json +5 -0
- package/app/javascript/src/translations/bg.json +5 -0
- package/app/javascript/src/translations/ca.json +5 -0
- package/app/javascript/src/translations/cs.json +5 -0
- package/app/javascript/src/translations/da.json +5 -0
- package/app/javascript/src/translations/de.json +5 -0
- package/app/javascript/src/translations/en.json +75 -0
- package/app/javascript/src/translations/es-MX.json +5 -0
- package/app/javascript/src/translations/es.json +5 -0
- package/app/javascript/src/translations/et.json +5 -0
- package/app/javascript/src/translations/fi.json +5 -0
- package/app/javascript/src/translations/fil.json +5 -0
- package/app/javascript/src/translations/fr.json +5 -0
- package/app/javascript/src/translations/he.json +5 -0
- package/app/javascript/src/translations/hi.json +5 -0
- package/app/javascript/src/translations/hr.json +5 -0
- package/app/javascript/src/translations/hu.json +5 -0
- package/app/javascript/src/translations/id.json +5 -0
- package/app/javascript/src/translations/index.js +3 -0
- package/app/javascript/src/translations/it.json +5 -0
- package/app/javascript/src/translations/ja.json +5 -0
- package/app/javascript/src/translations/ko.json +5 -0
- package/app/javascript/src/translations/nl.json +5 -0
- package/app/javascript/src/translations/pl.json +5 -0
- package/app/javascript/src/translations/pt-BR.json +5 -0
- package/app/javascript/src/translations/pt.json +5 -0
- package/app/javascript/src/translations/ro.json +5 -0
- package/app/javascript/src/translations/ru.json +5 -0
- package/app/javascript/src/translations/sk.json +5 -0
- package/app/javascript/src/translations/sl.json +5 -0
- package/app/javascript/src/translations/sv.json +5 -0
- package/app/javascript/src/translations/th.json +5 -0
- package/app/javascript/src/translations/tr.json +5 -0
- package/app/javascript/src/translations/uk.json +5 -0
- package/app/javascript/src/translations/vi.json +5 -0
- package/app/javascript/src/translations/zh-CN.json +5 -0
- package/app/javascript/src/translations/zh-TW.json +5 -0
- package/dist/.ready +1 -0
- package/dist/NeetoAssistButton.js +98 -0
- package/dist/NeetoAssistButton.js.map +1 -0
- package/dist/NeetoAssistPane.js +975 -0
- package/dist/NeetoAssistPane.js.map +1 -0
- package/dist/cjs/NeetoAssistButton.js +100 -0
- package/dist/cjs/NeetoAssistButton.js.map +1 -0
- package/dist/cjs/NeetoAssistPane.js +977 -0
- package/dist/cjs/NeetoAssistPane.js.map +1 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/useNeetoAssistStatus.js +18 -0
- package/dist/cjs/useNeetoAssistStatus.js.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/neeto_assist-BbwXxKis.js +121 -0
- package/dist/neeto_assist-BbwXxKis.js.map +1 -0
- package/dist/neeto_assist-Ha049T0Q.js +102 -0
- package/dist/neeto_assist-Ha049T0Q.js.map +1 -0
- package/dist/useNeetoAssistStatus.js +16 -0
- package/dist/useNeetoAssistStatus.js.map +1 -0
- package/dist/useNeetoAssistStore-B5U7FFgQ.js +218 -0
- package/dist/useNeetoAssistStore-B5U7FFgQ.js.map +1 -0
- package/dist/useNeetoAssistStore-C4fEnA_y.js +232 -0
- package/dist/useNeetoAssistStore-C4fEnA_y.js.map +1 -0
- package/package.json +231 -4
- package/types.d.ts +53 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
3
|
+
import { Button } from '@bigbinary/neeto-atoms';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { u as useNeetoAssistStore, a as useFetchRuns, l as latestDraftId, S as Sparkle } from './useNeetoAssistStore-B5U7FFgQ.js';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
import '@babel/runtime/helpers/objectWithoutProperties';
|
|
8
|
+
import '@tanstack/react-query';
|
|
9
|
+
import '@bigbinary/neeto-commons-frontend/v2/react-utils';
|
|
10
|
+
import './neeto_assist-Ha049T0Q.js';
|
|
11
|
+
import 'axios';
|
|
12
|
+
import 'ramda';
|
|
13
|
+
import '@bigbinary/neeto-commons-frontend/v2/utils';
|
|
14
|
+
import 'zustand';
|
|
15
|
+
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
var NeetoAssistIcon = function NeetoAssistIcon(props) {
|
|
19
|
+
return /*#__PURE__*/jsx(Sparkle, _objectSpread(_objectSpread({}, props), {}, {
|
|
20
|
+
className: "text-purple-600"
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Goes on the ticket: it opens the pane, and tells the pane which ticket it is
|
|
25
|
+
// about for as long as the button is on screen. A dot says a suggested reply is
|
|
26
|
+
// waiting, since the pane is closed until the rep asks for it.
|
|
27
|
+
var NeetoAssistButton = function NeetoAssistButton(_ref) {
|
|
28
|
+
var conversationId = _ref.conversationId,
|
|
29
|
+
onUseReply = _ref.onUseReply;
|
|
30
|
+
var _useTranslation = useTranslation(),
|
|
31
|
+
t = _useTranslation.t;
|
|
32
|
+
var isOpen = useNeetoAssistStore(function (state) {
|
|
33
|
+
return state.isOpen;
|
|
34
|
+
});
|
|
35
|
+
var toggle = useNeetoAssistStore(function (state) {
|
|
36
|
+
return state.toggle;
|
|
37
|
+
});
|
|
38
|
+
var setConversation = useNeetoAssistStore(function (state) {
|
|
39
|
+
return state.setConversation;
|
|
40
|
+
});
|
|
41
|
+
var clearConversation = useNeetoAssistStore(function (state) {
|
|
42
|
+
return state.clearConversation;
|
|
43
|
+
});
|
|
44
|
+
var seenDraftId = useNeetoAssistStore(function (state) {
|
|
45
|
+
return state.seenDrafts[conversationId];
|
|
46
|
+
});
|
|
47
|
+
var _useFetchRuns = useFetchRuns(conversationId),
|
|
48
|
+
_useFetchRuns$data = _useFetchRuns.data,
|
|
49
|
+
_useFetchRuns$data2 = _useFetchRuns$data === void 0 ? {} : _useFetchRuns$data,
|
|
50
|
+
_useFetchRuns$data2$r = _useFetchRuns$data2.runs,
|
|
51
|
+
runs = _useFetchRuns$data2$r === void 0 ? [] : _useFetchRuns$data2$r;
|
|
52
|
+
var draftId = latestDraftId(runs);
|
|
53
|
+
var hasUnseenDraft = !isOpen && !!draftId && draftId !== seenDraftId;
|
|
54
|
+
|
|
55
|
+
// The host's handler changes on every render, and only whether there is one
|
|
56
|
+
// matters to the pane.
|
|
57
|
+
var useReplyRef = useRef(onUseReply);
|
|
58
|
+
var canUseReply = !!onUseReply;
|
|
59
|
+
useEffect(function () {
|
|
60
|
+
useReplyRef.current = onUseReply;
|
|
61
|
+
});
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
setConversation({
|
|
64
|
+
id: conversationId,
|
|
65
|
+
onUseReply: canUseReply ? function (text, html) {
|
|
66
|
+
var _useReplyRef$current;
|
|
67
|
+
return (_useReplyRef$current = useReplyRef.current) === null || _useReplyRef$current === void 0 ? void 0 : _useReplyRef$current.call(useReplyRef, text, html);
|
|
68
|
+
} : undefined
|
|
69
|
+
});
|
|
70
|
+
return function () {
|
|
71
|
+
return clearConversation(conversationId);
|
|
72
|
+
};
|
|
73
|
+
}, [canUseReply, clearConversation, conversationId, setConversation]);
|
|
74
|
+
return /*#__PURE__*/jsxs("span", {
|
|
75
|
+
className: "relative inline-flex",
|
|
76
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
77
|
+
"aria-pressed": isOpen,
|
|
78
|
+
"data-testid": "neeto-assist-button",
|
|
79
|
+
icon: NeetoAssistIcon,
|
|
80
|
+
iconPosition: "left",
|
|
81
|
+
label: t("neetoAssist.askButton"),
|
|
82
|
+
size: "sm",
|
|
83
|
+
variant: isOpen ? "secondary" : "outline",
|
|
84
|
+
tooltipProps: hasUnseenDraft ? {
|
|
85
|
+
content: t("neetoAssist.draftReady")
|
|
86
|
+
} : undefined,
|
|
87
|
+
onClick: toggle
|
|
88
|
+
}), hasUnseenDraft && /*#__PURE__*/jsx("span", {
|
|
89
|
+
"aria-label": t("neetoAssist.draftReady"),
|
|
90
|
+
className: "ring-background absolute -end-0.5 -top-0.5 size-2.5 rounded-full bg-purple-600 ring-2",
|
|
91
|
+
"data-testid": "neeto-assist-draft-dot",
|
|
92
|
+
role: "status"
|
|
93
|
+
})]
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { NeetoAssistButton as default };
|
|
98
|
+
//# sourceMappingURL=NeetoAssistButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NeetoAssistButton.js","sources":["../app/javascript/src/components/NeetoAssistButton/index.jsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\nimport { Button } from \"neetoatoms\";\nimport { useTranslation } from \"react-i18next\";\n\nimport Sparkle from \"components/commons/Sparkle\";\nimport { useFetchRuns } from \"hooks/reactQuery/useRunsApi\";\nimport useNeetoAssistStore from \"stores/useNeetoAssistStore\";\nimport { latestDraftId } from \"utils/runs\";\n\nconst NeetoAssistIcon = props => (\n <Sparkle {...props} className=\"text-purple-600\" />\n);\n\n// Goes on the ticket: it opens the pane, and tells the pane which ticket it is\n// about for as long as the button is on screen. A dot says a suggested reply is\n// waiting, since the pane is closed until the rep asks for it.\nconst NeetoAssistButton = ({ conversationId, onUseReply }) => {\n const { t } = useTranslation();\n const isOpen = useNeetoAssistStore(state => state.isOpen);\n const toggle = useNeetoAssistStore(state => state.toggle);\n const setConversation = useNeetoAssistStore(state => state.setConversation);\n const clearConversation = useNeetoAssistStore(\n state => state.clearConversation\n );\n\n const seenDraftId = useNeetoAssistStore(\n state => state.seenDrafts[conversationId]\n );\n\n const { data: { runs = [] } = {} } = useFetchRuns(conversationId);\n const draftId = latestDraftId(runs);\n const hasUnseenDraft = !isOpen && !!draftId && draftId !== seenDraftId;\n\n // The host's handler changes on every render, and only whether there is one\n // matters to the pane.\n const useReplyRef = useRef(onUseReply);\n const canUseReply = !!onUseReply;\n useEffect(() => {\n useReplyRef.current = onUseReply;\n });\n\n useEffect(() => {\n setConversation({\n id: conversationId,\n onUseReply: canUseReply\n ? (text, html) => useReplyRef.current?.(text, html)\n : undefined,\n });\n\n return () => clearConversation(conversationId);\n }, [canUseReply, clearConversation, conversationId, setConversation]);\n\n return (\n <span className=\"relative inline-flex\">\n <Button\n aria-pressed={isOpen}\n data-testid=\"neeto-assist-button\"\n icon={NeetoAssistIcon}\n iconPosition=\"left\"\n label={t(\"neetoAssist.askButton\")}\n size=\"sm\"\n variant={isOpen ? \"secondary\" : \"outline\"}\n tooltipProps={\n hasUnseenDraft ? { content: t(\"neetoAssist.draftReady\") } : undefined\n }\n onClick={toggle}\n />\n {hasUnseenDraft && (\n <span\n aria-label={t(\"neetoAssist.draftReady\")}\n className=\"ring-background absolute -end-0.5 -top-0.5 size-2.5 rounded-full bg-purple-600 ring-2\"\n data-testid=\"neeto-assist-draft-dot\"\n role=\"status\"\n />\n )}\n </span>\n );\n};\n\nexport default NeetoAssistButton;\n"],"names":["NeetoAssistIcon","props","_jsx","Sparkle","_objectSpread","className","NeetoAssistButton","_ref","conversationId","onUseReply","_useTranslation","useTranslation","t","isOpen","useNeetoAssistStore","state","toggle","setConversation","clearConversation","seenDraftId","seenDrafts","_useFetchRuns","useFetchRuns","_useFetchRuns$data","data","_useFetchRuns$data2","_useFetchRuns$data2$r","runs","draftId","latestDraftId","hasUnseenDraft","useReplyRef","useRef","canUseReply","useEffect","current","id","text","html","_useReplyRef$current","call","undefined","_jsxs","children","Button","icon","iconPosition","label","size","variant","tooltipProps","content","onClick","role"],"mappings":";;;;;;;;;;;;;;;;;AAUA,IAAMA,eAAe,GAAG,SAAlBA,eAAeA,CAAGC,KAAK,EAAA;EAAA,oBAC3BC,GAAA,CAACC,OAAO,EAAAC,aAAA,CAAAA,aAAA,KAAKH,KAAK,CAAA,EAAA,EAAA,EAAA;AAAEI,IAAAA,SAAS,EAAC;AAAiB,GAAA,CAAE,CAAC;AAAA,CACnD;;AAED;AACA;AACA;AACA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAAC,IAAA,EAAuC;AAAA,EAAA,IAAjCC,cAAc,GAAAD,IAAA,CAAdC,cAAc;IAAEC,UAAU,GAAAF,IAAA,CAAVE,UAAU;AACrD,EAAA,IAAAC,eAAA,GAAcC,cAAc,EAAE;IAAtBC,CAAC,GAAAF,eAAA,CAADE,CAAC;AACT,EAAA,IAAMC,MAAM,GAAGC,mBAAmB,CAAC,UAAAC,KAAK,EAAA;IAAA,OAAIA,KAAK,CAACF,MAAM;EAAA,CAAA,CAAC;AACzD,EAAA,IAAMG,MAAM,GAAGF,mBAAmB,CAAC,UAAAC,KAAK,EAAA;IAAA,OAAIA,KAAK,CAACC,MAAM;EAAA,CAAA,CAAC;AACzD,EAAA,IAAMC,eAAe,GAAGH,mBAAmB,CAAC,UAAAC,KAAK,EAAA;IAAA,OAAIA,KAAK,CAACE,eAAe;EAAA,CAAA,CAAC;AAC3E,EAAA,IAAMC,iBAAiB,GAAGJ,mBAAmB,CAC3C,UAAAC,KAAK,EAAA;IAAA,OAAIA,KAAK,CAACG,iBAAiB;AAAA,EAAA,CAClC,CAAC;AAED,EAAA,IAAMC,WAAW,GAAGL,mBAAmB,CACrC,UAAAC,KAAK,EAAA;AAAA,IAAA,OAAIA,KAAK,CAACK,UAAU,CAACZ,cAAc,CAAC;AAAA,EAAA,CAC3C,CAAC;AAED,E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