@bigbinary/neeto-webhooks-frontend 2.2.12 → 2.2.13

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.
@@ -32,16 +32,18 @@ var Tab = require('@bigbinary/neetoui/Tab');
32
32
  var Tag = require('@bigbinary/neetoui/Tag');
33
33
  var i18next = require('i18next');
34
34
  var Alert = require('@bigbinary/neetoui/Alert');
35
+ var formik = require('formik');
35
36
  var Plus = require('@bigbinary/neeto-icons/Plus');
36
37
  var HelpPopover = require('@bigbinary/neeto-molecules/HelpPopover');
37
38
  var MoreDropdown = require('@bigbinary/neeto-molecules/MoreDropdown');
39
+ var Label = require('@bigbinary/neetoui/Label');
38
40
  var Input = require('@bigbinary/neetoui/formik/Input');
39
41
  var Form = require('@bigbinary/neetoui/formik/Form');
40
42
  var ActionBlock = require('@bigbinary/neetoui/formik/ActionBlock');
41
- var Select = require('@bigbinary/neetoui/formik/Select');
42
- var Switch = require('@bigbinary/neetoui/formik/Switch');
43
43
  var Textarea = require('@bigbinary/neetoui/formik/Textarea');
44
+ var Checkbox = require('@bigbinary/neetoui/Checkbox');
44
45
  var yup = require('yup');
46
+ var Switch = require('@bigbinary/neetoui/Switch');
45
47
  var SubHeader = require('@bigbinary/neeto-molecules/SubHeader');
46
48
 
47
49
  function _interopNamespaceDefault(e) {
@@ -472,7 +474,6 @@ var Deliveries = function Deliveries(_ref) {
472
474
  isFetching = _useFetchDeliveries.isFetching,
473
475
  _useFetchDeliveries$d = _useFetchDeliveries.data,
474
476
  _useFetchDeliveries$d2 = _useFetchDeliveries$d === void 0 ? {} : _useFetchDeliveries$d,
475
- endpoint = _useFetchDeliveries$d2.endpoint,
476
477
  totalCount = _useFetchDeliveries$d2.totalCount,
477
478
  _useFetchDeliveries$d3 = _useFetchDeliveries$d2.deliveries,
478
479
  deliveries = _useFetchDeliveries$d3 === void 0 ? [] : _useFetchDeliveries$d3;
@@ -484,7 +485,7 @@ var Deliveries = function Deliveries(_ref) {
484
485
  text: t("neetoWebhooks.webhook.title")
485
486
  }, {
486
487
  link: window.location.pathname,
487
- text: endpoint
488
+ text: t("neetoWebhooks.delivery.title")
488
489
  }]);
489
490
  if (isLoading) {
490
491
  return /*#__PURE__*/jsxRuntime.jsx("div", {
@@ -635,6 +636,44 @@ var useFetchEvents = function useFetchEvents() {
635
636
  });
636
637
  };
637
638
 
639
+ var MENU_ITEMS = {
640
+ EDIT: "edit",
641
+ DELETE: "delete"
642
+ };
643
+ var WEBHOOK_INITIAL_VALUES = {
644
+ endpoint: "",
645
+ events: [],
646
+ secret: "",
647
+ isActive: true
648
+ };
649
+
650
+ var EventCheckbox = function EventCheckbox(_ref) {
651
+ var events = _ref.events,
652
+ values = _ref.values,
653
+ arrayHelpers = _ref.arrayHelpers;
654
+ var handleToggle = function handleToggle(isSelected, index, event) {
655
+ if (isSelected) {
656
+ arrayHelpers.remove(index);
657
+ } else {
658
+ arrayHelpers.push(event);
659
+ }
660
+ };
661
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
662
+ children: events.map(function (event) {
663
+ var index = neetoCist.findIndexBy(event, values.events);
664
+ var isSelected = ramda.gt(index, -1);
665
+ return /*#__PURE__*/jsxRuntime.jsx(Checkbox, {
666
+ checked: isSelected,
667
+ className: "my-4",
668
+ label: event.label,
669
+ onChange: function onChange() {
670
+ return handleToggle(isSelected, index, event);
671
+ }
672
+ }, event.identifier);
673
+ })
674
+ });
675
+ };
676
+
638
677
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
639
678
  // require the crypto API and do not support built-in fallback to lower quality random number
640
679
  // generators (like Math.random()).
@@ -699,9 +738,29 @@ function v4(options, buf, offset) {
699
738
  return stringify(rnds);
700
739
  }
701
740
 
702
- var MENU_ITEMS = {
703
- EDIT: "edit",
704
- DELETE: "delete"
741
+ var ToggleActiveSwitch = function ToggleActiveSwitch(_ref) {
742
+ var isActive = _ref.isActive,
743
+ webhookId = _ref.webhookId;
744
+ var _useState = react.useState(isActive),
745
+ _useState2 = _slicedToArray(_useState, 2),
746
+ status = _useState2[0],
747
+ setStatus = _useState2[1];
748
+ var _useUpdateWebhook = useUpdateWebhook(webhookId),
749
+ updateWebhook = _useUpdateWebhook.mutate;
750
+ var handleToggle = function handleToggle(event) {
751
+ var updatedStatus = event.target.checked;
752
+ setStatus(updatedStatus);
753
+ updateWebhook({
754
+ id: webhookId,
755
+ payload: {
756
+ isActive: updatedStatus
757
+ }
758
+ });
759
+ };
760
+ return /*#__PURE__*/jsxRuntime.jsx(Switch, {
761
+ checked: status,
762
+ onChange: handleToggle
763
+ });
705
764
  };
706
765
 
707
766
  function ownKeys$2(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; }
@@ -797,13 +856,10 @@ var buildColumns = function buildColumns(_ref6) {
797
856
  title: i18next.t("neetoWebhooks.webhook.active"),
798
857
  key: "isActive",
799
858
  dataIndex: "isActive",
800
- render: function render(isActive) {
801
- return isActive ? /*#__PURE__*/jsxRuntime.jsx(Tag, {
802
- label: i18next.t("neetoWebhooks.webhook.activeStatuses.active"),
803
- style: "primary"
804
- }) : /*#__PURE__*/jsxRuntime.jsx(Tag, {
805
- label: i18next.t("neetoWebhooks.webhook.activeStatuses.inactive"),
806
- style: "danger"
859
+ render: function render(isActive, webhook) {
860
+ return /*#__PURE__*/jsxRuntime.jsx(ToggleActiveSwitch, {
861
+ isActive: isActive,
862
+ webhookId: webhook.id
807
863
  });
808
864
  },
809
865
  width: 150
@@ -859,12 +915,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
859
915
  var _useFetchEvents = useFetchEvents(),
860
916
  events = _useFetchEvents.data,
861
917
  isLoading = _useFetchEvents.isLoading;
862
- var initialValues = editingWebhookId ? webhook : {
863
- endpoint: "",
864
- events: events,
865
- secret: "",
866
- isActive: true
867
- };
918
+ var initialValues = editingWebhookId ? _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), webhook) : _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), {}, {
919
+ events: events
920
+ });
868
921
  var handleSubmit = function handleSubmit(values) {
869
922
  var payload = buildPayload({
870
923
  isEditing: editingWebhookId,
@@ -927,7 +980,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
927
980
  },
928
981
  children: function children(_ref2) {
929
982
  var setFieldValue = _ref2.setFieldValue,
930
- values = _ref2.values;
983
+ values = _ref2.values,
984
+ touched = _ref2.touched,
985
+ errors = _ref2.errors;
931
986
  return isLoading ? /*#__PURE__*/jsxRuntime.jsx("div", {
932
987
  className: "flex items-center justify-center",
933
988
  children: /*#__PURE__*/jsxRuntime.jsx(Spinner, {})
@@ -944,18 +999,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
944
999
  placeholder: t("neetoWebhooks.webhook.endpointPlaceholder"),
945
1000
  ref: endpointRef,
946
1001
  rows: 1
947
- }), !isLoading && /*#__PURE__*/jsxRuntime.jsx(Select, {
948
- isMulti: true,
949
- required: true,
950
- getOptionLabel: ramda.prop("label"),
951
- getOptionValue: ramda.prop("identifier"),
952
- label: t("neetoWebhooks.common.event", constants.PLURAL),
953
- name: "events",
954
- options: events,
955
- placeholder: t("neetoWebhooks.webhook.eventPlaceholder")
956
1002
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
957
1003
  className: "space-y-2",
958
- children: [/*#__PURE__*/jsxRuntime.jsxs("span", {
1004
+ children: [/*#__PURE__*/jsxRuntime.jsxs(Label, {
959
1005
  className: "flex items-center gap-x-2",
960
1006
  children: [t("neetoWebhooks.webhook.secret"), /*#__PURE__*/jsxRuntime.jsx(HelpPopover, {
961
1007
  helpLinkProps: {
@@ -1001,15 +1047,24 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
1001
1047
  }
1002
1048
  })]
1003
1049
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
1004
- className: "flex gap-2",
1005
- children: [/*#__PURE__*/jsxRuntime.jsx(Switch, {
1006
- label: t("neetoWebhooks.webhook.active"),
1007
- name: "isActive"
1008
- }), /*#__PURE__*/jsxRuntime.jsx(HelpPopover, {
1009
- popoverProps: {
1010
- position: "bottom"
1011
- },
1012
- description: values.isActive ? t("neetoWebhooks.webhook.statusActiveHelpDescription") : t("neetoWebhooks.webhook.statusInactiveHelpDescription")
1050
+ className: "space-y-2",
1051
+ children: [/*#__PURE__*/jsxRuntime.jsx(Label, {
1052
+ required: true,
1053
+ children: t("neetoWebhooks.common.event", constants.PLURAL)
1054
+ }), !isLoading && /*#__PURE__*/jsxRuntime.jsx(formik.FieldArray, {
1055
+ name: "events",
1056
+ render: function render(arrayHelpers) {
1057
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
1058
+ children: [/*#__PURE__*/jsxRuntime.jsx(EventCheckbox, {
1059
+ arrayHelpers: arrayHelpers,
1060
+ events: events,
1061
+ values: values
1062
+ }), touched.events && errors.events && /*#__PURE__*/jsxRuntime.jsx("div", {
1063
+ className: "neeto-ui-text-error-800 text-xs mt-1",
1064
+ children: errors.events
1065
+ })]
1066
+ });
1067
+ }
1013
1068
  })]
1014
1069
  })]
1015
1070
  })