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

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 { Pencil, CornerUpRight } from 'lucide-react';
6
+ import { noop, isPresent } from '@bigbinary/neeto-cist';
7
+ import { useQueryParams } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
8
+ import { buildUrl, showThumbsUpToastr } from '@bigbinary/neeto-commons-frontend/v2/utils';
9
+ import Container from '@bigbinary/neeto-molecules/v2/Container';
10
+ import Header from '@bigbinary/neeto-molecules/v2/Header';
11
+ import { isEmpty, isNotNil } from 'ramda';
12
+ import { useTranslation, Trans } from 'react-i18next';
13
+ 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';
14
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
15
+ import { Form, Input, ActionBlock, Switch } from '@bigbinary/neeto-atoms/formik';
16
+ import { t } from 'i18next';
17
+ import { RESERVED_PATHS, VALID_URL_REGEX, DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-frontend/v2/constants';
18
+ import * as yup from 'yup';
19
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
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 '@tanstack/react-query';
24
+ import '@bigbinary/neeto-commons-frontend/react-utils';
25
+ import 'axios';
26
+
27
+ var DeleteRedirectUrlModal = function DeleteRedirectUrlModal(_ref) {
28
+ var handleClose = _ref.handleClose,
29
+ handleSubmit = _ref.handleSubmit,
30
+ detailsToDelete = _ref.detailsToDelete,
31
+ isOpen = _ref.isOpen;
32
+ var _useTranslation = useTranslation(),
33
+ t = _useTranslation.t;
34
+ if (detailsToDelete === null) return null;
35
+ var id = detailsToDelete.id,
36
+ toPath = detailsToDelete.toPath,
37
+ fromPath = detailsToDelete.fromPath;
38
+ var title = t("neetoRedirectUrls.alerts.delete.title");
39
+ return /*#__PURE__*/jsx(Alert, {
40
+ isOpen: isOpen,
41
+ title: title,
42
+ submitButtonLabel: t("neetoRedirectUrls.common.delete"),
43
+ message: /*#__PURE__*/jsx(Trans, {
44
+ i18nKey: "neetoRedirectUrls.alerts.delete.confirm",
45
+ values: {
46
+ from_path: fromPath,
47
+ to_path: toPath
48
+ }
49
+ }),
50
+ onClose: handleClose,
51
+ onSubmit: function onSubmit() {
52
+ return handleSubmit(id);
53
+ }
54
+ });
55
+ };
56
+
57
+ var SETTINGS_CATEGORIES = {
58
+ GENERAL: "GENERAL"
59
+ };
60
+ var SETTINGS_CATEGORIES_LABELS = _defineProperty({}, SETTINGS_CATEGORIES.GENERAL, t("neetoRedirectUrls.settings.general.title"));
61
+ var SHOW_TOASTR_CONFIG = {
62
+ showToastr: false
63
+ };
64
+
65
+ var buildSettingsBreadcrumbs = function buildSettingsBreadcrumbs(category, pageTitle) {
66
+ return [{
67
+ link: routes.admin.adminPanel,
68
+ text: t("neetoRedirectUrls.settings.title")
69
+ }, {
70
+ link: buildUrl(routes.admin.adminPanel, {
71
+ category: category.toLowerCase()
72
+ }),
73
+ text: SETTINGS_CATEGORIES_LABELS[category]
74
+ }].concat(_toConsumableArray(pageTitle ? [{
75
+ text: pageTitle
76
+ }] : []));
77
+ };
78
+ var normalizeURL = function normalizeURL(url) {
79
+ return url ? url.replace(/\/+$/, "") : "";
80
+ };
81
+ var handleError = function handleError(setStatus, error) {
82
+ var response = error.response;
83
+ if (response && response.data && response.data.errors) {
84
+ setStatus(response.data.errors);
85
+ }
86
+ };
87
+ var isReservedPath = function isReservedPath(url) {
88
+ var _window$globalProps$o;
89
+ if (!url) return false;
90
+ 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)) || [];
91
+ return domainUrls.some(function (domainUrl) {
92
+ return RESERVED_PATHS.some(function (reservedPath) {
93
+ return normalizeURL(url) === normalizeURL("".concat(domainUrl, "/").concat(reservedPath));
94
+ });
95
+ });
96
+ };
97
+
98
+ var REDIRECT_URL_VALIDATION_SCHEMA = yup.object().shape({
99
+ fromPath: yup.string().required(t("neetoRedirectUrls.redirect.validations.required", {
100
+ entity: "Source"
101
+ })).matches(URL_PATHNAME_REGEX, t("neetoRedirectUrls.redirect.validations.source")),
102
+ toPath: yup.string().required(t("neetoRedirectUrls.redirect.validations.required", {
103
+ entity: "Destination"
104
+ })).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) {
105
+ var fromPath = context.parent.fromPath;
106
+ if (!value || !fromPath) return true;
107
+ return value !== fromPath;
108
+ }).test("reserved-path", t("neetoRedirectUrls.redirect.validations.reservedPath"), function (value) {
109
+ return !isReservedPath(value);
110
+ })
111
+ });
112
+
113
+ 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; }
114
+ 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; }
115
+ var RedirectUrlPane = function RedirectUrlPane(_ref) {
116
+ var handleClose = _ref.handleClose,
117
+ handleSubmit = _ref.handleSubmit,
118
+ _ref$initialValues = _ref.initialValues,
119
+ initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
120
+ _ref$setInitialFocusF = _ref.setInitialFocusField,
121
+ setInitialFocusField = _ref$setInitialFocusF === void 0 ? noop : _ref$setInitialFocusF;
122
+ var _useTranslation = useTranslation(),
123
+ t = _useTranslation.t;
124
+ var redirectUrlId = initialValues === null || initialValues === void 0 ? void 0 : initialValues.id;
125
+ return /*#__PURE__*/jsxs(Fragment, {
126
+ children: [/*#__PURE__*/jsx(Sheet.Header, {
127
+ children: /*#__PURE__*/jsx(Sheet.Title, {
128
+ children: redirectUrlId ? t("neetoRedirectUrls.redirect.edit") : t("neetoRedirectUrls.redirect.add")
129
+ })
130
+ }), /*#__PURE__*/jsx(Form, {
131
+ className: "flex min-h-0 w-full flex-1 flex-col",
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
+ size: "lg",
256
+ onClick: function onClick() {
257
+ return handleRemoveRedirection(domainRedirectionActive);
258
+ }
259
+ }), /*#__PURE__*/jsx(Typography, {
260
+ "data-testid": "domain-level-redirection-heading",
261
+ variant: "h5",
262
+ weight: "medium",
263
+ children: t("neetoRedirectUrls.redirect.domainLevelRedirect.label")
264
+ })]
265
+ }), /*#__PURE__*/jsx(Typography, {
266
+ variant: "body2",
267
+ children: /*#__PURE__*/jsx(Trans, {
268
+ i18nKey: "neetoRedirectUrls.redirect.domainLevelRedirect.description",
269
+ values: {
270
+ entity: entity,
271
+ app: window.globalProps.appName
272
+ },
273
+ components: {
274
+ Link: /*#__PURE__*/jsx(Button, {
275
+ className: "text-sm",
276
+ "data-testid": "domain-level-redirections-help-button",
277
+ target: "_blank",
278
+ variant: "link",
279
+ href: helpDocUrls.domainLevelRedirectUrl || DOMAIN_LEVEL_REDIRECT_HELP_DOC_URL
280
+ })
281
+ }
282
+ })
283
+ })]
284
+ })
285
+ }), domainRedirectionActive && /*#__PURE__*/jsx("div", {
286
+ className: "mt-2 flex w-1/2 items-start space-x-3",
287
+ children: isEditingDomainRedirect ? /*#__PURE__*/jsx(FormikInlineInput, {
288
+ "data-testid": "domain-level-redirection-link-text-field",
289
+ handleCancel: function handleCancel() {
290
+ return dirty;
291
+ },
292
+ name: "toPath",
293
+ placeholder: t("neetoRedirectUrls.common.placeholder.url"),
294
+ cancelButtonProps: {
295
+ disabled: !dirty,
296
+ "data-testid": "domain-level-redirection-link-cancel-button"
297
+ },
298
+ submitButtonProps: {
299
+ "data-testid": "domain-level-redirection-link-submit-button"
300
+ }
301
+ }) : /*#__PURE__*/jsxs(Fragment, {
302
+ children: [/*#__PURE__*/jsx(Input, {
303
+ disabled: true,
304
+ name: "toPath"
305
+ }), /*#__PURE__*/jsx(Button, {
306
+ "data-testid": "domain-level-redirection-edit-btn",
307
+ icon: Pencil,
308
+ variant: "link",
309
+ onClick: function onClick() {
310
+ return setIsEditingDomainRedirect(true);
311
+ }
312
+ })]
313
+ })
314
+ })]
315
+ });
316
+ }
317
+ });
318
+ };
319
+
320
+ var buildBreadcrumbs = function buildBreadcrumbs(pageTitle) {
321
+ return buildSettingsBreadcrumbs(SETTINGS_CATEGORIES.GENERAL, pageTitle);
322
+ };
323
+ var buildMoreMenuItems = function buildMoreMenuItems(_ref) {
324
+ var redirectUrl = _ref.redirectUrl,
325
+ setUrlDetailsToEdit = _ref.setUrlDetailsToEdit,
326
+ setUrlDetailsToDelete = _ref.setUrlDetailsToDelete;
327
+ var id = redirectUrl.id,
328
+ fromPath = redirectUrl.fromPath,
329
+ toPath = redirectUrl.toPath;
330
+ return [{
331
+ key: "edit-menu",
332
+ "data-testid": "neeto-redirect-url-edit-btn",
333
+ label: t("neetoRedirectUrls.common.edit"),
334
+ onClick: function onClick() {
335
+ setUrlDetailsToEdit({
336
+ id: id,
337
+ fromPath: fromPath,
338
+ toPath: toPath
339
+ });
340
+ }
341
+ }, {
342
+ key: "delete-menu",
343
+ "data-testid": "neeto-redirect-url-delete-btn",
344
+ label: t("neetoRedirectUrls.common.delete"),
345
+ onClick: function onClick() {
346
+ setUrlDetailsToDelete({
347
+ id: id,
348
+ fromPath: fromPath,
349
+ toPath: toPath
350
+ });
351
+ }
352
+ }];
353
+ };
354
+
355
+ var RedirectUrlsTable = function RedirectUrlsTable(_ref) {
356
+ var _ref$redirectUrls = _ref.redirectUrls,
357
+ redirectUrls = _ref$redirectUrls === void 0 ? [] : _ref$redirectUrls,
358
+ currentPageNumber = _ref.currentPageNumber,
359
+ setCurrentPageNumber = _ref.setCurrentPageNumber,
360
+ recordsCount = _ref.recordsCount,
361
+ setUrlDetailsToEdit = _ref.setUrlDetailsToEdit,
362
+ setUrlDetailsToDelete = _ref.setUrlDetailsToDelete,
363
+ isFetching = _ref.isFetching;
364
+ var truncateUrl = function truncateUrl(url) {
365
+ var urlString = String(url);
366
+ return urlString.length <= 50 ? urlString : "".concat(urlString.slice(0, 50), "...");
367
+ };
368
+ var _useTranslation = useTranslation(),
369
+ t = _useTranslation.t;
370
+ var columns = [{
371
+ header: t("neetoRedirectUrls.redirect.source"),
372
+ accessorKey: "fromPath",
373
+ id: "name",
374
+ size: 300,
375
+ cell: function cell(_ref2) {
376
+ var row = _ref2.row;
377
+ var redirectUrl = row.original;
378
+ var fromPath = redirectUrl.fromPath;
379
+ return /*#__PURE__*/jsxs("div", {
380
+ className: "flex items-center justify-between gap-x-3",
381
+ children: [/*#__PURE__*/jsx("span", {
382
+ children: fromPath && truncateUrl(fromPath)
383
+ }), /*#__PURE__*/jsx(MoreDropdown, {
384
+ dropdownProps: {
385
+ className: "w-max"
386
+ },
387
+ menuItems: buildMoreMenuItems({
388
+ redirectUrl: redirectUrl,
389
+ setUrlDetailsToEdit: setUrlDetailsToEdit,
390
+ setUrlDetailsToDelete: setUrlDetailsToDelete
391
+ })
392
+ })]
393
+ });
394
+ }
395
+ }, {
396
+ header: t("neetoRedirectUrls.redirect.destination"),
397
+ accessorKey: "toPath",
398
+ id: "toPath",
399
+ size: 300,
400
+ cell: function cell(_ref3) {
401
+ var getValue = _ref3.getValue;
402
+ var toPath = getValue();
403
+ return toPath && truncateUrl(toPath);
404
+ }
405
+ }];
406
+ return /*#__PURE__*/jsx(DataTable, {
407
+ columns: columns,
408
+ fixedHeight: true,
409
+ currentPage: currentPageNumber,
410
+ data: redirectUrls,
411
+ loading: isFetching,
412
+ pageSize: DEFAULT_PAGE_SIZE,
413
+ totalCount: recordsCount,
414
+ onPageChange: function onPageChange(page) {
415
+ return setCurrentPageNumber(page);
416
+ }
417
+ });
418
+ };
419
+
420
+ 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; }
421
+ 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; }
422
+ var RedirectUrls = function RedirectUrls(_ref) {
423
+ var entity = _ref.entity,
424
+ _ref$helpDocUrls = _ref.helpDocUrls,
425
+ helpDocUrls = _ref$helpDocUrls === void 0 ? {} : _ref$helpDocUrls;
426
+ var _useTranslation = useTranslation(),
427
+ t = _useTranslation.t;
428
+ var _useQueryParams = useQueryParams(),
429
+ _useQueryParams$searc = _useQueryParams.searchTerm,
430
+ searchTerm = _useQueryParams$searc === void 0 ? "" : _useQueryParams$searc;
431
+ var initialFocusField = useRef();
432
+ var _useState = useState(1),
433
+ _useState2 = _slicedToArray(_useState, 2),
434
+ currentPageNumber = _useState2[0],
435
+ setCurrentPageNumber = _useState2[1];
436
+ var _useState3 = useState(null),
437
+ _useState4 = _slicedToArray(_useState3, 2),
438
+ urlDetailsToDelete = _useState4[0],
439
+ setUrlDetailsToDelete = _useState4[1];
440
+ var _useState5 = useState(null),
441
+ _useState6 = _slicedToArray(_useState5, 2),
442
+ urlDetailsToEdit = _useState6[0],
443
+ setUrlDetailsToEdit = _useState6[1];
444
+ var _useState7 = useState(false),
445
+ _useState8 = _slicedToArray(_useState7, 2),
446
+ isModalOpen = _useState8[0],
447
+ setIsModalOpen = _useState8[1];
448
+ var _useCreateRedirectUrl = useCreateRedirectUrl(),
449
+ createRedirectUrl = _useCreateRedirectUrl.mutate;
450
+ var searchQuery = _objectSpread({
451
+ page: currentPageNumber
452
+ }, isEmpty(searchTerm) ? {} : {
453
+ searchTerm: searchTerm
454
+ });
455
+ var _useFetchAllRedirectU = useFetchAllRedirectUrls({
456
+ params: searchQuery
457
+ }),
458
+ _useFetchAllRedirectU2 = _useFetchAllRedirectU.data,
459
+ _useFetchAllRedirectU3 = _useFetchAllRedirectU2 === void 0 ? {} : _useFetchAllRedirectU2,
460
+ _useFetchAllRedirectU4 = _useFetchAllRedirectU3.redirectUrls,
461
+ redirectUrls = _useFetchAllRedirectU4 === void 0 ? [] : _useFetchAllRedirectU4,
462
+ domainRedirectUrl = _useFetchAllRedirectU3.domainRedirectUrl,
463
+ isLoading = _useFetchAllRedirectU.isLoading,
464
+ isFetching = _useFetchAllRedirectU.isFetching;
465
+ var isFiltersVisible = (redirectUrls === null || redirectUrls === void 0 ? void 0 : redirectUrls.length) > 0 || isPresent(searchTerm);
466
+ var _useUpdateRedirectUrl = useUpdateRedirectUrl(),
467
+ updateRedirectUrl = _useUpdateRedirectUrl.mutate;
468
+ var _useDestroyRedirectUr = useDestroyRedirectUrl(),
469
+ deleteRedirectUrl = _useDestroyRedirectUr.mutate;
470
+ var handleCreateRedirectUrl = function handleCreateRedirectUrl(redirectUrl, _ref2) {
471
+ var setSubmitting = _ref2.setSubmitting,
472
+ setStatus = _ref2.setStatus;
473
+ createRedirectUrl({
474
+ payload: redirectUrl,
475
+ config: SHOW_TOASTR_CONFIG
476
+ }, {
477
+ onError: function onError(error) {
478
+ handleError(setStatus, error);
479
+ setSubmitting(false);
480
+ },
481
+ onSuccess: function onSuccess() {
482
+ showThumbsUpToastr();
483
+ setIsModalOpen(false);
484
+ }
485
+ });
486
+ };
487
+ var handleRedirectUrlUpdate = function handleRedirectUrlUpdate(redirectUrl, _ref3) {
488
+ var setSubmitting = _ref3.setSubmitting,
489
+ setStatus = _ref3.setStatus;
490
+ updateRedirectUrl({
491
+ id: redirectUrl.id,
492
+ payload: redirectUrl,
493
+ config: SHOW_TOASTR_CONFIG
494
+ }, {
495
+ onError: function onError(error) {
496
+ handleError(setStatus, error);
497
+ setSubmitting(false);
498
+ },
499
+ onSuccess: function onSuccess() {
500
+ showThumbsUpToastr();
501
+ setUrlDetailsToEdit(null);
502
+ }
503
+ });
504
+ };
505
+ var handleRedirectUrlDelete = function handleRedirectUrlDelete(urlId) {
506
+ deleteRedirectUrl(urlId, {
507
+ onSettled: function onSettled() {
508
+ setUrlDetailsToDelete(null);
509
+ }
510
+ });
511
+ };
512
+ var pageTitle = t("neetoRedirectUrls.settings.redirecturl.title");
513
+ var setInitialFocusField = function setInitialFocusField(fieldRef) {
514
+ return initialFocusField.current = fieldRef;
515
+ };
516
+ return /*#__PURE__*/jsx(Container, {
517
+ className: "w-full",
518
+ children: isLoading ? /*#__PURE__*/jsx("div", {
519
+ className: "flex h-full w-full items-center justify-center",
520
+ children: /*#__PURE__*/jsx(Spinner, {})
521
+ }) : /*#__PURE__*/jsxs(Fragment, {
522
+ children: [/*#__PURE__*/jsx(Header, {
523
+ breadcrumbs: buildBreadcrumbs(pageTitle),
524
+ title: pageTitle,
525
+ actionBlock: /*#__PURE__*/jsx(Button, {
526
+ "data-testid": "add-new-redirect-url-button",
527
+ label: t("neetoRedirectUrls.redirect.add"),
528
+ onClick: function onClick() {
529
+ return setIsModalOpen(true);
530
+ }
531
+ }),
532
+ searchProps: isFiltersVisible && {
533
+ placeholder: t("neetoRedirectUrls.redirect.search")
534
+ },
535
+ titleHelpPopoverProps: {
536
+ title: t("neetoRedirectUrls.settings.redirecturl.title"),
537
+ description: t("neetoRedirectUrls.settings.redirecturl.description"),
538
+ helpLinkProps: {
539
+ href: helpDocUrls.createRedirectUrl || CREATE_REDIRECT_URL_HELP_DOC_URL
540
+ }
541
+ }
542
+ }), /*#__PURE__*/jsxs(Fragment, {
543
+ children: [isEmpty(redirectUrls) ? /*#__PURE__*/jsx("div", {
544
+ className: "flex h-full w-full items-center justify-center",
545
+ children: /*#__PURE__*/jsx(Empty, {
546
+ icon: CornerUpRight,
547
+ title: t("neetoRedirectUrls.emptyState.redirectURLs.title"),
548
+ description: /*#__PURE__*/jsx(Trans, {
549
+ i18nKey: "neetoRedirectUrls.emptyState.redirectURLs.description",
550
+ components: {
551
+ helpLink: /*#__PURE__*/jsx(Button, {
552
+ target: "_blank",
553
+ variant: "link",
554
+ href: helpDocUrls.createRedirectUrl || CREATE_REDIRECT_URL_HELP_DOC_URL
555
+ })
556
+ }
557
+ }),
558
+ primaryButtonProps: {
559
+ label: t("neetoRedirectUrls.redirect.add"),
560
+ onClick: function onClick() {
561
+ return setIsModalOpen(true);
562
+ }
563
+ }
564
+ })
565
+ }) : /*#__PURE__*/jsxs(Fragment, {
566
+ children: [/*#__PURE__*/jsx("div", {
567
+ className: "w-full",
568
+ children: /*#__PURE__*/jsx(DomainRedirection, {
569
+ domainRedirectUrl: domainRedirectUrl,
570
+ entity: entity,
571
+ helpDocUrls: helpDocUrls
572
+ })
573
+ }), /*#__PURE__*/jsx(RedirectUrlsTable, {
574
+ currentPageNumber: currentPageNumber,
575
+ isFetching: isFetching,
576
+ redirectUrls: redirectUrls,
577
+ setCurrentPageNumber: setCurrentPageNumber,
578
+ setUrlDetailsToDelete: setUrlDetailsToDelete,
579
+ setUrlDetailsToEdit: setUrlDetailsToEdit,
580
+ recordsCount: redirectUrls.length
581
+ })]
582
+ }), /*#__PURE__*/jsx(DeleteRedirectUrlModal, {
583
+ detailsToDelete: urlDetailsToDelete,
584
+ handleClose: function handleClose() {
585
+ return setUrlDetailsToDelete(null);
586
+ },
587
+ handleSubmit: handleRedirectUrlDelete,
588
+ isOpen: urlDetailsToDelete !== null
589
+ }), /*#__PURE__*/jsx(Sheet, {
590
+ isOpen: isModalOpen || isNotNil(urlDetailsToEdit),
591
+ size: "large",
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