Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Remove quantity from adding product dialog

dominik-zeglen07744f8de537
diff --git a/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
index f76d8ba44f..b2333167db 100644
--- a/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
@@ -3,9 +3,7 @@ import Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent";
import DialogTitle from "@material-ui/core/DialogTitle";
-import InputAdornment from "@material-ui/core/InputAdornment";
-import { withStyles, WithStyles } from "@material-ui/core/styles";
-import TextField from "@material-ui/core/TextField";
+import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
import Form from "../../../components/Form";
@@ -34,124 +32,64 @@ interface OrderProductAddDialogProps {
onSubmit: (data: FormData) => void;
}
-interface OrderProductAddDialogState {
- maxQuantity: number;
-}
-
const decorate = withStyles(
- theme => ({
- dialog: {
+ {
+ overflow: {
overflowY: "visible" as "visible"
- },
- root: {
- display: "grid" as "grid",
- gridColumnGap: theme.spacing.unit * 2 + "px",
- gridTemplateColumns: "1fr 6rem",
- overflowY: "visible" as "visible",
- width: theme.breakpoints.values.sm
- },
- select: {
- flex: 1,
- marginRight: theme.spacing.unit * 2
- },
- textRight: {
- textAlign: "right" as "right"
}
- }),
+ },
{ name: "OrderProductAddDialog" }
);
const initialForm: FormData = {
- quantity: 0,
+ quantity: 1,
variant: {
label: "",
value: ""
}
};
const OrderProductAddDialog = decorate<OrderProductAddDialogProps>(
- class OrderProductAddDialogComponent extends React.Component<
- OrderProductAddDialogProps &
- WithStyles<"dialog" | "root" | "select" | "textRight">
- > {
- state: OrderProductAddDialogState = { maxQuantity: 0 };
- render() {
- const {
- classes,
- open,
- loading,
- variants,
- fetchVariants,
- onClose,
- onSubmit
- } = this.props;
- return (
- <Dialog open={open} classes={{ paper: classes.dialog }}>
- <Form initial={initialForm} onSubmit={onSubmit}>
- {({ data, change }) => {
- const choices =
- !loading && variants
- ? variants.map(v => ({
- label: `${v.sku} ${v.name}`,
- value: v.id
- }))
- : [];
- const handleSelect = (event: React.ChangeEvent<any>) => {
- this.setState({
- maxQuantity: variants.filter(
- v => v.id === event.target.value.value
- )[0].stockQuantity
- });
- change(event);
- };
- return (
- <>
- <DialogTitle>{i18n.t("Add product")}</DialogTitle>
- <DialogContent className={classes.root}>
- <div className={classes.select}>
- <SingleAutocompleteSelectField
- name="variant"
- value={data.variant}
- choices={choices}
- onChange={handleSelect}
- fetchChoices={fetchVariants}
- loading={loading}
- />
- </div>
- <div>
- <TextField
- type="number"
- inputProps={{
- max: this.state.maxQuantity,
- style: { textAlign: "right", width: "4rem" }
- }}
- value={data.quantity}
- onChange={change}
- name="quantity"
- error={data.quantity > this.state.maxQuantity}
- InputProps={{
- endAdornment: (
- <InputAdornment position="end">
- {`/ ${this.state.maxQuantity}`}
- </InputAdornment>
- )
- }}
- />
- </div>
- </DialogContent>
- <DialogActions>
- <Button onClick={onClose}>
- {i18n.t("Cancel", { context: "button" })}
- </Button>
- <Button color="primary" variant="raised" type="submit">
- {i18n.t("Confirm", { context: "button" })}
- </Button>
- </DialogActions>
- </>
- );
- }}
- </Form>
- </Dialog>
- );
- }
- }
+ ({ classes, open, loading, variants, fetchVariants, onClose, onSubmit }) => (
+ <Dialog
+ open={open}
+ classes={{ paper: classes.overflow }}
+ fullWidth
+ maxWidth="sm"
+ >
+ <Form initial={initialForm} onSubmit={onSubmit}>
+ {({ data, change }) => {
+ const choices =
+ !loading && variants
+ ? variants.map(v => ({
+ label: `${v.sku} ${v.name}`,
+ value: v.id
+ }))
+ : [];
+ return (
+ <>
+ <DialogTitle>{i18n.t("Add product")}</DialogTitle>
+ <DialogContent className={classes.overflow}>
+ <SingleAutocompleteSelectField
+ name="variant"
+ value={data.variant}
+ choices={choices}
+ onChange={change}
+ fetchChoices={fetchVariants}
+ loading={loading}
+ />
+ </DialogContent>
+ <DialogActions>
+ <Button onClick={onClose}>
+ {i18n.t("Cancel", { context: "button" })}
+ </Button>
+ <Button color="primary" variant="contained" type="submit">
+ {i18n.t("Confirm", { context: "button" })}
+ </Button>
+ </DialogActions>
+ </>
+ );
+ }}
+ </Form>
+ </Dialog>
+ )
);
export default OrderProductAddDialog;