@bigbinary/neeto-webhooks-frontend 2.2.15 → 2.2.17

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.
@@ -296,6 +296,7 @@ var TransactionDetails = function TransactionDetails(_ref) {
296
296
  };
297
297
 
298
298
  var Details = function Details(_ref) {
299
+ var _delivery$webhook;
299
300
  var onClose = _ref.onClose,
300
301
  deliveryId = _ref.deliveryId,
301
302
  webhookSid = _ref.webhookSid;
@@ -366,7 +367,7 @@ var Details = function Details(_ref) {
366
367
  }), /*#__PURE__*/jsxRuntime.jsxs(Pane.Footer, {
367
368
  className: "gap-x-2",
368
369
  children: [(delivery === null || delivery === void 0 ? void 0 : delivery.eventId) && /*#__PURE__*/jsxRuntime.jsx(Button, {
369
- disabled: isRedelivering,
370
+ disabled: isRedelivering || ((_delivery$webhook = delivery.webhook) === null || _delivery$webhook === void 0 ? void 0 : _delivery$webhook.versionExpired),
370
371
  label: t("neetoWebhooks.delivery.redeliver"),
371
372
  loading: isRedelivering,
372
373
  style: "primary",
@@ -605,6 +606,10 @@ var useUpdateWebhook = function useUpdateWebhook(id, options) {
605
606
  onSuccess: function onSuccess() {
606
607
  var _options$onSuccess2;
607
608
  options === null || options === void 0 || (_options$onSuccess2 = options.onSuccess) === null || _options$onSuccess2 === void 0 || _options$onSuccess2.call(options);
609
+ },
610
+ onError: function onError(error) {
611
+ var _options$onError;
612
+ options === null || options === void 0 || (_options$onError = options.onError) === null || _options$onError === void 0 || _options$onError.call(options, error);
608
613
  }
609
614
  });
610
615
  };
@@ -743,10 +748,22 @@ var ToggleActiveSwitch = function ToggleActiveSwitch(_ref) {
743
748
  _useState2 = _slicedToArray(_useState, 2),
744
749
  status = _useState2[0],
745
750
  setStatus = _useState2[1];
746
- var _useUpdateWebhook = useUpdateWebhook(webhookId),
751
+ var previousStatusRef = react.useRef(isActive);
752
+ var _useUpdateWebhook = useUpdateWebhook(webhookId, {
753
+ onError: function onError() {
754
+ // Revert to the previous state
755
+ setStatus(previousStatusRef.current);
756
+ },
757
+ onSuccess: function onSuccess() {
758
+ // Update the previous status ref on successful update
759
+ previousStatusRef.current = status;
760
+ }
761
+ }),
747
762
  updateWebhook = _useUpdateWebhook.mutate;
748
763
  var handleToggle = function handleToggle(event) {
749
764
  var updatedStatus = event.target.checked;
765
+ // Store the current status as previous before changing
766
+ previousStatusRef.current = status;
750
767
  setStatus(updatedStatus);
751
768
  updateWebhook({
752
769
  id: webhookId,
@@ -817,6 +834,35 @@ var buildPayload = function buildPayload(_ref2) {
817
834
  eventsAttributes: [].concat(_toConsumableArray(creatable), _toConsumableArray(deletable))
818
835
  });
819
836
  };
837
+ var formatTimeUntilExpiration = function formatTimeUntilExpiration(expiresAt) {
838
+ if (!expiresAt) return null;
839
+ var now = new Date();
840
+ var expiry = new Date(expiresAt);
841
+ var diffMs = expiry - now;
842
+ if (diffMs <= 0) return null;
843
+ var diffHours = Math.floor(diffMs / (1000 * 60 * 60));
844
+ var diffDays = Math.floor(diffHours / 24);
845
+ if (diffDays > 0) {
846
+ return i18next.t("neetoWebhooks.webhook.versionStatus.expiresIn.days", {
847
+ count: diffDays
848
+ });
849
+ }
850
+ var remainingHours = diffHours;
851
+ var remainingMinutes = Math.floor(diffMs % (1000 * 60 * 60) / (1000 * 60));
852
+ return i18next.t("neetoWebhooks.webhook.versionStatus.expiresIn.hoursAndMinutes", {
853
+ hours: remainingHours,
854
+ hoursPlural: remainingHours !== 1 ? "s" : "",
855
+ minutes: remainingMinutes,
856
+ minutesPlural: remainingMinutes !== 1 ? "s" : ""
857
+ });
858
+ };
859
+ var formatExpiredDate = function formatExpiredDate(expiresAt) {
860
+ if (!expiresAt) return null;
861
+ var expiry = new Date(expiresAt);
862
+ return i18next.t("neetoWebhooks.webhook.versionStatus.expiredOn", {
863
+ date: expiry.toLocaleDateString()
864
+ });
865
+ };
820
866
  var buildColumns = function buildColumns(_ref6) {
821
867
  var handleDelete = _ref6.handleDelete,
822
868
  handleEdit = _ref6.handleEdit,
@@ -861,6 +907,38 @@ var buildColumns = function buildColumns(_ref6) {
861
907
  });
862
908
  },
863
909
  width: 150
910
+ }, {
911
+ title: i18next.t("neetoWebhooks.webhook.version"),
912
+ dataIndex: "version",
913
+ key: "version",
914
+ render: function render(version, webhook) {
915
+ var timeMessage = webhook.versionExpired ? formatExpiredDate(webhook.versionExpiresAt) : formatTimeUntilExpiration(webhook.versionExpiresAt);
916
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
917
+ className: "flex flex-col space-y-1",
918
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
919
+ className: "flex items-center space-x-2",
920
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
921
+ children: version
922
+ }), webhook.versionExpired && /*#__PURE__*/jsxRuntime.jsx(Tag, {
923
+ label: "expired",
924
+ style: "danger"
925
+ }), webhook.versionDeprecated && !webhook.versionExpired && /*#__PURE__*/jsxRuntime.jsx(Tag, {
926
+ label: "deprecated",
927
+ style: "warning"
928
+ })]
929
+ }), timeMessage && /*#__PURE__*/jsxRuntime.jsxs("div", {
930
+ className: "text-xs neeto-ui-text-gray-600",
931
+ children: [timeMessage, ".", " ", /*#__PURE__*/jsxRuntime.jsx("a", {
932
+ className: "text-blue-600 hover:text-blue-800 underline",
933
+ href: webhook.defaultVersionPayloadDocUrl,
934
+ rel: "noopener noreferrer",
935
+ target: "_blank",
936
+ children: i18next.t("neetoWebhooks.webhook.versionStatus.moreDetails")
937
+ }), "."]
938
+ })]
939
+ });
940
+ },
941
+ width: 200
864
942
  }, {
865
943
  title: i18next.t("neetoWebhooks.common.event", constants.PLURAL),
866
944
  dataIndex: "events",
@@ -919,7 +997,12 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
919
997
  var initialValues = editingWebhookId ? _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), webhook) : _objectSpread$1(_objectSpread$1({}, WEBHOOK_INITIAL_VALUES), {}, {
920
998
  events: events
921
999
  });
1000
+ var isWebhookExpiredOrDeprecated = editingWebhookId && (webhook.versionExpired || webhook.versionDeprecated);
922
1001
  var handleSubmit = function handleSubmit(values) {
1002
+ // Check if webhook is expired or deprecated before allowing edit
1003
+ if (editingWebhookId && (webhook.versionExpired || webhook.versionDeprecated)) {
1004
+ return;
1005
+ }
923
1006
  var payload = buildPayload({
924
1007
  isEditing: editingWebhookId,
925
1008
  values: values,
@@ -1062,6 +1145,7 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
1062
1145
  values: values
1063
1146
  }), touched.events && errors.events && /*#__PURE__*/jsxRuntime.jsx("div", {
1064
1147
  className: "neeto-ui-text-error-800 text-xs mt-1",
1148
+ "data-cy": "event-error-text",
1065
1149
  children: errors.events
1066
1150
  })]
1067
1151
  });
@@ -1073,6 +1157,9 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
1073
1157
  children: /*#__PURE__*/jsxRuntime.jsx(ActionBlock, {
1074
1158
  cancelButtonProps: {
1075
1159
  onClick: onClose
1160
+ },
1161
+ submitButtonProps: {
1162
+ disabled: isWebhookExpiredOrDeprecated
1076
1163
  }
1077
1164
  })
1078
1165
  })]