@bigbinary/neeto-access-control-frontend 1.3.29 → 1.3.30

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,711 @@
1
+ import { u as useBulkCreateInvitations, a as useListInvitations, b as useBulkDestroyInvitations, c as useShowConfiguration, d as useUpdateConfiguration, Q as QUERY_KEYS } from '../useConfigurationsApi-C2NuK3x4.js';
2
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
+ import { useRef, useState, Fragment as Fragment$1, createElement } from 'react';
5
+ import { Tooltip, Typography, Sheet, Button as Button$1, DataTable, Empty, Spinner, Alert, Label } from '@bigbinary/neeto-atoms';
6
+ import { Form, MultiEmailInput, Button, Input, RadioGroup, BlockNavigation, ActionBlock } from '@bigbinary/neeto-atoms/formik';
7
+ import classNames from 'classnames';
8
+ import { truncate, humanize, isNotEmpty, noop, nullSafe, filterBy } from '@bigbinary/neeto-cist';
9
+ import CardLayout from '@bigbinary/neeto-molecules/v2/CardLayout';
10
+ import Container from '@bigbinary/neeto-molecules/v2/Container';
11
+ import { prop, pluck, mergeDeepRight, indexBy, values, isEmpty, equals, pick, reject, pipe, trim, mergeLeft, keys } from 'ramda';
12
+ import { useTranslation, Trans } from 'react-i18next';
13
+ import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-frontend/v2/constants';
14
+ import Delete from '@bigbinary/neeto-icons/Delete';
15
+ import SubHeader from '@bigbinary/neeto-molecules/v2/SubHeader';
16
+ import TableWrapper from '@bigbinary/neeto-molecules/v2/TableWrapper';
17
+ import { t } from 'i18next';
18
+ import * as yup from 'yup';
19
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
20
+ import MoreDropdown from '@bigbinary/neeto-molecules/v2/MoreDropdown';
21
+ import { FieldArray } from 'formik';
22
+ import { withT } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
23
+ import NeetoHeader from '@bigbinary/neeto-molecules/v2/Header';
24
+ import '@babel/runtime/helpers/objectWithoutProperties';
25
+ import '@tanstack/react-query';
26
+ import '@bigbinary/neeto-commons-frontend/constants';
27
+ import '@bigbinary/neeto-commons-frontend/react-utils';
28
+ import 'axios';
29
+
30
+ var TRUNCATE_LENGTH = 45;
31
+ var ADD_EMAILS_FORM_INIT_VALUES = {
32
+ emails: []
33
+ };
34
+ var ADD_EMAILS_FORM_VALDATION_SCHEMA = yup.object().shape({
35
+ emails: yup.array().test("are-all-emails-valid", t("neetoAccessControl.inputs.validation.emailAddress"), function (emails) {
36
+ return emails.every(prop("valid"));
37
+ })
38
+ });
39
+
40
+ var AddEmails = function AddEmails(_ref) {
41
+ var configurationId = _ref.configurationId,
42
+ ownerType = _ref.ownerType,
43
+ ownerId = _ref.ownerId;
44
+ var _useTranslation = useTranslation(),
45
+ t = _useTranslation.t;
46
+ var emailsInputRef = useRef();
47
+ var _useBulkCreateInvitat = useBulkCreateInvitations({
48
+ configurationId: configurationId,
49
+ ownerType: ownerType,
50
+ ownerId: ownerId
51
+ }),
52
+ addEmails = _useBulkCreateInvitat.mutate;
53
+ var handleAddEmails = function handleAddEmails(_ref2, _ref3) {
54
+ var emails = _ref2.emails;
55
+ var setSubmitting = _ref3.setSubmitting,
56
+ resetForm = _ref3.resetForm;
57
+ var payload = {
58
+ emails: pluck("value", emails)
59
+ };
60
+ addEmails(payload, {
61
+ onSuccess: function onSuccess() {
62
+ setSubmitting(false);
63
+ resetForm();
64
+ },
65
+ onError: function onError() {
66
+ return setSubmitting(false);
67
+ }
68
+ });
69
+ };
70
+ return /*#__PURE__*/jsxs(Form, {
71
+ className: "mb-5 flex w-full space-x-5",
72
+ formikProps: {
73
+ initialValues: ADD_EMAILS_FORM_INIT_VALUES,
74
+ onSubmit: handleAddEmails,
75
+ validationSchema: ADD_EMAILS_FORM_VALDATION_SCHEMA
76
+ },
77
+ children: [/*#__PURE__*/jsx("div", {
78
+ className: "grow",
79
+ children: /*#__PURE__*/jsx(MultiEmailInput, {
80
+ helpText: t("neetoAccessControl.addEmails.helpText"),
81
+ label: t("neetoAccessControl.titles.emails"),
82
+ name: "emails",
83
+ placeholder: t("neetoAccessControl.addEmails.placeholder"),
84
+ ref: emailsInputRef
85
+ })
86
+ }), /*#__PURE__*/jsx(Button, {
87
+ className: "shrink-0 self-center whitespace-nowrap",
88
+ label: t("neetoAccessControl.buttons.invite"),
89
+ type: "submit"
90
+ })]
91
+ });
92
+ };
93
+
94
+ var defaultColumnData = function defaultColumnData(_ref) {
95
+ var onDelete = _ref.onDelete;
96
+ return [{
97
+ header: t("neetoAccessControl.titles.emails"),
98
+ accessorKey: "email",
99
+ id: "email",
100
+ size: 75,
101
+ cell: function cell(_ref2) {
102
+ var getValue = _ref2.getValue,
103
+ row = _ref2.row;
104
+ var email = getValue();
105
+ var inviteData = row.original;
106
+ return /*#__PURE__*/jsxs("div", {
107
+ className: "flex items-center justify-between gap-x-3",
108
+ children: [/*#__PURE__*/jsx(Tooltip, {
109
+ content: email,
110
+ disabled: email.length < TRUNCATE_LENGTH,
111
+ children: /*#__PURE__*/jsx(Typography, {
112
+ variant: "body2",
113
+ children: truncate(email, TRUNCATE_LENGTH)
114
+ })
115
+ }), /*#__PURE__*/jsx(MoreDropdown, {
116
+ dropdownProps: {
117
+ position: "bottom-end"
118
+ },
119
+ menuItems: [{
120
+ key: "delete",
121
+ label: t("neetoAccessControl.labels.delete"),
122
+ onClick: function onClick() {
123
+ return onDelete(inviteData);
124
+ }
125
+ }]
126
+ })]
127
+ });
128
+ }
129
+ }, {
130
+ header: t("neetoAccessControl.titles.status"),
131
+ accessorKey: "status",
132
+ id: "status",
133
+ size: 75,
134
+ cell: function cell(_ref3) {
135
+ var getValue = _ref3.getValue;
136
+ return humanize(getValue());
137
+ }
138
+ }];
139
+ };
140
+ var mergeByKey = function mergeByKey(key, a, b) {
141
+ var merge = mergeDeepRight(indexBy(prop(key), a), indexBy(prop(key), b));
142
+ return values(merge);
143
+ };
144
+ var renderColumnData = function renderColumnData(_ref4) {
145
+ var onDelete = _ref4.onDelete,
146
+ _ref4$extraColumnsDat = _ref4.extraColumnsData,
147
+ extraColumnsData = _ref4$extraColumnsDat === void 0 ? [] : _ref4$extraColumnsDat;
148
+ return mergeByKey("id", defaultColumnData({
149
+ onDelete: onDelete
150
+ }), extraColumnsData);
151
+ };
152
+
153
+ 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; }
154
+ 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), true).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; }
155
+ var Invitations$1 = function Invitations(_ref) {
156
+ var _selectedEmails$;
157
+ var _ref$extraColumnsData = _ref.extraColumnsData,
158
+ extraColumnsData = _ref$extraColumnsData === void 0 ? [] : _ref$extraColumnsData,
159
+ configurationId = _ref.configurationId,
160
+ _ref$ownerType = _ref.ownerType,
161
+ ownerType = _ref$ownerType === void 0 ? null : _ref$ownerType,
162
+ _ref$ownerId = _ref.ownerId,
163
+ ownerId = _ref$ownerId === void 0 ? null : _ref$ownerId,
164
+ isOpen = _ref.isOpen,
165
+ onClose = _ref.onClose,
166
+ _ref$hideAddEmailsFor = _ref.hideAddEmailsForm,
167
+ hideAddEmailsForm = _ref$hideAddEmailsFor === void 0 ? false : _ref$hideAddEmailsFor,
168
+ _ref$inviteButtonProp = _ref.inviteButtonProps,
169
+ inviteButtonProps = _ref$inviteButtonProp === void 0 ? {} : _ref$inviteButtonProp,
170
+ _ref$onDestroyInvitat = _ref.onDestroyInvitationsSuccess,
171
+ onDestroyInvitationsSuccess = _ref$onDestroyInvitat === void 0 ? noop : _ref$onDestroyInvitat;
172
+ var _useState = useState([]),
173
+ _useState2 = _slicedToArray(_useState, 2),
174
+ selectedEmails = _useState2[0],
175
+ setSelectedEmails = _useState2[1];
176
+ var _useState3 = useState(false),
177
+ _useState4 = _slicedToArray(_useState3, 2),
178
+ showDeleteAlert = _useState4[0],
179
+ setShowDeleteAlert = _useState4[1];
180
+ var _useState5 = useState(DEFAULT_PAGE_INDEX),
181
+ _useState6 = _slicedToArray(_useState5, 2),
182
+ page = _useState6[0],
183
+ setPage = _useState6[1];
184
+ var _useTranslation = useTranslation(),
185
+ t = _useTranslation.t;
186
+ var _useListInvitations = useListInvitations({
187
+ neetoAccessControlConfigurationId: configurationId,
188
+ ownerType: ownerType,
189
+ ownerId: ownerId,
190
+ page: page,
191
+ pageSize: DEFAULT_PAGE_SIZE
192
+ }, {
193
+ enabled: isOpen
194
+ }),
195
+ _useListInvitations$d = _useListInvitations.data,
196
+ _useListInvitations$d2 = _useListInvitations$d === void 0 ? {} : _useListInvitations$d,
197
+ _useListInvitations$d3 = _useListInvitations$d2.invitations,
198
+ invitations = _useListInvitations$d3 === void 0 ? [] : _useListInvitations$d3,
199
+ _useListInvitations$d4 = _useListInvitations$d2.totalCount,
200
+ totalCount = _useListInvitations$d4 === void 0 ? 0 : _useListInvitations$d4,
201
+ isFetching = _useListInvitations.isFetching,
202
+ isLoading = _useListInvitations.isLoading;
203
+ var _useBulkDestroyInvita = useBulkDestroyInvitations({
204
+ configurationId: configurationId,
205
+ ownerType: ownerType,
206
+ ownerId: ownerId
207
+ }),
208
+ deleteEmailInvites = _useBulkDestroyInvita.mutate,
209
+ isPending = _useBulkDestroyInvita.isPending;
210
+ var handleOnClose = function handleOnClose() {
211
+ onClose();
212
+ setSelectedEmails([]);
213
+ };
214
+ var handleDeleteEmailInvites = function handleDeleteEmailInvites() {
215
+ var payload = {
216
+ emails: pluck("email", selectedEmails)
217
+ };
218
+ deleteEmailInvites(payload, {
219
+ onSuccess: function onSuccess() {
220
+ setSelectedEmails([]);
221
+ setShowDeleteAlert(false);
222
+ onDestroyInvitationsSuccess();
223
+ }
224
+ });
225
+ };
226
+ var handleDeleteAction = function handleDeleteAction(inviteData) {
227
+ setSelectedEmails([inviteData]);
228
+ setShowDeleteAlert(true);
229
+ };
230
+ return /*#__PURE__*/jsxs(Fragment, {
231
+ children: [/*#__PURE__*/jsxs(Sheet, {
232
+ isOpen: isOpen,
233
+ size: "large",
234
+ onClose: handleOnClose,
235
+ children: [/*#__PURE__*/jsx(Sheet.Header, {
236
+ children: /*#__PURE__*/jsx(Sheet.Title, {
237
+ children: t("neetoAccessControl.titles.invitations")
238
+ })
239
+ }), /*#__PURE__*/jsxs(Sheet.Body, {
240
+ className: "space-y-4 pt-2",
241
+ children: [isNotEmpty(inviteButtonProps) && /*#__PURE__*/jsx("div", {
242
+ className: "flex w-full justify-end",
243
+ children: /*#__PURE__*/jsx(Button$1, _objectSpread$3({}, inviteButtonProps))
244
+ }), !hideAddEmailsForm && /*#__PURE__*/jsx(AddEmails, {
245
+ configurationId: configurationId,
246
+ ownerId: ownerId,
247
+ ownerType: ownerType
248
+ }), isNotEmpty(invitations) ? /*#__PURE__*/jsxs(Fragment, {
249
+ children: [/*#__PURE__*/jsx(SubHeader, {
250
+ leftActionBlock: isEmpty(selectedEmails) ? /*#__PURE__*/jsx(Typography, {
251
+ className: "min-h-8",
252
+ variant: "h4",
253
+ children: t("neetoAccessControl.titles.emailsWithCount", {
254
+ count: totalCount
255
+ })
256
+ }) : /*#__PURE__*/jsxs("div", {
257
+ className: "flex items-center gap-x-4",
258
+ children: [/*#__PURE__*/jsx(Typography, {
259
+ variant: "h4",
260
+ children: t("neetoAccessControl.titles.selectedEmailsWithCount", {
261
+ selectedCount: selectedEmails.length,
262
+ count: totalCount
263
+ })
264
+ }), /*#__PURE__*/jsx(Tooltip, {
265
+ content: t("neetoAccessControl.labels.delete"),
266
+ children: /*#__PURE__*/jsx(Button$1, {
267
+ icon: Delete,
268
+ variant: "outline",
269
+ onClick: function onClick() {
270
+ return setShowDeleteAlert(true);
271
+ }
272
+ })
273
+ })]
274
+ })
275
+ }), /*#__PURE__*/jsx(TableWrapper, {
276
+ hasPagination: totalCount > DEFAULT_PAGE_SIZE,
277
+ children: /*#__PURE__*/jsx(DataTable, {
278
+ totalCount: totalCount,
279
+ enableRowSelection: true,
280
+ fixedHeight: true,
281
+ currentPage: page,
282
+ data: invitations,
283
+ enableColumnFreeze: false,
284
+ getRowId: function getRowId(_ref2) {
285
+ var id = _ref2.id;
286
+ return String(id);
287
+ },
288
+ loading: isFetching,
289
+ pageSize: DEFAULT_PAGE_SIZE,
290
+ selectedRowKeys: selectedEmails.map(function (_ref3) {
291
+ var id = _ref3.id;
292
+ return String(id);
293
+ }),
294
+ columns: renderColumnData({
295
+ onDelete: handleDeleteAction,
296
+ extraColumnsData: extraColumnsData
297
+ }),
298
+ onPageChange: function onPageChange(index) {
299
+ return setPage(index);
300
+ },
301
+ onRowSelect: function onRowSelect(_, selectedRows) {
302
+ return setSelectedEmails(selectedRows);
303
+ }
304
+ })
305
+ })]
306
+ }) : /*#__PURE__*/jsxs("div", {
307
+ className: "flex h-full w-full justify-center",
308
+ children: [!isLoading && /*#__PURE__*/jsx(Empty, {
309
+ title: t("neetoAccessControl.labels.noInvitations")
310
+ }), isLoading && /*#__PURE__*/jsx("div", {
311
+ className: "flex h-full w-full items-center justify-center",
312
+ children: /*#__PURE__*/jsx(Spinner, {})
313
+ })]
314
+ })]
315
+ })]
316
+ }), /*#__PURE__*/jsx(Alert, {
317
+ isOpen: showDeleteAlert,
318
+ isSubmitting: isPending,
319
+ submitButtonLabel: t("neetoAccessControl.labels.delete"),
320
+ message: /*#__PURE__*/jsx(Trans, {
321
+ components: [{
322
+ strong: /*#__PURE__*/jsx("strong", {})
323
+ }],
324
+ i18nKey: "neetoAccessControl.alerts.deleteInviation.message",
325
+ values: {
326
+ count: selectedEmails.length,
327
+ email: (_selectedEmails$ = selectedEmails[0]) === null || _selectedEmails$ === void 0 ? void 0 : _selectedEmails$.email
328
+ }
329
+ }),
330
+ title: t("neetoAccessControl.alerts.deleteInviation.title", {
331
+ count: selectedEmails.length
332
+ }),
333
+ onClose: function onClose() {
334
+ return setShowDeleteAlert(false);
335
+ },
336
+ onSubmit: handleDeleteEmailInvites
337
+ })]
338
+ });
339
+ };
340
+
341
+ var AUTH = {
342
+ NO: "no",
343
+ EMAIL: "email",
344
+ BASIC: "basic",
345
+ SESSION: "session",
346
+ INVITED: "invited"
347
+ };
348
+ var CONFIGURATION_VALIDATION_SCHEMA = yup.object({
349
+ auth: yup.string().required(t("neetoAccessControl.inputs.validation.authRequired")),
350
+ password: yup.string().nullable().when("auth", {
351
+ is: equals(AUTH.BASIC),
352
+ then: yup.string().nullable().trim().min(4, t("neetoAccessControl.inputs.validation.passwordMinLength")).required(t("neetoAccessControl.inputs.validation.passwordRequired"))
353
+ }),
354
+ allowedKeywords: yup.array().when("auth", {
355
+ is: equals(AUTH.EMAIL),
356
+ then: yup.array().of(yup.string().required(t("neetoAccessControl.inputs.validation.keywordRequired")).max(254, t("neetoAccessControl.inputs.validation.maxLength", {
357
+ length: 254
358
+ })).matches(/^[A-Z0-9._%+\-@]+$/i, t("neetoAccessControl.inputs.validation.invalidCharacters")).trim().test("unique-keyword", t("neetoAccessControl.inputs.validation.duplicateKeywords"), function (value, testContext) {
359
+ if (!value || !testContext.parent) return true;
360
+ var trimmedValue = value === null || value === void 0 ? void 0 : value.trim();
361
+ if (!trimmedValue) return true;
362
+ var duplicateIndices = nullSafe(pluck)("index", filterBy({
363
+ item: trimmedValue
364
+ }, testContext.parent.map(function (item, index) {
365
+ return {
366
+ item: item === null || item === void 0 ? void 0 : item.trim(),
367
+ index: index
368
+ };
369
+ })));
370
+ var currentIndex = testContext.path.split("[").pop().split("]")[0];
371
+ var isLastOccurrence = duplicateIndices[duplicateIndices.length - 1] === parseInt(currentIndex);
372
+ return !isLastOccurrence || duplicateIndices.length === 1;
373
+ }))
374
+ })
375
+ });
376
+ var DEFAULT_CONFIGURATION_VALUES = {
377
+ auth: AUTH.NO,
378
+ password: "",
379
+ allowedKeywords: [""]
380
+ };
381
+
382
+ 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; }
383
+ 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), true).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; }
384
+ var buildConfigurationInitialValues = function buildConfigurationInitialValues(configuration) {
385
+ if (configuration.auth === AUTH.NO) {
386
+ return DEFAULT_CONFIGURATION_VALUES;
387
+ }
388
+ if (isEmpty(configuration.allowedKeywords)) {
389
+ configuration.allowedKeywords.push("");
390
+ }
391
+ return configuration;
392
+ };
393
+ var removeKeyword = function removeKeyword(_ref) {
394
+ var arrayHelpers = _ref.arrayHelpers,
395
+ index = _ref.index,
396
+ allowedKeywords = _ref.allowedKeywords;
397
+ if (allowedKeywords.length === 1) {
398
+ arrayHelpers.remove(index);
399
+ arrayHelpers.push("");
400
+ return;
401
+ }
402
+ arrayHelpers.remove(index);
403
+ };
404
+ var buildPayload = function buildPayload(values) {
405
+ var payload = pick(["auth"], values);
406
+ if (values.auth === AUTH.BASIC) {
407
+ payload["password"] = values.password;
408
+ return payload;
409
+ }
410
+ if (values.auth === AUTH.EMAIL) {
411
+ var rejectEmptyKeywords = reject(pipe(trim, isEmpty));
412
+ payload["allowedKeywords"] = rejectEmptyKeywords(values.allowedKeywords);
413
+ return payload;
414
+ }
415
+ return payload;
416
+ };
417
+ var renderLabelWithViewInvitation = function renderLabelWithViewInvitation(_ref2) {
418
+ var onViewInvites = _ref2.onViewInvites;
419
+ return /*#__PURE__*/jsx(Trans, {
420
+ i18nKey: "neetoAccessControl.auth.invitedWithViewButton",
421
+ components: {
422
+ button: /*#__PURE__*/jsx(Button$1, {
423
+ className: "mt-1",
424
+ size: "sm",
425
+ variant: "link",
426
+ onClick: onViewInvites
427
+ })
428
+ }
429
+ });
430
+ };
431
+ var getAuthOptions = function getAuthOptions(_ref3) {
432
+ var translationContext = _ref3.translationContext,
433
+ transProps = _ref3.transProps;
434
+ return [{
435
+ label: /*#__PURE__*/jsx(Trans, _objectSpread$2({
436
+ context: translationContext,
437
+ i18nKey: "neetoAccessControl.auth.no"
438
+ }, transProps[AUTH.NO])),
439
+ value: AUTH.NO,
440
+ "data-testid": "access-control-public-access-radio-input"
441
+ }, {
442
+ label: /*#__PURE__*/jsx(Trans, _objectSpread$2({
443
+ context: translationContext,
444
+ i18nKey: "neetoAccessControl.auth.basic"
445
+ }, transProps[AUTH.BASIC])),
446
+ value: AUTH.BASIC,
447
+ "data-testid": "access-control-password-protected-radio-input"
448
+ }, {
449
+ label: /*#__PURE__*/jsx(Trans, _objectSpread$2({
450
+ context: translationContext,
451
+ i18nKey: "neetoAccessControl.auth.invited"
452
+ }, transProps[AUTH.INVITED])),
453
+ value: AUTH.INVITED,
454
+ "data-testid": "access-control-only-invited-people-radio-input"
455
+ }, {
456
+ label: /*#__PURE__*/jsx(Trans, _objectSpread$2({
457
+ context: translationContext,
458
+ i18nKey: "neetoAccessControl.auth.email"
459
+ }, transProps[AUTH.EMAIL])),
460
+ value: AUTH.EMAIL,
461
+ "data-testid": "access-control-secure-by-email-patterns-radio-input"
462
+ }, {
463
+ label: /*#__PURE__*/jsx(Trans, _objectSpread$2({
464
+ context: translationContext,
465
+ i18nKey: "neetoAccessControl.auth.session"
466
+ }, transProps[AUTH.SESSION])),
467
+ value: AUTH.SESSION,
468
+ "data-testid": "access-control-logged-in-members-only-radio-input"
469
+ }];
470
+ };
471
+
472
+ var AllowedKeywords = withT(function (_ref) {
473
+ var t = _ref.t,
474
+ name = _ref.name,
475
+ _ref$label = _ref.label,
476
+ label = _ref$label === void 0 ? "" : _ref$label;
477
+ return /*#__PURE__*/jsx(FieldArray, {
478
+ name: name,
479
+ children: function children(arrayHelpers) {
480
+ var allowedKeywords = arrayHelpers.form.values[name];
481
+ var showDeleteButton = allowedKeywords.length > 1 || isNotEmpty(allowedKeywords[0]);
482
+ var handleAddKeyword = function handleAddKeyword() {
483
+ allowedKeywords.forEach(function (_, index) {
484
+ arrayHelpers.form.setFieldTouched("".concat(name, ".").concat(index), true);
485
+ });
486
+ arrayHelpers.push("");
487
+ };
488
+ return /*#__PURE__*/jsxs("div", {
489
+ className: "space-y-4 pt-4",
490
+ children: [/*#__PURE__*/jsx(Label, {
491
+ className: "leading-snug",
492
+ children: label
493
+ }), /*#__PURE__*/jsxs("div", {
494
+ className: "bg-muted rounded-sm space-y-4 p-6",
495
+ children: [allowedKeywords.map(function (_, index) {
496
+ return /*#__PURE__*/jsx(Input, {
497
+ className: "w-full",
498
+ name: "".concat(name, ".").concat(index),
499
+ placeholder: t("neetoAccessControl.inputs.placeholders.enterKeyword"),
500
+ suffix: showDeleteButton && /*#__PURE__*/jsx(Button$1, {
501
+ "data-testid": "allowed-keyword-delete-button",
502
+ icon: Delete,
503
+ size: "sm",
504
+ variant: "ghost",
505
+ onClick: function onClick() {
506
+ return removeKeyword({
507
+ index: index,
508
+ allowedKeywords: allowedKeywords,
509
+ arrayHelpers: arrayHelpers
510
+ });
511
+ }
512
+ })
513
+ }, index);
514
+ }), /*#__PURE__*/jsx(Button$1, {
515
+ className: "pt-2",
516
+ "data-testid": "add-allowed-keyword-button",
517
+ label: t("neetoAccessControl.actions.addKeyword"),
518
+ variant: "link",
519
+ onClick: handleAddKeyword
520
+ })]
521
+ })]
522
+ });
523
+ }
524
+ });
525
+ });
526
+
527
+ 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; }
528
+ 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; }
529
+ var Header = function Header(_ref) {
530
+ var headerProps = _ref.headerProps;
531
+ var title = headerProps.title,
532
+ helpLink = headerProps.helpLink,
533
+ description = headerProps.description;
534
+ return /*#__PURE__*/jsx(NeetoHeader, _objectSpread$1(_objectSpread$1({}, _objectSpread$1(_objectSpread$1({}, headerProps), {}, {
535
+ title: title
536
+ })), {}, {
537
+ titleHelpPopoverProps: {
538
+ description: description,
539
+ title: title,
540
+ helpLinkProps: {
541
+ href: helpLink
542
+ }
543
+ }
544
+ }));
545
+ };
546
+
547
+ 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; }
548
+ 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; }
549
+ var Configuration = function Configuration(_ref) {
550
+ var ownerId = _ref.ownerId,
551
+ ownerType = _ref.ownerType,
552
+ onReset = _ref.onReset,
553
+ _onSuccess = _ref.onSuccess,
554
+ headerProps = _ref.headerProps,
555
+ className = _ref.className,
556
+ _ref$handleCancel = _ref.handleCancel,
557
+ handleCancel = _ref$handleCancel === void 0 ? noop : _ref$handleCancel,
558
+ _ref$onConfigurationC = _ref.onConfigurationChangedToInviteOnly,
559
+ onConfigurationChangedToInviteOnly = _ref$onConfigurationC === void 0 ? noop : _ref$onConfigurationC,
560
+ _ref$invitationsTable = _ref.invitationsTableExtraColumnsData,
561
+ invitationsTableExtraColumnsData = _ref$invitationsTable === void 0 ? [] : _ref$invitationsTable,
562
+ _ref$hideAddEmailsFro = _ref.hideAddEmailsFromInvitationPane,
563
+ hideAddEmailsFromInvitationPane = _ref$hideAddEmailsFro === void 0 ? false : _ref$hideAddEmailsFro,
564
+ _ref$enableNavigation = _ref.enableNavigationBlocking,
565
+ enableNavigationBlocking = _ref$enableNavigation === void 0 ? false : _ref$enableNavigation,
566
+ _ref$onDestroyInvitat = _ref.onDestroyInvitationsSuccess,
567
+ onDestroyInvitationsSuccess = _ref$onDestroyInvitat === void 0 ? noop : _ref$onDestroyInvitat,
568
+ _ref$inviteButtonProp = _ref.inviteButtonProps,
569
+ inviteButtonProps = _ref$inviteButtonProp === void 0 ? {} : _ref$inviteButtonProp,
570
+ _ref$additionalFields = _ref.additionalFieldsInitialValues,
571
+ additionalFieldsInitialValues = _ref$additionalFields === void 0 ? {} : _ref$additionalFields,
572
+ children = _ref.children,
573
+ fieldsWrapper = _ref.fieldsWrapper,
574
+ translationContext = _ref.translationContext,
575
+ _ref$transProps = _ref.transProps,
576
+ transProps = _ref$transProps === void 0 ? {} : _ref$transProps;
577
+ var _useState = useState(false),
578
+ _useState2 = _slicedToArray(_useState, 2),
579
+ showInvitationsPane = _useState2[0],
580
+ setShowInvitationsPane = _useState2[1];
581
+ var FieldsWrapper = fieldsWrapper || Fragment$1;
582
+ var _useTranslation = useTranslation(),
583
+ t = _useTranslation.t;
584
+ var _useShowConfiguration = useShowConfiguration({
585
+ ownerId: ownerId,
586
+ ownerType: ownerType
587
+ }),
588
+ _useShowConfiguration2 = _useShowConfiguration.data,
589
+ configuration = _useShowConfiguration2 === void 0 ? {} : _useShowConfiguration2,
590
+ isLoading = _useShowConfiguration.isLoading,
591
+ isFetching = _useShowConfiguration.isFetching;
592
+ var configurationInitialValues = mergeLeft(buildConfigurationInitialValues(configuration), additionalFieldsInitialValues);
593
+ var _useUpdateConfigurati = useUpdateConfiguration({
594
+ ownerId: ownerId,
595
+ ownerType: ownerType
596
+ }, {
597
+ onSuccess: function onSuccess(values) {
598
+ var _values$configuration = values.configuration,
599
+ _values$configuration2 = _values$configuration === void 0 ? {} : _values$configuration,
600
+ auth = _values$configuration2.auth;
601
+ if (auth === AUTH.INVITED) {
602
+ handleShowInvitations();
603
+ }
604
+ _onSuccess(values);
605
+ }
606
+ }),
607
+ updateConfiguration = _useUpdateConfigurati.mutate;
608
+ var handleSubmit = function handleSubmit(values, _ref2) {
609
+ var setSubmitting = _ref2.setSubmitting;
610
+ var payload = mergeLeft(buildPayload(values), pick(keys(additionalFieldsInitialValues), values));
611
+ updateConfiguration(payload, {
612
+ onSettled: function onSettled() {
613
+ return setSubmitting(false);
614
+ }
615
+ });
616
+ };
617
+ var handleShowInvitations = onConfigurationChangedToInviteOnly === noop ? function () {
618
+ return setShowInvitationsPane(true);
619
+ } : onConfigurationChangedToInviteOnly;
620
+ return /*#__PURE__*/jsxs(Container, {
621
+ children: [/*#__PURE__*/jsx(Header, {
622
+ headerProps: headerProps
623
+ }), isLoading ? /*#__PURE__*/jsx("div", {
624
+ className: "flex h-full w-full items-center justify-center",
625
+ children: /*#__PURE__*/jsx(Spinner, {})
626
+ }) : /*#__PURE__*/jsxs("div", {
627
+ className: "min-h-0 w-full grow",
628
+ children: [/*#__PURE__*/jsx(Form, {
629
+ className: classNames(className),
630
+ formikProps: {
631
+ initialValues: configurationInitialValues,
632
+ validationSchema: CONFIGURATION_VALIDATION_SCHEMA,
633
+ onSubmit: handleSubmit,
634
+ onReset: onReset,
635
+ enableReinitialize: true
636
+ },
637
+ children: function children(_ref3) {
638
+ var values = _ref3.values;
639
+ return /*#__PURE__*/jsxs(CardLayout, {
640
+ actionBlock: /*#__PURE__*/jsx(ActionBlock, {
641
+ cancelButtonProps: {
642
+ onClick: handleCancel
643
+ },
644
+ submitButtonProps: values.auth === AUTH.INVITED ? {
645
+ label: t("neetoAccessControl.buttons.saveChangesAndInvite")
646
+ } : {}
647
+ }),
648
+ children: [/*#__PURE__*/jsxs(FieldsWrapper, {
649
+ children: [/*#__PURE__*/jsx(RadioGroup, {
650
+ name: "auth",
651
+ children: getAuthOptions({
652
+ translationContext: translationContext,
653
+ transProps: transProps
654
+ }).map(function (props) {
655
+ return /*#__PURE__*/createElement(RadioGroup.Item, _objectSpread(_objectSpread({}, props), {}, {
656
+ id: props.value,
657
+ key: props.value,
658
+ className: classNames({
659
+ "items-start": (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED
660
+ }),
661
+ label: (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED ? renderLabelWithViewInvitation({
662
+ onViewInvites: function onViewInvites() {
663
+ return setShowInvitationsPane(true);
664
+ }
665
+ }) : props.label
666
+ }));
667
+ })
668
+ }), values.auth === AUTH.BASIC && /*#__PURE__*/jsx("div", {
669
+ className: "space-y-4 pb-2 pt-4",
670
+ children: /*#__PURE__*/jsx(Input, {
671
+ autoFocus: true,
672
+ required: true,
673
+ unlimitedChars: true,
674
+ className: "w-7/12",
675
+ label: t("neetoAccessControl.inputs.labels.password"),
676
+ name: "password",
677
+ placeholder: t("neetoAccessControl.inputs.placeholders.enterPassword")
678
+ })
679
+ }), values.auth === AUTH.EMAIL && /*#__PURE__*/jsx(AllowedKeywords, {
680
+ label: t("neetoAccessControl.inputs.labels.keywords"),
681
+ name: "allowedKeywords"
682
+ })]
683
+ }), enableNavigationBlocking && /*#__PURE__*/jsx(BlockNavigation, {})]
684
+ });
685
+ }
686
+ }), /*#__PURE__*/jsx(Invitations$1, {
687
+ inviteButtonProps: inviteButtonProps,
688
+ onDestroyInvitationsSuccess: onDestroyInvitationsSuccess,
689
+ ownerId: ownerId,
690
+ ownerType: ownerType,
691
+ configurationId: configuration.id,
692
+ extraColumnsData: invitationsTableExtraColumnsData,
693
+ hideAddEmailsForm: hideAddEmailsFromInvitationPane,
694
+ isOpen: showInvitationsPane && !isFetching,
695
+ onClose: function onClose() {
696
+ return setShowInvitationsPane(false);
697
+ }
698
+ }), children]
699
+ })]
700
+ });
701
+ };
702
+
703
+ var INVITATIONS_QUERY_KEY = QUERY_KEYS.ACCESS_CONTROL_CONFIGURATION_INVITATIONS;
704
+ var Invitations = {
705
+ InvitationsPane: Invitations$1,
706
+ useBulkCreateInvitations: useBulkCreateInvitations,
707
+ INVITATIONS_QUERY_KEY: INVITATIONS_QUERY_KEY
708
+ };
709
+
710
+ export { Configuration, Invitations, useShowConfiguration };
711
+ //# sourceMappingURL=index.js.map