@bigbinary/neeto-webhooks-frontend 2.2.12 → 2.2.14

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,14 +1,15 @@
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';
9
9
  import Container from '@bigbinary/neeto-molecules/Container';
10
10
  import Header$2 from '@bigbinary/neeto-molecules/Header';
11
11
  import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
12
+ import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
12
13
  import NoData from '@bigbinary/neetoui/NoData';
13
14
  import Spinner from '@bigbinary/neetoui/Spinner';
14
15
  import Table from '@bigbinary/neetoui/Table';
@@ -30,16 +31,18 @@ import Tab from '@bigbinary/neetoui/Tab';
30
31
  import Tag from '@bigbinary/neetoui/Tag';
31
32
  import { t as t$1 } from 'i18next';
32
33
  import Alert from '@bigbinary/neetoui/Alert';
34
+ import { FieldArray } from 'formik';
33
35
  import Plus from '@bigbinary/neeto-icons/Plus';
34
36
  import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
35
37
  import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
38
+ import Label from '@bigbinary/neetoui/Label';
36
39
  import Input from '@bigbinary/neetoui/formik/Input';
37
40
  import Form from '@bigbinary/neetoui/formik/Form';
38
41
  import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
39
- import Select from '@bigbinary/neetoui/formik/Select';
40
- import Switch from '@bigbinary/neetoui/formik/Switch';
41
42
  import Textarea from '@bigbinary/neetoui/formik/Textarea';
43
+ import Checkbox from '@bigbinary/neetoui/Checkbox';
42
44
  import * as yup from 'yup';
45
+ import Switch from '@bigbinary/neetoui/Switch';
43
46
  import SubHeader from '@bigbinary/neeto-molecules/SubHeader';
44
47
 
45
48
  var HELP_LINK_URLS = {
@@ -451,7 +454,6 @@ var Deliveries = function Deliveries(_ref) {
451
454
  isFetching = _useFetchDeliveries.isFetching,
452
455
  _useFetchDeliveries$d = _useFetchDeliveries.data,
453
456
  _useFetchDeliveries$d2 = _useFetchDeliveries$d === void 0 ? {} : _useFetchDeliveries$d,
454
- endpoint = _useFetchDeliveries$d2.endpoint,
455
457
  totalCount = _useFetchDeliveries$d2.totalCount,
456
458
  _useFetchDeliveries$d3 = _useFetchDeliveries$d2.deliveries,
457
459
  deliveries = _useFetchDeliveries$d3 === void 0 ? [] : _useFetchDeliveries$d3;
@@ -463,13 +465,10 @@ var Deliveries = function Deliveries(_ref) {
463
465
  text: t("neetoWebhooks.webhook.title")
464
466
  }, {
465
467
  link: window.location.pathname,
466
- text: endpoint
468
+ text: t("neetoWebhooks.delivery.title")
467
469
  }]);
468
470
  if (isLoading) {
469
- return /*#__PURE__*/jsx("div", {
470
- className: "flex h-full w-full items-center justify-center",
471
- children: /*#__PURE__*/jsx(Spinner, {})
472
- });
471
+ return /*#__PURE__*/jsx(PageLoader, {});
473
472
  }
474
473
  return /*#__PURE__*/jsxs(Container, {
475
474
  className: "w-full",
@@ -498,7 +497,7 @@ var Deliveries = function Deliveries(_ref) {
498
497
  rowData: deliveries
499
498
  })
500
499
  }) : /*#__PURE__*/jsx("div", {
501
- className: "flex h-full w-full items-center justify-center",
500
+ className: "flex justify-center items-center w-full h-full",
502
501
  children: /*#__PURE__*/jsx(NoData, {
503
502
  description: t("neetoWebhooks.delivery.empty.description"),
504
503
  title: t("neetoWebhooks.delivery.empty.title")
@@ -614,6 +613,44 @@ var useFetchEvents = function useFetchEvents() {
614
613
  });
615
614
  };
616
615
 
616
+ var MENU_ITEMS = {
617
+ EDIT: "edit",
618
+ DELETE: "delete"
619
+ };
620
+ var WEBHOOK_INITIAL_VALUES = {
621
+ endpoint: "",
622
+ events: [],
623
+ secret: "",
624
+ isActive: true
625
+ };
626
+
627
+ var EventCheckbox = function EventCheckbox(_ref) {
628
+ var events = _ref.events,
629
+ values = _ref.values,
630
+ arrayHelpers = _ref.arrayHelpers;
631
+ var handleToggle = function handleToggle(isSelected, index, event) {
632
+ if (isSelected) {
633
+ arrayHelpers.remove(index);
634
+ } else {
635
+ arrayHelpers.push(event);
636
+ }
637
+ };
638
+ return /*#__PURE__*/jsx("div", {
639
+ children: events.map(function (event) {
640
+ var index = findIndexBy(event, values.events);
641
+ var isSelected = gt(index, -1);
642
+ return /*#__PURE__*/jsx(Checkbox, {
643
+ checked: isSelected,
644
+ className: "my-4",
645
+ label: event.label,
646
+ onChange: function onChange() {
647
+ return handleToggle(isSelected, index, event);
648
+ }
649
+ }, event.identifier);
650
+ })
651
+ });
652
+ };
653
+
617
654
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
618
655
  // require the crypto API and do not support built-in fallback to lower quality random number
619
656
  // generators (like Math.random()).
@@ -678,9 +715,29 @@ function v4(options, buf, offset) {
678
715
  return stringify(rnds);
679
716
  }
680
717
 
681
- var MENU_ITEMS = {
682
- EDIT: "edit",
683
- DELETE: "delete"
718
+ var ToggleActiveSwitch = function ToggleActiveSwitch(_ref) {
719
+ var isActive = _ref.isActive,
720
+ webhookId = _ref.webhookId;
721
+ var _useState = useState(isActive),
722
+ _useState2 = _slicedToArray(_useState, 2),
723
+ status = _useState2[0],
724
+ setStatus = _useState2[1];
725
+ var _useUpdateWebhook = useUpdateWebhook(webhookId),
726
+ updateWebhook = _useUpdateWebhook.mutate;
727
+ var handleToggle = function handleToggle(event) {
728
+ var updatedStatus = event.target.checked;
729
+ setStatus(updatedStatus);
730
+ updateWebhook({
731
+ id: webhookId,
732
+ payload: {
733
+ isActive: updatedStatus
734
+ }
735
+ });
736
+ };
737
+ return /*#__PURE__*/jsx(Switch, {
738
+ checked: status,
739
+ onChange: handleToggle
740
+ });
684
741
  };
685
742
 
686
743
  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 +833,10 @@ var buildColumns = function buildColumns(_ref6) {
776
833
  title: t$1("neetoWebhooks.webhook.active"),
777
834
  key: "isActive",
778
835
  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"
836
+ render: function render(isActive, webhook) {
837
+ return /*#__PURE__*/jsx(ToggleActiveSwitch, {
838
+ isActive: isActive,
839
+ webhookId: webhook.id
786
840
  });
787
841
  },
788
842
  width: 150
@@ -791,7 +845,10 @@ var buildColumns = function buildColumns(_ref6) {
791
845
  dataIndex: "events",
792
846
  key: "events",
793
847
  render: function render(events) {
794
- return pluck("label", events).sort().join(", ");
848
+ return /*#__PURE__*/jsx("span", {
849
+ className: "whitespace-normal",
850
+ children: pluck("label", events).sort().join(", ")
851
+ });
795
852
  },
796
853
  width: 300
797
854
  }];
@@ -838,12 +895,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
838
895
  var _useFetchEvents = useFetchEvents(),
839
896
  events = _useFetchEvents.data,
840
897
  isLoading = _useFetchEvents.isLoading;
841
- var initialValues = editingWebhookId ? webhook : {
842
- endpoint: "",
843
- events: events,
844
- secret: "",
845
- isActive: true
846
- };
898
+ var initialValues = editingWebhookId ? _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), webhook) : _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), {}, {
899
+ events: events
900
+ });
847
901
  var handleSubmit = function handleSubmit(values) {
848
902
  var payload = buildPayload({
849
903
  isEditing: editingWebhookId,
@@ -906,7 +960,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
906
960
  },
907
961
  children: function children(_ref2) {
908
962
  var setFieldValue = _ref2.setFieldValue,
909
- values = _ref2.values;
963
+ values = _ref2.values,
964
+ touched = _ref2.touched,
965
+ errors = _ref2.errors;
910
966
  return isLoading ? /*#__PURE__*/jsx("div", {
911
967
  className: "flex items-center justify-center",
912
968
  children: /*#__PURE__*/jsx(Spinner, {})
@@ -923,18 +979,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
923
979
  placeholder: t("neetoWebhooks.webhook.endpointPlaceholder"),
924
980
  ref: endpointRef,
925
981
  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
982
  }), /*#__PURE__*/jsxs("div", {
936
983
  className: "space-y-2",
937
- children: [/*#__PURE__*/jsxs("span", {
984
+ children: [/*#__PURE__*/jsxs(Label, {
938
985
  className: "flex items-center gap-x-2",
939
986
  children: [t("neetoWebhooks.webhook.secret"), /*#__PURE__*/jsx(HelpPopover, {
940
987
  helpLinkProps: {
@@ -980,15 +1027,24 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
980
1027
  }
981
1028
  })]
982
1029
  }), /*#__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")
1030
+ className: "space-y-2",
1031
+ children: [/*#__PURE__*/jsx(Label, {
1032
+ required: true,
1033
+ children: t("neetoWebhooks.common.event", PLURAL)
1034
+ }), !isLoading && /*#__PURE__*/jsx(FieldArray, {
1035
+ name: "events",
1036
+ render: function render(arrayHelpers) {
1037
+ return /*#__PURE__*/jsxs("div", {
1038
+ children: [/*#__PURE__*/jsx(EventCheckbox, {
1039
+ arrayHelpers: arrayHelpers,
1040
+ events: events,
1041
+ values: values
1042
+ }), touched.events && errors.events && /*#__PURE__*/jsx("div", {
1043
+ className: "neeto-ui-text-error-800 text-xs mt-1",
1044
+ children: errors.events
1045
+ })]
1046
+ });
1047
+ }
992
1048
  })]
993
1049
  })]
994
1050
  })
@@ -1117,10 +1173,7 @@ var Webhooks = function Webhooks(_ref) {
1117
1173
  setIsDeleteAlertOpen(true);
1118
1174
  }, []);
1119
1175
  if (isLoading) {
1120
- return /*#__PURE__*/jsx("div", {
1121
- className: "flex h-full w-full items-center justify-center",
1122
- children: /*#__PURE__*/jsx(Spinner, {})
1123
- });
1176
+ return /*#__PURE__*/jsx(PageLoader, {});
1124
1177
  }
1125
1178
  return /*#__PURE__*/jsxs(Container, {
1126
1179
  className: containerClassName,
@@ -1148,7 +1201,7 @@ var Webhooks = function Webhooks(_ref) {
1148
1201
  })
1149
1202
  })
1150
1203
  }) : /*#__PURE__*/jsx("div", {
1151
- className: "flex h-full w-full items-center justify-center",
1204
+ className: "flex justify-center items-center w-full h-full",
1152
1205
  children: /*#__PURE__*/jsx(NoData, {
1153
1206
  title: t("neetoWebhooks.webhook.empty"),
1154
1207
  helpText: /*#__PURE__*/jsx(Button, {