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

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