Merge pull request #784 from mirumee/SALEOR-1264-avatax-address-fix
Remove the finalization dialog on draft order complete
This commit is contained in:
commit
e4fc4489df
8 changed files with 3 additions and 272 deletions
|
@ -2905,39 +2905,6 @@
|
|||
"context": "button",
|
||||
"string": "Add products"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_115822814": {
|
||||
"string": "No billing address"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_1161061962": {
|
||||
"context": "dialog header",
|
||||
"string": "Finalize Draft Order"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_1297434244": {
|
||||
"string": "No user information"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_1472924390": {
|
||||
"string": "There are missing or incorrect informations about this order:"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_2430492151": {
|
||||
"string": "No shipping address"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_2725265632": {
|
||||
"context": "button",
|
||||
"string": "Finalize"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_2824936338": {
|
||||
"string": "Shipping method provided, but no product requires it"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_2968256006": {
|
||||
"string": "Some products require shipping, but no method provided"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_3358029330": {
|
||||
"string": "Are you sure you want to finalize draft #{orderNumber}?"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftFinalizeDialog_dot_678764806": {
|
||||
"context": "button",
|
||||
"string": "Finalize anyway"
|
||||
},
|
||||
"src_dot_orders_dot_components_dot_OrderDraftListPage_dot_2826235371": {
|
||||
"context": "button",
|
||||
"string": "Create order"
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
import DialogContentText from "@material-ui/core/DialogContentText";
|
||||
import ActionDialog from "@saleor/components/ActionDialog";
|
||||
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
||||
import FormSpacer from "@saleor/components/FormSpacer";
|
||||
import { OrderErrorFragment } from "@saleor/fragments/types/OrderErrorFragment";
|
||||
import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors";
|
||||
import getOrderErrorMessage from "@saleor/utils/errors/order";
|
||||
import React from "react";
|
||||
import { FormattedMessage, IntlShape, useIntl } from "react-intl";
|
||||
|
||||
export enum OrderDraftFinalizeWarning {
|
||||
NO_SHIPPING,
|
||||
NO_BILLING,
|
||||
NO_USER,
|
||||
NO_SHIPPING_METHOD,
|
||||
UNNECESSARY_SHIPPING_METHOD
|
||||
}
|
||||
|
||||
export interface OrderDraftFinalizeDialogProps {
|
||||
confirmButtonState: ConfirmButtonTransitionState;
|
||||
errors: OrderErrorFragment[];
|
||||
open: boolean;
|
||||
orderNumber: string;
|
||||
warnings: OrderDraftFinalizeWarning[];
|
||||
onClose: () => void;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
|
||||
function translateWarnings(
|
||||
intl: IntlShape
|
||||
): Record<OrderDraftFinalizeWarning, string> {
|
||||
return {
|
||||
[OrderDraftFinalizeWarning.NO_BILLING]: intl.formatMessage({
|
||||
defaultMessage: "No billing address"
|
||||
}),
|
||||
[OrderDraftFinalizeWarning.NO_SHIPPING]: intl.formatMessage({
|
||||
defaultMessage: "No shipping address"
|
||||
}),
|
||||
[OrderDraftFinalizeWarning.NO_SHIPPING_METHOD]: intl.formatMessage({
|
||||
defaultMessage: "Some products require shipping, but no method provided"
|
||||
}),
|
||||
[OrderDraftFinalizeWarning.NO_USER]: intl.formatMessage({
|
||||
defaultMessage: "No user information"
|
||||
}),
|
||||
[OrderDraftFinalizeWarning.UNNECESSARY_SHIPPING_METHOD]: intl.formatMessage(
|
||||
{
|
||||
defaultMessage: "Shipping method provided, but no product requires it"
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
const OrderDraftFinalizeDialog: React.FC<OrderDraftFinalizeDialogProps> = ({
|
||||
confirmButtonState,
|
||||
errors: apiErrors,
|
||||
open,
|
||||
warnings,
|
||||
onClose,
|
||||
onConfirm,
|
||||
orderNumber
|
||||
}) => {
|
||||
const intl = useIntl();
|
||||
const errors = useModalDialogErrors(apiErrors, open);
|
||||
|
||||
const translatedWarnings = translateWarnings(intl);
|
||||
|
||||
return (
|
||||
<ActionDialog
|
||||
onClose={onClose}
|
||||
onConfirm={onConfirm}
|
||||
open={open}
|
||||
title={intl.formatMessage({
|
||||
defaultMessage: "Finalize Draft Order",
|
||||
description: "dialog header"
|
||||
})}
|
||||
confirmButtonLabel={
|
||||
warnings.length > 0
|
||||
? intl.formatMessage({
|
||||
defaultMessage: "Finalize anyway",
|
||||
description: "button"
|
||||
})
|
||||
: intl.formatMessage({
|
||||
defaultMessage: "Finalize",
|
||||
description: "button"
|
||||
})
|
||||
}
|
||||
confirmButtonState={confirmButtonState}
|
||||
variant={warnings.length > 0 ? "delete" : "default"}
|
||||
>
|
||||
<DialogContentText component="div">
|
||||
{warnings.length > 0 && (
|
||||
<>
|
||||
<p>
|
||||
<FormattedMessage defaultMessage="There are missing or incorrect informations about this order:" />
|
||||
</p>
|
||||
<ul>
|
||||
{warnings.map(warning => (
|
||||
<li key={warning}>{translatedWarnings[warning]}</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
<FormattedMessage
|
||||
defaultMessage="Are you sure you want to finalize draft #{orderNumber}?"
|
||||
values={{
|
||||
orderNumber
|
||||
}}
|
||||
/>
|
||||
{errors.length > 0 && (
|
||||
<>
|
||||
<FormSpacer />
|
||||
{errors.map((err, index) => (
|
||||
<DialogContentText color="error" key={index}>
|
||||
{getOrderErrorMessage(err, intl)}
|
||||
</DialogContentText>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</DialogContentText>
|
||||
</ActionDialog>
|
||||
);
|
||||
};
|
||||
OrderDraftFinalizeDialog.displayName = "OrderDraftFinalize";
|
||||
export default OrderDraftFinalizeDialog;
|
|
@ -1,2 +0,0 @@
|
|||
export { default } from "./OrderDraftFinalizeDialog";
|
||||
export * from "./OrderDraftFinalizeDialog";
|
|
@ -255,7 +255,6 @@ export const OrderDetailsMessages: React.FC<OrderDetailsMessages> = ({
|
|||
defaultMessage: "Draft order successfully finalized"
|
||||
})
|
||||
});
|
||||
closeModal();
|
||||
}
|
||||
};
|
||||
const handleInvoiceGeneratePending = (data: InvoiceRequest) => {
|
||||
|
|
|
@ -39,9 +39,6 @@ import OrderAddressEditDialog from "../../components/OrderAddressEditDialog";
|
|||
import OrderCancelDialog from "../../components/OrderCancelDialog";
|
||||
import OrderDetailsPage from "../../components/OrderDetailsPage";
|
||||
import OrderDraftCancelDialog from "../../components/OrderDraftCancelDialog/OrderDraftCancelDialog";
|
||||
import OrderDraftFinalizeDialog, {
|
||||
OrderDraftFinalizeWarning
|
||||
} from "../../components/OrderDraftFinalizeDialog";
|
||||
import OrderDraftPage from "../../components/OrderDraftPage";
|
||||
import OrderFulfillmentCancelDialog from "../../components/OrderFulfillmentCancelDialog";
|
||||
import OrderFulfillmentTrackingDialog from "../../components/OrderFulfillmentTrackingDialog";
|
||||
|
@ -52,7 +49,6 @@ import OrderProductAddDialog from "../../components/OrderProductAddDialog";
|
|||
import OrderShippingMethodEditDialog from "../../components/OrderShippingMethodEditDialog";
|
||||
import OrderOperations from "../../containers/OrderOperations";
|
||||
import { TypedOrderDetailsQuery, useOrderVariantSearch } from "../../queries";
|
||||
import { OrderDetails_order } from "../../types/OrderDetails";
|
||||
import {
|
||||
orderDraftListUrl,
|
||||
orderFulfillUrl,
|
||||
|
@ -63,36 +59,6 @@ import {
|
|||
} from "../../urls";
|
||||
import { OrderDetailsMessages } from "./OrderDetailsMessages";
|
||||
|
||||
const orderDraftFinalizeWarnings = (order: OrderDetails_order) => {
|
||||
const warnings = [] as OrderDraftFinalizeWarning[];
|
||||
if (!(order && order.shippingAddress)) {
|
||||
warnings.push(OrderDraftFinalizeWarning.NO_SHIPPING);
|
||||
}
|
||||
if (!(order && order.billingAddress)) {
|
||||
warnings.push(OrderDraftFinalizeWarning.NO_BILLING);
|
||||
}
|
||||
if (!(order && (order.user || order.userEmail))) {
|
||||
warnings.push(OrderDraftFinalizeWarning.NO_USER);
|
||||
}
|
||||
if (
|
||||
order &&
|
||||
order.lines &&
|
||||
order.lines.filter(line => line.isShippingRequired).length > 0 &&
|
||||
order.shippingMethod === null
|
||||
) {
|
||||
warnings.push(OrderDraftFinalizeWarning.NO_SHIPPING_METHOD);
|
||||
}
|
||||
if (
|
||||
order &&
|
||||
order.lines &&
|
||||
order.lines.filter(line => line.isShippingRequired).length === 0 &&
|
||||
order.shippingMethod !== null
|
||||
) {
|
||||
warnings.push(OrderDraftFinalizeWarning.UNNECESSARY_SHIPPING_METHOD);
|
||||
}
|
||||
return warnings;
|
||||
};
|
||||
|
||||
interface OrderDetailsProps {
|
||||
id: string;
|
||||
params: OrderUrlQueryParams;
|
||||
|
@ -513,7 +479,9 @@ export const OrderDetails: React.FC<OrderDetailsProps> = ({ id, params }) => {
|
|||
input: data
|
||||
})
|
||||
}
|
||||
onDraftFinalize={() => openModal("finalize")}
|
||||
onDraftFinalize={() =>
|
||||
orderDraftFinalize.mutate({ id })
|
||||
}
|
||||
onDraftRemove={() => openModal("cancel")}
|
||||
onOrderLineAdd={() => openModal("add-order-line")}
|
||||
onBack={() => navigate(orderDraftListUrl())}
|
||||
|
@ -561,18 +529,6 @@ export const OrderDetails: React.FC<OrderDetailsProps> = ({ id, params }) => {
|
|||
open={params.action === "cancel"}
|
||||
orderNumber={getStringOrPlaceholder(order?.number)}
|
||||
/>
|
||||
<OrderDraftFinalizeDialog
|
||||
confirmButtonState={orderDraftFinalize.opts.status}
|
||||
errors={
|
||||
orderDraftFinalize.opts.data?.draftOrderComplete
|
||||
.errors || []
|
||||
}
|
||||
onClose={closeModal}
|
||||
onConfirm={() => orderDraftFinalize.mutate({ id })}
|
||||
open={params.action === "finalize"}
|
||||
orderNumber={getStringOrPlaceholder(order?.number)}
|
||||
warnings={orderDraftFinalizeWarnings(order)}
|
||||
/>
|
||||
<OrderShippingMethodEditDialog
|
||||
confirmButtonState={
|
||||
orderShippingMethodUpdate.opts.status
|
||||
|
|
|
@ -11673,24 +11673,6 @@ exports[`Storyshots Orders / OrderDraftCancelDialog errors 1`] = `
|
|||
/>
|
||||
`;
|
||||
|
||||
exports[`Storyshots Orders / OrderDraftFinalizeDialog default 1`] = `
|
||||
<div
|
||||
style="padding:24px"
|
||||
/>
|
||||
`;
|
||||
|
||||
exports[`Storyshots Orders / OrderDraftFinalizeDialog with errors 1`] = `
|
||||
<div
|
||||
style="padding:24px"
|
||||
/>
|
||||
`;
|
||||
|
||||
exports[`Storyshots Orders / OrderDraftFinalizeDialog with warnings 1`] = `
|
||||
<div
|
||||
style="padding:24px"
|
||||
/>
|
||||
`;
|
||||
|
||||
exports[`Storyshots Orders / OrderFulfillmentCancelDialog default 1`] = `
|
||||
<div
|
||||
style="padding:24px"
|
||||
|
|
|
@ -121,7 +121,6 @@ function loadStories() {
|
|||
require("./stories/orders/OrderCustomer");
|
||||
require("./stories/orders/OrderDetailsPage");
|
||||
require("./stories/orders/OrderDraftCancelDialog");
|
||||
require("./stories/orders/OrderDraftFinalizeDialog");
|
||||
require("./stories/orders/OrderDraftListPage");
|
||||
require("./stories/orders/OrderDraftPage");
|
||||
require("./stories/orders/OrderFulfillmentCancelDialog");
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
import { OrderErrorCode } from "@saleor/types/globalTypes";
|
||||
import { storiesOf } from "@storybook/react";
|
||||
import React from "react";
|
||||
|
||||
import OrderDraftFinalize, {
|
||||
OrderDraftFinalizeDialogProps,
|
||||
OrderDraftFinalizeWarning
|
||||
} from "../../../orders/components/OrderDraftFinalizeDialog";
|
||||
import Decorator from "../../Decorator";
|
||||
|
||||
const props: OrderDraftFinalizeDialogProps = {
|
||||
confirmButtonState: "default",
|
||||
errors: [],
|
||||
onClose: () => undefined,
|
||||
onConfirm: () => undefined,
|
||||
open: true,
|
||||
orderNumber: "5",
|
||||
warnings: []
|
||||
};
|
||||
|
||||
storiesOf("Orders / OrderDraftFinalizeDialog", module)
|
||||
.addDecorator(Decorator)
|
||||
.add("default", () => <OrderDraftFinalize {...props} />)
|
||||
.add("with warnings", () => (
|
||||
<OrderDraftFinalize
|
||||
{...props}
|
||||
warnings={[
|
||||
OrderDraftFinalizeWarning.NO_SHIPPING_METHOD,
|
||||
OrderDraftFinalizeWarning.NO_SHIPPING,
|
||||
OrderDraftFinalizeWarning.NO_BILLING,
|
||||
OrderDraftFinalizeWarning.NO_USER
|
||||
]}
|
||||
/>
|
||||
))
|
||||
.add("with errors", () => (
|
||||
<OrderDraftFinalize
|
||||
{...props}
|
||||
errors={[
|
||||
{
|
||||
__typename: "OrderError",
|
||||
code: OrderErrorCode.GRAPHQL_ERROR,
|
||||
field: null
|
||||
}
|
||||
]}
|
||||
/>
|
||||
));
|
Loading…
Reference in a new issue