@bigbinary/neeto-webhooks-frontend 2.2.10 → 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.
@@ -1,8 +1,8 @@
1
- import { prop, pluck, assoc, mergeRight } from 'ramda';
1
+ import { prop, gt, pluck, assoc, mergeRight } from 'ramda';
2
2
  import { useRouteMatch, useHistory, useParams, Switch as Switch$1, Route } from 'react-router-dom';
3
3
  import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
4
4
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
5
- import { isPresent, removeBy, isNotEmpty, removeById, findBy } from '@bigbinary/neeto-cist';
5
+ import { isPresent, removeBy, isNotEmpty, findIndexBy, removeById, findBy } from '@bigbinary/neeto-cist';
6
6
  import { DEFAULT_STALE_TIME, SINGULAR, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_INDEX, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
7
7
  import { useQueryParams, useMutationWithInvalidation, withT } from '@bigbinary/neeto-commons-frontend/react-utils';
8
8
  import { buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
@@ -30,16 +30,18 @@ import Tab from '@bigbinary/neetoui/Tab';
30
30
  import Tag from '@bigbinary/neetoui/Tag';
31
31
  import { t as t$1 } from 'i18next';
32
32
  import Alert from '@bigbinary/neetoui/Alert';
33
+ import { FieldArray } from 'formik';
33
34
  import Plus from '@bigbinary/neeto-icons/Plus';
34
35
  import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
35
36
  import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
37
+ import Label from '@bigbinary/neetoui/Label';
36
38
  import Input from '@bigbinary/neetoui/formik/Input';
37
39
  import Form from '@bigbinary/neetoui/formik/Form';
38
40
  import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
39
- import Select from '@bigbinary/neetoui/formik/Select';
40
- import Switch from '@bigbinary/neetoui/formik/Switch';
41
41
  import Textarea from '@bigbinary/neetoui/formik/Textarea';
42
+ import Checkbox from '@bigbinary/neetoui/Checkbox';
42
43
  import * as yup from 'yup';
44
+ import Switch from '@bigbinary/neetoui/Switch';
43
45
  import SubHeader from '@bigbinary/neeto-molecules/SubHeader';
44
46
 
45
47
  var HELP_LINK_URLS = {
@@ -451,7 +453,6 @@ var Deliveries = function Deliveries(_ref) {
451
453
  isFetching = _useFetchDeliveries.isFetching,
452
454
  _useFetchDeliveries$d = _useFetchDeliveries.data,
453
455
  _useFetchDeliveries$d2 = _useFetchDeliveries$d === void 0 ? {} : _useFetchDeliveries$d,
454
- endpoint = _useFetchDeliveries$d2.endpoint,
455
456
  totalCount = _useFetchDeliveries$d2.totalCount,
456
457
  _useFetchDeliveries$d3 = _useFetchDeliveries$d2.deliveries,
457
458
  deliveries = _useFetchDeliveries$d3 === void 0 ? [] : _useFetchDeliveries$d3;
@@ -463,7 +464,7 @@ var Deliveries = function Deliveries(_ref) {
463
464
  text: t("neetoWebhooks.webhook.title")
464
465
  }, {
465
466
  link: window.location.pathname,
466
- text: endpoint
467
+ text: t("neetoWebhooks.delivery.title")
467
468
  }]);
468
469
  if (isLoading) {
469
470
  return /*#__PURE__*/jsx("div", {
@@ -614,6 +615,44 @@ var useFetchEvents = function useFetchEvents() {
614
615
  });
615
616
  };
616
617
 
618
+ var MENU_ITEMS = {
619
+ EDIT: "edit",
620
+ DELETE: "delete"
621
+ };
622
+ var WEBHOOK_INITIAL_VALUES = {
623
+ endpoint: "",
624
+ events: [],
625
+ secret: "",
626
+ isActive: true
627
+ };
628
+
629
+ var EventCheckbox = function EventCheckbox(_ref) {
630
+ var events = _ref.events,
631
+ values = _ref.values,
632
+ arrayHelpers = _ref.arrayHelpers;
633
+ var handleToggle = function handleToggle(isSelected, index, event) {
634
+ if (isSelected) {
635
+ arrayHelpers.remove(index);
636
+ } else {
637
+ arrayHelpers.push(event);
638
+ }
639
+ };
640
+ return /*#__PURE__*/jsx("div", {
641
+ children: events.map(function (event) {
642
+ var index = findIndexBy(event, values.events);
643
+ var isSelected = gt(index, -1);
644
+ return /*#__PURE__*/jsx(Checkbox, {
645
+ checked: isSelected,
646
+ className: "my-4",
647
+ label: event.label,
648
+ onChange: function onChange() {
649
+ return handleToggle(isSelected, index, event);
650
+ }
651
+ }, event.identifier);
652
+ })
653
+ });
654
+ };
655
+
617
656
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
618
657
  // require the crypto API and do not support built-in fallback to lower quality random number
619
658
  // generators (like Math.random()).
@@ -678,9 +717,29 @@ function v4(options, buf, offset) {
678
717
  return stringify(rnds);
679
718
  }
680
719
 
681
- var MENU_ITEMS = {
682
- EDIT: "edit",
683
- DELETE: "delete"
720
+ var ToggleActiveSwitch = function ToggleActiveSwitch(_ref) {
721
+ var isActive = _ref.isActive,
722
+ webhookId = _ref.webhookId;
723
+ var _useState = useState(isActive),
724
+ _useState2 = _slicedToArray(_useState, 2),
725
+ status = _useState2[0],
726
+ setStatus = _useState2[1];
727
+ var _useUpdateWebhook = useUpdateWebhook(webhookId),
728
+ updateWebhook = _useUpdateWebhook.mutate;
729
+ var handleToggle = function handleToggle(event) {
730
+ var updatedStatus = event.target.checked;
731
+ setStatus(updatedStatus);
732
+ updateWebhook({
733
+ id: webhookId,
734
+ payload: {
735
+ isActive: updatedStatus
736
+ }
737
+ });
738
+ };
739
+ return /*#__PURE__*/jsx(Switch, {
740
+ checked: status,
741
+ onChange: handleToggle
742
+ });
684
743
  };
685
744
 
686
745
  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; }
@@ -776,13 +835,10 @@ var buildColumns = function buildColumns(_ref6) {
776
835
  title: t$1("neetoWebhooks.webhook.active"),
777
836
  key: "isActive",
778
837
  dataIndex: "isActive",
779
- render: function render(isActive) {
780
- return isActive ? /*#__PURE__*/jsx(Tag, {
781
- label: t$1("neetoWebhooks.webhook.activeStatuses.active"),
782
- style: "primary"
783
- }) : /*#__PURE__*/jsx(Tag, {
784
- label: t$1("neetoWebhooks.webhook.activeStatuses.inactive"),
785
- style: "danger"
838
+ render: function render(isActive, webhook) {
839
+ return /*#__PURE__*/jsx(ToggleActiveSwitch, {
840
+ isActive: isActive,
841
+ webhookId: webhook.id
786
842
  });
787
843
  },
788
844
  width: 150
@@ -838,12 +894,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
838
894
  var _useFetchEvents = useFetchEvents(),
839
895
  events = _useFetchEvents.data,
840
896
  isLoading = _useFetchEvents.isLoading;
841
- var initialValues = editingWebhookId ? webhook : {
842
- endpoint: "",
843
- events: events,
844
- secret: "",
845
- isActive: true
846
- };
897
+ var initialValues = editingWebhookId ? _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), webhook) : _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), {}, {
898
+ events: events
899
+ });
847
900
  var handleSubmit = function handleSubmit(values) {
848
901
  var payload = buildPayload({
849
902
  isEditing: editingWebhookId,
@@ -906,7 +959,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
906
959
  },
907
960
  children: function children(_ref2) {
908
961
  var setFieldValue = _ref2.setFieldValue,
909
- values = _ref2.values;
962
+ values = _ref2.values,
963
+ touched = _ref2.touched,
964
+ errors = _ref2.errors;
910
965
  return isLoading ? /*#__PURE__*/jsx("div", {
911
966
  className: "flex items-center justify-center",
912
967
  children: /*#__PURE__*/jsx(Spinner, {})
@@ -923,18 +978,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
923
978
  placeholder: t("neetoWebhooks.webhook.endpointPlaceholder"),
924
979
  ref: endpointRef,
925
980
  rows: 1
926
- }), !isLoading && /*#__PURE__*/jsx(Select, {
927
- isMulti: true,
928
- required: true,
929
- getOptionLabel: prop("label"),
930
- getOptionValue: prop("identifier"),
931
- label: t("neetoWebhooks.common.event", PLURAL),
932
- name: "events",
933
- options: events,
934
- placeholder: t("neetoWebhooks.webhook.eventPlaceholder")
935
981
  }), /*#__PURE__*/jsxs("div", {
936
982
  className: "space-y-2",
937
- children: [/*#__PURE__*/jsxs("span", {
983
+ children: [/*#__PURE__*/jsxs(Label, {
938
984
  className: "flex items-center gap-x-2",
939
985
  children: [t("neetoWebhooks.webhook.secret"), /*#__PURE__*/jsx(HelpPopover, {
940
986
  helpLinkProps: {
@@ -980,15 +1026,24 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
980
1026
  }
981
1027
  })]
982
1028
  }), /*#__PURE__*/jsxs("div", {
983
- className: "flex gap-2",
984
- children: [/*#__PURE__*/jsx(Switch, {
985
- label: t("neetoWebhooks.webhook.active"),
986
- name: "isActive"
987
- }), /*#__PURE__*/jsx(HelpPopover, {
988
- popoverProps: {
989
- position: "bottom"
990
- },
991
- description: values.isActive ? t("neetoWebhooks.webhook.statusActiveHelpDescription") : t("neetoWebhooks.webhook.statusInactiveHelpDescription")
1029
+ className: "space-y-2",
1030
+ children: [/*#__PURE__*/jsx(Label, {
1031
+ required: true,
1032
+ children: t("neetoWebhooks.common.event", PLURAL)
1033
+ }), !isLoading && /*#__PURE__*/jsx(FieldArray, {
1034
+ name: "events",
1035
+ render: function render(arrayHelpers) {
1036
+ return /*#__PURE__*/jsxs("div", {
1037
+ children: [/*#__PURE__*/jsx(EventCheckbox, {
1038
+ arrayHelpers: arrayHelpers,
1039
+ events: events,
1040
+ values: values
1041
+ }), touched.events && errors.events && /*#__PURE__*/jsx("div", {
1042
+ className: "neeto-ui-text-error-800 text-xs mt-1",
1043
+ children: errors.events
1044
+ })]
1045
+ });
1046
+ }
992
1047
  })]
993
1048
  })]
994
1049
  })
@@ -1152,7 +1207,7 @@ var Webhooks = function Webhooks(_ref) {
1152
1207
  children: /*#__PURE__*/jsx(NoData, {
1153
1208
  title: t("neetoWebhooks.webhook.empty"),
1154
1209
  helpText: /*#__PURE__*/jsx(Button, {
1155
- href: HELP_LINK_URLS.webhook,
1210
+ href: webhooksHelpLink,
1156
1211
  label: t("neetoWebhooks.webhook.emptyHelpText"),
1157
1212
  rel: "noreferrer",
1158
1213
  style: "link",