@bigbinary/neeto-custom-domains-frontend 2.0.2 → 2.1.0-beta1

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,903 +0,0 @@
1
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import { memo, useState } from 'react';
3
- import { isNotEmpty, isPresent, snakeToCamelCase } from '@bigbinary/neeto-cist';
4
- import useDebounce from '@bigbinary/neeto-commons-frontend/react-utils/useDebounce';
5
- import Container from '@bigbinary/neeto-molecules/Container';
6
- import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
7
- import SubHeader from '@bigbinary/neeto-molecules/SubHeader';
8
- import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
9
- import Table from '@bigbinary/neetoui/Table';
10
- import Typography from '@bigbinary/neetoui/Typography';
11
- import NoData from '@bigbinary/neetoui/NoData';
12
- import Button from '@bigbinary/neetoui/Button';
13
- import { Trans, useTranslation } from 'react-i18next';
14
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
15
- import { useQuery } from '@tanstack/react-query';
16
- import useMutationWithInvalidation from '@bigbinary/neeto-commons-frontend/react-utils/useMutationWithInvalidation';
17
- import axios from 'axios';
18
- import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
19
- import Alert from '@bigbinary/neetoui/Alert';
20
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
21
- import { PLURAL, SINGULAR } from '@bigbinary/neeto-commons-frontend/constants';
22
- import withT$1 from '@bigbinary/neeto-commons-frontend/react-utils/withT';
23
- import { withEventTargetValue, hyphenize } from '@bigbinary/neeto-commons-frontend/utils/general';
24
- import NeetoHeader from '@bigbinary/neeto-molecules/Header';
25
- import Pane from '@bigbinary/neetoui/Pane';
26
- import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
27
- import Input from '@bigbinary/neetoui/formik/Input';
28
- import FormikForm from '@bigbinary/neetoui/formik/Form';
29
- import { t as t$1 } from 'i18next';
30
- import * as Yup from 'yup';
31
- import Checkbox from '@bigbinary/neetoui/Checkbox';
32
- import Callout from '@bigbinary/neetoui/Callout';
33
- import Stepper from '@bigbinary/neetoui/Stepper';
34
- import CopyToClipboardButton from '@bigbinary/neeto-molecules/CopyToClipboardButton';
35
- import Tag from '@bigbinary/neetoui/Tag';
36
- import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
37
- import Toastr from '@bigbinary/neetoui/Toastr';
38
- import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
39
- import classnames from 'classnames';
40
-
41
- var getUrlwithId = function getUrlwithId(url, id) {
42
- return id ? "".concat(url, "/").concat(id) : url;
43
- };
44
- var fetchCustomDomain = function fetchCustomDomain(url) {
45
- return axios.get(url);
46
- };
47
- var updateCustomDomain = function updateCustomDomain(url, id) {
48
- return axios.patch(getUrlwithId(url, id));
49
- };
50
- var createCustomDomain = function createCustomDomain(url, payload) {
51
- return axios.post(url, payload);
52
- };
53
- var deleteCustomDomain = function deleteCustomDomain(url) {
54
- return axios["delete"](getUrlwithId(url));
55
- };
56
- var validateDomain = function validateDomain(url) {
57
- return axios.patch("".concat(url, "/validate_domain"), undefined, {
58
- showToastr: false
59
- });
60
- };
61
- var validateCname = function validateCname(url, id) {
62
- return axios.patch("".concat(getUrlwithId(url, id), "/validate_cname"));
63
- };
64
- var domainsApi = {
65
- createCustomDomain: createCustomDomain,
66
- deleteCustomDomain: deleteCustomDomain,
67
- validateDomain: validateDomain,
68
- fetchCustomDomain: fetchCustomDomain,
69
- validateCname: validateCname,
70
- updateCustomDomain: updateCustomDomain
71
- };
72
-
73
- var DOMAIN_QUERY_KEY = "custom-domain";
74
-
75
- function ownKeys$3(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; }
76
- function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
77
- var useCreateCustomDomain = function useCreateCustomDomain(url) {
78
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
79
- return useMutationWithInvalidation(function (payload) {
80
- return domainsApi.createCustomDomain(url, payload);
81
- }, _objectSpread$3({
82
- keysToInvalidate: [[DOMAIN_QUERY_KEY]]
83
- }, options));
84
- };
85
- var useDeleteCustomDomain = function useDeleteCustomDomain(url) {
86
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
87
- return useMutationWithInvalidation(function (id) {
88
- return domainsApi.deleteCustomDomain(url, id);
89
- }, _objectSpread$3({
90
- keysToInvalidate: [[DOMAIN_QUERY_KEY]]
91
- }, options));
92
- };
93
- var useFetchCustomDomain = function useFetchCustomDomain(params) {
94
- console.log("query");
95
- return useQuery({
96
- queryKey: [DOMAIN_QUERY_KEY, _objectSpread$3({}, params)],
97
- queryFn: function queryFn() {
98
- return domainsApi.fetchCustomDomain(params);
99
- }
100
- });
101
- };
102
- var useValidateDomain = function useValidateDomain(url) {
103
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
104
- return useMutationWithInvalidation(function () {
105
- return domainsApi.validateDomain(url);
106
- }, _objectSpread$3({
107
- keysToInvalidate: [[DOMAIN_QUERY_KEY]]
108
- }, options));
109
- };
110
- var useUpdateCustomDomain = function useUpdateCustomDomain(url) {
111
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
112
- return useMutationWithInvalidation(function (id) {
113
- return domainsApi.updateCustomDomain(url, id);
114
- }, _objectSpread$3({
115
- keysToInvalidate: [[DOMAIN_QUERY_KEY]]
116
- }, options));
117
- };
118
-
119
- var DeleteAlert = withT(function (_ref) {
120
- var t = _ref.t,
121
- onClose = _ref.onClose,
122
- onSubmit = _ref.onSubmit,
123
- isOpen = _ref.isOpen,
124
- isSubmitting = _ref.isSubmitting,
125
- hostname = _ref.hostname;
126
- return /*#__PURE__*/jsx(Alert, {
127
- isOpen: isOpen,
128
- isSubmitting: isSubmitting,
129
- onClose: onClose,
130
- onSubmit: onSubmit,
131
- cancelButtonLabel: t("neetoCustomDomains.actions.cancel"),
132
- submitButtonLabel: t("neetoCustomDomains.actions.delete"),
133
- title: t("neetoCustomDomains.delete"),
134
- message: /*#__PURE__*/jsx(Trans, {
135
- i18nKey: "neetoCustomDomains.alertMessage",
136
- values: {
137
- hostname: hostname
138
- }
139
- })
140
- });
141
- });
142
-
143
- 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; }
144
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
145
- var Header = withT$1(function (_ref) {
146
- var t = _ref.t,
147
- setIsPaneOpen = _ref.setIsPaneOpen,
148
- searchTerm = _ref.searchTerm,
149
- setSearchTerm = _ref.setSearchTerm,
150
- headerProps = _ref.headerProps,
151
- isFiltersVisible = _ref.isFiltersVisible;
152
- return /*#__PURE__*/jsx(NeetoHeader, _objectSpread$2({
153
- "data-testid": "custom-domain-header",
154
- title: t("neetoCustomDomains.customDomain", PLURAL),
155
- actionBlock: /*#__PURE__*/jsx(Button, {
156
- "data-cy": "add-new-custom-domain-button",
157
- label: t("neetoCustomDomains.addNew"),
158
- onClick: function onClick() {
159
- return setIsPaneOpen(true);
160
- }
161
- }),
162
- searchProps: isFiltersVisible && {
163
- value: searchTerm,
164
- onChange: withEventTargetValue(setSearchTerm),
165
- placeholder: t("neetoCustomDomains.search"),
166
- "data-cy": "custom-domain-search-field",
167
- className: "w-56"
168
- }
169
- }, headerProps));
170
- });
171
- var Header$1 = /*#__PURE__*/memo(Header);
172
-
173
- var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
174
-
175
- var css = ".neeto-molecule-custom-domain-pane{width:min(90%,1280px)}\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImFwcC9qYXZhc2NyaXB0L3NyYy9jb21wb25lbnRzL0N1c3RvbURvbWFpbkRhc2hib2FyZC9NYW5hZ2UvY3VzdG9tLWRvbWFpbi5zY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLG1DQUNFLHFCQUNGIiwic291cmNlc0NvbnRlbnQiOlsiLm5lZXRvLW1vbGVjdWxlLWN1c3RvbS1kb21haW4tcGFuZSB7XG4gIHdpZHRoOiBtaW4oOTAlLCAxMjgwcHgpO1xufVxuIl19 */";
176
- n(css,{});
177
-
178
- var HOSTNAME_REGEX = /^(https?:\/\/)?([a-zA-Z0-9][a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}(\/\S*)?$/;
179
- var INITIAL_VALUES = {
180
- hostname: ""
181
- };
182
- var STATUS_INDEX = ["pending_domain_validation", "pending_cname_validation", "active"];
183
- var DOMAIN_VALIDATION_STATUS = "pending_domain_validation";
184
- var STEPS = [{
185
- id: 1,
186
- label: "Domain validation"
187
- }, {
188
- id: 2,
189
- label: "Domain redirection"
190
- }];
191
-
192
- var getCustomDomainValidationSchema = function getCustomDomainValidationSchema() {
193
- return Yup.object().shape({
194
- hostname: Yup.string().required(t$1("neetoCustomDomains.formikValidation.required")).matches(HOSTNAME_REGEX, t$1("neetoCustomDomains.formikValidation.valid"))
195
- });
196
- };
197
-
198
- var DomainField = function DomainField(_ref) {
199
- var customDomain = _ref.customDomain,
200
- onCreate = _ref.onCreate,
201
- url = _ref.url,
202
- setCustomDomain = _ref.setCustomDomain,
203
- onClose = _ref.onClose;
204
- var _useTranslation = useTranslation(),
205
- t = _useTranslation.t;
206
- var _useCreateCustomDomai = useCreateCustomDomain(url),
207
- createCustomDomain = _useCreateCustomDomai.mutate,
208
- isCreating = _useCreateCustomDomai.isPending;
209
- var getHostname = function getHostname(url) {
210
- try {
211
- var parsedUrl = new URL(url);
212
- return parsedUrl.hostname;
213
- } catch (_unused) {
214
- return url;
215
- }
216
- };
217
- var handleSubmit = function handleSubmit(_ref2) {
218
- var hostname = _ref2.hostname;
219
- var parsedHostname = getHostname(hostname);
220
- var payload = {
221
- hostname: parsedHostname
222
- };
223
- createCustomDomain(payload, {
224
- onSuccess: function onSuccess(values) {
225
- setCustomDomain(values);
226
- onCreate === null || onCreate === void 0 ? void 0 : onCreate(values);
227
- }
228
- });
229
- };
230
- return /*#__PURE__*/jsxs(Fragment, {
231
- children: [/*#__PURE__*/jsx(Pane.Header, {
232
- children: /*#__PURE__*/jsx(Typography, {
233
- style: "h2",
234
- children: t("neetoCustomDomains.addNew")
235
- })
236
- }), /*#__PURE__*/jsx(FormikForm, {
237
- className: "flex-col space-y-6",
238
- formikProps: {
239
- enableReinitialize: true,
240
- initialValues: customDomain || INITIAL_VALUES,
241
- validationSchema: getCustomDomainValidationSchema(),
242
- onSubmit: handleSubmit
243
- },
244
- children: function children(_ref3) {
245
- var dirty = _ref3.dirty;
246
- return /*#__PURE__*/jsxs("div", {
247
- className: "w-full",
248
- children: [/*#__PURE__*/jsx(Pane.Body, {
249
- children: /*#__PURE__*/jsx(Input, {
250
- required: true,
251
- className: "w-full",
252
- "data-cy": "custom-domain-input-field",
253
- disabled: isNotEmpty(customDomain),
254
- label: t("neetoCustomDomains.label"),
255
- name: "hostname",
256
- placeholder: t("neetoCustomDomains.placeholder")
257
- })
258
- }), /*#__PURE__*/jsx(Pane.Footer, {
259
- children: /*#__PURE__*/jsx(ActionBlock, {
260
- cancelButtonProps: {
261
- onClick: onClose
262
- },
263
- isSubmitting: isCreating,
264
- submitButtonProps: {
265
- label: t("neetoCustomDomains.actions.continue"),
266
- "data-cy": "submit-custom-domain-button",
267
- "data-testid": "submit-custom-domain-button",
268
- disabled: !dirty || isCreating
269
- }
270
- })
271
- })]
272
- });
273
- }
274
- })]
275
- });
276
- };
277
-
278
- var Common = withT(function (_ref) {
279
- var t = _ref.t,
280
- currentStep = _ref.currentStep,
281
- handleStepChange = _ref.handleStepChange,
282
- hostname = _ref.hostname;
283
- return /*#__PURE__*/jsxs("div", {
284
- className: "mb-6 w-full space-y-6",
285
- children: [/*#__PURE__*/jsx("div", {
286
- className: "-ml-2",
287
- children: /*#__PURE__*/jsx(Stepper, {
288
- activeIndex: currentStep,
289
- setActiveIndex: handleStepChange,
290
- steps: STEPS
291
- })
292
- }), /*#__PURE__*/jsxs("div", {
293
- className: "space-y-1",
294
- children: [/*#__PURE__*/jsx(Typography, {
295
- style: "h4",
296
- children: t("neetoCustomDomains.yourDomain")
297
- }), /*#__PURE__*/jsx(Typography, {
298
- style: "body1",
299
- children: hostname
300
- })]
301
- })]
302
- });
303
- });
304
-
305
- var columnData = function columnData() {
306
- return [{
307
- title: t$1("neetoCustomDomains.common.record"),
308
- key: "record",
309
- dataIndex: "record",
310
- width: "90px",
311
- render: function render() {
312
- return /*#__PURE__*/jsx(Typography, {
313
- style: "body2",
314
- children: t$1("neetoCustomDomains.cname")
315
- });
316
- }
317
- }, {
318
- title: t$1("neetoCustomDomains.common.name"),
319
- dataIndex: "name",
320
- width: "35%",
321
- key: "name",
322
- render: function render(name, _) {
323
- return /*#__PURE__*/jsxs("div", {
324
- className: "flex items-center justify-between gap-1",
325
- children: [/*#__PURE__*/jsx(Typography, {
326
- className: "min-w-0 truncate",
327
- style: "body2",
328
- children: name
329
- }), /*#__PURE__*/jsx(CopyToClipboardButton, {
330
- className: "flex-shrink-0",
331
- size: "small",
332
- style: "secondary",
333
- value: name
334
- })]
335
- });
336
- }
337
- }, {
338
- title: t$1("neetoCustomDomains.common.value"),
339
- dataIndex: "value",
340
- width: "35%",
341
- key: "value",
342
- render: function render(value, _) {
343
- return /*#__PURE__*/jsxs("div", {
344
- className: "flex items-center justify-between gap-1",
345
- children: [/*#__PURE__*/jsx(Typography, {
346
- className: "min-w-0 truncate",
347
- style: "body2",
348
- children: value
349
- }), /*#__PURE__*/jsx(CopyToClipboardButton, {
350
- value: value,
351
- className: "flex-shrink-0",
352
- size: "small",
353
- style: "secondary"
354
- })]
355
- });
356
- }
357
- }, {
358
- title: t$1("neetoCustomDomains.common.status"),
359
- dataIndex: "status",
360
- key: "status",
361
- width: "130px",
362
- render: function render(status) {
363
- return /*#__PURE__*/jsx(Tag, {
364
- label: t$1("neetoCustomDomains.common.".concat(status)),
365
- style: status === "success" ? "success" : "warning"
366
- });
367
- }
368
- }];
369
- };
370
-
371
- var HELP_DOC_URL = "https://help.".concat(globalProps.appName.toLowerCase(), ".com/articles/custom-domains");
372
-
373
- var Redirection = function Redirection(_ref) {
374
- var customDomain = _ref.customDomain,
375
- onClose = _ref.onClose,
376
- setCustomDomain = _ref.setCustomDomain,
377
- url = _ref.url,
378
- currentStep = _ref.currentStep,
379
- handleStepChange = _ref.handleStepChange,
380
- incrementStep = _ref.incrementStep,
381
- hasOne = _ref.hasOne;
382
- var _useTranslation = useTranslation(),
383
- t = _useTranslation.t;
384
- var id = customDomain.id,
385
- hostname = customDomain.hostname,
386
- dnsTarget = customDomain.dnsTarget,
387
- addedCnameAt = customDomain.addedCnameAt,
388
- status = customDomain.status;
389
- var cnameAdded = isPresent(addedCnameAt);
390
- var customDomainId = hasOne ? null : id;
391
- var _useState = useState(cnameAdded),
392
- _useState2 = _slicedToArray(_useState, 2),
393
- addedRedirectionCname = _useState2[0],
394
- setAddedRedirectionCname = _useState2[1];
395
- var _useUpdateCustomDomai = useUpdateCustomDomain(url),
396
- updateCustomDomain = _useUpdateCustomDomai.mutate,
397
- isUpdating = _useUpdateCustomDomai.isPending;
398
- var handleUpdateCname = function handleUpdateCname() {
399
- addedRedirectionCname && updateCustomDomain(customDomainId, {
400
- onSuccess: function onSuccess(data) {
401
- incrementStep();
402
- setCustomDomain(data);
403
- }
404
- });
405
- };
406
- return /*#__PURE__*/jsxs(Fragment, {
407
- children: [/*#__PURE__*/jsxs(Pane.Body, {
408
- children: [/*#__PURE__*/jsx(Common, {
409
- currentStep: currentStep,
410
- handleStepChange: handleStepChange,
411
- hostname: hostname
412
- }), /*#__PURE__*/jsxs("div", {
413
- className: "mb-6 w-full space-y-6",
414
- children: [/*#__PURE__*/jsxs("div", {
415
- className: "space-y-1",
416
- children: [/*#__PURE__*/jsx(Typography, {
417
- style: "h4",
418
- children: t("neetoCustomDomains.domainRedirection")
419
- }), /*#__PURE__*/jsx(Typography, {
420
- style: "body2",
421
- children: /*#__PURE__*/jsx(Trans, {
422
- i18nKey: "neetoCustomDomains.cnameRecordInfo",
423
- components: {
424
- Link: /*#__PURE__*/jsx(Button, {
425
- href: HELP_DOC_URL,
426
- rel: "noreferrer",
427
- style: "link",
428
- target: "_blank"
429
- })
430
- }
431
- })
432
- })]
433
- }), /*#__PURE__*/jsx(TableWrapper, {
434
- className: "pb-0",
435
- children: /*#__PURE__*/jsx(Table, {
436
- allowRowClick: false,
437
- columnData: columnData(),
438
- rowSelection: false,
439
- rowData: [{
440
- name: hostname,
441
- value: dnsTarget,
442
- status: status === "active" ? "success" : "pending"
443
- }]
444
- })
445
- }), /*#__PURE__*/jsx(Checkbox, {
446
- checked: addedRedirectionCname,
447
- "data-testid": "cname-added-custom-domain-checkbox",
448
- disabled: cnameAdded,
449
- label: t("neetoCustomDomains.cnameAdded"),
450
- onChange: function onChange() {
451
- return setAddedRedirectionCname(function (value) {
452
- return !value;
453
- });
454
- }
455
- })]
456
- }), cnameAdded && /*#__PURE__*/jsx(Callout, {
457
- style: "warning",
458
- children: /*#__PURE__*/jsx(Typography, {
459
- style: "body2",
460
- children: /*#__PURE__*/jsx(Trans, {
461
- i18nKey: "neetoCustomDomains.domainRedirectionInfo",
462
- values: {
463
- hostname: hostname
464
- },
465
- components: {
466
- Link: /*#__PURE__*/jsx(Button, {
467
- href: HELP_DOC_URL,
468
- rel: "noreferrer",
469
- style: "link",
470
- target: "_blank"
471
- })
472
- }
473
- })
474
- })
475
- })]
476
- }), /*#__PURE__*/jsx(Pane.Footer, {
477
- children: /*#__PURE__*/jsxs("div", {
478
- className: "flex items-center gap-2",
479
- children: [status !== "active" ? /*#__PURE__*/jsx(Button, {
480
- disabled: isUpdating || !addedRedirectionCname,
481
- label: t("neetoCustomDomains.actions.continue"),
482
- loading: isUpdating,
483
- onClick: handleUpdateCname
484
- }) : /*#__PURE__*/jsx(Button, {
485
- label: t("neetoCustomDomains.actions.done"),
486
- onClick: onClose
487
- }), /*#__PURE__*/jsx(Button, {
488
- label: t("neetoCustomDomains.actions.cancel"),
489
- style: "text",
490
- onClick: onClose
491
- })]
492
- })
493
- })]
494
- });
495
- };
496
-
497
- function ownKeys$1(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; }
498
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
499
- var Validation = function Validation(_ref) {
500
- var customDomain = _ref.customDomain,
501
- onClose = _ref.onClose,
502
- setCustomDomain = _ref.setCustomDomain,
503
- url = _ref.url,
504
- currentStep = _ref.currentStep,
505
- handleStepChange = _ref.handleStepChange,
506
- incrementStep = _ref.incrementStep,
507
- hasOne = _ref.hasOne;
508
- var _useTranslation = useTranslation(),
509
- t = _useTranslation.t;
510
- var id = customDomain.id,
511
- hostname = customDomain.hostname,
512
- cnameValidationParams = customDomain.cnameValidationParams,
513
- status = customDomain.status;
514
- var isDomainValidated = status !== "pending_domain_validation";
515
- var customDomainId = hasOne ? null : id;
516
- var _useState = useState(false),
517
- _useState2 = _slicedToArray(_useState, 2),
518
- showValidationWarning = _useState2[0],
519
- setShowValidationWarning = _useState2[1];
520
- var _useValidateDomain = useValidateDomain(url),
521
- validateDomain = _useValidateDomain.mutate,
522
- isValidating = _useValidateDomain.isPending;
523
- var handleValidateDomain = function handleValidateDomain() {
524
- return validateDomain(customDomainId, {
525
- onError: function onError() {
526
- setShowValidationWarning(true);
527
- },
528
- onSuccess: function onSuccess(values) {
529
- Toastr.success(t("neetoCustomDomains.validation.successMessage"));
530
- incrementStep();
531
- setCustomDomain(values);
532
- }
533
- });
534
- };
535
- return /*#__PURE__*/jsxs(Fragment, {
536
- children: [/*#__PURE__*/jsxs(Pane.Body, {
537
- children: [/*#__PURE__*/jsx(Common, {
538
- currentStep: currentStep,
539
- handleStepChange: handleStepChange,
540
- hostname: hostname
541
- }), /*#__PURE__*/jsxs("div", {
542
- className: "mb-6 w-full space-y-6",
543
- children: [/*#__PURE__*/jsxs("div", {
544
- className: "space-y-1",
545
- children: [/*#__PURE__*/jsx(Typography, {
546
- style: "h4",
547
- children: t("neetoCustomDomains.domainValidation")
548
- }), /*#__PURE__*/jsx(Typography, {
549
- style: "body2",
550
- children: /*#__PURE__*/jsx(Trans, {
551
- i18nKey: "neetoCustomDomains.cnameRecordInfo",
552
- components: {
553
- Link: /*#__PURE__*/jsx(Button, {
554
- href: HELP_DOC_URL,
555
- rel: "noreferrer",
556
- style: "link",
557
- target: "_blank"
558
- })
559
- },
560
- values: {
561
- proxyMessage: t("neetoCustomDomains.proxyMessage")
562
- }
563
- })
564
- })]
565
- }), /*#__PURE__*/jsx(TableWrapper, {
566
- className: "pb-0",
567
- children: /*#__PURE__*/jsx(Table, {
568
- allowRowClick: false,
569
- columnData: columnData(),
570
- rowSelection: false,
571
- rowData: [_objectSpread$1(_objectSpread$1({}, cnameValidationParams), {}, {
572
- status: isDomainValidated ? "success" : "pending"
573
- })]
574
- })
575
- })]
576
- }), showValidationWarning && /*#__PURE__*/jsx(Callout, {
577
- style: "warning",
578
- children: /*#__PURE__*/jsx(Typography, {
579
- style: "body2",
580
- children: /*#__PURE__*/jsx(Trans, {
581
- i18nKey: "neetoCustomDomains.domainValidationInfo",
582
- components: {
583
- Link: /*#__PURE__*/jsx(Button, {
584
- href: HELP_DOC_URL,
585
- rel: "noreferrer",
586
- style: "link",
587
- target: "_blank"
588
- })
589
- }
590
- })
591
- })
592
- })]
593
- }), /*#__PURE__*/jsx(Pane.Footer, {
594
- children: /*#__PURE__*/jsxs("div", {
595
- className: "flex items-center gap-2",
596
- children: [/*#__PURE__*/jsx(Button, {
597
- disabled: isValidating,
598
- loading: isValidating,
599
- "data-cy": isDomainValidated ? "continue-button" : "validate-domain-button",
600
- label: isDomainValidated ? t("neetoCustomDomains.actions.continue") : t("neetoCustomDomains.validation.buttonLabel.domain"),
601
- onClick: isDomainValidated ? incrementStep : handleValidateDomain
602
- }), /*#__PURE__*/jsx(Button, {
603
- label: t("neetoCustomDomains.actions.cancel"),
604
- style: "text",
605
- onClick: onClose
606
- })]
607
- })
608
- })]
609
- });
610
- };
611
-
612
- function ownKeys(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; }
613
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
614
- var Settings = function Settings(_ref) {
615
- var customDomain = _ref.customDomain,
616
- url = _ref.url,
617
- onClose = _ref.onClose,
618
- setCustomDomain = _ref.setCustomDomain,
619
- hasOne = _ref.hasOne;
620
- var _useTranslation = useTranslation(),
621
- t = _useTranslation.t;
622
- var status = customDomain.status;
623
- var _useState = useState(STATUS_INDEX.indexOf(status)),
624
- _useState2 = _slicedToArray(_useState, 2),
625
- currentStep = _useState2[0],
626
- setCurrentStep = _useState2[1];
627
- var isNotValidationStep = STATUS_INDEX[currentStep] !== DOMAIN_VALIDATION_STATUS;
628
- var handleStepChange = function handleStepChange(index) {
629
- status !== DOMAIN_VALIDATION_STATUS && setCurrentStep(index);
630
- };
631
- var incrementStep = function incrementStep() {
632
- return setCurrentStep(function (step) {
633
- return step + 1;
634
- });
635
- };
636
- var recordProps = {
637
- currentStep: currentStep,
638
- customDomain: customDomain,
639
- handleStepChange: handleStepChange,
640
- onClose: onClose,
641
- setCustomDomain: setCustomDomain,
642
- url: url,
643
- incrementStep: incrementStep,
644
- hasOne: hasOne
645
- };
646
- return /*#__PURE__*/jsxs(Fragment, {
647
- children: [/*#__PURE__*/jsx(Pane.Header, {
648
- children: /*#__PURE__*/jsx(Typography, {
649
- style: "h2",
650
- children: t("neetoCustomDomains.settings")
651
- })
652
- }), isNotValidationStep ? /*#__PURE__*/jsx(Redirection, _objectSpread({}, recordProps)) : /*#__PURE__*/jsx(Validation, _objectSpread({}, recordProps))]
653
- });
654
- };
655
-
656
- var Manage = function Manage(_ref) {
657
- var isOpen = _ref.isOpen,
658
- onClose = _ref.onClose,
659
- customDomain = _ref.customDomain,
660
- setCustomDomain = _ref.setCustomDomain,
661
- url = _ref.url,
662
- hasOne = _ref.hasOne,
663
- onCreate = _ref.onCreate;
664
- return /*#__PURE__*/jsx(Pane, {
665
- isOpen: isOpen,
666
- onClose: onClose,
667
- className: "neeto-molecule-custom-domain-pane",
668
- size: "large",
669
- children: customDomain !== null && customDomain !== void 0 && customDomain.id ? /*#__PURE__*/jsx(Settings, {
670
- customDomain: customDomain,
671
- hasOne: hasOne,
672
- onClose: onClose,
673
- setCustomDomain: setCustomDomain,
674
- url: url
675
- }) : /*#__PURE__*/jsx(DomainField, {
676
- customDomain: customDomain,
677
- onClose: onClose,
678
- onCreate: onCreate,
679
- setCustomDomain: setCustomDomain,
680
- url: url
681
- })
682
- });
683
- };
684
-
685
- var TagBlock = function TagBlock(_ref) {
686
- var status = _ref.status,
687
- _ref$stacked = _ref.stacked,
688
- stacked = _ref$stacked === void 0 ? false : _ref$stacked;
689
- var _useTranslation = useTranslation(),
690
- t = _useTranslation.t;
691
- var isDomainValidated = status === "active" || status === "pending_cname_validation";
692
- var camelCasedStatus = snakeToCamelCase(status || "");
693
- return /*#__PURE__*/jsx("div", {
694
- className: classnames("flex gap-2", {
695
- "flex-col items-start": stacked
696
- }),
697
- children: status === "failed" ? /*#__PURE__*/jsx(Tag, {
698
- label: t("neetoCustomDomains.status.".concat(camelCasedStatus)),
699
- style: "danger"
700
- }) : /*#__PURE__*/jsxs(Fragment, {
701
- children: [/*#__PURE__*/jsx(Tag, {
702
- "data-cy": "".concat(hyphenize(status), "-tag-container"),
703
- label: t("neetoCustomDomains.status.domain.".concat(camelCasedStatus)),
704
- style: isDomainValidated ? "success" : "warning"
705
- }), isDomainValidated && /*#__PURE__*/jsx("div", {
706
- className: classnames("flex items-center justify-between gap-2", {
707
- "w-full": stacked
708
- }),
709
- children: /*#__PURE__*/jsx(Tag, {
710
- "data-cy": "".concat(hyphenize(status), "-tag-container"),
711
- label: t("neetoCustomDomains.status.cname.".concat(camelCasedStatus)),
712
- style: status === "active" ? "success" : "warning"
713
- })
714
- })]
715
- })
716
- });
717
- };
718
- var TagBlock$1 = /*#__PURE__*/memo(TagBlock);
719
-
720
- var renderColumnData = function renderColumnData(enableManagePane, enableDeleteAlert) {
721
- return [{
722
- title: t$1("neetoCustomDomains.customDomain", SINGULAR),
723
- dataIndex: "hostname",
724
- key: "hostname",
725
- width: "60%",
726
- render: function render(hostName, customDomain) {
727
- return /*#__PURE__*/jsxs("div", {
728
- className: "flex items-center justify-between gap-x-3",
729
- children: [/*#__PURE__*/jsx(Button, {
730
- "data-cy": "hostname-button",
731
- label: hostName,
732
- style: "link",
733
- onClick: function onClick() {
734
- return enableManagePane(customDomain);
735
- }
736
- }), /*#__PURE__*/jsx(MoreDropdown, {
737
- dropdownButtonProps: {
738
- "data-testid": "nui-dropdown-icon-".concat(customDomain.id)
739
- },
740
- dropdownProps: {
741
- position: "bottom-end",
742
- strategy: "fixed",
743
- autoWidth: true
744
- },
745
- menuItems: [{
746
- label: t$1("neetoCustomDomains.actions.edit"),
747
- onClick: function onClick() {
748
- return enableManagePane(customDomain);
749
- },
750
- key: "edit-custom-domain-button"
751
- }, {
752
- label: t$1("neetoCustomDomains.actions.delete"),
753
- onClick: function onClick() {
754
- return enableDeleteAlert(customDomain);
755
- },
756
- key: "delete-custom-domain"
757
- }]
758
- })]
759
- });
760
- }
761
- }, {
762
- title: t$1("neetoCustomDomains.common.status"),
763
- dataIndex: "status",
764
- key: "status",
765
- render: function render(status) {
766
- return /*#__PURE__*/jsx(TagBlock$1, {
767
- status: status
768
- });
769
- },
770
- width: "40%"
771
- }];
772
- };
773
-
774
- var CustomDomainDashboard = function CustomDomainDashboard(_ref) {
775
- var _data$customDomains, _data$customDomains2;
776
- var headerProps = _ref.headerProps,
777
- url = _ref.url,
778
- onCreate = _ref.onCreate;
779
- var _useState = useState(""),
780
- _useState2 = _slicedToArray(_useState, 2),
781
- searchTerm = _useState2[0],
782
- setSearchTerm = _useState2[1];
783
- var _useState3 = useState(false),
784
- _useState4 = _slicedToArray(_useState3, 2),
785
- isPaneOpen = _useState4[0],
786
- setIsPaneOpen = _useState4[1];
787
- var _useState5 = useState({}),
788
- _useState6 = _slicedToArray(_useState5, 2),
789
- customDomain = _useState6[0],
790
- setCustomDomain = _useState6[1];
791
- var _useState7 = useState(false),
792
- _useState8 = _slicedToArray(_useState7, 2),
793
- isAlertOpen = _useState8[0],
794
- setIsAlertOpen = _useState8[1];
795
- var _useTranslation = useTranslation(),
796
- t = _useTranslation.t;
797
- var debouncedSearchTerm = useDebounce(searchTerm, 500);
798
- var _useFetchCustomDomain = useFetchCustomDomain({
799
- url: url,
800
- params: {
801
- searchTerm: debouncedSearchTerm
802
- }
803
- }),
804
- data = _useFetchCustomDomain.data,
805
- isLoading = _useFetchCustomDomain.isLoading;
806
- var isFiltersVisible = isNotEmpty(data === null || data === void 0 ? void 0 : data.customDomains) || isPresent(searchTerm);
807
- var _useDeleteCustomDomai = useDeleteCustomDomain(url, {
808
- onSettled: function onSettled() {
809
- setIsAlertOpen(false);
810
- setCustomDomain({});
811
- }
812
- }),
813
- deleteCustomDomain = _useDeleteCustomDomai.mutate,
814
- isDeleting = _useDeleteCustomDomai.isPending;
815
- var enableManagePane = function enableManagePane(customDomain) {
816
- setCustomDomain(customDomain);
817
- setIsPaneOpen(true);
818
- };
819
- var enableDeleteAlert = function enableDeleteAlert(customDomain) {
820
- setCustomDomain(customDomain);
821
- setIsAlertOpen(true);
822
- };
823
- var disableManagePane = function disableManagePane() {
824
- setIsPaneOpen(false);
825
- setCustomDomain({});
826
- };
827
- var disableDeleteAlert = function disableDeleteAlert() {
828
- setIsAlertOpen(false);
829
- setCustomDomain({});
830
- };
831
- return /*#__PURE__*/jsxs(Fragment, {
832
- children: [/*#__PURE__*/jsxs(Container, {
833
- children: [/*#__PURE__*/jsx(Header$1, {
834
- headerProps: headerProps,
835
- isFiltersVisible: isFiltersVisible,
836
- searchTerm: searchTerm,
837
- setIsPaneOpen: setIsPaneOpen,
838
- setSearchTerm: setSearchTerm
839
- }), isLoading && /*#__PURE__*/jsx("div", {
840
- className: "h-screen w-full",
841
- children: /*#__PURE__*/jsx(PageLoader, {})
842
- }), !isLoading && /*#__PURE__*/jsxs(Fragment, {
843
- children: [/*#__PURE__*/jsx(SubHeader, {
844
- leftActionBlock: !!(data !== null && data !== void 0 && (_data$customDomains = data.customDomains) !== null && _data$customDomains !== void 0 && _data$customDomains.length) && /*#__PURE__*/jsx(Typography, {
845
- className: "neeto-ui-gray-800 font-semibold",
846
- component: "h4",
847
- children: t("neetoCustomDomains.customDomainWithCount", {
848
- count: data === null || data === void 0 ? void 0 : (_data$customDomains2 = data.customDomains) === null || _data$customDomains2 === void 0 ? void 0 : _data$customDomains2.length
849
- })
850
- })
851
- }), isNotEmpty(data === null || data === void 0 ? void 0 : data.customDomains) ? /*#__PURE__*/jsx(TableWrapper, {
852
- children: /*#__PURE__*/jsx(Table, {
853
- fixedHeight: true,
854
- allowRowClick: false,
855
- rowData: data === null || data === void 0 ? void 0 : data.customDomains,
856
- rowSelection: false,
857
- columnData: renderColumnData(enableManagePane, enableDeleteAlert)
858
- })
859
- }) : /*#__PURE__*/jsx("div", {
860
- className: "flex h-full w-full flex-grow items-center justify-center",
861
- children: /*#__PURE__*/jsx(NoData, {
862
- title: t("neetoCustomDomains.notFound"),
863
- helpText: /*#__PURE__*/jsx(Trans, {
864
- i18nKey: "neetoCustomDomains.learnMoreMessage",
865
- components: {
866
- button: /*#__PURE__*/jsx(Button, {
867
- href: "https://help.neetosite.com/p/a-95ad5b03",
868
- style: "link",
869
- target: "_blank"
870
- })
871
- }
872
- }),
873
- primaryButtonProps: {
874
- label: t("neetoCustomDomains.addNew"),
875
- onClick: function onClick() {
876
- return setIsPaneOpen(true);
877
- }
878
- }
879
- })
880
- })]
881
- })]
882
- }), /*#__PURE__*/jsx(Manage, {
883
- customDomain: customDomain,
884
- onCreate: onCreate,
885
- setCustomDomain: setCustomDomain,
886
- url: url,
887
- hasOne: false,
888
- isOpen: isPaneOpen,
889
- onClose: disableManagePane
890
- }), /*#__PURE__*/jsx(DeleteAlert, {
891
- hostname: customDomain === null || customDomain === void 0 ? void 0 : customDomain.hostname,
892
- isOpen: isAlertOpen,
893
- isSubmitting: isDeleting,
894
- onClose: disableDeleteAlert,
895
- onSubmit: function onSubmit() {
896
- return deleteCustomDomain(customDomain === null || customDomain === void 0 ? void 0 : customDomain.id);
897
- }
898
- })]
899
- });
900
- };
901
-
902
- export { CustomDomainDashboard as C, useValidateDomain as a, useFetchCustomDomain as b, useDeleteCustomDomain as c, useCreateCustomDomain as u };
903
- //# sourceMappingURL=index-a5a14202.js.map