From 037ace2a1b89025c5b36f8eec0bef270e3c23286 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Mon, 27 Apr 2020 15:42:56 +0200 Subject: [PATCH] Handle stock errors --- .../OrderFulfillPage/OrderFulfillPage.tsx | 18 ++++++++++++++++-- src/orders/mutations.ts | 2 ++ src/orders/types/FulfillOrder.ts | 2 ++ src/orders/views/OrderFulfill/OrderFulfill.tsx | 1 + src/types/globalTypes.ts | 3 ++- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx b/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx index 88d6fe49b..155eb421d 100644 --- a/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx +++ b/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx @@ -11,7 +11,10 @@ import classNames from "classnames"; import Typography from "@material-ui/core/Typography"; import useFormset, { FormsetData } from "@saleor/hooks/useFormset"; -import { OrderFulfillStockInput } from "@saleor/types/globalTypes"; +import { + OrderFulfillStockInput, + OrderErrorCode +} from "@saleor/types/globalTypes"; import { WarehouseFragment } from "@saleor/warehouses/types/WarehouseFragment"; import TableCellAvatar from "@saleor/components/TableCellAvatar"; import Container from "@saleor/components/Container"; @@ -31,6 +34,7 @@ import ControlledCheckbox from "@saleor/components/ControlledCheckbox"; import { renderCollection } from "@saleor/misc"; import Skeleton from "@saleor/components/Skeleton"; import AppHeader from "@saleor/components/AppHeader"; +import { FulfillOrder_orderFulfill_errors } from "@saleor/orders/types/FulfillOrder"; const useStyles = makeStyles( theme => ({ @@ -91,6 +95,7 @@ interface OrderFulfillSubmitData extends OrderFulfillFormData { } export interface OrderFulfillPageProps { disabled: boolean; + errors: FulfillOrder_orderFulfill_errors[]; order: OrderFulfillData_order; saveButtonBar: ConfirmButtonTransitionState; warehouses: WarehouseFragment[]; @@ -108,6 +113,7 @@ function getRemainingQuantity(line: OrderFulfillData_order_lines): number { const OrderFulfillPage: React.FC = ({ disabled, + errors, order, saveButtonBar, warehouses, @@ -336,7 +342,15 @@ const OrderFulfillPage: React.FC = ({ } error={ overfulfill || - formsetStock.quantity > availableQuantity + formsetStock.quantity > + availableQuantity || + !!errors?.find( + err => + err.warehouse === warehouse.id && + err.orderLine === line.id && + err.code === + OrderErrorCode.INSUFFICIENT_STOCK + ) } />
diff --git a/src/orders/mutations.ts b/src/orders/mutations.ts index ce0d09016..28fe5cb35 100644 --- a/src/orders/mutations.ts +++ b/src/orders/mutations.ts @@ -460,6 +460,8 @@ const fulfillOrder = gql` orderFulfill(order: $orderId, input: $input) { errors: orderErrors { ...OrderErrorFragment + warehouse + orderLine } order { ...OrderDetailsFragment diff --git a/src/orders/types/FulfillOrder.ts b/src/orders/types/FulfillOrder.ts index 83ccc4bf4..9aa8810ab 100644 --- a/src/orders/types/FulfillOrder.ts +++ b/src/orders/types/FulfillOrder.ts @@ -12,6 +12,8 @@ export interface FulfillOrder_orderFulfill_errors { __typename: "OrderError"; code: OrderErrorCode; field: string | null; + warehouse: string | null; + orderLine: string | null; } export interface FulfillOrder_orderFulfill_order_billingAddress_country { diff --git a/src/orders/views/OrderFulfill/OrderFulfill.tsx b/src/orders/views/OrderFulfill/OrderFulfill.tsx index 5ad743918..39dd898d3 100644 --- a/src/orders/views/OrderFulfill/OrderFulfill.tsx +++ b/src/orders/views/OrderFulfill/OrderFulfill.tsx @@ -66,6 +66,7 @@ const OrderFulfill: React.FC = ({ orderId }) => { /> navigate(orderUrl(orderId))} onSubmit={formData => fulfillOrder({ diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts index b26319b99..37cfba865 100644 --- a/src/types/globalTypes.ts +++ b/src/types/globalTypes.ts @@ -24,6 +24,7 @@ export enum AccountErrorCode { NOT_FOUND = "NOT_FOUND", OUT_OF_SCOPE_GROUP = "OUT_OF_SCOPE_GROUP", OUT_OF_SCOPE_PERMISSION = "OUT_OF_SCOPE_PERMISSION", + OUT_OF_SCOPE_SERVICE_ACCOUNT = "OUT_OF_SCOPE_SERVICE_ACCOUNT", OUT_OF_SCOPE_USER = "OUT_OF_SCOPE_USER", PASSWORD_ENTIRELY_NUMERIC = "PASSWORD_ENTIRELY_NUMERIC", PASSWORD_TOO_COMMON = "PASSWORD_TOO_COMMON", @@ -996,7 +997,7 @@ export interface DraftOrderInput { } export interface FulfillmentCancelInput { - restock?: boolean | null; + warehouseId: string; } export interface FulfillmentUpdateTrackingInput {