UNPKG

bananas-commerce-admin

Version:

What's this, an admin for apes?

46 lines 4.08 kB
import React, { useState } from "react"; import { Button, Stack, TableBody, TableRow, Typography } from "@mui/material"; import { tableCellClasses } from "@mui/material/TableCell"; import Card from "../../../components/Card"; import Table from "../../../components/Table"; import { TableCell } from "../../../components/Table/TableCell"; import TableCardHeader from "../../../components/TableCardHeader"; import { useDialog } from "../../../contexts/DialogContext"; import { useI18n } from "../../../contexts/I18nContext"; import { useUser } from "../../../contexts/UserContext"; import { hasPermission } from "../../../util/has_permission"; import { ReceiptTable } from "./ReceiptTable"; export const ReceiptPriceRow = ({ title, price, currency }) => (React.createElement(Stack, { direction: "row", gap: 1, justifyContent: "flex-end", sx: { minWidth: "max-content" } }, React.createElement(Typography, { fontWeight: 600, sx: { minWidth: 42 }, variant: "body2" }, title), React.createElement(Typography, { sx: { minWidth: 80 }, variant: "body2" }, price, " ", currency))); export const ReceiptCard = ({ purchase, refund }) => { const { t } = useI18n(); const { user } = useUser(); const [editing, setEditing] = useState(false); const [selected, setSelected] = useState([]); const openDialog = useDialog(); return (React.createElement(Card, { size: 12 }, React.createElement(TableCardHeader, { isDisabled: (!purchase.accounts || purchase.accounts.captured === "0.00") && !editing, isEditable: hasPermission(user, "pos.change_receipt"), title: t("Receipt"), toggled: editing, onChange: setEditing }), React.createElement(ReceiptTable, { currency: purchase.currency, editable: editing, lines: purchase.lines, onSelect: setSelected }), React.createElement(Table, { count: 0, tableProps: { sx: { p: 0, [`& .${tableCellClasses.root}`]: { borderBottom: "none" } } } }, React.createElement(TableBody, { sx: { border: "none" } }, React.createElement(TableRow, null, React.createElement(TableCell, { align: "left", sx: { width: "100%" } }, editing && (React.createElement(Button, { color: "error", disabled: selected.length === 0, variant: "contained", onClick: async () => { if (await openDialog(t("Are you sure?"), t("This will refund the selected quantity / amount to the customer and cannot be reversed"))) { refund?.(selected); setEditing(false); } } }, t("Refund")))), React.createElement(TableCell, { align: "right" }, purchase.total_debit_amount != null && (React.createElement(ReceiptPriceRow, { currency: purchase.currency, price: purchase.total_debit_amount, title: t("Total") })), Boolean(purchase.total_discount_amount != null && purchase.total_discount_amount !== "0.00") && (React.createElement(ReceiptPriceRow, { currency: purchase.currency, price: purchase.total_discount_amount, title: t("Discount") })), purchase.total_tax_amount && (React.createElement(ReceiptPriceRow, { currency: purchase.currency, price: purchase.total_tax_amount, title: t("Tax") })), purchase.accounts != null && (React.createElement(React.Fragment, null, purchase.accounts.reserved !== "0.00" && (React.createElement(ReceiptPriceRow, { currency: purchase.currency, price: purchase.accounts.reserved, title: t("Reserved") })), purchase.accounts.captured !== "0.00" && (React.createElement(ReceiptPriceRow, { currency: purchase.currency, price: purchase.accounts.captured, title: t("Captured") })), purchase.accounts.reverted !== "0.00" && (React.createElement(ReceiptPriceRow, { currency: purchase.currency, price: purchase.accounts.reverted, title: t("Refunded/Cancelled") })))))))))); }; //# sourceMappingURL=ReceiptCard.js.map