@bigbinary/neeto-molecules 1.0.0

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.
Files changed (45) hide show
  1. package/README.md +36 -0
  2. package/dist/BrowserSupport.cjs.js +1468 -0
  3. package/dist/BrowserSupport.js +1462 -0
  4. package/dist/Columns.cjs.js +183 -0
  5. package/dist/Columns.js +177 -0
  6. package/dist/CustomDomain.cjs.js +758 -0
  7. package/dist/CustomDomain.js +732 -0
  8. package/dist/DateRangeFilter.cjs.js +214 -0
  9. package/dist/DateRangeFilter.js +207 -0
  10. package/dist/EmailPreview.cjs.js +32409 -0
  11. package/dist/EmailPreview.js +32383 -0
  12. package/dist/ErrorPage.cjs.js +135 -0
  13. package/dist/ErrorPage.js +111 -0
  14. package/dist/IpRestriction.cjs.js +3578 -0
  15. package/dist/IpRestriction.js +3552 -0
  16. package/dist/KeyboardShortcuts.cjs.js +2212 -0
  17. package/dist/KeyboardShortcuts.js +2205 -0
  18. package/dist/LoginPage.cjs.js +598 -0
  19. package/dist/LoginPage.js +573 -0
  20. package/dist/NeetoWidget.cjs.js +86969 -0
  21. package/dist/NeetoWidget.js +86943 -0
  22. package/dist/PublishBlock.cjs.js +188 -0
  23. package/dist/PublishBlock.js +182 -0
  24. package/dist/Schedule.cjs.js +949 -0
  25. package/dist/Schedule.js +918 -0
  26. package/dist/ShareViaLink.cjs.js +1247 -0
  27. package/dist/ShareViaLink.js +1241 -0
  28. package/dist/Sidebar.cjs.js +222 -0
  29. package/dist/Sidebar.js +195 -0
  30. package/package.json +149 -0
  31. package/src/translations/en.json +244 -0
  32. package/types/BrowserSupport.d.ts +20 -0
  33. package/types/Columns.d.ts +22 -0
  34. package/types/CustomDomain.d.ts +7 -0
  35. package/types/DateRangeFilter.d.ts +17 -0
  36. package/types/EmailPreview.d.ts +11 -0
  37. package/types/ErrorPage.d.ts +8 -0
  38. package/types/IpRestriction.d.ts +5 -0
  39. package/types/KeyboardShortcuts.d.ts +21 -0
  40. package/types/LoginPage.d.ts +12 -0
  41. package/types/NeetoWidget.d.ts +17 -0
  42. package/types/PublishBlock.d.ts +20 -0
  43. package/types/Schedule.d.ts +15 -0
  44. package/types/ShareViaLink.d.ts +17 -0
  45. package/types/Sidebar.d.ts +28 -0
@@ -0,0 +1,758 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var pure = require('@bigbinary/neeto-commons-frontend/pure');
5
+ var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
6
+ var neetoui = require('@bigbinary/neetoui');
7
+ var layouts = require('@bigbinary/neetoui/layouts');
8
+ var reactI18next = require('react-i18next');
9
+ var neetoIcons = require('@bigbinary/neeto-icons');
10
+ var formik$1 = require('@bigbinary/neetoui/formik');
11
+ var formik = require('formik');
12
+ var utils = require('@bigbinary/neeto-commons-frontend/utils');
13
+ var i18next = require('i18next');
14
+ var Yup = require('yup');
15
+ var reactQuery = require('react-query');
16
+ var axios = require('axios');
17
+
18
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
+
20
+ function _interopNamespace(e) {
21
+ if (e && e.__esModule) return e;
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n["default"] = e;
35
+ return Object.freeze(n);
36
+ }
37
+
38
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
39
+ var Yup__namespace = /*#__PURE__*/_interopNamespace(Yup);
40
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
41
+
42
+ function _extends() {
43
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
44
+ for (var i = 1; i < arguments.length; i++) {
45
+ var source = arguments[i];
46
+ for (var key in source) {
47
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
48
+ target[key] = source[key];
49
+ }
50
+ }
51
+ }
52
+ return target;
53
+ };
54
+ return _extends.apply(this, arguments);
55
+ }
56
+
57
+ function _arrayWithHoles(arr) {
58
+ if (Array.isArray(arr)) return arr;
59
+ }
60
+
61
+ function _iterableToArrayLimit(arr, i) {
62
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
63
+ if (null != _i) {
64
+ var _s,
65
+ _e,
66
+ _x,
67
+ _r,
68
+ _arr = [],
69
+ _n = !0,
70
+ _d = !1;
71
+ try {
72
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
73
+ if (Object(_i) !== _i) return;
74
+ _n = !1;
75
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
76
+ } catch (err) {
77
+ _d = !0, _e = err;
78
+ } finally {
79
+ try {
80
+ if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
81
+ } finally {
82
+ if (_d) throw _e;
83
+ }
84
+ }
85
+ return _arr;
86
+ }
87
+ }
88
+
89
+ function _arrayLikeToArray(arr, len) {
90
+ if (len == null || len > arr.length) len = arr.length;
91
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
92
+ return arr2;
93
+ }
94
+
95
+ function _unsupportedIterableToArray(o, minLen) {
96
+ if (!o) return;
97
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
98
+ var n = Object.prototype.toString.call(o).slice(8, -1);
99
+ if (n === "Object" && o.constructor) n = o.constructor.name;
100
+ if (n === "Map" || n === "Set") return Array.from(o);
101
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
102
+ }
103
+
104
+ function _nonIterableRest() {
105
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
106
+ }
107
+
108
+ function _slicedToArray(arr, i) {
109
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
110
+ }
111
+
112
+ var DEFAULT_STALE_TIME = 60 * 60 * 1000;
113
+ var DOMAIN_QUERY_KEY = "custom-domain";
114
+ var ENTITY_COUNT = {
115
+ singular: 1,
116
+ plural: 2
117
+ };
118
+
119
+ var HOSTNAME_REGEX = /^(?!-)[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+/;
120
+ var INITIAL_VALUES = {
121
+ hostname: ""
122
+ };
123
+
124
+ var classnames$1 = {exports: {}};
125
+
126
+ /*!
127
+ Copyright (c) 2018 Jed Watson.
128
+ Licensed under the MIT License (MIT), see
129
+ http://jedwatson.github.io/classnames
130
+ */
131
+
132
+ (function (module) {
133
+ /* global define */
134
+
135
+ (function () {
136
+
137
+ var hasOwn = {}.hasOwnProperty;
138
+
139
+ function classNames() {
140
+ var classes = [];
141
+
142
+ for (var i = 0; i < arguments.length; i++) {
143
+ var arg = arguments[i];
144
+ if (!arg) continue;
145
+
146
+ var argType = typeof arg;
147
+
148
+ if (argType === 'string' || argType === 'number') {
149
+ classes.push(arg);
150
+ } else if (Array.isArray(arg)) {
151
+ if (arg.length) {
152
+ var inner = classNames.apply(null, arg);
153
+ if (inner) {
154
+ classes.push(inner);
155
+ }
156
+ }
157
+ } else if (argType === 'object') {
158
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {
159
+ classes.push(arg.toString());
160
+ continue;
161
+ }
162
+
163
+ for (var key in arg) {
164
+ if (hasOwn.call(arg, key) && arg[key]) {
165
+ classes.push(key);
166
+ }
167
+ }
168
+ }
169
+ }
170
+
171
+ return classes.join(' ');
172
+ }
173
+
174
+ if (module.exports) {
175
+ classNames.default = classNames;
176
+ module.exports = classNames;
177
+ } else {
178
+ window.classNames = classNames;
179
+ }
180
+ }());
181
+ } (classnames$1));
182
+
183
+ var classnames = classnames$1.exports;
184
+
185
+ var TagBlock = function TagBlock(_ref) {
186
+ var status = _ref.status,
187
+ isCnameRecordsAdded = _ref.isCnameRecordsAdded,
188
+ _ref$stacked = _ref.stacked,
189
+ stacked = _ref$stacked === void 0 ? false : _ref$stacked,
190
+ handleValidateCname = _ref.handleValidateCname;
191
+ var _useTranslation = reactI18next.useTranslation(),
192
+ t = _useTranslation.t;
193
+ var isTxtValidated = status === "active" || status === "pending_cname_validation";
194
+ var camelCasedStatus = pure.snakeToCamelCase(status || "");
195
+ return /*#__PURE__*/React__default["default"].createElement("div", {
196
+ className: classnames("flex gap-2", {
197
+ "flex-col items-start": stacked
198
+ })
199
+ }, status === "failed" ? /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
200
+ indicatorStyle: "danger",
201
+ label: t("neetoMolecules.customDomain.status.".concat(camelCasedStatus)),
202
+ style: "secondary"
203
+ }) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
204
+ indicatorStyle: isTxtValidated ? "success" : "warning",
205
+ style: "secondary",
206
+ label: t("neetoMolecules.customDomain.status.txt.".concat(camelCasedStatus))
207
+ }), isTxtValidated && /*#__PURE__*/React__default["default"].createElement("div", {
208
+ className: classnames("flex items-center justify-between gap-2", {
209
+ "w-full": stacked
210
+ })
211
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
212
+ indicatorStyle: status === "active" ? "success" : "warning",
213
+ style: "secondary",
214
+ label: t("neetoMolecules.customDomain.status.cname.".concat(camelCasedStatus))
215
+ }), isCnameRecordsAdded && status === "pending_cname_validation" && /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
216
+ className: "text-xs",
217
+ style: "link",
218
+ label: t("neetoMolecules.customDomain.validation.buttonLabel.cnameCheck"),
219
+ onClick: handleValidateCname
220
+ }))));
221
+ };
222
+
223
+ var Menu = neetoui.Dropdown.Menu,
224
+ MenuItem = neetoui.Dropdown.MenuItem;
225
+ var renderColumnData = function renderColumnData(enableManagePane, enableDeleteAlert) {
226
+ return [{
227
+ title: i18next.t("neetoMolecules.customDomain.customDomain", {
228
+ count: ENTITY_COUNT.singular
229
+ }),
230
+ dataIndex: "hostname",
231
+ key: "hostname"
232
+ }, {
233
+ title: i18next.t("neetoMolecules.common.status"),
234
+ dataIndex: "status",
235
+ key: "status",
236
+ render: function render(status) {
237
+ return /*#__PURE__*/React__default["default"].createElement(TagBlock, {
238
+ status: status
239
+ });
240
+ },
241
+ width: "40%"
242
+ }, {
243
+ id: "actions",
244
+ width: "10%",
245
+ render: function render(_, customDomain) {
246
+ return /*#__PURE__*/React__default["default"].createElement("div", {
247
+ onClick: function onClick(e) {
248
+ return e.stopPropagation();
249
+ }
250
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Dropdown, {
251
+ autoWidth: true,
252
+ buttonProps: {
253
+ style: "text"
254
+ },
255
+ icon: neetoIcons.MenuHorizontal,
256
+ position: "bottom-end",
257
+ strategy: "fixed"
258
+ }, /*#__PURE__*/React__default["default"].createElement(Menu, null, /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
259
+ onClick: function onClick() {
260
+ return enableManagePane(customDomain);
261
+ }
262
+ }, i18next.t("neetoMolecules.common.actions.edit")), /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
263
+ onClick: function onClick() {
264
+ return enableDeleteAlert(customDomain);
265
+ }
266
+ }, i18next.t("neetoMolecules.common.actions.delete")))));
267
+ }
268
+ }];
269
+ };
270
+ var recordData = function recordData(customDomain) {
271
+ var status = customDomain.status,
272
+ hostname = customDomain.hostname,
273
+ dnsTarget = customDomain.dnsTarget,
274
+ txtValue = customDomain.txtValue;
275
+ var isTxtValidated = status === "active" || status === "pending_cname_validation";
276
+ var recordName = isTxtValidated ? hostname : "_acme-challenge.".concat(hostname);
277
+ var recordValue = isTxtValidated ? dnsTarget : txtValue;
278
+ var recordType = isTxtValidated ? "CNAME" : "TXT";
279
+ var recordDescription = i18next.t("neetoMolecules.customDomain.validation.desc", {
280
+ record: recordType
281
+ });
282
+ var recordNameLabel = i18next.t("neetoMolecules.customDomain.validation.record", {
283
+ record: recordType,
284
+ type: i18next.t("neetoMolecules.common.name")
285
+ });
286
+ var recordValueLabel = i18next.t("neetoMolecules.customDomain.validation.record", {
287
+ record: recordType,
288
+ type: i18next.t("neetoMolecules.common.value")
289
+ });
290
+ return {
291
+ recordName: recordName,
292
+ recordValue: recordValue,
293
+ recordDescription: recordDescription,
294
+ recordNameLabel: recordNameLabel,
295
+ recordValueLabel: recordValueLabel
296
+ };
297
+ };
298
+
299
+ var Record = function Record(_ref) {
300
+ var customDomain = _ref.customDomain;
301
+ var _recordData = recordData(customDomain),
302
+ recordName = _recordData.recordName,
303
+ recordValue = _recordData.recordValue,
304
+ recordDescription = _recordData.recordDescription,
305
+ recordNameLabel = _recordData.recordNameLabel,
306
+ recordValueLabel = _recordData.recordValueLabel;
307
+ return /*#__PURE__*/React__default["default"].createElement("div", {
308
+ className: "grid gap-4 mt-6"
309
+ }, customDomain.status !== "active" && /*#__PURE__*/React__default["default"].createElement(neetoui.Callout, {
310
+ icon: neetoIcons.Info,
311
+ style: "info"
312
+ }, recordDescription), /*#__PURE__*/React__default["default"].createElement(neetoui.Input, {
313
+ disabled: true,
314
+ "data-cy": utils.joinHyphenCase(recordNameLabel),
315
+ label: recordNameLabel,
316
+ value: recordName,
317
+ suffix: /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
318
+ icon: neetoIcons.Copy,
319
+ style: "text",
320
+ onClick: function onClick() {
321
+ return utils.copyToClipboard(recordName);
322
+ }
323
+ })
324
+ }), /*#__PURE__*/React__default["default"].createElement(neetoui.Input, {
325
+ disabled: true,
326
+ "data-cy": utils.joinHyphenCase(recordValueLabel),
327
+ label: recordValueLabel,
328
+ value: recordValue,
329
+ suffix: /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
330
+ icon: neetoIcons.Copy,
331
+ style: "text",
332
+ onClick: function onClick() {
333
+ return utils.copyToClipboard(recordValue);
334
+ }
335
+ })
336
+ }));
337
+ };
338
+
339
+ var CustomDomainInfo = function CustomDomainInfo(_ref) {
340
+ var time = _ref.time;
341
+ var _useTranslation = reactI18next.useTranslation(),
342
+ t = _useTranslation.t;
343
+ return /*#__PURE__*/React__default["default"].createElement("div", {
344
+ className: "space-y-6"
345
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
346
+ className: "p-4 neeto-ui-rounded neeto-ui-bg-gray-100 space-y-3 neeto-ui-text-gray-700"
347
+ }, /*#__PURE__*/React__default["default"].createElement(reactI18next.Trans, {
348
+ i18nKey: "neetoMolecules.customDomain.messageBlock.dnsStatus"
349
+ }), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
350
+ href: "mailto:support@neeto.com",
351
+ label: "support@neeto.com",
352
+ style: "link"
353
+ })), /*#__PURE__*/React__default["default"].createElement(neetoui.Callout, {
354
+ icon: neetoIcons.Info,
355
+ style: "info"
356
+ }, t("neetoMolecules.customDomain.messageBlock.cnameAddedTime", {
357
+ time: utils.timeFormat.fromNow(time)
358
+ })));
359
+ };
360
+
361
+ var getCustomDomainValidationSchema = function getCustomDomainValidationSchema() {
362
+ return Yup__namespace.object().shape({
363
+ hostname: Yup__namespace.string().required(i18next.t("neetoMolecules.customDomain.formikValidation.required")).matches(HOSTNAME_REGEX, i18next.t("neetoMolecules.customDomain.formikValidation.valid"))
364
+ });
365
+ };
366
+
367
+ function _typeof(obj) {
368
+ "@babel/helpers - typeof";
369
+
370
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
371
+ return typeof obj;
372
+ } : function (obj) {
373
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
374
+ }, _typeof(obj);
375
+ }
376
+
377
+ function _toPrimitive(input, hint) {
378
+ if (_typeof(input) !== "object" || input === null) return input;
379
+ var prim = input[Symbol.toPrimitive];
380
+ if (prim !== undefined) {
381
+ var res = prim.call(input, hint || "default");
382
+ if (_typeof(res) !== "object") return res;
383
+ throw new TypeError("@@toPrimitive must return a primitive value.");
384
+ }
385
+ return (hint === "string" ? String : Number)(input);
386
+ }
387
+
388
+ function _toPropertyKey(arg) {
389
+ var key = _toPrimitive(arg, "string");
390
+ return _typeof(key) === "symbol" ? key : String(key);
391
+ }
392
+
393
+ function _defineProperty(obj, key, value) {
394
+ key = _toPropertyKey(key);
395
+ if (key in obj) {
396
+ Object.defineProperty(obj, key, {
397
+ value: value,
398
+ enumerable: true,
399
+ configurable: true,
400
+ writable: true
401
+ });
402
+ } else {
403
+ obj[key] = value;
404
+ }
405
+ return obj;
406
+ }
407
+
408
+ var customDomainsUrl = "custom_domains/domains";
409
+ var fetchCustomDomains = function fetchCustomDomains(payload) {
410
+ return axios__default["default"].get(customDomainsUrl, {
411
+ params: payload
412
+ });
413
+ };
414
+ var updateCustomDomain = function updateCustomDomain(id) {
415
+ return axios__default["default"].patch("".concat(customDomainsUrl, "/").concat(id));
416
+ };
417
+ var createCustomDomain = function createCustomDomain(payload) {
418
+ return axios__default["default"].post(customDomainsUrl, payload);
419
+ };
420
+ var deleteCustomDomain = function deleteCustomDomain(id) {
421
+ return axios__default["default"]["delete"]("".concat(customDomainsUrl, "/").concat(id));
422
+ };
423
+ var validateTxt = function validateTxt(id) {
424
+ return axios__default["default"].patch("".concat(customDomainsUrl, "/").concat(id, "/validate_txt"));
425
+ };
426
+ var validateCname = function validateCname(id) {
427
+ return axios__default["default"].patch("".concat(customDomainsUrl, "/").concat(id, "/validate_cname"));
428
+ };
429
+ var customDomainApi = {
430
+ createCustomDomain: createCustomDomain,
431
+ deleteCustomDomain: deleteCustomDomain,
432
+ validateTxt: validateTxt,
433
+ fetchCustomDomains: fetchCustomDomains,
434
+ validateCname: validateCname,
435
+ updateCustomDomain: updateCustomDomain
436
+ };
437
+
438
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
439
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
440
+ var useCreateCustomDomain = function useCreateCustomDomain() {
441
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
442
+ var queryClient = reactQuery.useQueryClient();
443
+ return reactQuery.useMutation(function (payload) {
444
+ return customDomainApi.createCustomDomain(payload);
445
+ }, _objectSpread(_objectSpread({}, options), {}, {
446
+ onSuccess: function onSuccess() {
447
+ return queryClient.invalidateQueries(DOMAIN_QUERY_KEY);
448
+ }
449
+ }));
450
+ };
451
+ var useDeleteCustomDomain = function useDeleteCustomDomain() {
452
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
453
+ var queryClient = reactQuery.useQueryClient();
454
+ return reactQuery.useMutation(function (id) {
455
+ return customDomainApi.deleteCustomDomain(id);
456
+ }, _objectSpread(_objectSpread({}, options), {}, {
457
+ onSuccess: function onSuccess(result) {
458
+ var _options$onSuccess;
459
+ (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call(options, result);
460
+ queryClient.invalidateQueries(DOMAIN_QUERY_KEY);
461
+ }
462
+ }));
463
+ };
464
+ var useFetchCustomDomains = function useFetchCustomDomains(payload) {
465
+ return reactQuery.useQuery([DOMAIN_QUERY_KEY, _objectSpread({}, payload)], function () {
466
+ return customDomainApi.fetchCustomDomains(payload);
467
+ }, {
468
+ staleTime: DEFAULT_STALE_TIME
469
+ });
470
+ };
471
+ var useValidateTxt = function useValidateTxt() {
472
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
473
+ var queryClient = reactQuery.useQueryClient();
474
+ return reactQuery.useMutation(function (id) {
475
+ return customDomainApi.validateTxt(id);
476
+ }, _objectSpread(_objectSpread({}, options), {}, {
477
+ onSuccess: function onSuccess() {
478
+ return queryClient.invalidateQueries(DOMAIN_QUERY_KEY);
479
+ }
480
+ }));
481
+ };
482
+ var useValidateCname = function useValidateCname() {
483
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
484
+ var queryClient = reactQuery.useQueryClient();
485
+ return reactQuery.useMutation(function (id) {
486
+ return customDomainApi.validateCname(id);
487
+ }, _objectSpread(_objectSpread({}, options), {}, {
488
+ onSuccess: function onSuccess() {
489
+ return queryClient.invalidateQueries(DOMAIN_QUERY_KEY);
490
+ }
491
+ }));
492
+ };
493
+ var useUpdateCustomDomain = function useUpdateCustomDomain() {
494
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
495
+ var queryClient = reactQuery.useQueryClient();
496
+ return reactQuery.useMutation(function (id) {
497
+ return customDomainApi.updateCustomDomain(id);
498
+ }, _objectSpread(_objectSpread({}, options), {}, {
499
+ onSuccess: function onSuccess() {
500
+ return queryClient.invalidateQueries(DOMAIN_QUERY_KEY);
501
+ }
502
+ }));
503
+ };
504
+
505
+ var Manage = function Manage(_ref) {
506
+ var isOpen = _ref.isOpen,
507
+ onClose = _ref.onClose,
508
+ customDomain = _ref.customDomain,
509
+ setCustomDomain = _ref.setCustomDomain;
510
+ var _useTranslation = reactI18next.useTranslation(),
511
+ t = _useTranslation.t;
512
+ var _useCreateCustomDomai = useCreateCustomDomain(),
513
+ createCustomDomain = _useCreateCustomDomai.mutate,
514
+ isCreating = _useCreateCustomDomai.isLoading;
515
+ var _useValidateTxt = useValidateTxt(),
516
+ validateTxt = _useValidateTxt.mutate,
517
+ isValidating = _useValidateTxt.isLoading;
518
+ var _useValidateCname = useValidateCname(),
519
+ validateCname = _useValidateCname.mutate,
520
+ isCnameValidating = _useValidateCname.isLoading;
521
+ var _useUpdateCustomDomai = useUpdateCustomDomain(),
522
+ updateCustomDomain = _useUpdateCustomDomai.mutate,
523
+ isUpdating = _useUpdateCustomDomai.isLoading;
524
+ var handleSubmit = function handleSubmit(values) {
525
+ return createCustomDomain(values, {
526
+ onSuccess: function onSuccess(values) {
527
+ return setCustomDomain(values);
528
+ }
529
+ });
530
+ };
531
+ var handleValidateTxt = function handleValidateTxt() {
532
+ return validateTxt(customDomain.id, {
533
+ onSuccess: function onSuccess(values) {
534
+ return setCustomDomain(values);
535
+ }
536
+ });
537
+ };
538
+ var handleValidateCname = function handleValidateCname() {
539
+ validateCname(customDomain.id, {
540
+ onSuccess: function onSuccess(data) {
541
+ return setCustomDomain(data);
542
+ }
543
+ });
544
+ };
545
+ var handleUpdateCname = function handleUpdateCname() {
546
+ updateCustomDomain(customDomain.id, {
547
+ onSuccess: function onSuccess(data) {
548
+ return setCustomDomain(data);
549
+ }
550
+ });
551
+ };
552
+ return /*#__PURE__*/React__default["default"].createElement(neetoui.Pane, {
553
+ isOpen: isOpen,
554
+ onClose: onClose
555
+ }, /*#__PURE__*/React__default["default"].createElement(formik.Formik, {
556
+ enableReinitialize: true,
557
+ initialValues: customDomain || INITIAL_VALUES,
558
+ validateOnBlur: isCreating,
559
+ validateOnChange: isCreating,
560
+ validationSchema: getCustomDomainValidationSchema(),
561
+ onSubmit: handleSubmit
562
+ }, function (_ref2) {
563
+ var dirty = _ref2.dirty;
564
+ return /*#__PURE__*/React__default["default"].createElement(formik.Form, null, /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Header, null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
565
+ "data-cy": "add-custom-domain-pane-heading",
566
+ style: "h2",
567
+ weight: "semibold"
568
+ }, customDomain ? t("neetoMolecules.common.actions.editTitle", {
569
+ entity: t("neetoMolecules.customDomain.customDomain", {
570
+ count: ENTITY_COUNT.singular
571
+ }).toLocaleLowerCase()
572
+ }) : t("neetoMolecules.common.actions.addNew", {
573
+ entity: t("neetoMolecules.customDomain.customDomain", {
574
+ count: ENTITY_COUNT.singular
575
+ }).toLocaleLowerCase()
576
+ }))), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Body, null, /*#__PURE__*/React__default["default"].createElement("div", {
577
+ className: "space-y-6 w-full"
578
+ }, !!customDomain && /*#__PURE__*/React__default["default"].createElement(TagBlock, {
579
+ stacked: true,
580
+ handleValidateCname: handleValidateCname,
581
+ isCnameRecordsAdded: customDomain.addedCnameAt,
582
+ status: customDomain.status
583
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
584
+ className: "space-y-2"
585
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Label, {
586
+ htmlFor: "hostname"
587
+ }, customDomain ? t("neetoMolecules.customDomain.customDomain", {
588
+ count: ENTITY_COUNT.singular
589
+ }) : t("neetoMolecules.customDomain.label")), /*#__PURE__*/React__default["default"].createElement("div", {
590
+ className: "flex items-start gap-2"
591
+ }, /*#__PURE__*/React__default["default"].createElement(formik$1.Input, {
592
+ autoFocus: true,
593
+ "data-cy": "custom-domain-input-field",
594
+ disabled: !!customDomain,
595
+ name: "hostname",
596
+ placeholder: t("neetoMolecules.customDomain.placeholder")
597
+ }), !customDomain && /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
598
+ "data-cy": "submit-custom-domain-button",
599
+ disabled: !dirty || isCreating,
600
+ icon: neetoIcons.Check,
601
+ loading: isCreating,
602
+ style: "primary",
603
+ type: "submit"
604
+ }))), !!customDomain && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(Record, {
605
+ customDomain: customDomain
606
+ }), customDomain.status === "pending_txt_validation" && /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
607
+ "data-cy": "validate-txt-record-button",
608
+ disabled: isValidating,
609
+ loading: isValidating,
610
+ label: t("neetoMolecules.customDomain.validation.buttonLabel.txt"),
611
+ onClick: handleValidateTxt
612
+ }), customDomain.status === "pending_cname_validation" && !customDomain.addedCnameAt && /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
613
+ "data-cy": "validate-cname-record-button",
614
+ loading: isCnameValidating || isUpdating,
615
+ label: t("neetoMolecules.customDomain.validation.buttonLabel.cnameAdded"),
616
+ onClick: handleUpdateCname
617
+ }), customDomain.status === "pending_cname_validation" && customDomain.addedCnameAt && /*#__PURE__*/React__default["default"].createElement(CustomDomainInfo, {
618
+ time: customDomain.addedCnameAt
619
+ })))));
620
+ }));
621
+ };
622
+
623
+ var CustomDomain = function CustomDomain(_ref) {
624
+ var _data$customDomains;
625
+ var headerProps = _ref.headerProps;
626
+ var _useState = React.useState(""),
627
+ _useState2 = _slicedToArray(_useState, 2),
628
+ searchTerm = _useState2[0],
629
+ setSearchTerm = _useState2[1];
630
+ var _useState3 = React.useState(false),
631
+ _useState4 = _slicedToArray(_useState3, 2),
632
+ isPaneOpen = _useState4[0],
633
+ setIsPaneOpen = _useState4[1];
634
+ var _useState5 = React.useState(null),
635
+ _useState6 = _slicedToArray(_useState5, 2),
636
+ customDomain = _useState6[0],
637
+ setCustomDomain = _useState6[1];
638
+ var _useState7 = React.useState(false),
639
+ _useState8 = _slicedToArray(_useState7, 2),
640
+ isAlertOpen = _useState8[0],
641
+ setIsAlertOpen = _useState8[1];
642
+ var _useTranslation = reactI18next.useTranslation(),
643
+ t = _useTranslation.t;
644
+ var debouncedSearchTerm = reactUtils.useDebounce(searchTerm, 500);
645
+ var _useFetchCustomDomain = useFetchCustomDomains({
646
+ search: debouncedSearchTerm
647
+ }),
648
+ data = _useFetchCustomDomain.data,
649
+ isLoading = _useFetchCustomDomain.isLoading;
650
+ var _useDeleteCustomDomai = useDeleteCustomDomain({
651
+ onSettled: function onSettled() {
652
+ return setIsAlertOpen(false);
653
+ }
654
+ }),
655
+ deleteCustomDomain = _useDeleteCustomDomai.mutate,
656
+ isDeleting = _useDeleteCustomDomai.isLoading;
657
+ var enableManagePane = function enableManagePane(customDomain) {
658
+ setCustomDomain(customDomain);
659
+ setIsPaneOpen(true);
660
+ };
661
+ var enableDeleteAlert = function enableDeleteAlert(customDomain) {
662
+ setCustomDomain(customDomain);
663
+ setIsAlertOpen(true);
664
+ };
665
+ return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(layouts.Container, null, /*#__PURE__*/React__default["default"].createElement(layouts.Header, _extends({
666
+ actionBlock: /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
667
+ "data-cy": "add-new-custom-domain-button",
668
+ label: t("neetoMolecules.common.actions.addNew", {
669
+ entity: t("neetoMolecules.customDomain.customDomain", {
670
+ count: ENTITY_COUNT.singular
671
+ }).toLocaleLowerCase()
672
+ }),
673
+ onClick: function onClick() {
674
+ return enableManagePane(null);
675
+ }
676
+ }),
677
+ searchProps: {
678
+ value: searchTerm,
679
+ onChange: function onChange(e) {
680
+ return setSearchTerm(e.target.value);
681
+ },
682
+ placeholder: t("neetoMolecules.common.search", {
683
+ entity: t("neetoMolecules.customDomain.customDomain", {
684
+ count: ENTITY_COUNT.plural
685
+ }).toLocaleLowerCase()
686
+ }),
687
+ "data-cy": "custom-domain-search-field"
688
+ },
689
+ title: t("neetoMolecules.customDomain.customDomain", {
690
+ count: ENTITY_COUNT.plural
691
+ })
692
+ }, headerProps)), isLoading && /*#__PURE__*/React__default["default"].createElement("div", {
693
+ className: "w-full h-screen"
694
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.PageLoader, null)), !isLoading && (pure.isNotEmpty(data === null || data === void 0 ? void 0 : data.customDomains) ? /*#__PURE__*/React__default["default"].createElement("div", {
695
+ className: "w-full flex-grow"
696
+ }, /*#__PURE__*/React__default["default"].createElement(layouts.SubHeader, {
697
+ leftActionBlock: /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
698
+ className: "neeto-ui-gray-800 font-semibold",
699
+ component: "h4"
700
+ }, t("neetoMolecules.customDomain.customDomainWithCount", {
701
+ count: data === null || data === void 0 ? void 0 : (_data$customDomains = data.customDomains) === null || _data$customDomains === void 0 ? void 0 : _data$customDomains.length
702
+ }))
703
+ }), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Table, {
704
+ allowRowClick: false,
705
+ rowData: data === null || data === void 0 ? void 0 : data.customDomains,
706
+ rowSelection: false,
707
+ columnData: renderColumnData(enableManagePane, enableDeleteAlert)
708
+ }))) : /*#__PURE__*/React__default["default"].createElement("div", {
709
+ className: "flex h-full w-full flex-grow items-center justify-center"
710
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.NoData, {
711
+ primaryButtonProps: {
712
+ label: t("neetoMolecules.common.actions.addNew", {
713
+ entity: t("neetoMolecules.customDomain.customDomain", {
714
+ count: ENTITY_COUNT.singular
715
+ }).toLocaleLowerCase()
716
+ }),
717
+ onClick: function onClick() {
718
+ return enableManagePane(null);
719
+ }
720
+ },
721
+ title: t("neetoMolecules.common.notFound.title", {
722
+ entity: t("neetoMolecules.customDomain.customDomain", {
723
+ count: ENTITY_COUNT.plural
724
+ }).toLocaleLowerCase()
725
+ })
726
+ })))), /*#__PURE__*/React__default["default"].createElement(Manage, {
727
+ customDomain: customDomain,
728
+ isOpen: isPaneOpen,
729
+ setCustomDomain: setCustomDomain,
730
+ onClose: function onClose() {
731
+ return setIsPaneOpen(false);
732
+ }
733
+ }), /*#__PURE__*/React__default["default"].createElement(neetoui.Alert, {
734
+ cancelButtonLabel: t("neetoMolecules.common.deleteAlert.no"),
735
+ isOpen: isAlertOpen,
736
+ isSubmitting: isDeleting,
737
+ submitButtonLabel: t("neetoMolecules.common.deleteAlert.yes"),
738
+ message: /*#__PURE__*/React__default["default"].createElement(reactI18next.Trans, {
739
+ i18nKey: "neetoMolecules.customDomain.alertMessage",
740
+ values: {
741
+ hostname: customDomain === null || customDomain === void 0 ? void 0 : customDomain.hostname
742
+ }
743
+ }),
744
+ title: t("neetoMolecules.common.deleteAlert.title", {
745
+ entity: t("neetoMolecules.customDomain.customDomain", {
746
+ count: ENTITY_COUNT.singular
747
+ }).toLocaleLowerCase()
748
+ }),
749
+ onClose: function onClose() {
750
+ return setIsAlertOpen(false);
751
+ },
752
+ onSubmit: function onSubmit() {
753
+ return deleteCustomDomain(customDomain === null || customDomain === void 0 ? void 0 : customDomain.id);
754
+ }
755
+ }));
756
+ };
757
+
758
+ module.exports = CustomDomain;