2021-05-14 08:15:15 +00:00
|
|
|
import {
|
|
|
|
Dialog,
|
|
|
|
DialogActions,
|
|
|
|
DialogContent,
|
|
|
|
DialogContentText,
|
|
|
|
DialogTitle,
|
|
|
|
TextField
|
|
|
|
} from "@material-ui/core";
|
2022-01-28 12:34:20 +00:00
|
|
|
import BackButton from "@saleor/components/BackButton";
|
|
|
|
import ConfirmButton from "@saleor/components/ConfirmButton";
|
2019-06-19 14:40:52 +00:00
|
|
|
import Form from "@saleor/components/Form";
|
2020-05-14 09:30:32 +00:00
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
2022-03-09 08:56:55 +00:00
|
|
|
import { OrderErrorFragment } from "@saleor/graphql";
|
2019-08-26 17:44:42 +00:00
|
|
|
import { buttonMessages } from "@saleor/intl";
|
2022-01-28 12:34:20 +00:00
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
|
2020-03-16 12:28:52 +00:00
|
|
|
import { getFormErrors } from "@saleor/utils/errors";
|
2020-05-14 09:30:32 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
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
|
2019-08-26 17:44:42 +00:00
|
|
|
}) => {
|
|
|
|
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);
|
|
|
|
|
2019-08-26 17:44:42 +00:00
|
|
|
return (
|
2020-03-16 12:28:52 +00:00
|
|
|
<Dialog onClose={onClose} open={open} fullWidth maxWidth="xs">
|
2019-08-26 17:44:42 +00:00
|
|
|
<Form
|
|
|
|
initial={{
|
|
|
|
amount: initial
|
|
|
|
}}
|
2020-03-16 12:28:52 +00:00
|
|
|
onSubmit={onSubmit}
|
2019-08-26 17:44:42 +00:00
|
|
|
>
|
|
|
|
{({ data, change, submit }) => (
|
|
|
|
<>
|
|
|
|
<DialogTitle>
|
2020-12-01 13:13:05 +00:00
|
|
|
{intl.formatMessage({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "+PbHKD",
|
2020-12-01 13:13:05 +00:00
|
|
|
defaultMessage: "Capture Payment",
|
|
|
|
description: "dialog header"
|
|
|
|
})}
|
2019-08-26 17:44:42 +00:00
|
|
|
</DialogTitle>
|
|
|
|
<DialogContent>
|
|
|
|
<TextField
|
2020-03-16 12:28:52 +00:00
|
|
|
error={!!formErrors.payment}
|
2019-08-26 17:44:42 +00:00
|
|
|
fullWidth
|
2020-03-16 12:28:52 +00:00
|
|
|
helperText={getOrderErrorMessage(formErrors.payment, intl)}
|
2019-08-26 17:44:42 +00:00
|
|
|
label={intl.formatMessage({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "OhdPS1",
|
2019-08-26 17:44:42 +00:00
|
|
|
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))
|
2020-07-02 10:59:09 +00:00
|
|
|
.map((err, index) => (
|
|
|
|
<DialogContentText color="error" key={index}>
|
2020-03-16 12:28:52 +00:00
|
|
|
{getOrderErrorMessage(err, intl)}
|
|
|
|
</DialogContentText>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
2019-08-26 17:44:42 +00:00
|
|
|
</DialogContent>
|
|
|
|
<DialogActions>
|
2022-01-28 12:34:20 +00:00
|
|
|
<BackButton onClick={onClose} />
|
2019-08-26 17:44:42 +00:00
|
|
|
<ConfirmButton
|
|
|
|
transitionState={confirmButtonState}
|
2020-03-16 12:28:52 +00:00
|
|
|
onClick={submit}
|
2019-08-26 17:44:42 +00:00
|
|
|
>
|
|
|
|
<FormattedMessage {...buttonMessages.confirm} />
|
|
|
|
</ConfirmButton>
|
|
|
|
</DialogActions>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
OrderPaymentDialog.displayName = "OrderPaymentDialog";
|
|
|
|
export default OrderPaymentDialog;
|