UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

75 lines (66 loc) 3.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const classnames_1 = tslib_1.__importDefault(require("classnames")); const material_1 = require("@mui/material"); const system_1 = require("@mui/system"); const react_core_1 = require("@selfcommunity/react-core"); const react_intl_1 = require("react-intl"); const PdfPreviewDialog_1 = tslib_1.__importDefault(require("../PdfPreviewDialog")); const api_services_1 = require("@selfcommunity/api-services"); const PREFIX = 'SCPaymentOrderPdfButton'; const classes = { root: `${PREFIX}-root` }; const Root = (0, material_1.styled)(material_1.Button, { name: PREFIX, slot: 'root' })(() => ({})); /** * > API documentation for the Community-JS PaymentOrderPdfButton component. Learn about the available props and the CSS API. #### Import ```jsx import {PaymentOrderPdfButton} from '@selfcommunity/react-ui'; ``` #### Component Name The name `PaymentOrderPdfButton` can be used when providing style overrides in the theme. #### CSS |Rule Name|Global class|Description| |---|---|---| |root|.SCPaymentOrderPdfButton-root|Styles applied to the root element.| * @param inProps */ function PaymentOrderPdfButton(inProps) { // PROPS const props = (0, system_1.useThemeProps)({ props: inProps, name: PREFIX }); const { className, paymentOrderId, paymentOrder, handleClick, PdfPreviewDialogComponentProps = {}, label } = props, rest = tslib_1.__rest(props, ["className", "paymentOrderId", "paymentOrder", "handleClick", "PdfPreviewDialogComponentProps", "label"]); // STATE const [open, setOpen] = (0, react_1.useState)(false); // CONTEXT const scContext = (0, react_core_1.useSCContext)(); const scUserContext = (0, react_core_1.useSCUser)(); const { isPaymentsEnabled } = (0, react_core_1.useSCPaymentsEnabled)(); const { scPaymentOrder } = (0, react_core_1.useSCFetchPaymentOrder)({ id: paymentOrderId, paymentOrder }); // HANDLERS const handleClose = (0, react_1.useCallback)(() => { setOpen(false); }, [open]); const handlePaymentOrderPdf = (0, react_1.useCallback)((e) => { if (handleClick) { handleClick(); } else if (!open) { setOpen(true); } }, [open, handleClick]); if (!scUserContext.user || !isPaymentsEnabled || !scPaymentOrder) { return null; } 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 })}` })))] })); } exports.default = PaymentOrderPdfButton;