Add warehouse selection to restock items
This commit is contained in:
parent
596cc41a7f
commit
7cc3492e71
4 changed files with 102 additions and 63 deletions
|
@ -81,6 +81,10 @@ export const commonMessages = defineMessages({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const buttonMessages = defineMessages({
|
export const buttonMessages = defineMessages({
|
||||||
|
accept: {
|
||||||
|
defaultMessage: "Accept",
|
||||||
|
description: "button"
|
||||||
|
},
|
||||||
back: {
|
back: {
|
||||||
defaultMessage: "Back",
|
defaultMessage: "Back",
|
||||||
description: "button"
|
description: "button"
|
||||||
|
|
|
@ -144,7 +144,7 @@ const OrderFulfillment: React.FC<OrderFulfillmentProps> = props => {
|
||||||
menuItems={[
|
menuItems={[
|
||||||
{
|
{
|
||||||
label: intl.formatMessage({
|
label: intl.formatMessage({
|
||||||
defaultMessage: "Cancel shipment",
|
defaultMessage: "Cancel Fulfillment",
|
||||||
description: "button"
|
description: "button"
|
||||||
}),
|
}),
|
||||||
onSelect: onOrderFulfillmentCancel
|
onSelect: onOrderFulfillmentCancel
|
||||||
|
|
|
@ -11,25 +11,29 @@ import { FormattedMessage, useIntl } from "react-intl";
|
||||||
import ConfirmButton, {
|
import ConfirmButton, {
|
||||||
ConfirmButtonTransitionState
|
ConfirmButtonTransitionState
|
||||||
} from "@saleor/components/ConfirmButton";
|
} from "@saleor/components/ConfirmButton";
|
||||||
import { ControlledCheckbox } from "@saleor/components/ControlledCheckbox";
|
|
||||||
import Form from "@saleor/components/Form";
|
import Form from "@saleor/components/Form";
|
||||||
import { buttonMessages } from "@saleor/intl";
|
import { buttonMessages } from "@saleor/intl";
|
||||||
import { OrderErrorFragment } from "@saleor/orders/types/OrderErrorFragment";
|
import { OrderErrorFragment } from "@saleor/orders/types/OrderErrorFragment";
|
||||||
import FormSpacer from "@saleor/components/FormSpacer";
|
import FormSpacer from "@saleor/components/FormSpacer";
|
||||||
import getOrderErrorMessage from "@saleor/utils/errors/order";
|
import getOrderErrorMessage from "@saleor/utils/errors/order";
|
||||||
|
import { WarehouseFragment } from "@saleor/warehouses/types/WarehouseFragment";
|
||||||
|
import SingleAutocompleteSelectField from "@saleor/components/SingleAutocompleteSelectField";
|
||||||
|
import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";
|
||||||
|
|
||||||
export interface FormData {
|
export interface OrderFulfillmentCancelDialogFormData {
|
||||||
restock: boolean;
|
warehouse: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
theme => ({
|
theme => ({
|
||||||
deleteButton: {
|
enableOverflow: {
|
||||||
"&:hover": {
|
overflow: "visible"
|
||||||
backgroundColor: theme.palette.error.main
|
|
||||||
},
|
},
|
||||||
backgroundColor: theme.palette.error.main,
|
paragraph: {
|
||||||
color: theme.palette.error.contrastText
|
marginBottom: theme.spacing(2)
|
||||||
|
},
|
||||||
|
selectCcontainer: {
|
||||||
|
width: "60%"
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
{ name: "OrderFulfillmentCancelDialog" }
|
{ name: "OrderFulfillmentCancelDialog" }
|
||||||
|
@ -39,20 +43,48 @@ export interface OrderFulfillmentCancelDialogProps {
|
||||||
confirmButtonState: ConfirmButtonTransitionState;
|
confirmButtonState: ConfirmButtonTransitionState;
|
||||||
errors: OrderErrorFragment[];
|
errors: OrderErrorFragment[];
|
||||||
open: boolean;
|
open: boolean;
|
||||||
|
warehouses: WarehouseFragment[];
|
||||||
onClose();
|
onClose();
|
||||||
onConfirm(data: FormData);
|
onConfirm(data: OrderFulfillmentCancelDialogFormData);
|
||||||
}
|
}
|
||||||
|
|
||||||
const OrderFulfillmentCancelDialog: React.FC<OrderFulfillmentCancelDialogProps> = props => {
|
const OrderFulfillmentCancelDialog: React.FC<OrderFulfillmentCancelDialogProps> = props => {
|
||||||
const { confirmButtonState, errors, open, onConfirm, onClose } = props;
|
const {
|
||||||
|
confirmButtonState,
|
||||||
|
errors,
|
||||||
|
open,
|
||||||
|
warehouses,
|
||||||
|
onConfirm,
|
||||||
|
onClose
|
||||||
|
} = props;
|
||||||
|
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const [displayValue, setDisplayValue] = React.useState("");
|
||||||
|
|
||||||
|
const choices = warehouses?.map(warehouse => ({
|
||||||
|
label: warehouse.name,
|
||||||
|
value: warehouse.id
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog onClose={onClose} open={open} fullWidth maxWidth="xs">
|
<Dialog
|
||||||
<Form initial={{ restock: true }} onSubmit={onConfirm}>
|
classes={{
|
||||||
{({ change, data, submit }) => (
|
paper: classes.enableOverflow
|
||||||
|
}}
|
||||||
|
onClose={onClose}
|
||||||
|
open={open}
|
||||||
|
fullWidth
|
||||||
|
maxWidth="sm"
|
||||||
|
>
|
||||||
|
<Form initial={{ warehouse: null }} onSubmit={onConfirm}>
|
||||||
|
{({ change, data: formData, submit }) => {
|
||||||
|
const handleChange = createSingleAutocompleteSelectHandler(
|
||||||
|
change,
|
||||||
|
setDisplayValue,
|
||||||
|
choices
|
||||||
|
);
|
||||||
|
return (
|
||||||
<>
|
<>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -60,19 +92,23 @@ const OrderFulfillmentCancelDialog: React.FC<OrderFulfillmentCancelDialogProps>
|
||||||
description="dialog header"
|
description="dialog header"
|
||||||
/>
|
/>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent className={classes.enableOverflow}>
|
||||||
<DialogContentText>
|
<DialogContentText className={classes.paragraph}>
|
||||||
<FormattedMessage defaultMessage="Are you sure you want to cancel this fulfillment?" />
|
<FormattedMessage defaultMessage="Are you sure you want to cancel fulfillment? Canceling a fulfillment will restock products at a selected warehouse." />
|
||||||
</DialogContentText>
|
</DialogContentText>
|
||||||
<ControlledCheckbox
|
<div className={classes.selectCcontainer}>
|
||||||
checked={data.restock}
|
<SingleAutocompleteSelectField
|
||||||
|
choices={choices}
|
||||||
|
displayValue={displayValue}
|
||||||
label={intl.formatMessage({
|
label={intl.formatMessage({
|
||||||
defaultMessage: "Restock items?",
|
defaultMessage: "Select Warehouse",
|
||||||
description: "switch button"
|
description: "select warehouse to restock items"
|
||||||
})}
|
})}
|
||||||
name="restock"
|
name="warehouse"
|
||||||
onChange={change}
|
value={formData.warehouse}
|
||||||
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
{errors.length > 0 && (
|
{errors.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<FormSpacer />
|
<FormSpacer />
|
||||||
|
@ -90,18 +126,15 @@ const OrderFulfillmentCancelDialog: React.FC<OrderFulfillmentCancelDialogProps>
|
||||||
</Button>
|
</Button>
|
||||||
<ConfirmButton
|
<ConfirmButton
|
||||||
transitionState={confirmButtonState}
|
transitionState={confirmButtonState}
|
||||||
className={classes.deleteButton}
|
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage {...buttonMessages.accept} />
|
||||||
defaultMessage="Cancel fulfillment"
|
|
||||||
description="button"
|
|
||||||
/>
|
|
||||||
</ConfirmButton>
|
</ConfirmButton>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</>
|
</>
|
||||||
)}
|
);
|
||||||
|
}}
|
||||||
</Form>
|
</Form>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { storiesOf } from "@storybook/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { OrderErrorCode } from "@saleor/types/globalTypes";
|
import { OrderErrorCode } from "@saleor/types/globalTypes";
|
||||||
|
import { warehouseList } from "@saleor/warehouses/fixtures";
|
||||||
import OrderFulfillmentCancelDialog, {
|
import OrderFulfillmentCancelDialog, {
|
||||||
OrderFulfillmentCancelDialogProps
|
OrderFulfillmentCancelDialogProps
|
||||||
} from "../../../orders/components/OrderFulfillmentCancelDialog";
|
} from "../../../orders/components/OrderFulfillmentCancelDialog";
|
||||||
|
@ -12,7 +13,8 @@ const props: OrderFulfillmentCancelDialogProps = {
|
||||||
errors: [],
|
errors: [],
|
||||||
onClose: () => undefined,
|
onClose: () => undefined,
|
||||||
onConfirm: () => undefined,
|
onConfirm: () => undefined,
|
||||||
open: true
|
open: true,
|
||||||
|
warehouses: warehouseList
|
||||||
};
|
};
|
||||||
|
|
||||||
storiesOf("Orders / OrderFulfillmentCancelDialog", module)
|
storiesOf("Orders / OrderFulfillmentCancelDialog", module)
|
||||||
|
|
Loading…
Reference in a new issue