import { Button } from "@dashboard/components/Button"; import CardTitle from "@dashboard/components/CardTitle"; import HorizontalSpacer from "@dashboard/components/HorizontalSpacer"; import Money from "@dashboard/components/Money"; import { Pill } from "@dashboard/components/Pill"; import Skeleton from "@dashboard/components/Skeleton"; import { OrderAction, OrderDetailsFragment, OrderDiscountType, OrderStatus, } from "@dashboard/graphql"; import { Card, CardContent } from "@material-ui/core"; import { Divider } from "@saleor/macaw-ui/next"; import clsx from "clsx"; import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; import { transformPaymentStatus } from "../../../misc"; import { orderPaymentMessages, paymentButtonMessages } from "./messages"; import { useStyles } from "./styles"; import { extractOrderGiftCardUsedAmount, extractRefundedAmount } from "./utils"; interface OrderPaymentProps { order: OrderDetailsFragment; onCapture: () => void; onMarkAsPaid: () => void; onRefund: () => void; onVoid: () => void; } const OrderPayment: React.FC = props => { const { order, onCapture, onMarkAsPaid, onRefund, onVoid } = props; const classes = useStyles(props); const intl = useIntl(); const canCapture = (order?.actions ?? []).includes(OrderAction.CAPTURE); const canVoid = (order?.actions ?? []).includes(OrderAction.VOID); const canRefund = (order?.actions ?? []).includes(OrderAction.REFUND); const canMarkAsPaid = (order?.actions ?? []).includes( OrderAction.MARK_AS_PAID, ); const payment = transformPaymentStatus(order?.paymentStatus, intl); const refundedAmount = extractRefundedAmount(order); const usedGiftCardAmount = extractOrderGiftCardUsedAmount(order); const getDeliveryMethodName = (order: OrderDetailsFragment) => { if ( order?.shippingMethodName === undefined && order?.shippingPrice === undefined && order?.collectionPointName === undefined ) { return ; } if (order.shippingMethodName === null) { return order.collectionPointName == null ? ( ) : ( ); } return order.shippingMethodName; }; return ( ) : (
{order?.status !== OrderStatus.CANCELED && (canCapture || canRefund || canVoid || canMarkAsPaid) && (
{canCapture && ( )} {canRefund && ( )} {canVoid && ( )} {canMarkAsPaid && ( )}
)}
) } />
{order?.discounts?.map(discount => (
{discount.type === OrderDiscountType.MANUAL ? ( ) : ( )}
-
))}
{ ?? }
{getDeliveryMethodName(order)}
{ ?? }
{order?.total.tax.amount > 0 && ( <>
{" "}
)}
{ ?? }
{ ?? }
{!!usedGiftCardAmount && (
)}
{ ?? }
{ ?? }
{!!refundedAmount?.amount && (
{}
)}
{order?.totalBalance.amount === 0 ? ( ) : ( ?? )} {}
); }; OrderPayment.displayName = "OrderPayment"; export default OrderPayment;