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