Add weight to simple products
This commit is contained in:
parent
4efce141da
commit
e066d3171f
11 changed files with 77 additions and 34 deletions
|
@ -43,6 +43,7 @@ import ProductDetailsForm from "../ProductDetailsForm";
|
||||||
import ProductOrganization from "../ProductOrganization";
|
import ProductOrganization from "../ProductOrganization";
|
||||||
import ProductPricing from "../ProductPricing";
|
import ProductPricing from "../ProductPricing";
|
||||||
import ProductStocks, { ProductStockInput } from "../ProductStocks";
|
import ProductStocks, { ProductStockInput } from "../ProductStocks";
|
||||||
|
import ProductShipping from "../ProductShipping/ProductShipping";
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
basePrice: number;
|
basePrice: number;
|
||||||
|
@ -59,6 +60,7 @@ interface FormData {
|
||||||
sku: string;
|
sku: string;
|
||||||
stockQuantity: number;
|
stockQuantity: number;
|
||||||
trackInventory: boolean;
|
trackInventory: boolean;
|
||||||
|
weight: string;
|
||||||
}
|
}
|
||||||
export interface ProductCreatePageSubmitData extends FormData {
|
export interface ProductCreatePageSubmitData extends FormData {
|
||||||
attributes: ProductAttributeInput[];
|
attributes: ProductAttributeInput[];
|
||||||
|
@ -82,6 +84,7 @@ interface ProductCreatePageProps {
|
||||||
}>;
|
}>;
|
||||||
header: string;
|
header: string;
|
||||||
saveButtonBarState: ConfirmButtonTransitionState;
|
saveButtonBarState: ConfirmButtonTransitionState;
|
||||||
|
weightUnit: string;
|
||||||
warehouses: SearchWarehouses_search_edges_node[];
|
warehouses: SearchWarehouses_search_edges_node[];
|
||||||
fetchCategories: (data: string) => void;
|
fetchCategories: (data: string) => void;
|
||||||
fetchCollections: (data: string) => void;
|
fetchCollections: (data: string) => void;
|
||||||
|
@ -107,6 +110,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
warehouses,
|
warehouses,
|
||||||
onBack,
|
onBack,
|
||||||
fetchProductTypes,
|
fetchProductTypes,
|
||||||
|
weightUnit,
|
||||||
onSubmit
|
onSubmit
|
||||||
}: ProductCreatePageProps) => {
|
}: ProductCreatePageProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
@ -143,7 +147,8 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
seoTitle: "",
|
seoTitle: "",
|
||||||
sku: null,
|
sku: null,
|
||||||
stockQuantity: null,
|
stockQuantity: null,
|
||||||
trackInventory: false
|
trackInventory: false,
|
||||||
|
weight: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
// Display values
|
// Display values
|
||||||
|
@ -242,6 +247,14 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
{!!productType && !productType.hasVariants && (
|
{!!productType && !productType.hasVariants && (
|
||||||
<>
|
<>
|
||||||
|
<ProductShipping
|
||||||
|
data={data}
|
||||||
|
disabled={disabled}
|
||||||
|
errors={errors}
|
||||||
|
weightUnit={weightUnit}
|
||||||
|
onChange={change}
|
||||||
|
/>
|
||||||
|
<CardSpacer />
|
||||||
<ProductStocks
|
<ProductStocks
|
||||||
data={data}
|
data={data}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|
|
@ -50,8 +50,10 @@ import ProductOrganization from "../ProductOrganization";
|
||||||
import ProductPricing from "../ProductPricing";
|
import ProductPricing from "../ProductPricing";
|
||||||
import ProductVariants from "../ProductVariants";
|
import ProductVariants from "../ProductVariants";
|
||||||
import ProductStocks, { ProductStockInput } from "../ProductStocks";
|
import ProductStocks, { ProductStockInput } from "../ProductStocks";
|
||||||
|
import ProductShipping from "../ProductShipping/ProductShipping";
|
||||||
|
|
||||||
export interface ProductUpdatePageProps extends ListActions {
|
export interface ProductUpdatePageProps extends ListActions {
|
||||||
|
defaultWeightUnit: string;
|
||||||
errors: ProductErrorFragment[];
|
errors: ProductErrorFragment[];
|
||||||
placeholderImage: string;
|
placeholderImage: string;
|
||||||
collections: SearchCollections_search_edges_node[];
|
collections: SearchCollections_search_edges_node[];
|
||||||
|
@ -89,6 +91,7 @@ export interface ProductUpdatePageSubmitData extends ProductUpdatePageFormData {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
|
defaultWeightUnit,
|
||||||
disabled,
|
disabled,
|
||||||
categories: categoryChoiceList,
|
categories: categoryChoiceList,
|
||||||
collections: collectionChoiceList,
|
collections: collectionChoiceList,
|
||||||
|
@ -269,6 +272,15 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
toggleAll={toggleAll}
|
toggleAll={toggleAll}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
<>
|
||||||
|
<ProductShipping
|
||||||
|
data={data}
|
||||||
|
disabled={disabled}
|
||||||
|
errors={errors}
|
||||||
|
weightUnit={product?.weight?.unit || defaultWeightUnit}
|
||||||
|
onChange={change}
|
||||||
|
/>
|
||||||
|
<CardSpacer />
|
||||||
<ProductStocks
|
<ProductStocks
|
||||||
data={data}
|
data={data}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
@ -296,6 +308,7 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
removeStock(id);
|
removeStock(id);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<SeoForm
|
<SeoForm
|
||||||
|
|
|
@ -206,6 +206,7 @@ export const simpleProductUpdateMutation = gql`
|
||||||
$addStocks: [StockInput!]!
|
$addStocks: [StockInput!]!
|
||||||
$deleteStocks: [ID!]!
|
$deleteStocks: [ID!]!
|
||||||
$updateStocks: [StockInput!]!
|
$updateStocks: [StockInput!]!
|
||||||
|
$weight: WeightScalar
|
||||||
) {
|
) {
|
||||||
productUpdate(
|
productUpdate(
|
||||||
id: $id
|
id: $id
|
||||||
|
@ -220,6 +221,7 @@ export const simpleProductUpdateMutation = gql`
|
||||||
name: $name
|
name: $name
|
||||||
basePrice: $basePrice
|
basePrice: $basePrice
|
||||||
seo: $seo
|
seo: $seo
|
||||||
|
weight: $weight
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
errors: productErrors {
|
errors: productErrors {
|
||||||
|
|
|
@ -770,4 +770,5 @@ export interface SimpleProductUpdateVariables {
|
||||||
addStocks: StockInput[];
|
addStocks: StockInput[];
|
||||||
deleteStocks: string[];
|
deleteStocks: string[];
|
||||||
updateStocks: StockInput[];
|
updateStocks: StockInput[];
|
||||||
|
weight?: any | null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,6 +181,7 @@ export interface ProductUpdatePageFormData {
|
||||||
seoTitle: string;
|
seoTitle: string;
|
||||||
sku: string;
|
sku: string;
|
||||||
trackInventory: boolean;
|
trackInventory: boolean;
|
||||||
|
weight: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProductUpdatePageFormData(
|
export function getProductUpdatePageFormData(
|
||||||
|
@ -210,7 +211,8 @@ export function getProductUpdatePageFormData(
|
||||||
: undefined,
|
: undefined,
|
||||||
""
|
""
|
||||||
),
|
),
|
||||||
trackInventory: !!product?.variants[0]?.trackInventory
|
trackInventory: !!product?.variants[0]?.trackInventory,
|
||||||
|
weight: product?.weight?.value.toString() || ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import useCategorySearch from "@saleor/searches/useCategorySearch";
|
||||||
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
||||||
import useProductTypeSearch from "@saleor/searches/useProductTypeSearch";
|
import useProductTypeSearch from "@saleor/searches/useProductTypeSearch";
|
||||||
import { useWarehouseList } from "@saleor/warehouses/queries";
|
import { useWarehouseList } from "@saleor/warehouses/queries";
|
||||||
import { decimal, maybe } from "../../misc";
|
import { decimal, maybe, weight } from "../../misc";
|
||||||
import ProductCreatePage, {
|
import ProductCreatePage, {
|
||||||
ProductCreatePageSubmitData
|
ProductCreatePageSubmitData
|
||||||
} from "../components/ProductCreatePage";
|
} from "../components/ProductCreatePage";
|
||||||
|
@ -95,7 +95,8 @@ export const ProductCreateView: React.FC = () => {
|
||||||
quantity: parseInt(stock.value, 0),
|
quantity: parseInt(stock.value, 0),
|
||||||
warehouse: stock.id
|
warehouse: stock.id
|
||||||
})),
|
})),
|
||||||
trackInventory: formData.trackInventory
|
trackInventory: formData.trackInventory,
|
||||||
|
weight: weight(formData.weight)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -157,6 +158,7 @@ export const ProductCreateView: React.FC = () => {
|
||||||
warehouses={
|
warehouses={
|
||||||
warehouses.data?.warehouses.edges.map(edge => edge.node) || []
|
warehouses.data?.warehouses.edges.map(edge => edge.node) || []
|
||||||
}
|
}
|
||||||
|
weightUnit={shop?.defaultWeightUnit}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,6 +17,7 @@ import useCollectionSearch from "@saleor/searches/useCollectionSearch";
|
||||||
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers";
|
||||||
import NotFoundPage from "@saleor/components/NotFoundPage";
|
import NotFoundPage from "@saleor/components/NotFoundPage";
|
||||||
import { useWarehouseList } from "@saleor/warehouses/queries";
|
import { useWarehouseList } from "@saleor/warehouses/queries";
|
||||||
|
import useShop from "@saleor/hooks/useShop";
|
||||||
import { getMutationState, maybe } from "../../../misc";
|
import { getMutationState, maybe } from "../../../misc";
|
||||||
import ProductUpdatePage from "../../components/ProductUpdatePage";
|
import ProductUpdatePage from "../../components/ProductUpdatePage";
|
||||||
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
|
import ProductUpdateOperations from "../../containers/ProductUpdateOperations";
|
||||||
|
@ -75,6 +76,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
first: 50
|
first: 50
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const shop = useShop();
|
||||||
|
|
||||||
const [openModal, closeModal] = createDialogActionHandlers<
|
const [openModal, closeModal] = createDialogActionHandlers<
|
||||||
ProductUrlDialog,
|
ProductUrlDialog,
|
||||||
|
@ -213,6 +215,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
<ProductUpdatePage
|
<ProductUpdatePage
|
||||||
categories={categories}
|
categories={categories}
|
||||||
collections={collections}
|
collections={collections}
|
||||||
|
defaultWeightUnit={shop?.defaultWeightUnit}
|
||||||
disabled={disableFormSave}
|
disabled={disableFormSave}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
fetchCategories={searchCategories}
|
fetchCategories={searchCategories}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { decimal } from "@saleor/misc";
|
import { decimal, weight } from "@saleor/misc";
|
||||||
import { ProductUpdatePageSubmitData } from "@saleor/products/components/ProductUpdatePage";
|
import { ProductUpdatePageSubmitData } from "@saleor/products/components/ProductUpdatePage";
|
||||||
import { ProductDetails_product } from "@saleor/products/types/ProductDetails";
|
import { ProductDetails_product } from "@saleor/products/types/ProductDetails";
|
||||||
import { ProductImageCreateVariables } from "@saleor/products/types/ProductImageCreate";
|
import { ProductImageCreateVariables } from "@saleor/products/types/ProductImageCreate";
|
||||||
|
@ -48,7 +48,8 @@ export function createUpdateHandler(
|
||||||
sku: data.sku,
|
sku: data.sku,
|
||||||
trackInventory: data.trackInventory
|
trackInventory: data.trackInventory
|
||||||
},
|
},
|
||||||
updateStocks: data.updateStocks.map(mapFormsetStockToStockInput)
|
updateStocks: data.updateStocks.map(mapFormsetStockToStockInput),
|
||||||
|
weight: weight(data.weight)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,6 +34,7 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onSubmit={() => undefined}
|
onSubmit={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
weightUnit="kg"
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("When loading", () => (
|
.add("When loading", () => (
|
||||||
|
@ -55,6 +56,7 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onSubmit={() => undefined}
|
onSubmit={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={undefined}
|
warehouses={undefined}
|
||||||
|
weightUnit="kg"
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("form errors", () => (
|
.add("form errors", () => (
|
||||||
|
@ -82,5 +84,6 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onSubmit={() => undefined}
|
onSubmit={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
weightUnit="kg"
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -19,6 +19,7 @@ const props: ProductUpdatePageProps = {
|
||||||
...listActionsProps,
|
...listActionsProps,
|
||||||
categories: [product.category],
|
categories: [product.category],
|
||||||
collections,
|
collections,
|
||||||
|
defaultWeightUnit: "kg",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
errors: [],
|
errors: [],
|
||||||
fetchCategories: () => undefined,
|
fetchCategories: () => undefined,
|
||||||
|
|
|
@ -51,7 +51,9 @@ const WarehouseDetailsPage: React.FC<WarehouseDetailsPageProps> = ({
|
||||||
onSubmit
|
onSubmit
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [displayCountry, setDisplayCountry] = useStateFromProps("");
|
const [displayCountry, setDisplayCountry] = useStateFromProps(
|
||||||
|
warehouse?.address?.country.country || ""
|
||||||
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
errors: validationErrors,
|
errors: validationErrors,
|
||||||
|
|
Loading…
Reference in a new issue