@bigbinary/neeto-api-keys-frontend 1.2.0-beta1 → 2.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.
package/dist/index.js CHANGED
@@ -1,703 +1,36 @@
1
- import { useRef, useState, useEffect } from 'react';
2
- import { t } from 'i18next';
3
- import { isPresent, isNotPresent, isNotEmpty } from '@bigbinary/neeto-cist';
4
- import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
5
- import { useMutationWithInvalidation, withT, useDebounce, withTitle, useQueryParams } from '@bigbinary/neeto-commons-frontend/react-utils';
6
- import Header from '@bigbinary/neeto-molecules/Header';
7
- import Alert from '@bigbinary/neetoui/Alert';
8
- import Button from '@bigbinary/neetoui/Button';
9
- import { useTranslation, Trans } from 'react-i18next';
10
- import { useQuery } from '@tanstack/react-query';
11
- import axios from 'axios';
12
- import Pane from '@bigbinary/neetoui/Pane';
13
- import Typography from '@bigbinary/neetoui/Typography';
14
- import NeetoUIForm from '@bigbinary/neetoui/formik/Form';
15
- import Input from '@bigbinary/neetoui/formik/Input';
16
- import Checkbox from '@bigbinary/neetoui/formik/Checkbox';
17
- import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
18
- import { Field } from 'formik';
19
- import NeetoUIDatePicker from '@bigbinary/neetoui/DatePicker';
20
- import { prop, isEmpty } from 'ramda';
21
- import dayjs from 'dayjs';
22
- import { dateFormat, getQueryParams, buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
23
- import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
24
- import CopyToClipboardButton from '@bigbinary/neeto-molecules/CopyToClipboardButton';
25
- import Tag from '@bigbinary/neetoui/Tag';
26
- import * as yup from 'yup';
27
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
28
- import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
29
- import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
30
- import NeetoUITable from '@bigbinary/neetoui/Table';
31
- import NoData from '@bigbinary/neetoui/NoData';
32
- import { useHistory } from 'react-router-dom';
33
-
34
- function _typeof(o) {
35
- "@babel/helpers - typeof";
36
-
37
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
38
- return typeof o;
39
- } : function (o) {
40
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
41
- }, _typeof(o);
42
- }
43
-
44
- function _toPrimitive(input, hint) {
45
- if (_typeof(input) !== "object" || input === null) return input;
46
- var prim = input[Symbol.toPrimitive];
47
- if (prim !== undefined) {
48
- var res = prim.call(input, hint || "default");
49
- if (_typeof(res) !== "object") return res;
50
- throw new TypeError("@@toPrimitive must return a primitive value.");
51
- }
52
- return (hint === "string" ? String : Number)(input);
53
- }
54
-
55
- function _toPropertyKey(arg) {
56
- var key = _toPrimitive(arg, "string");
57
- return _typeof(key) === "symbol" ? key : String(key);
58
- }
59
-
60
- function _defineProperty(obj, key, value) {
61
- key = _toPropertyKey(key);
62
- if (key in obj) {
63
- Object.defineProperty(obj, key, {
64
- value: value,
65
- enumerable: true,
66
- configurable: true,
67
- writable: true
68
- });
69
- } else {
70
- obj[key] = value;
71
- }
72
- return obj;
73
- }
74
-
75
- function _arrayWithHoles(arr) {
76
- if (Array.isArray(arr)) return arr;
77
- }
78
-
79
- function _iterableToArrayLimit(r, l) {
80
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
81
- if (null != t) {
82
- var e,
83
- n,
84
- i,
85
- u,
86
- a = [],
87
- f = !0,
88
- o = !1;
89
- try {
90
- if (i = (t = t.call(r)).next, 0 === l) {
91
- if (Object(t) !== t) return;
92
- f = !1;
93
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
94
- } catch (r) {
95
- o = !0, n = r;
96
- } finally {
97
- try {
98
- if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
99
- } finally {
100
- if (o) throw n;
101
- }
102
- }
103
- return a;
104
- }
105
- }
106
-
107
- function _arrayLikeToArray(arr, len) {
108
- if (len == null || len > arr.length) len = arr.length;
109
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
110
- return arr2;
111
- }
112
-
113
- function _unsupportedIterableToArray(o, minLen) {
114
- if (!o) return;
115
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
116
- var n = Object.prototype.toString.call(o).slice(8, -1);
117
- if (n === "Object" && o.constructor) n = o.constructor.name;
118
- if (n === "Map" || n === "Set") return Array.from(o);
119
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
120
- }
121
-
122
- function _nonIterableRest() {
123
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
124
- }
125
-
126
- function _slicedToArray(arr, i) {
127
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
128
- }
129
-
130
- var API_KEYS_BASE_URL = "/neeto_api_keys_engine/api/v1/api_keys";
131
-
132
- var fetch = function fetch(params) {
133
- return axios.get(API_KEYS_BASE_URL, {
134
- params: params
135
- });
136
- };
137
- var create = function create(payload) {
138
- return axios.post(API_KEYS_BASE_URL, {
139
- apiKey: payload
140
- });
141
- };
142
- var update = function update(_ref) {
143
- var id = _ref.id,
144
- payload = _ref.payload;
145
- return axios.put("".concat(API_KEYS_BASE_URL, "/").concat(id), {
146
- apiKey: payload
147
- });
148
- };
149
- var destroy = function destroy(id) {
150
- return axios["delete"]("".concat(API_KEYS_BASE_URL, "/").concat(id));
151
- };
152
- var apiKeysApi = {
153
- fetch: fetch,
154
- create: create,
155
- update: update,
156
- destroy: destroy
157
- };
158
-
159
- var QUERY_KEYS = {
160
- API_KEYS: "api-keys"
161
- };
162
-
163
- function ownKeys$4(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; }
164
- function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
165
- var useFetchApiKeys = function useFetchApiKeys(_ref) {
166
- var params = _ref.params,
167
- _ref$options = _ref.options,
168
- options = _ref$options === void 0 ? {} : _ref$options;
169
- return useQuery(_objectSpread$4({
170
- queryKey: [QUERY_KEYS.API_KEYS, params],
171
- queryFn: function queryFn() {
172
- return apiKeysApi.fetch(params);
173
- }
174
- }, options));
175
- };
176
- var useCreateApiKey = function useCreateApiKey(onSuccess) {
177
- return useMutationWithInvalidation(apiKeysApi.create, {
178
- keysToInvalidate: [QUERY_KEYS.API_KEYS],
179
- onSuccess: onSuccess
180
- });
181
- };
182
- var useUpdateApiKey = function useUpdateApiKey(onSuccess) {
183
- return useMutationWithInvalidation(function (_ref2) {
184
- var id = _ref2.id,
185
- payload = _ref2.payload;
186
- return apiKeysApi.update({
187
- id: id,
188
- payload: payload
189
- });
190
- }, {
191
- keysToInvalidate: [QUERY_KEYS.API_KEYS],
192
- onSuccess: onSuccess
193
- });
194
- };
195
- var useDeleteApiKey = function useDeleteApiKey(onSuccess) {
196
- return useMutationWithInvalidation(apiKeysApi.destroy, {
197
- keysToInvalidate: [QUERY_KEYS.API_KEYS],
198
- onSuccess: onSuccess
199
- });
200
- };
201
-
202
- var INITIAL_VALUES = {
203
- expiresAt: null,
204
- label: "",
205
- hasNoExpiry: true
206
- };
207
- var NEXT_DAY = dayjs().add(1, "day").startOf("day");
208
- var VALIDATION_SCHEMA = yup.object({
209
- expiresAt: yup.date().when("hasNoExpiry", function (hasNoExpiry, field) {
210
- return hasNoExpiry ? field.nullable() : field.nullable().required(t("neetoApiKeys.validations.required", {
211
- entity: t("neetoApiKeys.fields.expiryDate")
212
- })).min(NEXT_DAY, t("neetoApiKeys.validations.expiry", {
213
- date: dateFormat.date(NEXT_DAY)
214
- }));
215
- }),
216
- label: yup.string().required(t("neetoApiKeys.validations.required", {
217
- entity: t("neetoApiKeys.fields.label")
218
- }))
219
- });
220
- var MENU_ITEMS = {
221
- EDIT: "edit",
222
- DELETE: "delete"
223
- };
224
-
225
- var isInPast = function isInPast(date) {
226
- return dayjs(date).isBefore(dayjs());
227
- };
228
- var partlyHideToken = function partlyHideToken(key) {
229
- return key.slice(-4).padStart(20, "*");
230
- };
231
- var formatExpiry = function formatExpiry(date) {
232
- return dayjs(date).diff(dayjs(), "day") <= 2 ? dateFormat.fromNow(date) : dateFormat.date(date);
233
- };
234
- var getMenuItems = function getMenuItems(_ref) {
235
- var onEdit = _ref.onEdit,
236
- onDelete = _ref.onDelete;
237
- return [{
238
- key: MENU_ITEMS.EDIT,
239
- label: t("neetoApiKeys.buttons.edit"),
240
- onClick: onEdit
241
- }, {
242
- key: MENU_ITEMS.DELETE,
243
- label: t("neetoApiKeys.buttons.delete"),
244
- onClick: onDelete
245
- }];
246
- };
247
- var buildColumnData = function buildColumnData(_ref2) {
248
- var handleDelete = _ref2.handleDelete,
249
- handleEdit = _ref2.handleEdit;
250
- return [{
251
- title: t("neetoApiKeys.table.headers.label"),
252
- key: "label",
253
- dataIndex: "label",
254
- width: 400,
255
- render: function render(label, apiKey) {
256
- return /*#__PURE__*/jsxs("div", {
257
- className: "flex items-center justify-between space-x-3",
258
- children: [/*#__PURE__*/jsx(Typography, {
259
- style: "body2",
260
- children: label
261
- }), /*#__PURE__*/jsx(MoreDropdown, {
262
- dropdownProps: {
263
- strategy: "fixed"
264
- },
265
- menuItems: getMenuItems({
266
- onEdit: function onEdit() {
267
- return handleEdit(apiKey);
268
- },
269
- onDelete: function onDelete() {
270
- return handleDelete(apiKey);
271
- }
272
- })
273
- })]
274
- });
275
- }
276
- }, {
277
- title: t("neetoApiKeys.table.headers.token"),
278
- key: "token",
279
- dataIndex: "token",
280
- width: 400,
281
- render: function render(token) {
282
- return /*#__PURE__*/jsxs("div", {
283
- className: "flex items-center justify-between gap-x-3",
284
- children: [/*#__PURE__*/jsx(Typography, {
285
- style: "body2",
286
- children: partlyHideToken(token)
287
- }), /*#__PURE__*/jsx(CopyToClipboardButton, {
288
- style: "text",
289
- value: token
290
- })]
291
- });
292
- }
293
- }, {
294
- title: t("neetoApiKeys.table.headers.status"),
295
- key: "status",
296
- width: 144,
297
- render: function render(_, _ref3) {
298
- var expiresAt = _ref3.expiresAt;
299
- return isPresent(expiresAt) && isInPast(expiresAt) ? /*#__PURE__*/jsx(Tag, {
300
- style: "warning",
301
- children: t("neetoApiKeys.tags.expired")
302
- }) : /*#__PURE__*/jsx(Tag, {
303
- style: "success",
304
- children: t("neetoApiKeys.tags.active")
305
- });
306
- }
307
- }, {
308
- title: t("neetoApiKeys.table.headers.expiresAt"),
309
- key: "expiresAt",
310
- dataIndex: "expiresAt",
311
- width: 200,
312
- render: function render(expiresAt) {
313
- return isPresent(expiresAt) ? formatExpiry(expiresAt) : /*#__PURE__*/jsx(Typography, {
314
- style: "body2",
315
- children: t("neetoApiKeys.common.never")
316
- });
317
- }
318
- }, {
319
- title: t("neetoApiKeys.table.headers.createdAt"),
320
- key: "createdAt",
321
- dataIndex: "createdAt",
322
- width: 200,
323
- render: function render(createdAt) {
324
- return isPresent(createdAt) ? dateFormat.dateTime(createdAt) : /*#__PURE__*/jsx(Typography, {
325
- style: "body2",
326
- children: t("neetoApiKeys.common.never")
327
- });
328
- }
329
- }];
330
- };
331
- var getStartOfTime = function getStartOfTime(time, unit) {
332
- return dayjs(time).startOf(unit);
333
- };
334
-
335
- 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; }
336
- 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; }
337
- var DatePicker = function DatePicker(_ref) {
338
- var defaultValue = _ref.defaultValue,
339
- disabledDate = _ref.disabledDate,
340
- label = _ref.label,
341
- placeholder = _ref.placeholder,
342
- name = _ref.name,
343
- _ref$disabled = _ref.disabled,
344
- disabled = _ref$disabled === void 0 ? false : _ref$disabled;
345
- return /*#__PURE__*/jsx(Field, {
346
- name: name,
347
- children: function children(_ref2) {
348
- var _globalProps;
349
- var field = _ref2.field,
350
- meta = _ref2.meta,
351
- setFieldValue = _ref2.form.setFieldValue;
352
- return /*#__PURE__*/jsx(NeetoUIDatePicker, _objectSpread$3(_objectSpread$3({
353
- disabled: disabled,
354
- disabledDate: disabledDate,
355
- label: label,
356
- placeholder: placeholder,
357
- defaultValue: defaultValue,
358
- allowClear: false,
359
- className: "w-full",
360
- error: meta.touched && meta.error,
361
- format: (_globalProps = globalProps) === null || _globalProps === void 0 || (_globalProps = _globalProps.user) === null || _globalProps === void 0 ? void 0 : _globalProps.dateFormat,
362
- getPopupContainer: prop("parentNode")
363
- }, field), {}, {
364
- onChange: function onChange(date) {
365
- setFieldValue(field.name, getStartOfTime(date, "day"));
366
- }
367
- }));
368
- }
369
- });
370
- };
371
-
372
- var Form = withT(function (_ref) {
373
- var t = _ref.t,
374
- _ref$initialValues = _ref.initialValues,
375
- initialValues = _ref$initialValues === void 0 ? INITIAL_VALUES : _ref$initialValues,
376
- isSubmitting = _ref.isSubmitting,
377
- onClose = _ref.onClose,
378
- onSubmit = _ref.onSubmit,
379
- initialFocusRef = _ref.initialFocusRef;
380
- return /*#__PURE__*/jsx(NeetoUIForm, {
381
- formikProps: {
382
- validationSchema: VALIDATION_SCHEMA,
383
- initialValues: initialValues,
384
- onSubmit: onSubmit
385
- },
386
- children: function children(_ref2) {
387
- var setFieldValue = _ref2.setFieldValue,
388
- _ref2$values = _ref2.values,
389
- _ref2$values2 = _ref2$values === void 0 ? {} : _ref2$values,
390
- hasNoExpiry = _ref2$values2.hasNoExpiry,
391
- expiresAt = _ref2$values2.expiresAt;
392
- return /*#__PURE__*/jsxs(Fragment, {
393
- children: [/*#__PURE__*/jsx(Pane.Body, {
394
- children: /*#__PURE__*/jsxs("div", {
395
- className: "w-full space-y-4",
396
- children: [/*#__PURE__*/jsx(Input, {
397
- autoFocus: true,
398
- label: t("neetoApiKeys.fields.label"),
399
- name: "label",
400
- placeholder: t("neetoApiKeys.placeholders.label"),
401
- ref: initialFocusRef
402
- }), /*#__PURE__*/jsxs("div", {
403
- className: "space-y-2",
404
- children: [!hasNoExpiry && /*#__PURE__*/jsx(DatePicker, {
405
- defaultValue: expiresAt,
406
- disabledDate: function disabledDate(date) {
407
- return date < NEXT_DAY;
408
- },
409
- label: t("neetoApiKeys.fields.expiryDate"),
410
- name: "expiresAt",
411
- placeholder: t("neetoApiKeys.placeholders.selectExpiryDate")
412
- }), /*#__PURE__*/jsx(Checkbox, {
413
- checked: hasNoExpiry,
414
- label: t("neetoApiKeys.fields.neverExpire"),
415
- name: "hasNoExpiry",
416
- onChange: function onChange() {
417
- setFieldValue("expiresAt", null);
418
- setFieldValue("hasNoExpiry", !hasNoExpiry);
419
- }
420
- })]
421
- })]
422
- })
423
- }), /*#__PURE__*/jsx(Pane.Footer, {
424
- children: /*#__PURE__*/jsx(ActionBlock, {
425
- isSubmitting: isSubmitting,
426
- cancelButtonProps: {
427
- onClick: onClose
428
- }
429
- })
430
- })]
431
- });
432
- }
433
- });
434
- });
435
-
436
- var Create = function Create(_ref) {
437
- var onClose = _ref.onClose,
438
- isOpen = _ref.isOpen;
439
- var initialFocusRef = useRef(null);
440
- var _useCreateApiKey = useCreateApiKey(onClose),
441
- createApiKey = _useCreateApiKey.mutate,
442
- isCreating = _useCreateApiKey.isPending;
443
- var _useTranslation = useTranslation(),
444
- t = _useTranslation.t;
445
- return /*#__PURE__*/jsxs(Pane, {
446
- initialFocusRef: initialFocusRef,
447
- isOpen: isOpen,
448
- onClose: onClose,
449
- children: [/*#__PURE__*/jsx(Pane.Header, {
450
- children: /*#__PURE__*/jsx(Typography, {
451
- style: "h2",
452
- children: t("neetoApiKeys.headers.createApiKey")
453
- })
454
- }), /*#__PURE__*/jsx(Form, {
455
- initialFocusRef: initialFocusRef,
456
- onClose: onClose,
457
- isSubmitting: isCreating,
458
- onSubmit: createApiKey
459
- })]
460
- });
461
- };
462
-
463
- 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; }
464
- 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; }
465
- var Update = function Update(_ref) {
466
- var onClose = _ref.onClose,
467
- apiKey = _ref.apiKey;
468
- var initialFocusRef = useRef(null);
469
- var _useUpdateApiKey = useUpdateApiKey(onClose),
470
- updateApiKey = _useUpdateApiKey.mutate,
471
- isUpdating = _useUpdateApiKey.isPending;
472
- var _useTranslation = useTranslation(),
473
- t = _useTranslation.t;
474
- var handleUpdate = function handleUpdate(values) {
475
- updateApiKey({
476
- id: apiKey.id,
477
- payload: values
478
- });
479
- };
480
- var initialValues = _objectSpread$2(_objectSpread$2({}, apiKey), {}, {
481
- hasNoExpiry: isNotPresent(apiKey.expiresAt)
482
- });
483
- return /*#__PURE__*/jsxs(Pane, {
484
- initialFocusRef: initialFocusRef,
485
- onClose: onClose,
486
- isOpen: isNotEmpty(apiKey),
487
- children: [/*#__PURE__*/jsx(Pane.Header, {
488
- children: /*#__PURE__*/jsx(Typography, {
489
- style: "h2",
490
- children: t("neetoApiKeys.headers.updateApiKey")
491
- })
492
- }), /*#__PURE__*/jsx(Form, {
493
- initialFocusRef: initialFocusRef,
494
- initialValues: initialValues,
495
- onClose: onClose,
496
- isSubmitting: isUpdating,
497
- onSubmit: handleUpdate
498
- })]
499
- });
500
- };
501
-
502
- var getPageFromSearchParams = function getPageFromSearchParams() {
503
- var _getQueryParams = getQueryParams(),
504
- page = _getQueryParams.page;
505
- return parseInt(page) || DEFAULT_PAGE_INDEX;
506
- };
507
- var setPageSearchParam = function setPageSearchParam(_ref) {
508
- var page = _ref.page,
509
- history = _ref.history;
510
- var searchParams = page !== DEFAULT_PAGE_INDEX && buildUrl("", {
511
- page: page
512
- });
513
- history.push({
514
- search: searchParams
515
- });
516
- };
517
-
518
- var usePagination = function usePagination(_ref) {
519
- var searchTerm = _ref.searchTerm;
520
- var _useState = useState(getPageFromSearchParams),
521
- _useState2 = _slicedToArray(_useState, 2),
522
- currentPage = _useState2[0],
523
- setCurrentPage = _useState2[1];
524
- var history = useHistory();
525
- useEffect(function () {
526
- handlePageChange(getPageFromSearchParams());
527
- }, []);
528
- useEffect(function () {
529
- if (isNotEmpty(searchTerm) && currentPage !== DEFAULT_PAGE_INDEX) {
530
- handlePageChange(DEFAULT_PAGE_INDEX);
531
- }
532
- }, [searchTerm]);
533
- var handlePageChange = function handlePageChange(page) {
534
- setCurrentPage(page);
535
- setPageSearchParam({
536
- page: page,
537
- history: history
538
- });
539
- };
540
- var onFetchSuccess = function onFetchSuccess(_ref2) {
541
- var totalCount = _ref2.totalCount,
542
- apiKeys = _ref2.apiKeys;
543
- if (totalCount !== 0 && isEmpty(apiKeys)) {
544
- handlePageChange(DEFAULT_PAGE_INDEX);
545
- }
546
- };
547
- return {
548
- currentPage: currentPage,
549
- handlePageChange: handlePageChange,
550
- onFetchSuccess: onFetchSuccess
551
- };
552
- };
553
-
554
- 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; }
555
- 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; }
556
- var Table = function Table(_ref) {
557
- var handleDelete = _ref.handleDelete,
558
- handleEdit = _ref.handleEdit,
559
- searchTerm = _ref.searchTerm,
560
- setIsCreatePaneOpen = _ref.setIsCreatePaneOpen,
561
- _ref$noDataProps = _ref.noDataProps,
562
- noDataProps = _ref$noDataProps === void 0 ? {} : _ref$noDataProps;
563
- var debouncedSearchTerm = useDebounce(searchTerm);
564
- var _useTranslation = useTranslation(),
565
- t = _useTranslation.t;
566
- var _usePagination = usePagination({
567
- searchTerm: debouncedSearchTerm
568
- }),
569
- currentPage = _usePagination.currentPage,
570
- handlePageChange = _usePagination.handlePageChange,
571
- onFetchSuccess = _usePagination.onFetchSuccess;
572
- var queryParams = {
573
- searchTerm: debouncedSearchTerm,
574
- page: currentPage,
575
- pageSize: DEFAULT_PAGE_SIZE
576
- };
577
- var _useFetchApiKeys = useFetchApiKeys({
578
- params: queryParams
579
- }),
580
- data = _useFetchApiKeys.data,
581
- isLoading = _useFetchApiKeys.isLoading,
582
- isFetching = _useFetchApiKeys.isFetching;
583
- useEffect(function () {
584
- if (!data) return;
585
- onFetchSuccess(data);
586
- }, [data]);
587
- if (isLoading) return /*#__PURE__*/jsx(PageLoader, {});
588
- if (isEmpty(data === null || data === void 0 ? void 0 : data.apiKeys)) {
589
- return /*#__PURE__*/jsxs("div", {
590
- className: "flex h-full w-full items-center justify-center",
591
- children: [/*#__PURE__*/jsx(NoData, _objectSpread$1({
592
- className: "w-full",
593
- title: t("neetoApiKeys.noData.title"),
594
- primaryButtonProps: {
595
- label: t("neetoApiKeys.buttons.addApiKey"),
596
- onClick: function onClick() {
597
- return setIsCreatePaneOpen(true);
598
- }
599
- }
600
- }, noDataProps)), ";"]
601
- });
602
- }
603
- return /*#__PURE__*/jsx(TableWrapper, {
604
- hasPagination: (data === null || data === void 0 ? void 0 : data.totalCount) > DEFAULT_PAGE_SIZE,
605
- children: /*#__PURE__*/jsx(NeetoUITable, {
606
- handlePageChange: handlePageChange,
607
- fixedHeight: true,
608
- columnData: buildColumnData({
609
- handleDelete: handleDelete,
610
- handleEdit: handleEdit
611
- }),
612
- currentPageNumber: currentPage,
613
- defaultPageSize: DEFAULT_PAGE_SIZE,
614
- loading: isFetching,
615
- rowData: data === null || data === void 0 ? void 0 : data.apiKeys,
616
- totalCount: data === null || data === void 0 ? void 0 : data.totalCount
617
- })
618
- });
619
- };
620
-
621
- 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; }
622
- 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; }
623
- var ApiKeys = function ApiKeys(_ref) {
624
- var noDataProps = _ref.noDataProps,
625
- headerProps = _ref.headerProps;
626
- var _useState = useState({}),
627
- _useState2 = _slicedToArray(_useState, 2),
628
- apiKeyToBeDeleted = _useState2[0],
629
- setApiKeyToBeDeleted = _useState2[1];
630
- var _useState3 = useState({}),
631
- _useState4 = _slicedToArray(_useState3, 2),
632
- apiKeyToBeEdited = _useState4[0],
633
- setApiKeyToBeEdited = _useState4[1];
634
- var _useState5 = useState(false),
635
- _useState6 = _slicedToArray(_useState5, 2),
636
- isCreatePaneOpen = _useState6[0],
637
- setIsCreatePaneOpen = _useState6[1];
638
- var _useTranslation = useTranslation(),
639
- t = _useTranslation.t;
640
- var _useQueryParams = useQueryParams(),
641
- _useQueryParams$searc = _useQueryParams.searchTerm,
642
- searchTerm = _useQueryParams$searc === void 0 ? "" : _useQueryParams$searc;
643
- var _useDeleteApiKey = useDeleteApiKey(function () {
644
- return setApiKeyToBeDeleted({});
645
- }),
646
- deleteApiKey = _useDeleteApiKey.mutate,
647
- isDeleting = _useDeleteApiKey.isPending;
648
- return /*#__PURE__*/jsxs("div", {
649
- className: "flex h-full w-full flex-col",
650
- children: [/*#__PURE__*/jsx(Header, _objectSpread({
651
- title: t("neetoApiKeys.common.apiKey", PLURAL),
652
- actionBlock: /*#__PURE__*/jsx(Button, {
653
- label: t("neetoApiKeys.buttons.addApiKey"),
654
- onClick: function onClick() {
655
- return setIsCreatePaneOpen(true);
656
- }
657
- }),
658
- searchProps: {
659
- placeholder: t("neetoApiKeys.placeholders.search")
660
- }
661
- }, headerProps)), /*#__PURE__*/jsx(Table, {
662
- noDataProps: noDataProps,
663
- searchTerm: searchTerm,
664
- setIsCreatePaneOpen: setIsCreatePaneOpen,
665
- handleDelete: setApiKeyToBeDeleted,
666
- handleEdit: setApiKeyToBeEdited
667
- }), /*#__PURE__*/jsx(Alert, {
668
- isOpen: isNotEmpty(apiKeyToBeDeleted),
669
- isSubmitting: isDeleting,
670
- submitButtonLabel: t("neetoApiKeys.buttons.delete"),
671
- title: t("neetoApiKeys.alert.titles.deleteApiKey"),
672
- message: /*#__PURE__*/jsx(Trans, {
673
- components: {
674
- bold: /*#__PURE__*/jsx("strong", {})
675
- },
676
- i18nKey: "neetoApiKeys.alert.descriptions.deleteApiKey",
677
- values: {
678
- name: apiKeyToBeDeleted.label
679
- }
680
- }),
681
- onClose: function onClose() {
682
- return setApiKeyToBeDeleted({});
683
- },
684
- onSubmit: function onSubmit() {
685
- return deleteApiKey(apiKeyToBeDeleted.id);
686
- }
687
- }), /*#__PURE__*/jsx(Create, {
688
- isOpen: isCreatePaneOpen,
689
- onClose: function onClose() {
690
- return setIsCreatePaneOpen(false);
691
- }
692
- }), /*#__PURE__*/jsx(Update, {
693
- apiKey: apiKeyToBeEdited,
694
- onClose: function onClose() {
695
- return setApiKeyToBeEdited({});
696
- }
697
- })]
698
- });
699
- };
700
- var index = withTitle(ApiKeys, t("neetoApiKeys.common.apiKey", PLURAL));
701
-
702
- export { index as ApiKeys };
1
+ export { default as ApiKeys } from './ApiKeys.js';
2
+ import 'react';
3
+ import 'i18next';
4
+ import '@bigbinary/neeto-cist';
5
+ import '@bigbinary/neeto-commons-frontend/constants';
6
+ import '@bigbinary/neeto-commons-frontend/react-utils';
7
+ import '@bigbinary/neeto-molecules/Header';
8
+ import '@bigbinary/neeto-molecules/HelpPopover';
9
+ import '@bigbinary/neetoui/Alert';
10
+ import '@bigbinary/neetoui/Button';
11
+ import 'react-i18next';
12
+ import '@bigbinary/neeto-commons-frontend/initializers';
13
+ import '@tanstack/react-query';
14
+ import 'axios';
15
+ import '@bigbinary/neetoui/Pane';
16
+ import '@bigbinary/neetoui/Typography';
17
+ import '@bigbinary/neetoui/formik/Form';
18
+ import '@bigbinary/neetoui/formik/Input';
19
+ import '@bigbinary/neetoui/formik/Checkbox';
20
+ import '@bigbinary/neetoui/formik/ActionBlock';
21
+ import 'formik';
22
+ import '@bigbinary/neetoui/DatePicker';
23
+ import 'ramda';
24
+ import 'dayjs';
25
+ import '@bigbinary/neeto-commons-frontend/utils';
26
+ import '@bigbinary/neeto-molecules/MoreDropdown';
27
+ import '@bigbinary/neeto-molecules/CopyToClipboardButton';
28
+ import '@bigbinary/neetoui/Tag';
29
+ import 'yup';
30
+ import 'react/jsx-runtime';
31
+ import '@bigbinary/neeto-molecules/PageLoader';
32
+ import '@bigbinary/neeto-molecules/TableWrapper';
33
+ import '@bigbinary/neetoui/Table';
34
+ import '@bigbinary/neetoui/NoData';
35
+ import 'react-router-dom';
703
36
  //# sourceMappingURL=index.js.map