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