@bigbinary/neeto-molecules 3.15.25 → 3.15.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ShareViaLink.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPresent, slugify, noop } from '@bigbinary/neeto-cist';
|
|
2
2
|
import { omit } from 'ramda';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import Typography from '@bigbinary/neetoui/Typography';
|
|
5
|
+
import { useTranslation, Trans } from 'react-i18next';
|
|
6
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
7
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
8
|
import React__default, { useRef, useCallback, useEffect, useState, createElement } from 'react';
|
|
5
9
|
import ExternalLink from '@bigbinary/neeto-icons/ExternalLink';
|
|
6
10
|
import Button from '@bigbinary/neetoui/Button';
|
|
7
|
-
import { useTranslation, Trans } from 'react-i18next';
|
|
8
11
|
import CopyToClipboardButton from './CopyToClipboardButton.js';
|
|
9
12
|
import MoreDropdown from './MoreDropdown.js';
|
|
10
13
|
import { Formik, Form } from 'formik';
|
|
11
|
-
import Typography from '@bigbinary/neetoui/Typography';
|
|
12
14
|
import Pane from '@bigbinary/neetoui/Pane';
|
|
13
15
|
import Input from '@bigbinary/neetoui/formik/Input';
|
|
14
16
|
import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
|
|
@@ -19,11 +21,12 @@ import Twitter from '@bigbinary/neeto-icons/Twitter';
|
|
|
19
21
|
import * as yup from 'yup';
|
|
20
22
|
import { buildUrl } from '@bigbinary/neeto-commons-frontend/utils/general';
|
|
21
23
|
import { n } from './inject-css-DmrvuTKK.js';
|
|
22
|
-
import {
|
|
24
|
+
import { dayjs } from '@bigbinary/neeto-commons-frontend/utils';
|
|
23
25
|
import Modal from '@bigbinary/neetoui/Modal';
|
|
24
26
|
import Input$1 from '@bigbinary/neetoui/Input';
|
|
27
|
+
import Select from '@bigbinary/neetoui/Select';
|
|
28
|
+
import DatePicker from '@bigbinary/neetoui/DatePicker';
|
|
25
29
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
26
|
-
import classnames from 'classnames';
|
|
27
30
|
import { Link as Link$1 } from 'react-router-dom';
|
|
28
31
|
import '@babel/runtime/helpers/objectWithoutProperties';
|
|
29
32
|
import '@bigbinary/neeto-icons/Copy';
|
|
@@ -33,6 +36,32 @@ import '@bigbinary/neeto-icons/MenuVertical';
|
|
|
33
36
|
import '@bigbinary/neetoui/Dropdown';
|
|
34
37
|
import '@bigbinary/neetoui/Tooltip';
|
|
35
38
|
|
|
39
|
+
var ExpiryNotice = function ExpiryNotice(_ref) {
|
|
40
|
+
var expiryConfiguration = _ref.expiryConfiguration;
|
|
41
|
+
var _useTranslation = useTranslation(),
|
|
42
|
+
t = _useTranslation.t;
|
|
43
|
+
var daysBeforeExpiry = expiryConfiguration.daysBeforeExpiry;
|
|
44
|
+
var notice = t("neetoMolecules.shareViaLink.expiryNotice.daysRemaining", {
|
|
45
|
+
count: daysBeforeExpiry
|
|
46
|
+
});
|
|
47
|
+
if (daysBeforeExpiry < 1) {
|
|
48
|
+
notice = t("neetoMolecules.shareViaLink.expiryNotice.expiresToday");
|
|
49
|
+
}
|
|
50
|
+
if (daysBeforeExpiry <= 0) {
|
|
51
|
+
notice = t("neetoMolecules.shareViaLink.expiryNotice.expired");
|
|
52
|
+
}
|
|
53
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
54
|
+
"data-testid": "expiry-notice",
|
|
55
|
+
lineHeight: "normal",
|
|
56
|
+
style: "body2",
|
|
57
|
+
className: classnames({
|
|
58
|
+
"neeto-ui-text-error-800": daysBeforeExpiry <= 1,
|
|
59
|
+
"neeto-ui-text-gray-700": daysBeforeExpiry > 1
|
|
60
|
+
}),
|
|
61
|
+
children: notice
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
36
65
|
var facebookShareLink = function facebookShareLink(_ref) {
|
|
37
66
|
var url = _ref.url;
|
|
38
67
|
return buildUrl("https://www.facebook.com/sharer/sharer.php", {
|
|
@@ -206,14 +235,42 @@ var EditURL = function EditURL(_ref) {
|
|
|
206
235
|
};
|
|
207
236
|
|
|
208
237
|
var RegenerateURL = function RegenerateURL(_ref) {
|
|
238
|
+
var _regenerateConfig$exp, _regenerateConfig$exp2, _globalProps$user$dat, _globalProps;
|
|
209
239
|
var isOpen = _ref.isOpen,
|
|
210
240
|
onClose = _ref.onClose,
|
|
211
241
|
url = _ref.url,
|
|
212
242
|
isLoading = _ref.isLoading,
|
|
213
|
-
handleRegenerate = _ref.handleRegenerate
|
|
243
|
+
handleRegenerate = _ref.handleRegenerate,
|
|
244
|
+
_ref$regenerateConfig = _ref.regenerateConfig,
|
|
245
|
+
regenerateConfig = _ref$regenerateConfig === void 0 ? {
|
|
246
|
+
expiresInOptions: []
|
|
247
|
+
} : _ref$regenerateConfig;
|
|
214
248
|
var _useTranslation = useTranslation(),
|
|
215
249
|
t = _useTranslation.t;
|
|
216
250
|
var prevIsLoadingRef = useRef(isLoading);
|
|
251
|
+
var regenerateStrategy = isPresent(regenerateConfig === null || regenerateConfig === void 0 ? void 0 : regenerateConfig.expiresInOptions) ? "expiryBased" : "basic";
|
|
252
|
+
var _useState = useState(regenerateConfig === null || regenerateConfig === void 0 || (_regenerateConfig$exp = regenerateConfig.expiresInOptions) === null || _regenerateConfig$exp === void 0 || (_regenerateConfig$exp = _regenerateConfig$exp[0]) === null || _regenerateConfig$exp === void 0 ? void 0 : _regenerateConfig$exp.value),
|
|
253
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
254
|
+
selectedExpiresInOption = _useState2[0],
|
|
255
|
+
setSelectedExpiresInOption = _useState2[1];
|
|
256
|
+
var _useState3 = useState(dayjs().add(10, "day").toDate()),
|
|
257
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
258
|
+
selectedExpiresOnDate = _useState4[0],
|
|
259
|
+
setSelectedExpiresOnDate = _useState4[1];
|
|
260
|
+
var isSelectedExpiresInOptionNever = selectedExpiresInOption === "never";
|
|
261
|
+
var isSelectedExpiresInOptionCustom = selectedExpiresInOption === "custom";
|
|
262
|
+
var isSelectedExpiresInOptionValidNumberOfDays = isPresent(selectedExpiresInOption) && !isSelectedExpiresInOptionCustom && !isSelectedExpiresInOptionNever;
|
|
263
|
+
var isValidExpiryConfig = isSelectedExpiresInOptionNever || isSelectedExpiresInOptionCustom && isPresent(selectedExpiresOnDate) || isSelectedExpiresInOptionValidNumberOfDays;
|
|
264
|
+
var expiryConfigPayload = isSelectedExpiresInOptionValidNumberOfDays ? {
|
|
265
|
+
expiresInDays: selectedExpiresInOption
|
|
266
|
+
} : {
|
|
267
|
+
expiresOnDate: selectedExpiresOnDate
|
|
268
|
+
};
|
|
269
|
+
var onSubmit = function onSubmit() {
|
|
270
|
+
return regenerateStrategy === "basic" || isSelectedExpiresInOptionNever ? handleRegenerate() : handleRegenerate({
|
|
271
|
+
payload: expiryConfigPayload
|
|
272
|
+
});
|
|
273
|
+
};
|
|
217
274
|
useEffect(function () {
|
|
218
275
|
if (prevIsLoadingRef.current && !isLoading) onClose();
|
|
219
276
|
prevIsLoadingRef.current = isLoading;
|
|
@@ -222,6 +279,7 @@ var RegenerateURL = function RegenerateURL(_ref) {
|
|
|
222
279
|
isOpen: isOpen,
|
|
223
280
|
onClose: onClose,
|
|
224
281
|
"data-testid": "regenerate-url-modal",
|
|
282
|
+
size: regenerateStrategy === "basic" ? "medium" : "large",
|
|
225
283
|
children: [/*#__PURE__*/jsx(Modal.Header, {
|
|
226
284
|
children: /*#__PURE__*/jsx(Typography, {
|
|
227
285
|
lineHeight: "normal",
|
|
@@ -232,10 +290,36 @@ var RegenerateURL = function RegenerateURL(_ref) {
|
|
|
232
290
|
}), /*#__PURE__*/jsx(Modal.Body, {
|
|
233
291
|
children: /*#__PURE__*/jsxs("div", {
|
|
234
292
|
className: "w-full space-y-6",
|
|
235
|
-
children: [/*#__PURE__*/jsx(Input$1, {
|
|
293
|
+
children: [regenerateStrategy === "basic" && /*#__PURE__*/jsx(Input$1, {
|
|
236
294
|
disabled: true,
|
|
237
295
|
label: t("neetoMolecules.shareViaLink.regenerateUrl.inputLabel"),
|
|
238
296
|
value: url
|
|
297
|
+
}), regenerateStrategy === "expiryBased" && /*#__PURE__*/jsxs("div", {
|
|
298
|
+
className: "flex flex-row gap-2",
|
|
299
|
+
children: [/*#__PURE__*/jsx(Select, {
|
|
300
|
+
"data-testid": "expires-in-select",
|
|
301
|
+
defaultValue: (_regenerateConfig$exp2 = regenerateConfig.expiresInOptions) === null || _regenerateConfig$exp2 === void 0 ? void 0 : _regenerateConfig$exp2[0],
|
|
302
|
+
options: regenerateConfig.expiresInOptions,
|
|
303
|
+
className: classnames({
|
|
304
|
+
"w-1/2": isSelectedExpiresInOptionCustom,
|
|
305
|
+
"w-full": !isSelectedExpiresInOptionCustom
|
|
306
|
+
}),
|
|
307
|
+
label: t("neetoMolecules.shareViaLink.regenerateUrl.expiresInLabel"),
|
|
308
|
+
onChange: function onChange(option) {
|
|
309
|
+
return setSelectedExpiresInOption(option.value);
|
|
310
|
+
}
|
|
311
|
+
}), isSelectedExpiresInOptionCustom && /*#__PURE__*/jsx(DatePicker, {
|
|
312
|
+
"data-testid": "expires-on-date-picker",
|
|
313
|
+
dateFormat: (_globalProps$user$dat = (_globalProps = globalProps) === null || _globalProps === void 0 || (_globalProps = _globalProps.user) === null || _globalProps === void 0 ? void 0 : _globalProps.dateFormat) !== null && _globalProps$user$dat !== void 0 ? _globalProps$user$dat : undefined,
|
|
314
|
+
disabledDate: function disabledDate(d) {
|
|
315
|
+
return !d || d.isBefore(dayjs());
|
|
316
|
+
},
|
|
317
|
+
picker: "date",
|
|
318
|
+
type: "date",
|
|
319
|
+
value: selectedExpiresOnDate,
|
|
320
|
+
label: t("neetoMolecules.shareViaLink.regenerateUrl.expiresOnLabel"),
|
|
321
|
+
onChange: setSelectedExpiresOnDate
|
|
322
|
+
})]
|
|
239
323
|
}), /*#__PURE__*/jsx(Typography, {
|
|
240
324
|
className: "neeto-ui-text-gray-700",
|
|
241
325
|
lineHeight: "normal",
|
|
@@ -249,8 +333,9 @@ var RegenerateURL = function RegenerateURL(_ref) {
|
|
|
249
333
|
"data-cy": "regenerate-url-confirm-button",
|
|
250
334
|
"data-testid": "regenerate-url-confirm-button",
|
|
251
335
|
loading: isLoading,
|
|
336
|
+
disabled: regenerateStrategy === "expiryBased" && !isValidExpiryConfig,
|
|
252
337
|
label: t("neetoMolecules.shareViaLink.regenerateUrl.submitButtonLabel"),
|
|
253
|
-
onClick:
|
|
338
|
+
onClick: onSubmit
|
|
254
339
|
}), /*#__PURE__*/jsx(Button, {
|
|
255
340
|
"data-cy": "regenerate-url-cancel-button",
|
|
256
341
|
"data-testid": "regenerate-url-cancel-button",
|
|
@@ -316,7 +401,7 @@ var Link = function Link(_ref) {
|
|
|
316
401
|
}), isDropdownEnabled && /*#__PURE__*/jsxs(Fragment, {
|
|
317
402
|
children: [/*#__PURE__*/jsx(MoreDropdown, {
|
|
318
403
|
menuItems: [{
|
|
319
|
-
isVisible: enabledOptions.regenerate,
|
|
404
|
+
isVisible: enabledOptions.regenerate || isPresent(enabledOptions.regenerate),
|
|
320
405
|
"data-testid": "regenerate-url-button",
|
|
321
406
|
"data-cy": "regenerate-url-button",
|
|
322
407
|
onClick: function onClick() {
|
|
@@ -339,6 +424,7 @@ var Link = function Link(_ref) {
|
|
|
339
424
|
isLoading: isLoading,
|
|
340
425
|
url: url,
|
|
341
426
|
isOpen: isRegenerateURLModalOpen,
|
|
427
|
+
regenerateConfig: enabledOptions.regenerate,
|
|
342
428
|
onClose: function onClose() {
|
|
343
429
|
return setIsRegenerateURLModalOpen(false);
|
|
344
430
|
}
|
|
@@ -1406,7 +1492,9 @@ var ShareViaLink = function ShareViaLink(_ref) {
|
|
|
1406
1492
|
_ref$disableShareSoci = _ref.disableShareSocialMedia,
|
|
1407
1493
|
disableShareSocialMedia = _ref$disableShareSoci === void 0 ? false : _ref$disableShareSoci,
|
|
1408
1494
|
_ref$disableQRDownloa = _ref.disableQRDownload,
|
|
1409
|
-
disableQRDownload = _ref$disableQRDownloa === void 0 ? false : _ref$disableQRDownloa
|
|
1495
|
+
disableQRDownload = _ref$disableQRDownloa === void 0 ? false : _ref$disableQRDownloa,
|
|
1496
|
+
_ref$publicLinkExpiry = _ref.publicLinkExpiryConfiguration,
|
|
1497
|
+
publicLinkExpiryConfiguration = _ref$publicLinkExpiry === void 0 ? {} : _ref$publicLinkExpiry;
|
|
1410
1498
|
return /*#__PURE__*/jsxs("div", {
|
|
1411
1499
|
className: "neeto-ui-border-gray-300 neeto-ui-rounded-lg neeto-ui-bg-white col-span-2 space-y-4 border p-6 sm:p-8",
|
|
1412
1500
|
"data-testid": "share-via-link",
|
|
@@ -1422,6 +1510,8 @@ var ShareViaLink = function ShareViaLink(_ref) {
|
|
|
1422
1510
|
previewUrl: urlOption.previewUrl,
|
|
1423
1511
|
url: urlOption.url
|
|
1424
1512
|
});
|
|
1513
|
+
}), isPresent(publicLinkExpiryConfiguration) && /*#__PURE__*/jsx(ExpiryNotice, {
|
|
1514
|
+
expiryConfiguration: publicLinkExpiryConfiguration
|
|
1425
1515
|
}), isOtherShareOptionsEnabled && /*#__PURE__*/jsx(ShareBlock, {
|
|
1426
1516
|
disableQRDownload: disableQRDownload,
|
|
1427
1517
|
disableShareSocialMedia: disableShareSocialMedia,
|