diff --git a/src/products/components/ProductPricing/ProductPricing.tsx b/src/products/components/ProductPricing/ProductPricing.tsx index 153ec3fd2..790f12784 100644 --- a/src/products/components/ProductPricing/ProductPricing.tsx +++ b/src/products/components/ProductPricing/ProductPricing.tsx @@ -5,6 +5,7 @@ import CardTitle from "@saleor/components/CardTitle"; import PriceField from "@saleor/components/PriceField"; import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors"; +import createNonNegativeValueChangeHandler from "@saleor/utils/handlers/nonNegativeValueChangeHandler"; import React from "react"; import { useIntl } from "react-intl"; @@ -37,6 +38,8 @@ const ProductPricing: React.FC = props => { const formErrors = getFormErrors(["basePrice"], errors); + const handlePriceChange = createNonNegativeValueChangeHandler(onChange); + return ( = props => { name="basePrice" value={data.basePrice} currencySymbol={currency} - onChange={onChange} + onChange={handlePriceChange} InputProps={{ inputProps: { min: 0 diff --git a/src/products/components/ProductVariantPrice/ProductVariantPrice.tsx b/src/products/components/ProductVariantPrice/ProductVariantPrice.tsx index d39a927b0..0712f5cfe 100644 --- a/src/products/components/ProductVariantPrice/ProductVariantPrice.tsx +++ b/src/products/components/ProductVariantPrice/ProductVariantPrice.tsx @@ -5,6 +5,7 @@ import CardTitle from "@saleor/components/CardTitle"; import PriceField from "@saleor/components/PriceField"; import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment"; import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors"; +import createNonNegativeValueChangeHandler from "@saleor/utils/handlers/nonNegativeValueChangeHandler"; import React from "react"; import { useIntl } from "react-intl"; @@ -36,6 +37,8 @@ const ProductVariantPrice: React.FC = props => { const formErrors = getFormErrors(["price", "cost_price"], errors); + const handlePriceChange = createNonNegativeValueChangeHandler(onChange); + return ( = props => { })} value={price} currencySymbol={currencySymbol} - onChange={onChange} + onChange={handlePriceChange} disabled={loading} + InputProps={{ + inputProps: { + min: "0" + } + }} />
@@ -76,8 +84,13 @@ const ProductVariantPrice: React.FC = props => { } value={costPrice} currencySymbol={currencySymbol} - onChange={onChange} + onChange={handlePriceChange} disabled={loading} + InputProps={{ + inputProps: { + min: "0" + } + }} />
diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index a4478f4a0..280992f7a 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -141166,6 +141166,7 @@ exports[`Storyshots Views / Products / Create product variant add first variant ) => { + if (/^\d*(\.\d+)?$/.test(event.target.value)) { + change(event); + } + }; +} + +export default createNonNegativeValueChangeHandler;