@bigbinary/neeto-rules-frontend 0.4.6 → 0.4.8
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 +20 -0
- package/app/javascript/src/translations/en.json +4 -2
- package/dist/index.cjs.js +79 -37
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +82 -40
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -3,15 +3,15 @@ import { BrowserRouter } from 'react-router-dom';
|
|
|
3
3
|
import { shallow } from 'zustand/shallow';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import { useFormikContext, Formik, Form, useField, FieldArray, ErrorMessage } from 'formik';
|
|
6
|
-
import { findBy, noop,
|
|
6
|
+
import { findBy, noop, isPresent, renameKeys, isNotEmpty, toLabelAndValue, removeBy } from '@bigbinary/neeto-cist';
|
|
7
7
|
import { ActionBlock, Textarea, MultiEmailInput, Input as Input$2, Select as Select$1, Radio } from '@bigbinary/neetoui/formik';
|
|
8
8
|
import { t as t$1 } from 'i18next';
|
|
9
9
|
import * as yup from 'yup';
|
|
10
10
|
import { isEditorEmpty, FormikEditor } from '@bigbinary/neeto-editor';
|
|
11
|
-
import { withImmutableActions, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
11
|
+
import { withImmutableActions, useDebounce, useStateWithDependency } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
12
12
|
import { create } from 'zustand';
|
|
13
13
|
import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
|
|
14
|
-
import { Typography, Button, Pane, DatePicker, Dropdown as Dropdown$1, Input as Input$1,
|
|
14
|
+
import { Typography, Button, Pane, DatePicker, Dropdown as Dropdown$1, Input as Input$1, Select, Checkbox, Tooltip, Label } from '@bigbinary/neetoui';
|
|
15
15
|
import { useTranslation } from 'react-i18next';
|
|
16
16
|
import { Down, Up, Check, Search, Close, Delete, Plus, Refresh, Eye } from '@bigbinary/neeto-icons';
|
|
17
17
|
import { pluck, isNil, isNotNil, assocPath, toLower, isEmpty, without, append, pipe, partition } from 'ramda';
|
|
@@ -1500,7 +1500,9 @@ var EditorAction = function EditorAction(_ref) {
|
|
|
1500
1500
|
value = _ref$value === void 0 ? "" : _ref$value,
|
|
1501
1501
|
label = _ref.label,
|
|
1502
1502
|
_ref$variables = _ref.variables,
|
|
1503
|
-
variables = _ref$variables === void 0 ? [] : _ref$variables
|
|
1503
|
+
variables = _ref$variables === void 0 ? [] : _ref$variables,
|
|
1504
|
+
_ref$editorRef = _ref.editorRef,
|
|
1505
|
+
editorRef = _ref$editorRef === void 0 ? null : _ref$editorRef;
|
|
1504
1506
|
var _useFormikContext = useFormikContext(),
|
|
1505
1507
|
setFieldValue = _useFormikContext.setFieldValue;
|
|
1506
1508
|
var _useState = useState(value),
|
|
@@ -1520,9 +1522,8 @@ var EditorAction = function EditorAction(_ref) {
|
|
|
1520
1522
|
addons: EDITOR_ADDONS,
|
|
1521
1523
|
className: "w-full",
|
|
1522
1524
|
"data-cy": "neeto-editor",
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
}
|
|
1525
|
+
ref: editorRef,
|
|
1526
|
+
onChange: setEditorData
|
|
1526
1527
|
});
|
|
1527
1528
|
};
|
|
1528
1529
|
|
|
@@ -1566,19 +1567,6 @@ function _extends() {
|
|
|
1566
1567
|
return _extends.apply(this, arguments);
|
|
1567
1568
|
}
|
|
1568
1569
|
|
|
1569
|
-
var useDebouncedUpdate = function useDebouncedUpdate(value, setValue) {
|
|
1570
|
-
var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200;
|
|
1571
|
-
var _useState = useState(value),
|
|
1572
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
1573
|
-
text = _useState2[0],
|
|
1574
|
-
setText = _useState2[1];
|
|
1575
|
-
var debouncedValue = useDebounce(text, duration);
|
|
1576
|
-
useEffect(function () {
|
|
1577
|
-
setValue(text);
|
|
1578
|
-
}, [debouncedValue]);
|
|
1579
|
-
return [text, setText];
|
|
1580
|
-
};
|
|
1581
|
-
|
|
1582
1570
|
var _excluded$8 = ["initialFocusRef", "name", "label"];
|
|
1583
1571
|
var InputField$2 = function InputField(_ref) {
|
|
1584
1572
|
var initialFocusRef = _ref.initialFocusRef,
|
|
@@ -1586,24 +1574,15 @@ var InputField$2 = function InputField(_ref) {
|
|
|
1586
1574
|
label = _ref.label,
|
|
1587
1575
|
otherProps = _objectWithoutProperties(_ref, _excluded$8);
|
|
1588
1576
|
var _useField = useField(name),
|
|
1589
|
-
_useField2 = _slicedToArray(_useField,
|
|
1577
|
+
_useField2 = _slicedToArray(_useField, 2),
|
|
1590
1578
|
field = _useField2[0],
|
|
1591
|
-
meta = _useField2[1]
|
|
1592
|
-
setValue = _useField2[2].setValue;
|
|
1593
|
-
var _useDebouncedUpdate = useDebouncedUpdate(field.value, setValue),
|
|
1594
|
-
_useDebouncedUpdate2 = _slicedToArray(_useDebouncedUpdate, 2),
|
|
1595
|
-
text = _useDebouncedUpdate2[0],
|
|
1596
|
-
setText = _useDebouncedUpdate2[1];
|
|
1579
|
+
meta = _useField2[1];
|
|
1597
1580
|
return /*#__PURE__*/React.createElement(Input$1, _extends({
|
|
1598
1581
|
label: label,
|
|
1599
1582
|
type: "text"
|
|
1600
1583
|
}, field, {
|
|
1601
1584
|
error: meta.touched ? meta.error : "",
|
|
1602
|
-
ref: initialFocusRef
|
|
1603
|
-
value: text,
|
|
1604
|
-
onChange: function onChange(e) {
|
|
1605
|
-
return setText(e.target.value);
|
|
1606
|
-
}
|
|
1585
|
+
ref: initialFocusRef
|
|
1607
1586
|
}, otherProps));
|
|
1608
1587
|
};
|
|
1609
1588
|
|
|
@@ -1619,12 +1598,18 @@ var EmailFields = function EmailFields(_ref) {
|
|
|
1619
1598
|
index = _ref.index;
|
|
1620
1599
|
var _useFormikContext = useFormikContext(),
|
|
1621
1600
|
errors = _useFormikContext.errors,
|
|
1622
|
-
touched = _useFormikContext.touched
|
|
1601
|
+
touched = _useFormikContext.touched,
|
|
1602
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
1623
1603
|
var _useState = useState(false),
|
|
1624
1604
|
_useState2 = _slicedToArray(_useState, 2),
|
|
1625
1605
|
showPane = _useState2[0],
|
|
1626
1606
|
setShowPane = _useState2[1];
|
|
1607
|
+
var _useStateWithDependen = useStateWithDependency(null, [selectedField]),
|
|
1608
|
+
_useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 2),
|
|
1609
|
+
selectedTemplate = _useStateWithDependen2[0],
|
|
1610
|
+
setSelectedTemplate = _useStateWithDependen2[1];
|
|
1627
1611
|
var initialFocusRef = useRef(null);
|
|
1612
|
+
var editorRef = useRef(null);
|
|
1628
1613
|
var _useTranslation = useTranslation(),
|
|
1629
1614
|
t = _useTranslation.t;
|
|
1630
1615
|
useOnButtonPressed(initialFocusRef, function () {
|
|
@@ -1633,6 +1618,36 @@ var EmailFields = function EmailFields(_ref) {
|
|
|
1633
1618
|
var isValid = errors.actions && isNotNil((_errors$actions = errors.actions) === null || _errors$actions === void 0 || (_errors$actions = _errors$actions.value) === null || _errors$actions === void 0 ? void 0 : _errors$actions[index]) && isNotNil((_touched$actions = touched.actions) === null || _touched$actions === void 0 || (_touched$actions = _touched$actions.value) === null || _touched$actions === void 0 ? void 0 : _touched$actions[index]);
|
|
1634
1619
|
var separator = (selectedField === null || selectedField === void 0 || (_selectedField$separa = selectedField.separator) === null || _selectedField$separa === void 0 ? void 0 : _selectedField$separa.toLowerCase()) || t("neetoRules.common.as");
|
|
1635
1620
|
var defaultLabel = (selectedField === null || selectedField === void 0 ? void 0 : selectedField.emailPlaceholder) || t("neetoRules.common.email");
|
|
1621
|
+
var templates = selectedField === null || selectedField === void 0 ? void 0 : selectedField.templates;
|
|
1622
|
+
var isTemplateSelectionEnabled = isPresent(templates);
|
|
1623
|
+
var setEmailContent = function setEmailContent(ref, content) {
|
|
1624
|
+
if (!ref.current) return;
|
|
1625
|
+
ref.current.editor.commands.setContent(content);
|
|
1626
|
+
};
|
|
1627
|
+
var handleTemplateChange = function handleTemplateChange(option) {
|
|
1628
|
+
setSelectedTemplate(option);
|
|
1629
|
+
if (!option) return;
|
|
1630
|
+
var template = findBy({
|
|
1631
|
+
id: option.value
|
|
1632
|
+
}, templates);
|
|
1633
|
+
setFieldValue("".concat(name, ".body"), template.body);
|
|
1634
|
+
setEmailContent(editorRef, template.body);
|
|
1635
|
+
if (selectedField.hideSubject) return;
|
|
1636
|
+
setFieldValue("".concat(name, ".subject"), template.subject);
|
|
1637
|
+
};
|
|
1638
|
+
var isFirstFieldInForm = function isFirstFieldInForm(field) {
|
|
1639
|
+
if (isTemplateSelectionEnabled) {
|
|
1640
|
+
return false;
|
|
1641
|
+
}
|
|
1642
|
+
switch (field) {
|
|
1643
|
+
case "emails":
|
|
1644
|
+
return true;
|
|
1645
|
+
case "subject":
|
|
1646
|
+
return !isEmailIdField;
|
|
1647
|
+
default:
|
|
1648
|
+
return !isEmailIdField && selectedField.hideSubject;
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1636
1651
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Typography, {
|
|
1637
1652
|
className: "neeto-ui-text-gray-700 mt-1",
|
|
1638
1653
|
"data-cy": "action-email-seperator-text",
|
|
@@ -1665,18 +1680,32 @@ var EmailFields = function EmailFields(_ref) {
|
|
|
1665
1680
|
weight: "semibold"
|
|
1666
1681
|
}, defaultLabel)), /*#__PURE__*/React.createElement(Pane.Body, null, /*#__PURE__*/React.createElement("div", {
|
|
1667
1682
|
className: "w-full"
|
|
1668
|
-
},
|
|
1683
|
+
}, isTemplateSelectionEnabled && /*#__PURE__*/React.createElement(Select, {
|
|
1684
|
+
isClearable: true,
|
|
1685
|
+
isSearchable: true,
|
|
1686
|
+
className: "mb-4",
|
|
1687
|
+
innerRef: initialFocusRef,
|
|
1688
|
+
label: t("neetoRules.labels.template"),
|
|
1689
|
+
options: renameKeys({
|
|
1690
|
+
name: "label",
|
|
1691
|
+
id: "value"
|
|
1692
|
+
}, templates),
|
|
1693
|
+
placeholder: t("neetoRules.placeholders.selectTemplate"),
|
|
1694
|
+
value: selectedTemplate,
|
|
1695
|
+
onChange: handleTemplateChange
|
|
1696
|
+
}), isEmailIdField && /*#__PURE__*/React.createElement(EmailIdFields, {
|
|
1669
1697
|
emails: emails,
|
|
1670
|
-
|
|
1671
|
-
|
|
1698
|
+
name: "".concat(name, ".emails"),
|
|
1699
|
+
initialFocusRef: isFirstFieldInForm("emails") ? initialFocusRef : null
|
|
1672
1700
|
}), !selectedField.hideSubject && /*#__PURE__*/React.createElement(InputField$2, {
|
|
1673
1701
|
className: "mb-4",
|
|
1674
1702
|
"data-cy": "email-action-subject-text-field",
|
|
1675
|
-
initialFocusRef: isEmailIdField ? null : initialFocusRef,
|
|
1676
1703
|
label: t("neetoRules.labels.subject"),
|
|
1677
|
-
name: "".concat(name, ".subject")
|
|
1704
|
+
name: "".concat(name, ".subject"),
|
|
1705
|
+
initialFocusRef: isFirstFieldInForm("subject") ? initialFocusRef : null
|
|
1678
1706
|
}), /*#__PURE__*/React.createElement(EditorAction, {
|
|
1679
|
-
|
|
1707
|
+
editorRef: editorRef,
|
|
1708
|
+
autoFocus: isFirstFieldInForm("body"),
|
|
1680
1709
|
label: t("neetoRules.labels.body"),
|
|
1681
1710
|
name: "".concat(name, ".body"),
|
|
1682
1711
|
value: (_action$metadata = action.metadata) === null || _action$metadata === void 0 ? void 0 : _action$metadata.body,
|
|
@@ -2357,7 +2386,7 @@ var ActionItem = function ActionItem(_ref) {
|
|
|
2357
2386
|
}) : t("neetoRules.common.then");
|
|
2358
2387
|
var actionOptions = useMemo(function () {
|
|
2359
2388
|
return getActionOptions(action, actions, optionList);
|
|
2360
|
-
}, [action, actions]);
|
|
2389
|
+
}, [action, actions, optionList]);
|
|
2361
2390
|
var selectedField = useMemo(function () {
|
|
2362
2391
|
return getFieldDetails$1(action.name, actionOptions);
|
|
2363
2392
|
}, [action, actionOptions]);
|
|
@@ -4573,6 +4602,19 @@ var Events = function Events(_ref) {
|
|
|
4573
4602
|
}));
|
|
4574
4603
|
};
|
|
4575
4604
|
|
|
4605
|
+
var useDebouncedUpdate = function useDebouncedUpdate(value, setValue) {
|
|
4606
|
+
var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200;
|
|
4607
|
+
var _useState = useState(value),
|
|
4608
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
4609
|
+
text = _useState2[0],
|
|
4610
|
+
setText = _useState2[1];
|
|
4611
|
+
var debouncedValue = useDebounce(text, duration);
|
|
4612
|
+
useEffect(function () {
|
|
4613
|
+
setValue(text);
|
|
4614
|
+
}, [debouncedValue]);
|
|
4615
|
+
return [text, setText];
|
|
4616
|
+
};
|
|
4617
|
+
|
|
4576
4618
|
var _excluded$4 = ["data", "name", "label"];
|
|
4577
4619
|
var InputField = function InputField(_ref) {
|
|
4578
4620
|
var data = _ref.data,
|