@bigbinary/neeto-rules-frontend 0.4.5 → 0.4.7

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/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, isNotEmpty, isPresent, toLabelAndValue, removeBy } from '@bigbinary/neeto-cist';
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, Checkbox, Select, Tooltip, Label } from '@bigbinary/neetoui';
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';
@@ -1243,7 +1243,7 @@ var dayjs_min = {exports: {}};
1243
1243
  dayjs_min.exports;
1244
1244
 
1245
1245
  (function (module, exports) {
1246
- !function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return "["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0;}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return b},m.isValid=function(){return !(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g;}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
1246
+ !function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",f="month",h="quarter",c="year",d="date",$="Invalid Date",l=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},g={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,f),s=n-i<0,u=e.clone().add(r+(s?-1:1),f);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:f,y:c,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:h}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},v="en",D={};D[v]=M;var p=function(t){return t instanceof _},S=function t(e,n,r){var i;if(!e)return v;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(v=i),i||!r&&v},w=function(t,e){if(p(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},O=g;O.l=S,O.i=p,O.w=function(t,e){return w(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=S(t.locale,null,!0),this.parse(t);}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(O.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(l);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.$x=t.x||{},this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return O},m.isValid=function(){return !(this.$d.toString()===$)},m.isSame=function(t,e){var n=w(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return w(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<w(t)},m.$g=function(t,e,n){return O.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!O.u(e)||e,h=O.p(t),$=function(t,e){var i=O.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},l=function(t,e){return O.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,g="set"+(this.$u?"UTC":"");switch(h){case c:return r?$(1,0):$(31,11);case f:return r?$(1,M):$(0,M+1);case o:var v=this.$locale().weekStart||0,D=(y<v?y+7:y)-v;return $(r?m-D:m+(6-D),M);case a:case d:return l(g+"Hours",0);case u:return l(g+"Minutes",1);case s:return l(g+"Seconds",2);case i:return l(g+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=O.p(t),h="set"+(this.$u?"UTC":""),$=(n={},n[a]=h+"Date",n[d]=h+"Date",n[f]=h+"Month",n[c]=h+"FullYear",n[u]=h+"Hours",n[s]=h+"Minutes",n[i]=h+"Seconds",n[r]=h+"Milliseconds",n)[o],l=o===a?this.$D+(e-this.$W):e;if(o===f||o===c){var y=this.clone().set(d,1);y.$d[$](l),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else $&&this.$d[$](l);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[O.p(t)]()},m.add=function(r,h){var d,$=this;r=Number(r);var l=O.p(h),y=function(t){var e=w($);return O.w(e.date(e.date()+Math.round(t*r)),$)};if(l===f)return this.set(f,this.$M+r);if(l===c)return this.set(c,this.$y+r);if(l===a)return y(1);if(l===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[l]||1,m=this.$d.getTime()+r*M;return O.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||$;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=O.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,f=n.months,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},c=function(t){return O.s(s%12||12,t,"0")},d=n.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r},l={YY:String(this.$y).slice(-2),YYYY:this.$y,M:a+1,MM:O.s(a+1,2,"0"),MMM:h(n.monthsShort,a,f,3),MMMM:h(f,a),D:this.$D,DD:O.s(this.$D,2,"0"),d:String(this.$W),dd:h(n.weekdaysMin,this.$W,o,2),ddd:h(n.weekdaysShort,this.$W,o,3),dddd:o[this.$W],H:String(s),HH:O.s(s,2,"0"),h:c(1),hh:c(2),a:d(s,u,!0),A:d(s,u,!1),m:String(u),mm:O.s(u,2,"0"),s:String(this.$s),ss:O.s(this.$s,2,"0"),SSS:O.s(this.$ms,3,"0"),Z:i};return r.replace(y,(function(t,e){return e||l[t]||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,$){var l,y=O.p(d),M=w(r),m=(M.utcOffset()-this.utcOffset())*e,g=this-M,v=O.m(this,M);return v=(l={},l[c]=v/12,l[f]=v,l[h]=v/3,l[o]=(g-m)/6048e5,l[a]=(g-m)/864e5,l[u]=g/n,l[s]=g/e,l[i]=g/t,l)[y]||g,$?v:O.a(v)},m.daysInMonth=function(){return this.endOf(f).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=S(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return O.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),T=_.prototype;return w.prototype=T,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",f],["$y",c],["$D",d]].forEach((function(t){T[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),w.extend=function(t,e){return t.$i||(t(e,_,w),t.$i=!0),w},w.locale=S,w.isDayjs=p,w.unix=function(t){return w(1e3*t)},w.en=D[v],w.Ls=D,w.p={},w}));
1247
1247
  } (dayjs_min, dayjs_min.exports));
1248
1248
 
1249
1249
  var dayjs_minExports = dayjs_min.exports;
@@ -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
- onChange: function onChange(value) {
1524
- return setEditorData(value);
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, 3),
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
- }, isEmailIdField && /*#__PURE__*/React.createElement(EmailIdFields, {
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
- initialFocusRef: initialFocusRef,
1671
- name: "".concat(name, ".emails")
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
- autoFocus: !isEmailIdField && selectedField.hideSubject,
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,