@selfcommunity/react-ui 0.10.5-payments.184 → 0.10.5-payments.186

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.
@@ -89,6 +89,7 @@ function GroupSubscribeButton(inProps) {
89
89
  * Define if the buyButton is visible
90
90
  */
91
91
  const showBuyButton = !isGroupAdmin &&
92
+ !user &&
92
93
  isPaymentsEnabled &&
93
94
  ((_b = scGroup.paywalls) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
94
95
  (scGroup.privacy === types_1.SCGroupPrivacyType.PUBLIC ||
@@ -9,13 +9,16 @@ const system_1 = require("@mui/system");
9
9
  const classnames_1 = tslib_1.__importDefault(require("classnames"));
10
10
  const react_intl_1 = require("react-intl");
11
11
  const react_pdf_1 = require("react-pdf");
12
+ const utils_1 = require("@selfcommunity/utils");
12
13
  const Button_1 = tslib_1.__importDefault(require("@mui/material/Button"));
13
14
  const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
15
+ const api_services_1 = require("@selfcommunity/api-services");
14
16
  const react_core_1 = require("@selfcommunity/react-core");
17
+ const Errors_1 = require("../../constants/Errors");
15
18
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
16
19
  // @ts-ignore
17
20
  react_pdf_1.pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.js', import.meta.url).toString();
18
- const PREFIX = 'PWAInvoicePdfView';
21
+ const PREFIX = 'SCPdfPreview';
19
22
  const classes = {
20
23
  root: `${PREFIX}-root`,
21
24
  documentPdfWrapper: `${PREFIX}-document-pdf-wrapper`,
@@ -27,23 +30,7 @@ const Root = (0, material_1.styled)(material_1.Box, {
27
30
  name: PREFIX,
28
31
  slot: 'Root',
29
32
  overridesResolver: (props, styles) => styles.root
30
- })(({ theme }) => ({
31
- display: 'flex',
32
- flexDirection: 'column',
33
- [`& .${classes.documentPdfWrapper}`]: {
34
- filter: 'drop-shadow(0 0 5px #00000040)'
35
- },
36
- [`& .${classes.documentPdfLink}`]: {
37
- padding: 10,
38
- '&:hover': {
39
- opacity: 0.5
40
- }
41
- },
42
- [`& .${classes.documentPdfPage}`]: {
43
- display: 'flex',
44
- justifyContent: 'center'
45
- }
46
- }));
33
+ })(({ theme }) => ({}));
47
34
  // Default options conf PDFViewer
48
35
  const options = {
49
36
  cMapUrl: '/cmaps/',
@@ -80,10 +67,8 @@ function PdfPreview(inProps) {
80
67
  setIsLoading(false);
81
68
  }
82
69
  const fetchBlob = (0, react_1.useCallback)((url) => tslib_1.__awaiter(this, void 0, void 0, function* () {
83
- const request = yield fetch(url, {
84
- headers: Object.assign({}, (scUserContext.user && { Authorization: `Bearer ${scUserContext.session.authToken.accessToken}` }))
85
- });
86
- return yield request.blob();
70
+ const response = yield api_services_1.http.request({ url, responseType: 'blob' });
71
+ return response.data;
87
72
  }), [scUserContext.user, scUserContext.session]);
88
73
  (0, react_1.useEffect)(() => {
89
74
  if (pdfUrl) {
@@ -94,7 +79,9 @@ function PdfPreview(inProps) {
94
79
  setUrl(_url);
95
80
  setIsLoading(false);
96
81
  })
97
- .catch(console.error);
82
+ .catch((error) => {
83
+ utils_1.Logger.error(Errors_1.SCOPE_SC_UI, error);
84
+ });
98
85
  }
99
86
  }, [scUserContext.user, scUserContext.session]);
100
87
  function renderDocument() {
@@ -168,17 +168,9 @@ function UserToastNotifications(inProps) {
168
168
  * - the enqueue message is persistent (it remains on the screen while the others replace each other) if type notification_banner
169
169
  */
170
170
  const messageKey = data.data.feed_serialization_id ? data.data.feed_serialization_id : data.data.id;
171
- enqueueSnackbar(getContent(data.data), {
172
- preventDuplicate: true,
173
- key: messageKey,
174
- variant: 'notification',
175
- persist: data.data.activity_type === types_1.SCNotificationTypologyType.NOTIFICATION_BANNER ? true : false,
176
- anchorOrigin: { horizontal: 'left', vertical: 'bottom' },
177
- action: null,
178
- SnackbarProps: {
171
+ enqueueSnackbar(getContent(data.data), Object.assign(Object.assign({ preventDuplicate: true, key: messageKey, variant: 'notification', persist: data.data.activity_type === types_1.SCNotificationTypologyType.NOTIFICATION_BANNER }, (data.data.activity_type !== types_1.SCNotificationTypologyType.NOTIFICATION_BANNER && { autoHideDuration: 10000 })), { anchorOrigin: { horizontal: 'left', vertical: 'bottom' }, action: null, SnackbarProps: {
179
172
  id: messageKey
180
- }
181
- });
173
+ } }));
182
174
  }
183
175
  };
184
176
  /**
@@ -87,6 +87,7 @@ export default function GroupSubscribeButton(inProps) {
87
87
  * Define if the buyButton is visible
88
88
  */
89
89
  const showBuyButton = !isGroupAdmin &&
90
+ !user &&
90
91
  isPaymentsEnabled &&
91
92
  ((_b = scGroup.paywalls) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
92
93
  (scGroup.privacy === SCGroupPrivacyType.PUBLIC ||
@@ -6,13 +6,16 @@ import { useThemeProps } from '@mui/system';
6
6
  import classNames from 'classnames';
7
7
  import { FormattedMessage } from 'react-intl';
8
8
  import { Document, Page, pdfjs } from 'react-pdf';
9
+ import { Logger } from '@selfcommunity/utils';
9
10
  import Button from '@mui/material/Button';
10
11
  import Skeleton from './Skeleton';
12
+ import { http } from '@selfcommunity/api-services';
11
13
  import { useResizeObserver, useSCUser } from '@selfcommunity/react-core';
14
+ import { SCOPE_SC_UI } from '../../constants/Errors';
12
15
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
13
16
  // @ts-ignore
14
17
  pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.js', import.meta.url).toString();
15
- const PREFIX = 'PWAInvoicePdfView';
18
+ const PREFIX = 'SCPdfPreview';
16
19
  const classes = {
17
20
  root: `${PREFIX}-root`,
18
21
  documentPdfWrapper: `${PREFIX}-document-pdf-wrapper`,
@@ -24,23 +27,7 @@ const Root = styled(Box, {
24
27
  name: PREFIX,
25
28
  slot: 'Root',
26
29
  overridesResolver: (props, styles) => styles.root
27
- })(({ theme }) => ({
28
- display: 'flex',
29
- flexDirection: 'column',
30
- [`& .${classes.documentPdfWrapper}`]: {
31
- filter: 'drop-shadow(0 0 5px #00000040)'
32
- },
33
- [`& .${classes.documentPdfLink}`]: {
34
- padding: 10,
35
- '&:hover': {
36
- opacity: 0.5
37
- }
38
- },
39
- [`& .${classes.documentPdfPage}`]: {
40
- display: 'flex',
41
- justifyContent: 'center'
42
- }
43
- }));
30
+ })(({ theme }) => ({}));
44
31
  // Default options conf PDFViewer
45
32
  const options = {
46
33
  cMapUrl: '/cmaps/',
@@ -77,10 +64,8 @@ export default function PdfPreview(inProps) {
77
64
  setIsLoading(false);
78
65
  }
79
66
  const fetchBlob = useCallback((url) => __awaiter(this, void 0, void 0, function* () {
80
- const request = yield fetch(url, {
81
- headers: Object.assign({}, (scUserContext.user && { Authorization: `Bearer ${scUserContext.session.authToken.accessToken}` }))
82
- });
83
- return yield request.blob();
67
+ const response = yield http.request({ url, responseType: 'blob' });
68
+ return response.data;
84
69
  }), [scUserContext.user, scUserContext.session]);
85
70
  useEffect(() => {
86
71
  if (pdfUrl) {
@@ -91,7 +76,9 @@ export default function PdfPreview(inProps) {
91
76
  setUrl(_url);
92
77
  setIsLoading(false);
93
78
  })
94
- .catch(console.error);
79
+ .catch((error) => {
80
+ Logger.error(SCOPE_SC_UI, error);
81
+ });
95
82
  }
96
83
  }, [scUserContext.user, scUserContext.session]);
97
84
  function renderDocument() {
@@ -165,17 +165,9 @@ export default function UserToastNotifications(inProps) {
165
165
  * - the enqueue message is persistent (it remains on the screen while the others replace each other) if type notification_banner
166
166
  */
167
167
  const messageKey = data.data.feed_serialization_id ? data.data.feed_serialization_id : data.data.id;
168
- enqueueSnackbar(getContent(data.data), {
169
- preventDuplicate: true,
170
- key: messageKey,
171
- variant: 'notification',
172
- persist: data.data.activity_type === SCNotificationTypologyType.NOTIFICATION_BANNER ? true : false,
173
- anchorOrigin: { horizontal: 'left', vertical: 'bottom' },
174
- action: null,
175
- SnackbarProps: {
168
+ enqueueSnackbar(getContent(data.data), Object.assign(Object.assign({ preventDuplicate: true, key: messageKey, variant: 'notification', persist: data.data.activity_type === SCNotificationTypologyType.NOTIFICATION_BANNER }, (data.data.activity_type !== SCNotificationTypologyType.NOTIFICATION_BANNER && { autoHideDuration: 10000 })), { anchorOrigin: { horizontal: 'left', vertical: 'bottom' }, action: null, SnackbarProps: {
176
169
  id: messageKey
177
- }
178
- });
170
+ } }));
179
171
  }
180
172
  };
181
173
  /**