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