@bigbinary/neeto-access-control-frontend 0.1.0-beta1 → 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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { createElement } from 'react';
1
+ import { useRef, useState, createElement } from 'react';
2
2
  import classNames from 'classnames';
3
- import { hyphenate, isNotEmpty, noop } from '@bigbinary/neeto-cist';
3
+ import { truncate, humanize, isNotEmpty, hyphenate, noop } from '@bigbinary/neeto-cist';
4
4
  import Container from '@bigbinary/neeto-molecules/Container';
5
5
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
6
6
  import Scrollable from '@bigbinary/neeto-molecules/Scrollable';
@@ -9,18 +9,29 @@ import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
9
9
  import Form from '@bigbinary/neetoui/formik/Form';
10
10
  import Input from '@bigbinary/neetoui/formik/Input';
11
11
  import Radio from '@bigbinary/neetoui/formik/Radio';
12
- import { useTranslation } from 'react-i18next';
12
+ import { useTranslation, Trans } from 'react-i18next';
13
+ import { DEFAULT_STALE_TIME, DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-frontend/constants';
14
+ import Delete from '@bigbinary/neeto-icons/Delete';
15
+ import SubHeader from '@bigbinary/neeto-molecules/SubHeader';
16
+ import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
17
+ import Alert from '@bigbinary/neetoui/Alert';
18
+ import Button from '@bigbinary/neetoui/Button';
19
+ import NoData from '@bigbinary/neetoui/NoData';
20
+ import Pane from '@bigbinary/neetoui/Pane';
21
+ import Table from '@bigbinary/neetoui/Table';
22
+ import Typography from '@bigbinary/neetoui/Typography';
23
+ import { pluck, isEmpty, prop, equals, pick, reject, pipe, trim } from 'ramda';
13
24
  import { useQuery } from '@tanstack/react-query';
14
- import { DEFAULT_STALE_TIME } from '@bigbinary/neeto-commons-frontend/constants';
15
25
  import { useMutationWithInvalidation, withT } from '@bigbinary/neeto-commons-frontend/react-utils';
16
- import { prop, equals, isEmpty, pick, reject, pipe, trim } from 'ramda';
17
26
  import axios from 'axios';
18
- import { FieldArray } from 'formik';
19
- import { Delete } from '@bigbinary/neeto-icons';
20
- import Button from '@bigbinary/neetoui/Button';
27
+ import Modal from '@bigbinary/neetoui/Modal';
28
+ import MultiEmailInput from '@bigbinary/neetoui/formik/MultiEmailInput';
29
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
21
30
  import { t } from 'i18next';
31
+ import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
32
+ import Tooltip from '@bigbinary/neetoui/Tooltip';
33
+ import { FieldArray } from 'formik';
22
34
  import * as yup from 'yup';
23
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
24
35
  import NeetoHeader from '@bigbinary/neeto-molecules/Header';
25
36
  import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
26
37
 
@@ -65,8 +76,461 @@ function _defineProperty(obj, key, value) {
65
76
  return obj;
66
77
  }
67
78
 
79
+ function _arrayWithHoles(arr) {
80
+ if (Array.isArray(arr)) return arr;
81
+ }
82
+
83
+ function _iterableToArrayLimit(r, l) {
84
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
85
+ if (null != t) {
86
+ var e,
87
+ n,
88
+ i,
89
+ u,
90
+ a = [],
91
+ f = !0,
92
+ o = !1;
93
+ try {
94
+ if (i = (t = t.call(r)).next, 0 === l) {
95
+ if (Object(t) !== t) return;
96
+ f = !1;
97
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
98
+ } catch (r) {
99
+ o = !0, n = r;
100
+ } finally {
101
+ try {
102
+ if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
103
+ } finally {
104
+ if (o) throw n;
105
+ }
106
+ }
107
+ return a;
108
+ }
109
+ }
110
+
111
+ function _arrayLikeToArray(arr, len) {
112
+ if (len == null || len > arr.length) len = arr.length;
113
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
114
+ return arr2;
115
+ }
116
+
117
+ function _unsupportedIterableToArray(o, minLen) {
118
+ if (!o) return;
119
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
120
+ var n = Object.prototype.toString.call(o).slice(8, -1);
121
+ if (n === "Object" && o.constructor) n = o.constructor.name;
122
+ if (n === "Map" || n === "Set") return Array.from(o);
123
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
124
+ }
125
+
126
+ function _nonIterableRest() {
127
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
128
+ }
129
+
130
+ function _slicedToArray(arr, i) {
131
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
132
+ }
133
+
134
+ function _objectWithoutPropertiesLoose(source, excluded) {
135
+ if (source == null) return {};
136
+ var target = {};
137
+ var sourceKeys = Object.keys(source);
138
+ var key, i;
139
+ for (i = 0; i < sourceKeys.length; i++) {
140
+ key = sourceKeys[i];
141
+ if (excluded.indexOf(key) >= 0) continue;
142
+ target[key] = source[key];
143
+ }
144
+ return target;
145
+ }
146
+
147
+ function _objectWithoutProperties(source, excluded) {
148
+ if (source == null) return {};
149
+ var target = _objectWithoutPropertiesLoose(source, excluded);
150
+ var key, i;
151
+ if (Object.getOwnPropertySymbols) {
152
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
153
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
154
+ key = sourceSymbolKeys[i];
155
+ if (excluded.indexOf(key) >= 0) continue;
156
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
157
+ target[key] = source[key];
158
+ }
159
+ }
160
+ return target;
161
+ }
162
+
68
163
  var ACCESS_CONTROL_BASE_PATH = "/secure/api/v1";
69
164
 
165
+ var invitationsPath = "".concat(ACCESS_CONTROL_BASE_PATH, "/configuration/invitations");
166
+ var list = function list(params) {
167
+ return axios.get(invitationsPath, {
168
+ params: params
169
+ });
170
+ };
171
+ var bulkCreate = function bulkCreate(_ref) {
172
+ var configurationId = _ref.configurationId,
173
+ payload = _ref.payload;
174
+ return axios.post("".concat(invitationsPath, "/bulk_create"), payload, {
175
+ params: {
176
+ neetoAccessControlConfigurationId: configurationId
177
+ }
178
+ });
179
+ };
180
+ var bulkDestroy = function bulkDestroy(_ref2) {
181
+ var configurationId = _ref2.configurationId,
182
+ payload = _ref2.payload;
183
+ return axios.post("".concat(invitationsPath, "/bulk_destroy"), payload, {
184
+ params: {
185
+ neetoAccessControlConfigurationId: configurationId
186
+ }
187
+ });
188
+ };
189
+ var invitationsApi = {
190
+ list: list,
191
+ bulkDestroy: bulkDestroy,
192
+ bulkCreate: bulkCreate
193
+ };
194
+
195
+ var QUERY_KEYS = {
196
+ ACCESS_CONTROL_CONFIGURATION: "access-control-configuration",
197
+ ACCESS_CONTROL_CONFIGURATION_INVITATIONS: "access-control-configuration-invitations"
198
+ };
199
+
200
+ var _excluded = ["ownerId", "ownerType"];
201
+ 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; }
202
+ 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; }
203
+ var ACCESS_CONTROL_CONFIGURATION_INVITATIONS$1 = QUERY_KEYS.ACCESS_CONTROL_CONFIGURATION_INVITATIONS;
204
+ var useListInvitations = function useListInvitations(_ref, options) {
205
+ var ownerId = _ref.ownerId,
206
+ ownerType = _ref.ownerType,
207
+ otherParams = _objectWithoutProperties(_ref, _excluded);
208
+ return useQuery(_objectSpread$3({
209
+ queryKey: [ACCESS_CONTROL_CONFIGURATION_INVITATIONS$1, ownerType, ownerId, otherParams],
210
+ queryFn: function queryFn() {
211
+ return invitationsApi.list(otherParams);
212
+ },
213
+ staleTime: DEFAULT_STALE_TIME
214
+ }, options));
215
+ };
216
+ var useBulkCreateInvitations = function useBulkCreateInvitations(_ref2, options) {
217
+ var configurationId = _ref2.configurationId,
218
+ ownerId = _ref2.ownerId,
219
+ ownerType = _ref2.ownerType;
220
+ return useMutationWithInvalidation(function (payload) {
221
+ return invitationsApi.bulkCreate({
222
+ configurationId: configurationId,
223
+ payload: payload
224
+ });
225
+ }, _objectSpread$3({
226
+ keysToInvalidate: [[ACCESS_CONTROL_CONFIGURATION_INVITATIONS$1, ownerType, ownerId]]
227
+ }, options));
228
+ };
229
+ var useBulkDestroyInvitations = function useBulkDestroyInvitations(_ref3, options) {
230
+ var configurationId = _ref3.configurationId,
231
+ ownerId = _ref3.ownerId,
232
+ ownerType = _ref3.ownerType;
233
+ return useMutationWithInvalidation(function (payload) {
234
+ return invitationsApi.bulkDestroy({
235
+ configurationId: configurationId,
236
+ payload: payload
237
+ });
238
+ }, _objectSpread$3({
239
+ keysToInvalidate: [[ACCESS_CONTROL_CONFIGURATION_INVITATIONS$1, ownerType, ownerId]]
240
+ }, options));
241
+ };
242
+
243
+ var TRUNCATE_LENGTH = 45;
244
+ var ADD_EMAILS_FORM_INIT_VALUES = {
245
+ emails: []
246
+ };
247
+
248
+ var AddEmails = function AddEmails(_ref) {
249
+ var isOpen = _ref.isOpen,
250
+ onClose = _ref.onClose,
251
+ configurationId = _ref.configurationId,
252
+ ownerType = _ref.ownerType,
253
+ ownerId = _ref.ownerId;
254
+ var _useTranslation = useTranslation(),
255
+ t = _useTranslation.t;
256
+ var emailsInputRef = useRef();
257
+ var _useBulkCreateInvitat = useBulkCreateInvitations({
258
+ configurationId: configurationId,
259
+ ownerType: ownerType,
260
+ ownerId: ownerId
261
+ }),
262
+ addEmails = _useBulkCreateInvitat.mutate;
263
+ var handleAddEmails = function handleAddEmails(_ref2, _ref3) {
264
+ var emails = _ref2.emails;
265
+ var setSubmitting = _ref3.setSubmitting;
266
+ var payload = {
267
+ emails: pluck("value", emails)
268
+ };
269
+ addEmails(payload, {
270
+ onSuccess: function onSuccess() {
271
+ onClose();
272
+ },
273
+ onError: function onError() {
274
+ return setSubmitting(false);
275
+ }
276
+ });
277
+ };
278
+ return /*#__PURE__*/jsxs(Modal, {
279
+ isOpen: isOpen,
280
+ onClose: onClose,
281
+ initialFocusRef: emailsInputRef,
282
+ children: [/*#__PURE__*/jsx(Modal.Header, {
283
+ description: t("neetoAccessControl.addEmails.description"),
284
+ children: /*#__PURE__*/jsx(Typography, {
285
+ style: "h2",
286
+ children: t("neetoAccessControl.buttons.addEmails")
287
+ })
288
+ }), /*#__PURE__*/jsxs(Form, {
289
+ formikProps: {
290
+ initialValues: ADD_EMAILS_FORM_INIT_VALUES,
291
+ onSubmit: handleAddEmails
292
+ },
293
+ children: [/*#__PURE__*/jsx(Modal.Body, {
294
+ children: /*#__PURE__*/jsx(MultiEmailInput, {
295
+ name: "emails",
296
+ placeholder: t("neetoAccessControl.addEmails.placeholder"),
297
+ ref: emailsInputRef
298
+ })
299
+ }), /*#__PURE__*/jsx(Modal.Footer, {
300
+ children: /*#__PURE__*/jsx(ActionBlock, {
301
+ cancelButtonProps: {
302
+ onClick: onClose
303
+ },
304
+ submitButtonProps: {
305
+ label: t("neetoAccessControl.buttons.addEmails")
306
+ }
307
+ })
308
+ })]
309
+ })]
310
+ });
311
+ };
312
+
313
+ var renderColumnData = function renderColumnData(_ref) {
314
+ var onDelete = _ref.onDelete;
315
+ return [{
316
+ title: t("neetoAccessControl.titles.emails"),
317
+ dataIndex: "email",
318
+ key: "email",
319
+ width: 75,
320
+ render: function render(email, inviteData) {
321
+ return /*#__PURE__*/jsxs("div", {
322
+ className: "flex items-center justify-between gap-x-3",
323
+ children: [/*#__PURE__*/jsx(Tooltip, {
324
+ content: email,
325
+ disabled: email.length < TRUNCATE_LENGTH,
326
+ children: /*#__PURE__*/jsx(Typography, {
327
+ style: "body2",
328
+ children: truncate(email, TRUNCATE_LENGTH)
329
+ })
330
+ }), /*#__PURE__*/jsx(MoreDropdown, {
331
+ dropdownProps: {
332
+ strategy: "fixed"
333
+ },
334
+ menuItems: [{
335
+ key: "delete",
336
+ label: t("neetoAccessControl.labels.delete"),
337
+ onClick: function onClick() {
338
+ return onDelete(inviteData);
339
+ }
340
+ }]
341
+ })]
342
+ });
343
+ }
344
+ }, {
345
+ title: t("neetoAccessControl.titles.status"),
346
+ dataIndex: "status",
347
+ key: "status",
348
+ width: 75,
349
+ render: function render(status) {
350
+ return humanize(status);
351
+ }
352
+ }];
353
+ };
354
+
355
+ var Invitations = function Invitations(_ref) {
356
+ var _selectedEmails$;
357
+ var invitationsTableColumnData = _ref.invitationsTableColumnData,
358
+ configurationId = _ref.configurationId,
359
+ ownerType = _ref.ownerType,
360
+ ownerId = _ref.ownerId,
361
+ isOpen = _ref.isOpen,
362
+ onClose = _ref.onClose;
363
+ var _useState = useState([]),
364
+ _useState2 = _slicedToArray(_useState, 2),
365
+ selectedEmails = _useState2[0],
366
+ setSelectedEmails = _useState2[1];
367
+ var _useState3 = useState(false),
368
+ _useState4 = _slicedToArray(_useState3, 2),
369
+ showDeleteAlert = _useState4[0],
370
+ setShowDeleteAlert = _useState4[1];
371
+ var _useState5 = useState(false),
372
+ _useState6 = _slicedToArray(_useState5, 2),
373
+ showAddEmails = _useState6[0],
374
+ setShowAddEmails = _useState6[1];
375
+ var _useState7 = useState(DEFAULT_PAGE_INDEX),
376
+ _useState8 = _slicedToArray(_useState7, 2),
377
+ page = _useState8[0],
378
+ setPage = _useState8[1];
379
+ var _useTranslation = useTranslation(),
380
+ t = _useTranslation.t;
381
+ var _useListInvitations = useListInvitations({
382
+ neetoAccessControlConfigurationId: configurationId,
383
+ ownerType: ownerType,
384
+ ownerId: ownerId,
385
+ page: page,
386
+ pageSize: DEFAULT_PAGE_SIZE
387
+ }, {
388
+ enabled: isOpen
389
+ }),
390
+ _useListInvitations$d = _useListInvitations.data,
391
+ _useListInvitations$d2 = _useListInvitations$d === void 0 ? {} : _useListInvitations$d,
392
+ _useListInvitations$d3 = _useListInvitations$d2.invitations,
393
+ invitations = _useListInvitations$d3 === void 0 ? [] : _useListInvitations$d3,
394
+ _useListInvitations$d4 = _useListInvitations$d2.totalCount,
395
+ totalCount = _useListInvitations$d4 === void 0 ? 0 : _useListInvitations$d4,
396
+ isFetching = _useListInvitations.isFetching,
397
+ isLoading = _useListInvitations.isLoading;
398
+ var _useBulkDestroyInvita = useBulkDestroyInvitations({
399
+ configurationId: configurationId,
400
+ ownerType: ownerType,
401
+ ownerId: ownerId
402
+ }),
403
+ deleteEmailInvites = _useBulkDestroyInvita.mutate,
404
+ isPending = _useBulkDestroyInvita.isPending;
405
+ var handleAddEmails = function handleAddEmails() {
406
+ setShowAddEmails(true);
407
+ };
408
+ var handleOnClose = function handleOnClose() {
409
+ onClose();
410
+ setSelectedEmails([]);
411
+ };
412
+ var handleDeleteEmailInvites = function handleDeleteEmailInvites() {
413
+ var payload = {
414
+ emails: pluck("email", selectedEmails)
415
+ };
416
+ deleteEmailInvites(payload, {
417
+ onSuccess: function onSuccess() {
418
+ setSelectedEmails([]);
419
+ setShowDeleteAlert(false);
420
+ }
421
+ });
422
+ };
423
+ var handleDeleteAction = function handleDeleteAction(inviteData) {
424
+ setSelectedEmails([inviteData]);
425
+ setShowDeleteAlert(true);
426
+ };
427
+ return /*#__PURE__*/jsxs(Fragment, {
428
+ children: [/*#__PURE__*/jsxs(Pane, {
429
+ isOpen: isOpen,
430
+ size: "large",
431
+ onClose: handleOnClose,
432
+ children: [/*#__PURE__*/jsx(Pane.Header, {
433
+ children: /*#__PURE__*/jsx(Typography, {
434
+ style: "h2",
435
+ weight: "semibold",
436
+ children: t("neetoAccessControl.titles.invitations")
437
+ })
438
+ }), /*#__PURE__*/jsx(Pane.Body, {
439
+ className: "pt-2",
440
+ children: isNotEmpty(invitations) ? /*#__PURE__*/jsxs(Fragment, {
441
+ children: [/*#__PURE__*/jsx(SubHeader, {
442
+ leftActionBlock: isEmpty(selectedEmails) ? /*#__PURE__*/jsx(Typography, {
443
+ component: "h4",
444
+ style: "h4",
445
+ children: t("neetoAccessControl.titles.emailsWithCount", {
446
+ count: totalCount
447
+ })
448
+ }) : /*#__PURE__*/jsxs("div", {
449
+ className: "flex items-center gap-4",
450
+ children: [/*#__PURE__*/jsx(Typography, {
451
+ style: "h4",
452
+ children: t("neetoAccessControl.titles.selectedEmailsWithCount", {
453
+ count: selectedEmails.length,
454
+ totalCount: totalCount
455
+ })
456
+ }), /*#__PURE__*/jsx(Button, {
457
+ icon: Delete,
458
+ style: "secondary",
459
+ tooltipProps: {
460
+ content: t("neetoAccessControl.labels.delete")
461
+ },
462
+ onClick: function onClick() {
463
+ return setShowDeleteAlert(true);
464
+ }
465
+ })]
466
+ }),
467
+ rightActionBlock: /*#__PURE__*/jsx(Button, {
468
+ label: t("neetoAccessControl.buttons.addEmails"),
469
+ onClick: handleAddEmails
470
+ })
471
+ }), /*#__PURE__*/jsx(TableWrapper, {
472
+ hasPagination: totalCount > DEFAULT_PAGE_SIZE,
473
+ children: /*#__PURE__*/jsx(Table, {
474
+ totalCount: totalCount,
475
+ fixedHeight: true,
476
+ rowSelection: true,
477
+ currentPageNumber: page,
478
+ handlePageChange: setPage,
479
+ loading: isFetching,
480
+ rowData: invitations,
481
+ selectedRowKeys: pluck("id", selectedEmails),
482
+ columnData: invitationsTableColumnData !== null && invitationsTableColumnData !== void 0 ? invitationsTableColumnData : renderColumnData({
483
+ onDelete: handleDeleteAction
484
+ }),
485
+ onRowSelect: function onRowSelect(_, selectedRows) {
486
+ return setSelectedEmails(selectedRows);
487
+ }
488
+ })
489
+ })]
490
+ }) : /*#__PURE__*/jsxs("div", {
491
+ className: "flex h-full w-full justify-center",
492
+ children: [!isLoading && /*#__PURE__*/jsx(NoData, {
493
+ title: t("neetoAccessControl.labels.noInvitations"),
494
+ primaryButtonProps: {
495
+ label: t("neetoAccessControl.buttons.addEmails"),
496
+ onClick: handleAddEmails
497
+ }
498
+ }), isLoading && /*#__PURE__*/jsx(PageLoader, {})]
499
+ })
500
+ })]
501
+ }), /*#__PURE__*/jsx(AddEmails, {
502
+ configurationId: configurationId,
503
+ ownerId: ownerId,
504
+ ownerType: ownerType,
505
+ isOpen: showAddEmails,
506
+ onClose: function onClose() {
507
+ return setShowAddEmails(false);
508
+ }
509
+ }), /*#__PURE__*/jsx(Alert, {
510
+ isOpen: showDeleteAlert,
511
+ isSubmitting: isPending,
512
+ submitButtonLabel: t("neetoAccessControl.labels.delete"),
513
+ message: /*#__PURE__*/jsx(Trans, {
514
+ components: [{
515
+ strong: /*#__PURE__*/jsx("strong", {})
516
+ }],
517
+ i18nKey: "neetoAccessControl.alerts.deleteInviation.message",
518
+ values: {
519
+ count: selectedEmails.length,
520
+ email: (_selectedEmails$ = selectedEmails[0]) === null || _selectedEmails$ === void 0 ? void 0 : _selectedEmails$.email
521
+ }
522
+ }),
523
+ title: t("neetoAccessControl.alerts.deleteInviation.title", {
524
+ count: selectedEmails.length
525
+ }),
526
+ onClose: function onClose() {
527
+ return setShowDeleteAlert(false);
528
+ },
529
+ onSubmit: handleDeleteEmailInvites
530
+ })]
531
+ });
532
+ };
533
+
70
534
  var configurationPath = "".concat(ACCESS_CONTROL_BASE_PATH, "/configuration");
71
535
  var show = function show(params) {
72
536
  return axios.get(configurationPath, {
@@ -91,13 +555,10 @@ var configurationsApi = {
91
555
  update: update
92
556
  };
93
557
 
94
- var QUERY_KEYS = {
95
- ACCESS_CONTROL_CONFIGURATION: "access-control-configuration"
96
- };
97
-
98
558
  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; }
99
559
  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; }
100
- var ACCESS_CONTROL_CONFIGURATION = QUERY_KEYS.ACCESS_CONTROL_CONFIGURATION;
560
+ var ACCESS_CONTROL_CONFIGURATION = QUERY_KEYS.ACCESS_CONTROL_CONFIGURATION,
561
+ ACCESS_CONTROL_CONFIGURATION_INVITATIONS = QUERY_KEYS.ACCESS_CONTROL_CONFIGURATION_INVITATIONS;
101
562
  var useShowConfiguration = function useShowConfiguration(_ref) {
102
563
  var ownerId = _ref.ownerId,
103
564
  ownerType = _ref.ownerType;
@@ -123,7 +584,7 @@ var useUpdateConfiguration = function useUpdateConfiguration(_ref2, options) {
123
584
  payload: payload
124
585
  });
125
586
  }, _objectSpread$2({
126
- keysToInvalidate: [[ACCESS_CONTROL_CONFIGURATION, ownerType, ownerId]]
587
+ keysToInvalidate: [[ACCESS_CONTROL_CONFIGURATION, ownerType, ownerId], [ACCESS_CONTROL_CONFIGURATION_INVITATIONS, ownerType, ownerId]]
127
588
  }, options));
128
589
  };
129
590
 
@@ -131,7 +592,8 @@ var AUTH = {
131
592
  NO: "no",
132
593
  EMAIL: "email",
133
594
  BASIC: "basic",
134
- SESSION: "session"
595
+ SESSION: "session",
596
+ INVITED: "invited"
135
597
  };
136
598
  var AUTH_OPTIONS = [{
137
599
  label: t("neetoAccessControl.auth.no"),
@@ -141,6 +603,9 @@ var AUTH_OPTIONS = [{
141
603
  label: t("neetoAccessControl.auth.basic"),
142
604
  value: AUTH.BASIC,
143
605
  "data-cy": hyphenate(t("neetoAccessControl.auth.basic"))
606
+ }, {
607
+ label: t("neetoAccessControl.auth.invited"),
608
+ value: AUTH.INVITED
144
609
  }, {
145
610
  label: t("neetoAccessControl.auth.email"),
146
611
  value: AUTH.EMAIL,
@@ -200,6 +665,20 @@ var buildPayload = function buildPayload(values) {
200
665
  }
201
666
  return payload;
202
667
  };
668
+ var renderLabelWithViewInvitation = function renderLabelWithViewInvitation(_ref2) {
669
+ var onViewInvites = _ref2.onViewInvites;
670
+ return /*#__PURE__*/jsx(Trans, {
671
+ i18nKey: "neetoAccessControl.auth.invitedWithViewButton",
672
+ components: {
673
+ button: /*#__PURE__*/jsx(Button, {
674
+ className: "mt-1",
675
+ size: "small",
676
+ style: "link",
677
+ onClick: onViewInvites
678
+ })
679
+ }
680
+ });
681
+ };
203
682
 
204
683
  var AllowedKeywords = withT(function (_ref) {
205
684
  var t = _ref.t,
@@ -279,11 +758,19 @@ var Configuration = function Configuration(_ref) {
279
758
  var ownerId = _ref.ownerId,
280
759
  ownerType = _ref.ownerType,
281
760
  onReset = _ref.onReset,
282
- onSuccess = _ref.onSuccess,
761
+ _onSuccess = _ref.onSuccess,
283
762
  headerProps = _ref.headerProps,
284
763
  className = _ref.className,
285
764
  _ref$handleCancel = _ref.handleCancel,
286
- handleCancel = _ref$handleCancel === void 0 ? noop : _ref$handleCancel;
765
+ handleCancel = _ref$handleCancel === void 0 ? noop : _ref$handleCancel,
766
+ _ref$onConfigurationC = _ref.onConfigurationChangedToInviteOnly,
767
+ onConfigurationChangedToInviteOnly = _ref$onConfigurationC === void 0 ? noop : _ref$onConfigurationC,
768
+ _ref$invitationsTable = _ref.invitationsTableColumnData,
769
+ invitationsTableColumnData = _ref$invitationsTable === void 0 ? null : _ref$invitationsTable;
770
+ var _useState = useState(false),
771
+ _useState2 = _slicedToArray(_useState, 2),
772
+ showInviationsPane = _useState2[0],
773
+ setShowInviationsPane = _useState2[1];
287
774
  var _useTranslation = useTranslation(),
288
775
  t = _useTranslation.t;
289
776
  var _useShowConfiguration = useShowConfiguration({
@@ -292,13 +779,22 @@ var Configuration = function Configuration(_ref) {
292
779
  }),
293
780
  _useShowConfiguration2 = _useShowConfiguration.data,
294
781
  configuration = _useShowConfiguration2 === void 0 ? {} : _useShowConfiguration2,
295
- isLoading = _useShowConfiguration.isLoading;
782
+ isLoading = _useShowConfiguration.isLoading,
783
+ isFetching = _useShowConfiguration.isFetching;
296
784
  var configurationInitialValues = buildConfigurationInitialValues(configuration);
297
785
  var _useUpdateConfigurati = useUpdateConfiguration({
298
786
  ownerId: ownerId,
299
787
  ownerType: ownerType
300
788
  }, {
301
- onSuccess: onSuccess
789
+ onSuccess: function onSuccess(values) {
790
+ var _values$configuration = values.configuration,
791
+ _values$configuration2 = _values$configuration === void 0 ? {} : _values$configuration,
792
+ auth = _values$configuration2.auth;
793
+ if (auth === AUTH.INVITED) {
794
+ handleShowInvitations();
795
+ }
796
+ _onSuccess(values);
797
+ }
302
798
  }),
303
799
  updateConfiguration = _useUpdateConfigurati.mutate;
304
800
  var handleSubmit = function handleSubmit(values, _ref2) {
@@ -310,12 +806,15 @@ var Configuration = function Configuration(_ref) {
310
806
  }
311
807
  });
312
808
  };
809
+ var handleShowInvitations = onConfigurationChangedToInviteOnly === noop ? function () {
810
+ return setShowInviationsPane(true);
811
+ } : onConfigurationChangedToInviteOnly;
313
812
  return /*#__PURE__*/jsxs(Container, {
314
813
  children: [/*#__PURE__*/jsx(Header, {
315
814
  headerProps: headerProps
316
- }), isLoading ? /*#__PURE__*/jsx(PageLoader, {}) : /*#__PURE__*/jsx(Scrollable, {
815
+ }), isLoading ? /*#__PURE__*/jsx(PageLoader, {}) : /*#__PURE__*/jsxs(Scrollable, {
317
816
  className: "w-full",
318
- children: /*#__PURE__*/jsx(Form, {
817
+ children: [/*#__PURE__*/jsx(Form, {
319
818
  className: classNames("space-y-6", className),
320
819
  formikProps: {
321
820
  initialValues: configurationInitialValues,
@@ -335,7 +834,20 @@ var Configuration = function Configuration(_ref) {
335
834
  name: "auth",
336
835
  children: AUTH_OPTIONS.map(function (props) {
337
836
  return /*#__PURE__*/createElement(Radio.Item, _objectSpread(_objectSpread({}, props), {}, {
338
- key: props.value
837
+ key: props.value,
838
+ className: classNames({
839
+ "items-start": (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED
840
+ }),
841
+ label: (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED ? renderLabelWithViewInvitation({
842
+ onViewInvites: function onViewInvites() {
843
+ return setShowInviationsPane(true);
844
+ }
845
+ }) : props.label,
846
+ labelProps: {
847
+ className: classNames({
848
+ "flex flex-col items-start justify-start": (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED
849
+ })
850
+ }
339
851
  }));
340
852
  })
341
853
  }), values.auth === AUTH.BASIC && /*#__PURE__*/jsx("div", {
@@ -355,11 +867,23 @@ var Configuration = function Configuration(_ref) {
355
867
  }), /*#__PURE__*/jsx(ActionBlock, {
356
868
  cancelButtonProps: {
357
869
  onClick: handleCancel
358
- }
870
+ },
871
+ submitButtonProps: values.auth === AUTH.INVITED ? {
872
+ label: t("neetoAccessControl.buttons.saveChangesAndInvite")
873
+ } : {}
359
874
  })]
360
875
  });
361
876
  }
362
- })
877
+ }), /*#__PURE__*/jsx(Invitations, {
878
+ invitationsTableColumnData: invitationsTableColumnData,
879
+ ownerId: ownerId,
880
+ ownerType: ownerType,
881
+ configurationId: configuration.id,
882
+ isOpen: showInviationsPane && !isFetching,
883
+ onClose: function onClose() {
884
+ return setShowInviationsPane(false);
885
+ }
886
+ })]
363
887
  })]
364
888
  });
365
889
  };