@bigbinary/neeto-webhooks-frontend 3.0.8 → 3.0.10

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.
@@ -24,13 +24,13 @@ import DateFormat from '@bigbinary/neeto-molecules/DateFormat';
24
24
  import Button from '@bigbinary/neetoui/Button';
25
25
  import Pane from '@bigbinary/neetoui/Pane';
26
26
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
27
- import { useState, useRef, useEffect, memo, useCallback } from 'react';
27
+ import { useState, useRef, useMemo, useEffect, memo, useCallback } from 'react';
28
28
  import Typography from '@bigbinary/neetoui/Typography';
29
29
  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
+ import { FieldArray, ErrorMessage } from 'formik';
34
34
  import Plus from '@bigbinary/neeto-icons/Plus';
35
35
  import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
36
36
  import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
@@ -634,13 +634,15 @@ var WEBHOOK_INITIAL_VALUES = {
634
634
  var EventCheckbox = function EventCheckbox(_ref) {
635
635
  var events = _ref.events,
636
636
  values = _ref.values,
637
- arrayHelpers = _ref.arrayHelpers;
637
+ arrayHelpers = _ref.arrayHelpers,
638
+ onEventsChange = _ref.onEventsChange;
638
639
  var handleToggle = function handleToggle(isSelected, index, event) {
639
640
  if (isSelected) {
640
641
  arrayHelpers.remove(index);
641
642
  } else {
642
643
  arrayHelpers.push(event);
643
644
  }
645
+ onEventsChange === null || onEventsChange === void 0 || onEventsChange();
644
646
  };
645
647
  return /*#__PURE__*/jsx("div", {
646
648
  children: events.map(function (event) {
@@ -781,7 +783,7 @@ var getValidationSchema = function getValidationSchema(webhooks) {
781
783
  endpoint: yup.string().trim().matches(/^(https?):\/\//i, t$1("neetoWebhooks.errors.webhook.invalidUrlProtocol")).url(t$1("neetoWebhooks.errors.webhook.invalidUrl")).required(t$1("neetoWebhooks.errors.webhook.required")).test("Is endpoint unique", t$1("neetoWebhooks.errors.webhook.urlNotUnique"), function (endpoint, ctx) {
782
784
  return !pluck("endpoint", removeById(ctx.parent.id, webhooks)).includes(endpoint === null || endpoint === void 0 ? void 0 : endpoint.trim());
783
785
  }),
784
- events: yup.array().min(1, t$1("neetoWebhooks.errors.webhook.events.required")),
786
+ events: yup.array()["default"]([]).min(1, t$1("neetoWebhooks.errors.webhook.events.required")),
785
787
  secret: yup.string().trim().nullable()
786
788
  });
787
789
  };
@@ -982,9 +984,13 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
982
984
  _useFetchEvents$data = _useFetchEvents.data,
983
985
  events = _useFetchEvents$data === void 0 ? [] : _useFetchEvents$data,
984
986
  isLoading = _useFetchEvents.isLoading;
985
- var initialValues = editingWebhookId ? _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), webhook) : _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), {}, {
986
- events: events
987
- });
987
+ var initialValues = useMemo(function () {
988
+ return editingWebhookId ? _objectSpread$1(_objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), webhook), {}, {
989
+ events: Array.isArray(webhook === null || webhook === void 0 ? void 0 : webhook.events) ? webhook === null || webhook === void 0 ? void 0 : webhook.events : []
990
+ }) : _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), {}, {
991
+ events: events
992
+ });
993
+ }, [editingWebhookId, webhook, events]);
988
994
  var isWebhookExpiredOrDeprecated = editingWebhookId && (webhook.versionExpired || webhook.versionDeprecated);
989
995
  var handleSubmit = function handleSubmit(values) {
990
996
  // Check if webhook is expired or deprecated before allowing edit
@@ -1052,10 +1058,10 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
1052
1058
  },
1053
1059
  children: function children(_ref2) {
1054
1060
  var setFieldValue = _ref2.setFieldValue,
1061
+ setFieldTouched = _ref2.setFieldTouched,
1055
1062
  values = _ref2.values,
1056
- touched = _ref2.touched,
1057
- errors = _ref2.errors,
1058
- isValid = _ref2.isValid;
1063
+ isValid = _ref2.isValid,
1064
+ dirty = _ref2.dirty;
1059
1065
  return isLoading ? /*#__PURE__*/jsx("div", {
1060
1066
  className: "flex items-center justify-center",
1061
1067
  children: /*#__PURE__*/jsx(Spinner, {})
@@ -1128,19 +1134,25 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
1128
1134
  children: [/*#__PURE__*/jsx(Label, {
1129
1135
  required: true,
1130
1136
  children: t("neetoWebhooks.common.event", PLURAL)
1131
- }), !isLoading && /*#__PURE__*/jsx(FieldArray, {
1137
+ }), /*#__PURE__*/jsx(FieldArray, {
1132
1138
  name: "events",
1133
1139
  render: function render(arrayHelpers) {
1134
- return /*#__PURE__*/jsxs("div", {
1135
- children: [/*#__PURE__*/jsx(EventCheckbox, {
1136
- arrayHelpers: arrayHelpers,
1137
- events: events,
1138
- values: values
1139
- }), touched.events && errors.events && /*#__PURE__*/jsx("div", {
1140
- className: "neeto-ui-text-error-800 text-xs mt-1",
1141
- "data-testid": "event-error-text",
1142
- children: errors.events
1143
- })]
1140
+ return /*#__PURE__*/jsx(EventCheckbox, {
1141
+ arrayHelpers: arrayHelpers,
1142
+ events: events,
1143
+ values: values,
1144
+ onEventsChange: function onEventsChange() {
1145
+ return setFieldTouched("events", true);
1146
+ }
1147
+ });
1148
+ }
1149
+ }), /*#__PURE__*/jsx(ErrorMessage, {
1150
+ name: "events",
1151
+ render: function render(msg) {
1152
+ return /*#__PURE__*/jsx("div", {
1153
+ className: "neeto-ui-text-error-800 text-xs mt-1",
1154
+ "data-testid": "event-error-text",
1155
+ children: msg
1144
1156
  });
1145
1157
  }
1146
1158
  })]
@@ -1152,7 +1164,7 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
1152
1164
  onClick: onClose
1153
1165
  },
1154
1166
  submitButtonProps: {
1155
- disabled: isWebhookExpiredOrDeprecated || !isValid
1167
+ disabled: isWebhookExpiredOrDeprecated || !isValid || editingWebhookId && !dirty
1156
1168
  }
1157
1169
  })
1158
1170
  })]