saleor-dashboard/src/components/PriceField/PriceField.tsx
Dawid Tarasiuk eb351b396a
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 14:13:05 +01:00

113 lines
2.4 KiB
TypeScript

import { InputProps } from "@material-ui/core/Input";
import InputAdornment from "@material-ui/core/InputAdornment";
import { makeStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import React from "react";
import { FormattedMessage } from "react-intl";
const useStyles = makeStyles(
theme => ({
currencySymbol: {
fontSize: "0.875rem"
},
inputContainer: {
display: "grid",
gridTemplateColumns: "1fr 2rem 1fr"
},
pullDown: {
marginTop: theme.spacing(2)
},
separator: {
marginTop: theme.spacing(3),
textAlign: "center",
width: "100%"
},
widgetContainer: {
marginTop: theme.spacing(2)
}
}),
{ name: "PriceField" }
);
interface PriceFieldProps {
className?: string;
currencySymbol?: string;
disabled?: boolean;
error?: boolean;
hint?: string;
label?: string;
name?: string;
value?: string | number;
InputProps?: InputProps;
inputProps?: InputProps["inputProps"];
required?: boolean;
onChange(event: any);
}
export const PriceField: React.FC<PriceFieldProps> = props => {
const {
className,
disabled,
error,
label,
hint = "",
currencySymbol,
name,
onChange,
required,
value,
InputProps,
inputProps
} = props;
const classes = useStyles(props);
const minValue = 0;
return (
<TextField
className={className}
error={error || value < minValue}
helperText={
hint ? (
hint
) : value < minValue ? (
<FormattedMessage defaultMessage="Price cannot be lower than 0" />
) : (
""
)
}
label={label}
fullWidth
value={value}
InputProps={{
...InputProps,
endAdornment: currencySymbol ? (
<InputAdornment position="end" className={classes.currencySymbol}>
{currencySymbol}
</InputAdornment>
) : (
<span />
),
inputProps: {
min: 0,
...InputProps?.inputProps
},
type: "number"
}}
inputProps={{
min: minValue,
type: "number",
...inputProps
}}
name={name}
disabled={disabled}
required={required}
onChange={onChange}
/>
);
};
PriceField.defaultProps = {
name: "price"
};
PriceField.displayName = "PriceField";
export default PriceField;