@bigbinary/neeto-redirect-urls-frontend 3.0.4 → 3.0.5

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,611 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
+ import { useState, useEffect, useRef } from 'react';
4
+ import { Alert, Sheet, Label, Typography, Button, DataTable, Spinner, Empty } from '@bigbinary/neeto-atoms';
5
+ import { noop, isPresent } from '@bigbinary/neeto-cist';
6
+ import { useQueryParams } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
7
+ import { buildUrl, showThumbsUpToastr } from '@bigbinary/neeto-commons-frontend/v2/utils';
8
+ import Container from '@bigbinary/neeto-molecules/v2/Container';
9
+ import Header from '@bigbinary/neeto-molecules/v2/Header';
10
+ import { isEmpty, isNotNil } from 'ramda';
11
+ import { useTranslation, Trans } from 'react-i18next';
12
+ import { r as routes, U as URL_PATHNAME_REGEX, u as useCreateRedirectUrl, a as useUpdateRedirectUrl, b as useDestroyRedirectUrl, D as DOMAIN_LEVEL_REDIRECT_HELP_DOC_URL, c as useFetchAllRedirectUrls, C as CREATE_REDIRECT_URL_HELP_DOC_URL } from '../helpUrls-C3F0oNrV.js';
13
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
14
+ import { Form, Input, ActionBlock, Switch } from '@bigbinary/neeto-atoms/formik';
15
+ import { t } from 'i18next';
16
+ import { RESERVED_PATHS, VALID_URL_REGEX, DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-frontend/v2/constants';
17
+ import * as yup from 'yup';
18
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
19
+ import Edit from '@bigbinary/neeto-icons/Edit';
20
+ import CardLayout from '@bigbinary/neeto-molecules/v2/CardLayout';
21
+ import { FormikInlineInput } from '@bigbinary/neeto-molecules/v2/InlineInput';
22
+ import MoreDropdown from '@bigbinary/neeto-molecules/v2/MoreDropdown';
23
+ import TableWrapper from '@bigbinary/neeto-molecules/v2/TableWrapper';
24
+ import '@tanstack/react-query';
25
+ import '@bigbinary/neeto-commons-frontend/react-utils';
26
+ import 'axios';
27
+
28
+ var DeleteRedirectUrlModal = function DeleteRedirectUrlModal(_ref) {
29
+ var handleClose = _ref.handleClose,
30
+ handleSubmit = _ref.handleSubmit,
31
+ detailsToDelete = _ref.detailsToDelete,
32
+ isOpen = _ref.isOpen;
33
+ var _useTranslation = useTranslation(),
34
+ t = _useTranslation.t;
35
+ if (detailsToDelete === null) return null;
36
+ var id = detailsToDelete.id,
37
+ toPath = detailsToDelete.toPath,
38
+ fromPath = detailsToDelete.fromPath;
39
+ var title = t("neetoRedirectUrls.alerts.delete.title");
40
+ return /*#__PURE__*/jsx(Alert, {
41
+ isOpen: isOpen,
42
+ title: title,
43
+ submitButtonLabel: t("neetoRedirectUrls.common.delete"),
44
+ message: /*#__PURE__*/jsx(Trans, {
45
+ i18nKey: "neetoRedirectUrls.alerts.delete.confirm",
46
+ values: {
47
+ from_path: fromPath,
48
+ to_path: toPath
49
+ }
50
+ }),
51
+ onClose: handleClose,
52
+ onSubmit: function onSubmit() {
53
+ return handleSubmit(id);
54
+ }
55
+ });
56
+ };
57
+
58
+ var SETTINGS_CATEGORIES = {
59
+ GENERAL: "GENERAL"
60
+ };
61
+ var SETTINGS_CATEGORIES_LABELS = _defineProperty({}, SETTINGS_CATEGORIES.GENERAL, t("neetoRedirectUrls.settings.general.title"));
62
+ var SHOW_TOASTR_CONFIG = {
63
+ showToastr: false
64
+ };
65
+
66
+ var buildSettingsBreadcrumbs = function buildSettingsBreadcrumbs(category, pageTitle) {
67
+ return [{
68
+ link: routes.admin.adminPanel,
69
+ text: t("neetoRedirectUrls.settings.title")
70
+ }, {
71
+ link: buildUrl(routes.admin.adminPanel, {
72
+ category: category.toLowerCase()
73
+ }),
74
+ text: SETTINGS_CATEGORIES_LABELS[category]
75
+ }].concat(_toConsumableArray(pageTitle ? [{
76
+ text: pageTitle
77
+ }] : []));
78
+ };
79
+ var normalizeURL = function normalizeURL(url) {
80
+ return url ? url.replace(/\/+$/, "") : "";
81
+ };
82
+ var handleError = function handleError(setStatus, error) {
83
+ var response = error.response;
84
+ if (response && response.data && response.data.errors) {
85
+ setStatus(response.data.errors);
86
+ }
87
+ };
88
+ var isReservedPath = function isReservedPath(url) {
89
+ var _window$globalProps$o;
90
+ if (!url) return false;
91
+ var domainUrls = ((_window$globalProps$o = window.globalProps.organization) === null || _window$globalProps$o === void 0 || (_window$globalProps$o = _window$globalProps$o.domainUrls) === null || _window$globalProps$o === void 0 ? void 0 : _window$globalProps$o.map(normalizeURL)) || [];
92
+ return domainUrls.some(function (domainUrl) {
93
+ return RESERVED_PATHS.some(function (reservedPath) {
94
+ return normalizeURL(url) === normalizeURL("".concat(domainUrl, "/").concat(reservedPath));
95
+ });
96
+ });
97
+ };
98
+
99
+ var REDIRECT_URL_VALIDATION_SCHEMA = yup.object().shape({
100
+ fromPath: yup.string().required(t("neetoRedirectUrls.redirect.validations.required", {
101
+ entity: "Source"
102
+ })).matches(URL_PATHNAME_REGEX, t("neetoRedirectUrls.redirect.validations.source")),
103
+ toPath: yup.string().required(t("neetoRedirectUrls.redirect.validations.required", {
104
+ entity: "Destination"
105
+ })).matches(new RegExp("".concat(VALID_URL_REGEX.source, "|").concat(URL_PATHNAME_REGEX.source)), t("neetoRedirectUrls.redirect.validations.destination")).test("paths-not-same", t("neetoRedirectUrls.redirect.validations.samePaths"), function (value, context) {
106
+ var fromPath = context.parent.fromPath;
107
+ if (!value || !fromPath) return true;
108
+ return value !== fromPath;
109
+ }).test("reserved-path", t("neetoRedirectUrls.redirect.validations.reservedPath"), function (value) {
110
+ return !isReservedPath(value);
111
+ })
112
+ });
113
+
114
+ 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; }
115
+ 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), true).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; }
116
+ var RedirectUrlPane = function RedirectUrlPane(_ref) {
117
+ var handleClose = _ref.handleClose,
118
+ handleSubmit = _ref.handleSubmit,
119
+ _ref$initialValues = _ref.initialValues,
120
+ initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
121
+ _ref$setInitialFocusF = _ref.setInitialFocusField,
122
+ setInitialFocusField = _ref$setInitialFocusF === void 0 ? noop : _ref$setInitialFocusF;
123
+ var _useTranslation = useTranslation(),
124
+ t = _useTranslation.t;
125
+ var redirectUrlId = initialValues === null || initialValues === void 0 ? void 0 : initialValues.id;
126
+ return /*#__PURE__*/jsxs(Fragment, {
127
+ children: [/*#__PURE__*/jsx(Sheet.Header, {
128
+ children: /*#__PURE__*/jsx(Sheet.Title, {
129
+ children: redirectUrlId ? t("neetoRedirectUrls.redirect.edit") : t("neetoRedirectUrls.redirect.add")
130
+ })
131
+ }), /*#__PURE__*/jsx(Form, {
132
+ formikProps: {
133
+ initialValues: initialValues || {
134
+ fromPath: "",
135
+ toPath: ""
136
+ },
137
+ validationSchema: REDIRECT_URL_VALIDATION_SCHEMA,
138
+ onSubmit: function onSubmit(values, formikBag) {
139
+ handleSubmit(_objectSpread$1({}, values), formikBag);
140
+ }
141
+ },
142
+ children: /*#__PURE__*/jsxs(Fragment, {
143
+ children: [/*#__PURE__*/jsx(Sheet.Body, {
144
+ children: /*#__PURE__*/jsxs("div", {
145
+ className: "w-full space-y-4",
146
+ children: [/*#__PURE__*/jsx(Input, {
147
+ required: true,
148
+ id: "fromPath",
149
+ label: t("neetoRedirectUrls.redirect.source"),
150
+ name: "fromPath",
151
+ ref: setInitialFocusField,
152
+ placeholder: t("neetoRedirectUrls.common.placeholder.relativeUrl")
153
+ }), /*#__PURE__*/jsx(Input, {
154
+ required: true,
155
+ id: "toPath",
156
+ label: t("neetoRedirectUrls.redirect.destination"),
157
+ name: "toPath",
158
+ placeholder: window.location.origin
159
+ })]
160
+ })
161
+ }), /*#__PURE__*/jsx(Sheet.Footer, {
162
+ children: /*#__PURE__*/jsx(ActionBlock, {
163
+ cancelButtonProps: {
164
+ onClick: handleClose
165
+ }
166
+ })
167
+ })]
168
+ })
169
+ })]
170
+ });
171
+ };
172
+
173
+ var DOMAIN_REDIRECTION_VALIDATION_SCHEMA = yup.object().shape({
174
+ toPath: yup.string().nullable().when("domainRedirectionActive", {
175
+ is: true,
176
+ then: yup.string().required(t("neetoRedirectUrls.redirect.validations.required", {
177
+ entity: "Destination"
178
+ })).matches(VALID_URL_REGEX, t("neetoRedirectUrls.redirect.validations.destination")).test("not-duplicate-domain", t("neetoRedirectUrls.redirect.validations.duplicateDomain"), function (value) {
179
+ var _window$globalProps$o;
180
+ if (!value) return true;
181
+ var domainUrls = ((_window$globalProps$o = window.globalProps.organization) === null || _window$globalProps$o === void 0 || (_window$globalProps$o = _window$globalProps$o.domainUrls) === null || _window$globalProps$o === void 0 ? void 0 : _window$globalProps$o.map(normalizeURL)) || [];
182
+ return !domainUrls.includes(normalizeURL(value));
183
+ }).test("reserved-path", t("neetoRedirectUrls.redirect.validations.reservedPath"), function (value) {
184
+ return !isReservedPath(value);
185
+ })
186
+ })
187
+ });
188
+
189
+ var DomainRedirection = function DomainRedirection(_ref) {
190
+ var domainRedirectUrl = _ref.domainRedirectUrl,
191
+ entity = _ref.entity,
192
+ helpDocUrls = _ref.helpDocUrls;
193
+ var _useState = useState(true),
194
+ _useState2 = _slicedToArray(_useState, 2),
195
+ isEditingDomainRedirect = _useState2[0],
196
+ setIsEditingDomainRedirect = _useState2[1];
197
+ var _useTranslation = useTranslation(),
198
+ t = _useTranslation.t;
199
+ var _useCreateRedirectUrl = useCreateRedirectUrl(),
200
+ createLink = _useCreateRedirectUrl.mutateAsync;
201
+ var _useUpdateRedirectUrl = useUpdateRedirectUrl(),
202
+ updateLink = _useUpdateRedirectUrl.mutateAsync;
203
+ var _useDestroyRedirectUr = useDestroyRedirectUrl(),
204
+ destroyLink = _useDestroyRedirectUr.mutate;
205
+ var initialValues = {
206
+ domainRedirectionActive: isPresent(domainRedirectUrl === null || domainRedirectUrl === void 0 ? void 0 : domainRedirectUrl.toPath),
207
+ toPath: domainRedirectUrl === null || domainRedirectUrl === void 0 ? void 0 : domainRedirectUrl.toPath
208
+ };
209
+ var handleSubmit = function handleSubmit(values) {
210
+ var payload = {
211
+ toPath: values.toPath,
212
+ redirection_type: "domain"
213
+ };
214
+ return domainRedirectUrl ? updateLink({
215
+ id: domainRedirectUrl.id,
216
+ payload: payload
217
+ }) : createLink({
218
+ payload: payload
219
+ });
220
+ };
221
+ var handleRemoveRedirection = function handleRemoveRedirection(domainLinkActive) {
222
+ if (!(domainLinkActive && domainRedirectUrl)) {
223
+ setIsEditingDomainRedirect(true);
224
+ return;
225
+ }
226
+ destroyLink(domainRedirectUrl.id);
227
+ };
228
+ useEffect(function () {
229
+ if (isPresent(domainRedirectUrl === null || domainRedirectUrl === void 0 ? void 0 : domainRedirectUrl.toPath)) {
230
+ setIsEditingDomainRedirect(false);
231
+ }
232
+ }, [domainRedirectUrl]);
233
+ return /*#__PURE__*/jsx(Form, {
234
+ className: "mb-6 w-full",
235
+ formikProps: {
236
+ initialValues: initialValues,
237
+ validationSchema: DOMAIN_REDIRECTION_VALIDATION_SCHEMA,
238
+ enableReinitialize: true,
239
+ onSubmit: handleSubmit
240
+ },
241
+ children: function children(_ref2) {
242
+ var domainRedirectionActive = _ref2.values.domainRedirectionActive,
243
+ dirty = _ref2.dirty;
244
+ return /*#__PURE__*/jsxs(CardLayout, {
245
+ containerClassName: "ms-0",
246
+ children: [/*#__PURE__*/jsx("div", {
247
+ className: "flex items-center justify-between",
248
+ children: /*#__PURE__*/jsxs("div", {
249
+ className: "flex flex-col space-y-2",
250
+ children: [/*#__PURE__*/jsxs(Label, {
251
+ className: "flex items-center gap-2",
252
+ children: [/*#__PURE__*/jsx(Switch, {
253
+ "data-testid": "domain-level-redirection-switch",
254
+ name: "domainRedirectionActive",
255
+ onClick: function onClick() {
256
+ return handleRemoveRedirection(domainRedirectionActive);
257
+ }
258
+ }), /*#__PURE__*/jsx(Typography, {
259
+ "data-testid": "domain-level-redirection-heading",
260
+ variant: "h5",
261
+ weight: "medium",
262
+ children: t("neetoRedirectUrls.redirect.domainLevelRedirect.label")
263
+ })]
264
+ }), /*#__PURE__*/jsx(Typography, {
265
+ variant: "body2",
266
+ children: /*#__PURE__*/jsx(Trans, {
267
+ i18nKey: "neetoRedirectUrls.redirect.domainLevelRedirect.description",
268
+ values: {
269
+ entity: entity,
270
+ app: window.globalProps.appName
271
+ },
272
+ components: {
273
+ Link: /*#__PURE__*/jsx(Button, {
274
+ className: "text-sm",
275
+ "data-testid": "domain-level-redirections-help-button",
276
+ target: "_blank",
277
+ variant: "link",
278
+ href: helpDocUrls.domainLevelRedirectUrl || DOMAIN_LEVEL_REDIRECT_HELP_DOC_URL
279
+ })
280
+ }
281
+ })
282
+ })]
283
+ })
284
+ }), domainRedirectionActive && /*#__PURE__*/jsx("div", {
285
+ className: "mt-2 flex w-1/2 items-start space-x-3",
286
+ children: isEditingDomainRedirect ? /*#__PURE__*/jsx(FormikInlineInput, {
287
+ "data-testid": "domain-level-redirection-link-text-field",
288
+ handleCancel: function handleCancel() {
289
+ return dirty;
290
+ },
291
+ name: "toPath",
292
+ placeholder: t("neetoRedirectUrls.common.placeholder.url"),
293
+ cancelButtonProps: {
294
+ disabled: !dirty,
295
+ "data-testid": "domain-level-redirection-link-cancel-button"
296
+ },
297
+ submitButtonProps: {
298
+ "data-testid": "domain-level-redirection-link-submit-button"
299
+ }
300
+ }) : /*#__PURE__*/jsxs(Fragment, {
301
+ children: [/*#__PURE__*/jsx(Input, {
302
+ disabled: true,
303
+ name: "toPath"
304
+ }), /*#__PURE__*/jsx(Button, {
305
+ "data-testid": "domain-level-redirection-edit-btn",
306
+ icon: Edit,
307
+ variant: "link",
308
+ onClick: function onClick() {
309
+ return setIsEditingDomainRedirect(true);
310
+ }
311
+ })]
312
+ })
313
+ })]
314
+ });
315
+ }
316
+ });
317
+ };
318
+
319
+ var buildBreadcrumbs = function buildBreadcrumbs(pageTitle) {
320
+ return buildSettingsBreadcrumbs(SETTINGS_CATEGORIES.GENERAL, pageTitle);
321
+ };
322
+ var buildMoreMenuItems = function buildMoreMenuItems(_ref) {
323
+ var redirectUrl = _ref.redirectUrl,
324
+ setUrlDetailsToEdit = _ref.setUrlDetailsToEdit,
325
+ setUrlDetailsToDelete = _ref.setUrlDetailsToDelete;
326
+ var id = redirectUrl.id,
327
+ fromPath = redirectUrl.fromPath,
328
+ toPath = redirectUrl.toPath;
329
+ return [{
330
+ key: "edit-menu",
331
+ "data-testid": "neeto-redirect-url-edit-btn",
332
+ label: t("neetoRedirectUrls.common.edit"),
333
+ onClick: function onClick() {
334
+ setUrlDetailsToEdit({
335
+ id: id,
336
+ fromPath: fromPath,
337
+ toPath: toPath
338
+ });
339
+ }
340
+ }, {
341
+ key: "delete-menu",
342
+ "data-testid": "neeto-redirect-url-delete-btn",
343
+ label: t("neetoRedirectUrls.common.delete"),
344
+ onClick: function onClick() {
345
+ setUrlDetailsToDelete({
346
+ id: id,
347
+ fromPath: fromPath,
348
+ toPath: toPath
349
+ });
350
+ }
351
+ }];
352
+ };
353
+
354
+ var RedirectUrlsTable = function RedirectUrlsTable(_ref) {
355
+ var _ref$redirectUrls = _ref.redirectUrls,
356
+ redirectUrls = _ref$redirectUrls === void 0 ? [] : _ref$redirectUrls,
357
+ currentPageNumber = _ref.currentPageNumber,
358
+ setCurrentPageNumber = _ref.setCurrentPageNumber,
359
+ recordsCount = _ref.recordsCount,
360
+ setUrlDetailsToEdit = _ref.setUrlDetailsToEdit,
361
+ setUrlDetailsToDelete = _ref.setUrlDetailsToDelete,
362
+ isFetching = _ref.isFetching;
363
+ var truncateUrl = function truncateUrl(url) {
364
+ var urlString = String(url);
365
+ return urlString.length <= 50 ? urlString : "".concat(urlString.slice(0, 50), "...");
366
+ };
367
+ var _useTranslation = useTranslation(),
368
+ t = _useTranslation.t;
369
+ var columns = [{
370
+ header: t("neetoRedirectUrls.redirect.source"),
371
+ accessorKey: "fromPath",
372
+ id: "name",
373
+ size: 300,
374
+ cell: function cell(_ref2) {
375
+ var row = _ref2.row;
376
+ var redirectUrl = row.original;
377
+ var fromPath = redirectUrl.fromPath;
378
+ return /*#__PURE__*/jsxs("div", {
379
+ className: "flex items-center justify-between gap-x-3",
380
+ children: [/*#__PURE__*/jsx("span", {
381
+ children: fromPath && truncateUrl(fromPath)
382
+ }), /*#__PURE__*/jsx(MoreDropdown, {
383
+ dropdownProps: {
384
+ position: "bottom-end"
385
+ },
386
+ menuItems: buildMoreMenuItems({
387
+ redirectUrl: redirectUrl,
388
+ setUrlDetailsToEdit: setUrlDetailsToEdit,
389
+ setUrlDetailsToDelete: setUrlDetailsToDelete
390
+ })
391
+ })]
392
+ });
393
+ }
394
+ }, {
395
+ header: t("neetoRedirectUrls.redirect.destination"),
396
+ accessorKey: "toPath",
397
+ id: "toPath",
398
+ size: 300,
399
+ cell: function cell(_ref3) {
400
+ var getValue = _ref3.getValue;
401
+ var toPath = getValue();
402
+ return toPath && truncateUrl(toPath);
403
+ }
404
+ }];
405
+ return /*#__PURE__*/jsx(TableWrapper, {
406
+ hasPagination: recordsCount > DEFAULT_PAGE_SIZE,
407
+ children: /*#__PURE__*/jsx(DataTable, {
408
+ columns: columns,
409
+ fixedHeight: true,
410
+ currentPage: currentPageNumber,
411
+ data: redirectUrls,
412
+ loading: isFetching,
413
+ pageSize: DEFAULT_PAGE_SIZE,
414
+ totalCount: recordsCount,
415
+ onPageChange: function onPageChange(page) {
416
+ return setCurrentPageNumber(page);
417
+ }
418
+ })
419
+ });
420
+ };
421
+
422
+ 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; }
423
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).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; }
424
+ var RedirectUrls = function RedirectUrls(_ref) {
425
+ var entity = _ref.entity,
426
+ _ref$helpDocUrls = _ref.helpDocUrls,
427
+ helpDocUrls = _ref$helpDocUrls === void 0 ? {} : _ref$helpDocUrls;
428
+ var _useTranslation = useTranslation(),
429
+ t = _useTranslation.t;
430
+ var _useQueryParams = useQueryParams(),
431
+ _useQueryParams$searc = _useQueryParams.searchTerm,
432
+ searchTerm = _useQueryParams$searc === void 0 ? "" : _useQueryParams$searc;
433
+ var initialFocusField = useRef();
434
+ var _useState = useState(1),
435
+ _useState2 = _slicedToArray(_useState, 2),
436
+ currentPageNumber = _useState2[0],
437
+ setCurrentPageNumber = _useState2[1];
438
+ var _useState3 = useState(null),
439
+ _useState4 = _slicedToArray(_useState3, 2),
440
+ urlDetailsToDelete = _useState4[0],
441
+ setUrlDetailsToDelete = _useState4[1];
442
+ var _useState5 = useState(null),
443
+ _useState6 = _slicedToArray(_useState5, 2),
444
+ urlDetailsToEdit = _useState6[0],
445
+ setUrlDetailsToEdit = _useState6[1];
446
+ var _useState7 = useState(false),
447
+ _useState8 = _slicedToArray(_useState7, 2),
448
+ isModalOpen = _useState8[0],
449
+ setIsModalOpen = _useState8[1];
450
+ var _useCreateRedirectUrl = useCreateRedirectUrl(),
451
+ createRedirectUrl = _useCreateRedirectUrl.mutate;
452
+ var searchQuery = _objectSpread({
453
+ page: currentPageNumber
454
+ }, isEmpty(searchTerm) ? {} : {
455
+ searchTerm: searchTerm
456
+ });
457
+ var _useFetchAllRedirectU = useFetchAllRedirectUrls({
458
+ params: searchQuery
459
+ }),
460
+ _useFetchAllRedirectU2 = _useFetchAllRedirectU.data,
461
+ _useFetchAllRedirectU3 = _useFetchAllRedirectU2 === void 0 ? {} : _useFetchAllRedirectU2,
462
+ _useFetchAllRedirectU4 = _useFetchAllRedirectU3.redirectUrls,
463
+ redirectUrls = _useFetchAllRedirectU4 === void 0 ? [] : _useFetchAllRedirectU4,
464
+ domainRedirectUrl = _useFetchAllRedirectU3.domainRedirectUrl,
465
+ isLoading = _useFetchAllRedirectU.isLoading,
466
+ isFetching = _useFetchAllRedirectU.isFetching;
467
+ var isFiltersVisible = (redirectUrls === null || redirectUrls === void 0 ? void 0 : redirectUrls.length) > 0 || isPresent(searchTerm);
468
+ var _useUpdateRedirectUrl = useUpdateRedirectUrl(),
469
+ updateRedirectUrl = _useUpdateRedirectUrl.mutate;
470
+ var _useDestroyRedirectUr = useDestroyRedirectUrl(),
471
+ deleteRedirectUrl = _useDestroyRedirectUr.mutate;
472
+ var handleCreateRedirectUrl = function handleCreateRedirectUrl(redirectUrl, _ref2) {
473
+ var setSubmitting = _ref2.setSubmitting,
474
+ setStatus = _ref2.setStatus;
475
+ createRedirectUrl({
476
+ payload: redirectUrl,
477
+ config: SHOW_TOASTR_CONFIG
478
+ }, {
479
+ onError: function onError(error) {
480
+ handleError(setStatus, error);
481
+ setSubmitting(false);
482
+ },
483
+ onSuccess: function onSuccess() {
484
+ showThumbsUpToastr();
485
+ setIsModalOpen(false);
486
+ }
487
+ });
488
+ };
489
+ var handleRedirectUrlUpdate = function handleRedirectUrlUpdate(redirectUrl, _ref3) {
490
+ var setSubmitting = _ref3.setSubmitting,
491
+ setStatus = _ref3.setStatus;
492
+ updateRedirectUrl({
493
+ id: redirectUrl.id,
494
+ payload: redirectUrl,
495
+ config: SHOW_TOASTR_CONFIG
496
+ }, {
497
+ onError: function onError(error) {
498
+ handleError(setStatus, error);
499
+ setSubmitting(false);
500
+ },
501
+ onSuccess: function onSuccess() {
502
+ showThumbsUpToastr();
503
+ setUrlDetailsToEdit(null);
504
+ }
505
+ });
506
+ };
507
+ var handleRedirectUrlDelete = function handleRedirectUrlDelete(urlId) {
508
+ deleteRedirectUrl(urlId, {
509
+ onSettled: function onSettled() {
510
+ setUrlDetailsToDelete(null);
511
+ }
512
+ });
513
+ };
514
+ var pageTitle = t("neetoRedirectUrls.settings.redirecturl.title");
515
+ var setInitialFocusField = function setInitialFocusField(fieldRef) {
516
+ return initialFocusField.current = fieldRef;
517
+ };
518
+ return /*#__PURE__*/jsx(Container, {
519
+ className: "w-full",
520
+ children: isLoading ? /*#__PURE__*/jsx("div", {
521
+ className: "flex h-full w-full items-center justify-center",
522
+ children: /*#__PURE__*/jsx(Spinner, {})
523
+ }) : /*#__PURE__*/jsxs(Fragment, {
524
+ children: [/*#__PURE__*/jsx(Header, {
525
+ breadcrumbs: buildBreadcrumbs(pageTitle),
526
+ title: pageTitle,
527
+ actionBlock: /*#__PURE__*/jsx(Button, {
528
+ "data-testid": "add-new-redirect-url-button",
529
+ label: t("neetoRedirectUrls.redirect.add"),
530
+ onClick: function onClick() {
531
+ return setIsModalOpen(true);
532
+ }
533
+ }),
534
+ searchProps: isFiltersVisible && {
535
+ placeholder: t("neetoRedirectUrls.redirect.search")
536
+ },
537
+ titleHelpPopoverProps: {
538
+ title: t("neetoRedirectUrls.settings.redirecturl.title"),
539
+ description: t("neetoRedirectUrls.settings.redirecturl.description"),
540
+ helpLinkProps: {
541
+ href: helpDocUrls.createRedirectUrl || CREATE_REDIRECT_URL_HELP_DOC_URL
542
+ }
543
+ }
544
+ }), /*#__PURE__*/jsxs(Fragment, {
545
+ children: [isEmpty(redirectUrls) ? /*#__PURE__*/jsx("div", {
546
+ className: "flex h-full w-full items-center justify-center",
547
+ children: /*#__PURE__*/jsx(Empty, {
548
+ title: t("neetoRedirectUrls.emptyState.redirectURLs.title"),
549
+ description: /*#__PURE__*/jsx(Trans, {
550
+ i18nKey: "neetoRedirectUrls.emptyState.redirectURLs.description",
551
+ components: {
552
+ helpLink: /*#__PURE__*/jsx(Button, {
553
+ target: "_blank",
554
+ variant: "link",
555
+ href: helpDocUrls.createRedirectUrl || CREATE_REDIRECT_URL_HELP_DOC_URL
556
+ })
557
+ }
558
+ }),
559
+ primaryButtonProps: {
560
+ label: t("neetoRedirectUrls.redirect.add"),
561
+ onClick: function onClick() {
562
+ return setIsModalOpen(true);
563
+ }
564
+ }
565
+ })
566
+ }) : /*#__PURE__*/jsxs(Fragment, {
567
+ children: [/*#__PURE__*/jsx("div", {
568
+ className: "w-full",
569
+ children: /*#__PURE__*/jsx(DomainRedirection, {
570
+ domainRedirectUrl: domainRedirectUrl,
571
+ entity: entity,
572
+ helpDocUrls: helpDocUrls
573
+ })
574
+ }), /*#__PURE__*/jsx(RedirectUrlsTable, {
575
+ currentPageNumber: currentPageNumber,
576
+ isFetching: isFetching,
577
+ redirectUrls: redirectUrls,
578
+ setCurrentPageNumber: setCurrentPageNumber,
579
+ setUrlDetailsToDelete: setUrlDetailsToDelete,
580
+ setUrlDetailsToEdit: setUrlDetailsToEdit,
581
+ recordsCount: redirectUrls.length
582
+ })]
583
+ }), /*#__PURE__*/jsx(DeleteRedirectUrlModal, {
584
+ detailsToDelete: urlDetailsToDelete,
585
+ handleClose: function handleClose() {
586
+ return setUrlDetailsToDelete(null);
587
+ },
588
+ handleSubmit: handleRedirectUrlDelete,
589
+ isOpen: urlDetailsToDelete !== null
590
+ }), /*#__PURE__*/jsx(Sheet, {
591
+ isOpen: isModalOpen || isNotNil(urlDetailsToEdit),
592
+ onClose: function onClose() {
593
+ setIsModalOpen(false);
594
+ setUrlDetailsToEdit(null);
595
+ },
596
+ children: /*#__PURE__*/jsx(RedirectUrlPane, {
597
+ setInitialFocusField: setInitialFocusField,
598
+ handleClose: function handleClose() {
599
+ return setIsModalOpen(false);
600
+ },
601
+ initialValues: urlDetailsToEdit !== null && urlDetailsToEdit !== void 0 ? urlDetailsToEdit : {},
602
+ handleSubmit: isNotNil(urlDetailsToEdit) ? handleRedirectUrlUpdate : handleCreateRedirectUrl
603
+ })
604
+ })]
605
+ })]
606
+ })
607
+ });
608
+ };
609
+
610
+ export { RedirectUrls as default };
611
+ //# sourceMappingURL=RedirectUrls.js.map