@selfcommunity/react-ui 0.10.5-payments.186 → 0.10.5-payments.187
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/lib/cjs/components/PaymentOrderPdfButton/PaymentOrderPdfButton.js +1 -1
- package/lib/cjs/components/PaymentOrders/PaymentOrders.js +2 -1
- package/lib/cjs/components/PdfPreview/PdfPreview.d.ts +0 -1
- package/lib/cjs/components/PdfPreview/PdfPreview.js +5 -5
- package/lib/cjs/components/PdfPreviewDialog/PdfPreviewDialog.js +23 -1
- package/lib/esm/components/PaymentOrderPdfButton/PaymentOrderPdfButton.js +1 -1
- package/lib/esm/components/PaymentOrders/PaymentOrders.js +2 -1
- package/lib/esm/components/PdfPreview/PdfPreview.d.ts +0 -1
- package/lib/esm/components/PdfPreview/PdfPreview.js +6 -6
- package/lib/esm/components/PdfPreviewDialog/PdfPreviewDialog.js +24 -2
- package/lib/umd/react-ui.js +1 -1
- package/package.json +8 -8
|
@@ -69,6 +69,6 @@ function PaymentOrderPdfButton(inProps) {
|
|
|
69
69
|
if (!scUserContext.user || !isPaymentsEnabled || !scPaymentOrder) {
|
|
70
70
|
return null;
|
|
71
71
|
}
|
|
72
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: !scPaymentOrder ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paymentOrderPdfButton.disabled", defaultMessage: "ui.paymentOrderPdfButton.disabled" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paymentOrder.ticket.view", defaultMessage: "ui.paymentOrder.ticket.view" })) }, { children: (0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), variant: "contained", onClick: handlePaymentOrderPdf }, rest, { children: label ? label : (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "picture_as_pdf" }) })) })), open && ((0, jsx_runtime_1.jsx)(PdfPreviewDialog_1.default, Object.assign({ open: true, onClose: handleClose }, PdfPreviewDialogComponentProps, { pdfUrl:
|
|
72
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: !scPaymentOrder ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paymentOrderPdfButton.disabled", defaultMessage: "ui.paymentOrderPdfButton.disabled" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paymentOrder.ticket.view", defaultMessage: "ui.paymentOrder.ticket.view" })) }, { children: (0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), variant: "contained", onClick: handlePaymentOrderPdf }, rest, { children: label ? label : (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "picture_as_pdf" }) })) })), open && ((0, jsx_runtime_1.jsx)(PdfPreviewDialog_1.default, Object.assign({ open: true, onClose: handleClose }, PdfPreviewDialogComponentProps, { pdfUrl: `${new URL(scContext.settings.portal)}${api_services_1.Endpoints.GetPaymentOrderPdf.url({ id: scPaymentOrder.id })}` })))] }));
|
|
73
73
|
}
|
|
74
74
|
exports.default = PaymentOrderPdfButton;
|
|
@@ -20,6 +20,7 @@ const Category_1 = tslib_1.__importDefault(require("../Category"));
|
|
|
20
20
|
const Course_1 = tslib_1.__importDefault(require("../Course"));
|
|
21
21
|
const Group_1 = tslib_1.__importDefault(require("../Group"));
|
|
22
22
|
const PaymentProduct_1 = tslib_1.__importDefault(require("../PaymentProduct"));
|
|
23
|
+
const PaymentOrderPdfButton_1 = tslib_1.__importDefault(require("../PaymentOrderPdfButton"));
|
|
23
24
|
const PREFIX = 'SCPaymentOrders';
|
|
24
25
|
const classes = {
|
|
25
26
|
root: `${PREFIX}-root`,
|
|
@@ -154,6 +155,6 @@ function PaymentOrders(inProps) {
|
|
|
154
155
|
hour: 'numeric',
|
|
155
156
|
minute: 'numeric'
|
|
156
157
|
})
|
|
157
|
-
: '-' })), (0, jsx_runtime_1.jsx)(material_1.TableCell, Object.assign({ scope: "row" }, { children: (0, jsx_runtime_1.jsx)(material_1.Chip, { variant: 'outlined', label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paymentOrders.status.paid", defaultMessage: "ui.paymentOrders.status.paid" }), color: "success", size: "small" }) })), (0, jsx_runtime_1.jsx)(material_1.TableCell, Object.assign({ scope: "row" }, { children: (0, jsx_runtime_1.
|
|
158
|
+
: '-' })), (0, jsx_runtime_1.jsx)(material_1.TableCell, Object.assign({ scope: "row" }, { children: (0, jsx_runtime_1.jsx)(material_1.Chip, { variant: 'outlined', label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paymentOrders.status.paid", defaultMessage: "ui.paymentOrders.status.paid" }), color: "success", size: "small" }) })), (0, jsx_runtime_1.jsx)(material_1.TableCell, Object.assign({ scope: "row" }, { children: (0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", justifyContent: "left", alignItems: "center", spacing: 2 }, { children: [(0, jsx_runtime_1.jsx)(PaymentOrderPdfButton_1.default, { paymentOrder: order }), Boolean(!order.paid && order.billing_reason === 'subscription_create') && ((0, jsx_runtime_1.jsx)(LoadingButton_1.default, Object.assign({ size: "small", variant: "contained", disabled: true }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paymentOrders.pay", defaultMessage: "ui.paymentOrders.pay" }) })))] })) }))] }, index))), orders.length < 1 && ((0, jsx_runtime_1.jsx)(material_1.TableRow, { children: (0, jsx_runtime_1.jsx)(material_1.TableCell, Object.assign({ align: "left", colSpan: 6 }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: (0, jsx_runtime_1.jsx)(material_1.TableCell, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.paymentOrders.noOrders", defaultMessage: "ui.paymentOrders.noOrders" }) }) })) })) })), hasMore && (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: skeleton() })] })] })) }))) : ((0, jsx_runtime_1.jsx)(material_1.CircularProgress, {})) })) })));
|
|
158
159
|
}
|
|
159
160
|
exports.default = PaymentOrders;
|
|
@@ -7,10 +7,8 @@ const react_1 = require("react");
|
|
|
7
7
|
const material_1 = require("@mui/material");
|
|
8
8
|
const system_1 = require("@mui/system");
|
|
9
9
|
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
10
|
-
const react_intl_1 = require("react-intl");
|
|
11
10
|
const react_pdf_1 = require("react-pdf");
|
|
12
11
|
const utils_1 = require("@selfcommunity/utils");
|
|
13
|
-
const Button_1 = tslib_1.__importDefault(require("@mui/material/Button"));
|
|
14
12
|
const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
|
|
15
13
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
16
14
|
const react_core_1 = require("@selfcommunity/react-core");
|
|
@@ -46,7 +44,7 @@ function PdfPreview(inProps) {
|
|
|
46
44
|
props: inProps,
|
|
47
45
|
name: PREFIX
|
|
48
46
|
});
|
|
49
|
-
const { className, pdfUrl, maxWidth = exports.PdfMaxWidth
|
|
47
|
+
const { className, pdfUrl, maxWidth = exports.PdfMaxWidth } = props, rest = tslib_1.__rest(props, ["className", "pdfUrl", "maxWidth"]);
|
|
50
48
|
// STATE
|
|
51
49
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
52
50
|
const [url, setUrl] = (0, react_1.useState)(null);
|
|
@@ -85,8 +83,10 @@ function PdfPreview(inProps) {
|
|
|
85
83
|
}
|
|
86
84
|
}, [scUserContext.user, scUserContext.session]);
|
|
87
85
|
function renderDocument() {
|
|
88
|
-
return ((0, jsx_runtime_1.jsx)(react_pdf_1.Document, Object.assign({ onLoadSuccess: onDocumentLoadSuccess, loading: (0, jsx_runtime_1.jsx)(Skeleton_1.default, {}), file:
|
|
86
|
+
return ((0, jsx_runtime_1.jsx)(react_pdf_1.Document, Object.assign({ onLoadSuccess: onDocumentLoadSuccess, loading: (0, jsx_runtime_1.jsx)(Skeleton_1.default, {}), file: url, className: classes.documentPdf, options: options }, { children: Array.from({ length: numPages }, (el, index) => {
|
|
87
|
+
return ((0, jsx_runtime_1.jsx)(react_pdf_1.Page, { className: classes.documentPdfPage, pageNumber: index + 1, width: containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth, renderTextLayer: false }, `page_${index + 1}`));
|
|
88
|
+
}) })));
|
|
89
89
|
}
|
|
90
|
-
return ((0, jsx_runtime_1.
|
|
90
|
+
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.documentPdfWrapper, ref: setContainerRef }, { children: isLoading || !pdfUrl ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.documentPdfPage }, { children: (0, jsx_runtime_1.jsx)(Skeleton_1.default, { maxWidth: maxWidth }) }))) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: renderDocument() })) })) })));
|
|
91
91
|
}
|
|
92
92
|
exports.default = PdfPreview;
|
|
@@ -9,6 +9,9 @@ const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
|
9
9
|
const react_core_1 = require("@selfcommunity/react-core");
|
|
10
10
|
const BaseDialog_1 = tslib_1.__importDefault(require("../../shared/BaseDialog"));
|
|
11
11
|
const PdfPreview_1 = tslib_1.__importDefault(require("../PdfPreview"));
|
|
12
|
+
const api_services_1 = require("@selfcommunity/api-services");
|
|
13
|
+
const utils_1 = require("@selfcommunity/utils");
|
|
14
|
+
const Errors_1 = require("../../constants/Errors");
|
|
12
15
|
const PREFIX = 'SCPdfPreviewDialog';
|
|
13
16
|
const classes = {
|
|
14
17
|
root: `${PREFIX}-root`,
|
|
@@ -33,9 +36,28 @@ function PdfPreviewDialog(inProps) {
|
|
|
33
36
|
const { className, title, pdfUrl, disableInitialTransition = false, onClose, PdfPreviewComponentProps = {} } = props, rest = tslib_1.__rest(props, ["className", "title", "pdfUrl", "disableInitialTransition", "onClose", "PdfPreviewComponentProps"]);
|
|
34
37
|
// HOOKS
|
|
35
38
|
const { isPaymentsEnabled } = (0, react_core_1.useSCPaymentsEnabled)();
|
|
39
|
+
/**
|
|
40
|
+
* handle download pdf
|
|
41
|
+
*/
|
|
42
|
+
const handleDownload = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
try {
|
|
44
|
+
const response = yield api_services_1.http.request({ url: pdfUrl, responseType: 'blob' });
|
|
45
|
+
const blob = new Blob([response.data], { type: 'application/pdf' });
|
|
46
|
+
const url = window.URL.createObjectURL(blob);
|
|
47
|
+
const link = document.createElement('a');
|
|
48
|
+
link.href = url;
|
|
49
|
+
link.download = 'order.pdf';
|
|
50
|
+
link.click();
|
|
51
|
+
// Cleanup
|
|
52
|
+
window.URL.revokeObjectURL(url);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, error);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
36
58
|
if (!isPaymentsEnabled) {
|
|
37
59
|
return null;
|
|
38
60
|
}
|
|
39
|
-
return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ fullScreen: true, scroll: 'paper', open: true, maxWidth: 'md' }, (disableInitialTransition ? { TransitionComponent: NoTransition } : { TransitionComponent: Transition }), { className: (0, classnames_1.default)(classes.root, className), TransitionComponent: Transition }, rest, { children: [(0, jsx_runtime_1.jsx)(material_1.AppBar, Object.assign({ sx: { position: 'fixed', top: 0 } }, { children: (0, jsx_runtime_1.jsxs)(material_1.Toolbar, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h6", component: "div", sx: { flexGrow: 1 } }, { children: title })), pdfUrl && ((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ edge: "end", color: "inherit",
|
|
61
|
+
return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ fullScreen: true, scroll: 'paper', open: true, maxWidth: 'md' }, (disableInitialTransition ? { TransitionComponent: NoTransition } : { TransitionComponent: Transition }), { className: (0, classnames_1.default)(classes.root, className), TransitionComponent: Transition }, rest, { children: [(0, jsx_runtime_1.jsx)(material_1.AppBar, Object.assign({ sx: { position: 'fixed', top: 0 } }, { children: (0, jsx_runtime_1.jsxs)(material_1.Toolbar, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h6", component: "div", sx: { flexGrow: 1 } }, { children: title })), pdfUrl && ((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ edge: "end", color: "inherit", onClick: handleDownload, "aria-label": "close" }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "download" }) }))), (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ edge: "end", color: "inherit", onClick: onClose, "aria-label": "close", sx: { ml: 2 } }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "close" }) }))] }) })), (0, jsx_runtime_1.jsx)(material_1.Grid, Object.assign({ container: true, className: classes.content }, { children: (0, jsx_runtime_1.jsx)(material_1.Grid, Object.assign({ item: true, xs: 12, justifyContent: 'center', alignContent: 'center' }, { children: (0, jsx_runtime_1.jsx)(PdfPreview_1.default, Object.assign({}, PdfPreviewComponentProps, { pdfUrl: pdfUrl })) })) }))] })));
|
|
40
62
|
}
|
|
41
63
|
exports.default = PdfPreviewDialog;
|
|
@@ -67,5 +67,5 @@ export default function PaymentOrderPdfButton(inProps) {
|
|
|
67
67
|
if (!scUserContext.user || !isPaymentsEnabled || !scPaymentOrder) {
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
70
|
-
return (_jsxs(_Fragment, { children: [_jsx(Tooltip, Object.assign({ title: !scPaymentOrder ? (_jsx(FormattedMessage, { id: "ui.paymentOrderPdfButton.disabled", defaultMessage: "ui.paymentOrderPdfButton.disabled" })) : (_jsx(FormattedMessage, { id: "ui.paymentOrder.ticket.view", defaultMessage: "ui.paymentOrder.ticket.view" })) }, { children: _jsx(Root, Object.assign({ className: classNames(classes.root, className), variant: "contained", onClick: handlePaymentOrderPdf }, rest, { children: label ? label : _jsx(Icon, { children: "picture_as_pdf" }) })) })), open && (_jsx(PdfPreviewDialog, Object.assign({ open: true, onClose: handleClose }, PdfPreviewDialogComponentProps, { pdfUrl:
|
|
70
|
+
return (_jsxs(_Fragment, { children: [_jsx(Tooltip, Object.assign({ title: !scPaymentOrder ? (_jsx(FormattedMessage, { id: "ui.paymentOrderPdfButton.disabled", defaultMessage: "ui.paymentOrderPdfButton.disabled" })) : (_jsx(FormattedMessage, { id: "ui.paymentOrder.ticket.view", defaultMessage: "ui.paymentOrder.ticket.view" })) }, { children: _jsx(Root, Object.assign({ className: classNames(classes.root, className), variant: "contained", onClick: handlePaymentOrderPdf }, rest, { children: label ? label : _jsx(Icon, { children: "picture_as_pdf" }) })) })), open && (_jsx(PdfPreviewDialog, Object.assign({ open: true, onClose: handleClose }, PdfPreviewDialogComponentProps, { pdfUrl: `${new URL(scContext.settings.portal)}${Endpoints.GetPaymentOrderPdf.url({ id: scPaymentOrder.id })}` })))] }));
|
|
71
71
|
}
|
|
@@ -18,6 +18,7 @@ import Category from '../Category';
|
|
|
18
18
|
import Course from '../Course';
|
|
19
19
|
import Group from '../Group';
|
|
20
20
|
import PaymentProduct from '../PaymentProduct';
|
|
21
|
+
import PaymentOrderPdfButton from '../PaymentOrderPdfButton';
|
|
21
22
|
const PREFIX = 'SCPaymentOrders';
|
|
22
23
|
const classes = {
|
|
23
24
|
root: `${PREFIX}-root`,
|
|
@@ -152,5 +153,5 @@ export default function PaymentOrders(inProps) {
|
|
|
152
153
|
hour: 'numeric',
|
|
153
154
|
minute: 'numeric'
|
|
154
155
|
})
|
|
155
|
-
: '-' })), _jsx(TableCell, Object.assign({ scope: "row" }, { children: _jsx(Chip, { variant: 'outlined', label: _jsx(FormattedMessage, { id: "ui.paymentOrders.status.paid", defaultMessage: "ui.paymentOrders.status.paid" }), color: "success", size: "small" }) })), _jsx(TableCell, Object.assign({ scope: "row" }, { children:
|
|
156
|
+
: '-' })), _jsx(TableCell, Object.assign({ scope: "row" }, { children: _jsx(Chip, { variant: 'outlined', label: _jsx(FormattedMessage, { id: "ui.paymentOrders.status.paid", defaultMessage: "ui.paymentOrders.status.paid" }), color: "success", size: "small" }) })), _jsx(TableCell, Object.assign({ scope: "row" }, { children: _jsxs(Stack, Object.assign({ direction: "row", justifyContent: "left", alignItems: "center", spacing: 2 }, { children: [_jsx(PaymentOrderPdfButton, { paymentOrder: order }), Boolean(!order.paid && order.billing_reason === 'subscription_create') && (_jsx(LoadingButton, Object.assign({ size: "small", variant: "contained", disabled: true }, { children: _jsx(FormattedMessage, { id: "ui.paymentOrders.pay", defaultMessage: "ui.paymentOrders.pay" }) })))] })) }))] }, index))), orders.length < 1 && (_jsx(TableRow, { children: _jsx(TableCell, Object.assign({ align: "left", colSpan: 6 }, { children: _jsx(Typography, Object.assign({ variant: "body2" }, { children: _jsx(TableCell, { children: _jsx(FormattedMessage, { id: "ui.paymentOrders.noOrders", defaultMessage: "ui.paymentOrders.noOrders" }) }) })) })) })), hasMore && _jsx(_Fragment, { children: skeleton() })] })] })) }))) : (_jsx(CircularProgress, {})) })) })));
|
|
156
157
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { __awaiter, __rest } from "tslib";
|
|
2
|
-
import { jsx as _jsx, Fragment as _Fragment
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useCallback, useEffect, useState } from 'react';
|
|
4
4
|
import { Box, styled } from '@mui/material';
|
|
5
5
|
import { useThemeProps } from '@mui/system';
|
|
6
6
|
import classNames from 'classnames';
|
|
7
|
-
import { FormattedMessage } from 'react-intl';
|
|
8
7
|
import { Document, Page, pdfjs } from 'react-pdf';
|
|
9
8
|
import { Logger } from '@selfcommunity/utils';
|
|
10
|
-
import Button from '@mui/material/Button';
|
|
11
9
|
import Skeleton from './Skeleton';
|
|
12
10
|
import { http } from '@selfcommunity/api-services';
|
|
13
11
|
import { useResizeObserver, useSCUser } from '@selfcommunity/react-core';
|
|
@@ -43,7 +41,7 @@ export default function PdfPreview(inProps) {
|
|
|
43
41
|
props: inProps,
|
|
44
42
|
name: PREFIX
|
|
45
43
|
});
|
|
46
|
-
const { className, pdfUrl, maxWidth = PdfMaxWidth
|
|
44
|
+
const { className, pdfUrl, maxWidth = PdfMaxWidth } = props, rest = __rest(props, ["className", "pdfUrl", "maxWidth"]);
|
|
47
45
|
// STATE
|
|
48
46
|
const [isLoading, setIsLoading] = useState(true);
|
|
49
47
|
const [url, setUrl] = useState(null);
|
|
@@ -82,7 +80,9 @@ export default function PdfPreview(inProps) {
|
|
|
82
80
|
}
|
|
83
81
|
}, [scUserContext.user, scUserContext.session]);
|
|
84
82
|
function renderDocument() {
|
|
85
|
-
return (_jsx(Document, Object.assign({ onLoadSuccess: onDocumentLoadSuccess, loading: _jsx(Skeleton, {}), file:
|
|
83
|
+
return (_jsx(Document, Object.assign({ onLoadSuccess: onDocumentLoadSuccess, loading: _jsx(Skeleton, {}), file: url, className: classes.documentPdf, options: options }, { children: Array.from({ length: numPages }, (el, index) => {
|
|
84
|
+
return (_jsx(Page, { className: classes.documentPdfPage, pageNumber: index + 1, width: containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth, renderTextLayer: false }, `page_${index + 1}`));
|
|
85
|
+
}) })));
|
|
86
86
|
}
|
|
87
|
-
return (
|
|
87
|
+
return (_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: _jsx(Box, Object.assign({ className: classes.documentPdfWrapper, ref: setContainerRef }, { children: isLoading || !pdfUrl ? (_jsx(Box, Object.assign({ className: classes.documentPdfPage }, { children: _jsx(Skeleton, { maxWidth: maxWidth }) }))) : (_jsx(_Fragment, { children: renderDocument() })) })) })));
|
|
88
88
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __rest } from "tslib";
|
|
1
|
+
import { __awaiter, __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { AppBar, Grid, IconButton, Slide, Icon, Toolbar, Typography, styled } from '@mui/material';
|
|
@@ -7,6 +7,9 @@ import classNames from 'classnames';
|
|
|
7
7
|
import { useSCPaymentsEnabled } from '@selfcommunity/react-core';
|
|
8
8
|
import BaseDialog from '../../shared/BaseDialog';
|
|
9
9
|
import PdfPreview from '../PdfPreview';
|
|
10
|
+
import { http } from '@selfcommunity/api-services';
|
|
11
|
+
import { Logger } from '@selfcommunity/utils';
|
|
12
|
+
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
10
13
|
const PREFIX = 'SCPdfPreviewDialog';
|
|
11
14
|
const classes = {
|
|
12
15
|
root: `${PREFIX}-root`,
|
|
@@ -31,8 +34,27 @@ export default function PdfPreviewDialog(inProps) {
|
|
|
31
34
|
const { className, title, pdfUrl, disableInitialTransition = false, onClose, PdfPreviewComponentProps = {} } = props, rest = __rest(props, ["className", "title", "pdfUrl", "disableInitialTransition", "onClose", "PdfPreviewComponentProps"]);
|
|
32
35
|
// HOOKS
|
|
33
36
|
const { isPaymentsEnabled } = useSCPaymentsEnabled();
|
|
37
|
+
/**
|
|
38
|
+
* handle download pdf
|
|
39
|
+
*/
|
|
40
|
+
const handleDownload = () => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
try {
|
|
42
|
+
const response = yield http.request({ url: pdfUrl, responseType: 'blob' });
|
|
43
|
+
const blob = new Blob([response.data], { type: 'application/pdf' });
|
|
44
|
+
const url = window.URL.createObjectURL(blob);
|
|
45
|
+
const link = document.createElement('a');
|
|
46
|
+
link.href = url;
|
|
47
|
+
link.download = 'order.pdf';
|
|
48
|
+
link.click();
|
|
49
|
+
// Cleanup
|
|
50
|
+
window.URL.revokeObjectURL(url);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
Logger.error(SCOPE_SC_UI, error);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
34
56
|
if (!isPaymentsEnabled) {
|
|
35
57
|
return null;
|
|
36
58
|
}
|
|
37
|
-
return (_jsxs(Root, Object.assign({ fullScreen: true, scroll: 'paper', open: true, maxWidth: 'md' }, (disableInitialTransition ? { TransitionComponent: NoTransition } : { TransitionComponent: Transition }), { className: classNames(classes.root, className), TransitionComponent: Transition }, rest, { children: [_jsx(AppBar, Object.assign({ sx: { position: 'fixed', top: 0 } }, { children: _jsxs(Toolbar, { children: [_jsx(Typography, Object.assign({ variant: "h6", component: "div", sx: { flexGrow: 1 } }, { children: title })), pdfUrl && (_jsx(IconButton, Object.assign({ edge: "end", color: "inherit",
|
|
59
|
+
return (_jsxs(Root, Object.assign({ fullScreen: true, scroll: 'paper', open: true, maxWidth: 'md' }, (disableInitialTransition ? { TransitionComponent: NoTransition } : { TransitionComponent: Transition }), { className: classNames(classes.root, className), TransitionComponent: Transition }, rest, { children: [_jsx(AppBar, Object.assign({ sx: { position: 'fixed', top: 0 } }, { children: _jsxs(Toolbar, { children: [_jsx(Typography, Object.assign({ variant: "h6", component: "div", sx: { flexGrow: 1 } }, { children: title })), pdfUrl && (_jsx(IconButton, Object.assign({ edge: "end", color: "inherit", onClick: handleDownload, "aria-label": "close" }, { children: _jsx(Icon, { children: "download" }) }))), _jsx(IconButton, Object.assign({ edge: "end", color: "inherit", onClick: onClose, "aria-label": "close", sx: { ml: 2 } }, { children: _jsx(Icon, { children: "close" }) }))] }) })), _jsx(Grid, Object.assign({ container: true, className: classes.content }, { children: _jsx(Grid, Object.assign({ item: true, xs: 12, justifyContent: 'center', alignContent: 'center' }, { children: _jsx(PdfPreview, Object.assign({}, PdfPreviewComponentProps, { pdfUrl: pdfUrl })) })) }))] })));
|
|
38
60
|
}
|