saleor-dashboard/src/orders/components/OrderPaymentDialog/OrderPaymentDialog.tsx

113 lines
3.5 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Button from "@material-ui/core/Button";
import Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent";
2020-03-16 12:28:52 +00:00
import DialogContentText from "@material-ui/core/DialogContentText";
2019-06-19 14:40:52 +00:00
import DialogTitle from "@material-ui/core/DialogTitle";
import TextField from "@material-ui/core/TextField";
import ConfirmButton, {
ConfirmButtonTransitionState
} from "@saleor/components/ConfirmButton";
import Form from "@saleor/components/Form";
import FormSpacer from "@saleor/components/FormSpacer";
import { OrderErrorFragment } from "@saleor/fragments/types/OrderErrorFragment";
import { buttonMessages } from "@saleor/intl";
2020-03-16 12:28:52 +00:00
import { getFormErrors } from "@saleor/utils/errors";
import getOrderErrorMessage from "@saleor/utils/errors/order";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
export interface FormData {
amount: number;
}
2020-03-16 12:28:52 +00:00
export interface OrderPaymentDialogProps {
2019-06-19 14:40:52 +00:00
confirmButtonState: ConfirmButtonTransitionState;
2020-03-16 12:28:52 +00:00
errors: OrderErrorFragment[];
2019-06-19 14:40:52 +00:00
open: boolean;
initial: number;
onClose: () => void;
onSubmit: (data: FormData) => void;
}
const OrderPaymentDialog: React.FC<OrderPaymentDialogProps> = ({
2019-06-19 14:40:52 +00:00
confirmButtonState,
2020-03-16 12:28:52 +00:00
errors,
2019-06-19 14:40:52 +00:00
open,
initial,
onClose,
onSubmit
}) => {
const intl = useIntl();
2019-06-19 14:40:52 +00:00
2020-03-16 12:28:52 +00:00
const formFields = ["payment"];
const formErrors = getFormErrors(formFields, errors);
return (
2020-03-16 12:28:52 +00:00
<Dialog onClose={onClose} open={open} fullWidth maxWidth="xs">
<Form
initial={{
amount: initial
}}
2020-03-16 12:28:52 +00:00
onSubmit={onSubmit}
>
{({ data, change, submit }) => (
<>
<DialogTitle>
Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
{intl.formatMessage({
defaultMessage: "Capture Payment",
description: "dialog header"
})}
</DialogTitle>
<DialogContent>
<TextField
2020-03-16 12:28:52 +00:00
error={!!formErrors.payment}
fullWidth
2020-03-16 12:28:52 +00:00
helperText={getOrderErrorMessage(formErrors.payment, intl)}
label={intl.formatMessage({
defaultMessage: "Amount",
description: "amount of refunded money"
})}
name="amount"
onChange={change}
inputProps={{
step: "0.01"
}}
type="number"
value={data.amount}
/>
2020-03-16 12:28:52 +00:00
{errors.length > 0 && (
<>
<FormSpacer />
{errors
.filter(err => !formFields.includes(err.field))
.map((err, index) => (
<DialogContentText color="error" key={index}>
2020-03-16 12:28:52 +00:00
{getOrderErrorMessage(err, intl)}
</DialogContentText>
))}
</>
)}
</DialogContent>
<DialogActions>
<Button onClick={onClose}>
2019-10-21 14:46:12 +00:00
<FormattedMessage {...buttonMessages.back} />
</Button>
<ConfirmButton
transitionState={confirmButtonState}
color="primary"
variant="contained"
2020-03-16 12:28:52 +00:00
onClick={submit}
>
<FormattedMessage {...buttonMessages.confirm} />
</ConfirmButton>
</DialogActions>
</>
)}
</Form>
</Dialog>
);
};
2019-06-19 14:40:52 +00:00
OrderPaymentDialog.displayName = "OrderPaymentDialog";
export default OrderPaymentDialog;