Remove base price from product create page
This commit is contained in:
parent
831bde8311
commit
0b099e882c
10 changed files with 1 additions and 126 deletions
|
@ -41,11 +41,9 @@ import ProductAttributes, {
|
||||||
} from "../ProductAttributes";
|
} from "../ProductAttributes";
|
||||||
import ProductDetailsForm from "../ProductDetailsForm";
|
import ProductDetailsForm from "../ProductDetailsForm";
|
||||||
import ProductOrganization from "../ProductOrganization";
|
import ProductOrganization from "../ProductOrganization";
|
||||||
import ProductPricing from "../ProductPricing";
|
|
||||||
import ProductStocks, { ProductStockInput } from "../ProductStocks";
|
import ProductStocks, { ProductStockInput } from "../ProductStocks";
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
basePrice: number;
|
|
||||||
publicationDate: string;
|
publicationDate: string;
|
||||||
category: string;
|
category: string;
|
||||||
collections: string[];
|
collections: string[];
|
||||||
|
@ -69,7 +67,6 @@ interface ProductCreatePageProps {
|
||||||
errors: ProductErrorFragment[];
|
errors: ProductErrorFragment[];
|
||||||
collections: SearchCollections_search_edges_node[];
|
collections: SearchCollections_search_edges_node[];
|
||||||
categories: SearchCategories_search_edges_node[];
|
categories: SearchCategories_search_edges_node[];
|
||||||
currency: string;
|
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
fetchMoreCategories: FetchMoreProps;
|
fetchMoreCategories: FetchMoreProps;
|
||||||
fetchMoreCollections: FetchMoreProps;
|
fetchMoreCollections: FetchMoreProps;
|
||||||
|
@ -91,7 +88,6 @@ interface ProductCreatePageProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
currency,
|
|
||||||
disabled,
|
disabled,
|
||||||
categories: categoryChoiceList,
|
categories: categoryChoiceList,
|
||||||
collections: collectionChoiceList,
|
collections: collectionChoiceList,
|
||||||
|
@ -130,7 +126,6 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
convertToRaw(ContentState.createFromText(""))
|
convertToRaw(ContentState.createFromText(""))
|
||||||
);
|
);
|
||||||
const initialData: FormData = {
|
const initialData: FormData = {
|
||||||
basePrice: 0,
|
|
||||||
category: "",
|
category: "",
|
||||||
chargeTaxes: false,
|
chargeTaxes: false,
|
||||||
collections: [],
|
collections: [],
|
||||||
|
@ -232,14 +227,6 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<ProductPricing
|
|
||||||
currency={currency}
|
|
||||||
data={data}
|
|
||||||
disabled={disabled}
|
|
||||||
errors={errors}
|
|
||||||
onChange={change}
|
|
||||||
/>
|
|
||||||
<CardSpacer />
|
|
||||||
{!!productType && !productType.hasVariants && (
|
{!!productType && !productType.hasVariants && (
|
||||||
<>
|
<>
|
||||||
<ProductStocks
|
<ProductStocks
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
import Card from "@material-ui/core/Card";
|
|
||||||
import CardContent from "@material-ui/core/CardContent";
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
|
||||||
import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
|
|
||||||
import CardTitle from "@saleor/components/CardTitle";
|
|
||||||
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
|
|
||||||
import PriceField from "@saleor/components/PriceField";
|
|
||||||
import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors";
|
|
||||||
import React from "react";
|
|
||||||
import { useIntl } from "react-intl";
|
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
|
||||||
theme => ({
|
|
||||||
root: {
|
|
||||||
display: "grid",
|
|
||||||
gridColumnGap: theme.spacing(2),
|
|
||||||
gridTemplateColumns: "1fr 1fr"
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
{ name: "ProductPricing" }
|
|
||||||
);
|
|
||||||
|
|
||||||
interface ProductPricingProps {
|
|
||||||
currency?: string;
|
|
||||||
data: {
|
|
||||||
chargeTaxes: boolean;
|
|
||||||
basePrice: number;
|
|
||||||
};
|
|
||||||
disabled: boolean;
|
|
||||||
errors: ProductErrorFragment[];
|
|
||||||
onChange: (event: React.ChangeEvent<any>) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ProductPricing: React.FC<ProductPricingProps> = props => {
|
|
||||||
const { currency, data, disabled, errors, onChange } = props;
|
|
||||||
|
|
||||||
const classes = useStyles(props);
|
|
||||||
const intl = useIntl();
|
|
||||||
|
|
||||||
const formErrors = getFormErrors(["basePrice"], errors);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card>
|
|
||||||
<CardTitle
|
|
||||||
title={intl.formatMessage({
|
|
||||||
defaultMessage: "Pricing",
|
|
||||||
description: "product pricing"
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<ControlledCheckbox
|
|
||||||
name="chargeTaxes"
|
|
||||||
label={intl.formatMessage({
|
|
||||||
defaultMessage: "Charge taxes for this item"
|
|
||||||
})}
|
|
||||||
checked={data.chargeTaxes}
|
|
||||||
onChange={onChange}
|
|
||||||
disabled={disabled}
|
|
||||||
/>
|
|
||||||
</CardTitle>
|
|
||||||
<CardContent>
|
|
||||||
<div className={classes.root}>
|
|
||||||
<PriceField
|
|
||||||
disabled={disabled}
|
|
||||||
label={intl.formatMessage({
|
|
||||||
defaultMessage: "Price",
|
|
||||||
description: "product price"
|
|
||||||
})}
|
|
||||||
error={!!formErrors.basePrice}
|
|
||||||
hint={getProductErrorMessage(formErrors.basePrice, intl)}
|
|
||||||
name="basePrice"
|
|
||||||
value={data.basePrice}
|
|
||||||
currencySymbol={currency}
|
|
||||||
onChange={onChange}
|
|
||||||
InputProps={{
|
|
||||||
inputProps: {
|
|
||||||
min: 0
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
ProductPricing.displayName = "ProductPricing";
|
|
||||||
export default ProductPricing;
|
|
|
@ -1,2 +0,0 @@
|
||||||
export { default } from "./ProductPricing";
|
|
||||||
export * from "./ProductPricing";
|
|
|
@ -47,7 +47,6 @@ import ProductAttributes, { ProductAttributeInput } from "../ProductAttributes";
|
||||||
import ProductDetailsForm from "../ProductDetailsForm";
|
import ProductDetailsForm from "../ProductDetailsForm";
|
||||||
import ProductImages from "../ProductImages";
|
import ProductImages from "../ProductImages";
|
||||||
import ProductOrganization from "../ProductOrganization";
|
import ProductOrganization from "../ProductOrganization";
|
||||||
import ProductPricing from "../ProductPricing";
|
|
||||||
import ProductStocks, { ProductStockInput } from "../ProductStocks";
|
import ProductStocks, { ProductStockInput } from "../ProductStocks";
|
||||||
import ProductVariants from "../ProductVariants";
|
import ProductVariants from "../ProductVariants";
|
||||||
|
|
||||||
|
@ -159,7 +158,6 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
|
|
||||||
const categories = getChoices(categoryChoiceList);
|
const categories = getChoices(categoryChoiceList);
|
||||||
const collections = getChoices(collectionChoiceList);
|
const collections = getChoices(collectionChoiceList);
|
||||||
const currency = maybe(() => product.basePrice.currency);
|
|
||||||
const hasVariants = maybe(() => product.productType.hasVariants, false);
|
const hasVariants = maybe(() => product.productType.hasVariants, false);
|
||||||
|
|
||||||
const handleSubmit = (data: ProductUpdatePageFormData) => {
|
const handleSubmit = (data: ProductUpdatePageFormData) => {
|
||||||
|
@ -246,14 +244,6 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<ProductPricing
|
|
||||||
currency={currency}
|
|
||||||
data={data}
|
|
||||||
disabled={disabled}
|
|
||||||
errors={errors}
|
|
||||||
onChange={change}
|
|
||||||
/>
|
|
||||||
<CardSpacer />
|
|
||||||
{hasVariants ? (
|
{hasVariants ? (
|
||||||
<ProductVariants
|
<ProductVariants
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|
|
@ -198,7 +198,6 @@ export const simpleProductUpdateMutation = gql`
|
||||||
$descriptionJson: JSONString
|
$descriptionJson: JSONString
|
||||||
$isPublished: Boolean!
|
$isPublished: Boolean!
|
||||||
$name: String
|
$name: String
|
||||||
$basePrice: Decimal
|
|
||||||
$productVariantId: ID!
|
$productVariantId: ID!
|
||||||
$productVariantInput: ProductVariantInput!
|
$productVariantInput: ProductVariantInput!
|
||||||
$seo: SeoInput
|
$seo: SeoInput
|
||||||
|
@ -217,7 +216,6 @@ export const simpleProductUpdateMutation = gql`
|
||||||
descriptionJson: $descriptionJson
|
descriptionJson: $descriptionJson
|
||||||
isPublished: $isPublished
|
isPublished: $isPublished
|
||||||
name: $name
|
name: $name
|
||||||
basePrice: $basePrice
|
|
||||||
seo: $seo
|
seo: $seo
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
@ -288,7 +286,6 @@ export const productCreateMutation = gql`
|
||||||
$descriptionJson: JSONString
|
$descriptionJson: JSONString
|
||||||
$isPublished: Boolean!
|
$isPublished: Boolean!
|
||||||
$name: String!
|
$name: String!
|
||||||
$basePrice: Decimal
|
|
||||||
$productType: ID!
|
$productType: ID!
|
||||||
$sku: String
|
$sku: String
|
||||||
$seo: SeoInput
|
$seo: SeoInput
|
||||||
|
@ -305,7 +302,6 @@ export const productCreateMutation = gql`
|
||||||
descriptionJson: $descriptionJson
|
descriptionJson: $descriptionJson
|
||||||
isPublished: $isPublished
|
isPublished: $isPublished
|
||||||
name: $name
|
name: $name
|
||||||
basePrice: $basePrice
|
|
||||||
productType: $productType
|
productType: $productType
|
||||||
sku: $sku
|
sku: $sku
|
||||||
seo: $seo
|
seo: $seo
|
||||||
|
|
|
@ -222,7 +222,6 @@ export interface ProductCreateVariables {
|
||||||
descriptionJson?: any | null;
|
descriptionJson?: any | null;
|
||||||
isPublished: boolean;
|
isPublished: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
basePrice?: any | null;
|
|
||||||
productType: string;
|
productType: string;
|
||||||
sku?: string | null;
|
sku?: string | null;
|
||||||
seo?: SeoInput | null;
|
seo?: SeoInput | null;
|
||||||
|
|
|
@ -721,7 +721,6 @@ export interface SimpleProductUpdateVariables {
|
||||||
descriptionJson?: any | null;
|
descriptionJson?: any | null;
|
||||||
isPublished: boolean;
|
isPublished: boolean;
|
||||||
name?: string | null;
|
name?: string | null;
|
||||||
basePrice?: any | null;
|
|
||||||
productVariantId: string;
|
productVariantId: string;
|
||||||
productVariantInput: ProductVariantInput;
|
productVariantInput: ProductVariantInput;
|
||||||
seo?: SeoInput | null;
|
seo?: SeoInput | null;
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { WindowTitle } from "@saleor/components/WindowTitle";
|
||||||
import { DEFAULT_INITIAL_SEARCH_DATA } from "@saleor/config";
|
import { DEFAULT_INITIAL_SEARCH_DATA } from "@saleor/config";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import useShop from "@saleor/hooks/useShop";
|
|
||||||
import useCategorySearch from "@saleor/searches/useCategorySearch";
|
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";
|
||||||
|
@ -10,7 +9,7 @@ import { useWarehouseList } from "@saleor/warehouses/queries";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { decimal, maybe } from "../../misc";
|
import { maybe } from "../../misc";
|
||||||
import ProductCreatePage, {
|
import ProductCreatePage, {
|
||||||
ProductCreatePageSubmitData
|
ProductCreatePageSubmitData
|
||||||
} from "../components/ProductCreatePage";
|
} from "../components/ProductCreatePage";
|
||||||
|
@ -21,7 +20,6 @@ import { productListUrl, productUrl } from "../urls";
|
||||||
export const ProductCreateView: React.FC = () => {
|
export const ProductCreateView: React.FC = () => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const shop = useShop();
|
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const {
|
const {
|
||||||
loadMore: loadMoreCategories,
|
loadMore: loadMoreCategories,
|
||||||
|
@ -74,7 +72,6 @@ export const ProductCreateView: React.FC = () => {
|
||||||
id: attribute.id,
|
id: attribute.id,
|
||||||
values: attribute.value
|
values: attribute.value
|
||||||
})),
|
})),
|
||||||
basePrice: decimal(formData.basePrice),
|
|
||||||
category: formData.category,
|
category: formData.category,
|
||||||
chargeTaxes: formData.chargeTaxes,
|
chargeTaxes: formData.chargeTaxes,
|
||||||
collections: formData.collections,
|
collections: formData.collections,
|
||||||
|
@ -109,7 +106,6 @@ export const ProductCreateView: React.FC = () => {
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<ProductCreatePage
|
<ProductCreatePage
|
||||||
currency={maybe(() => shop.defaultCurrency)}
|
|
||||||
categories={maybe(
|
categories={maybe(
|
||||||
() => searchCategoryOpts.data.search.edges,
|
() => searchCategoryOpts.data.search.edges,
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -17,7 +17,6 @@ storiesOf("Views / Products / Create product", module)
|
||||||
.addDecorator(Decorator)
|
.addDecorator(Decorator)
|
||||||
.add("default", () => (
|
.add("default", () => (
|
||||||
<ProductCreatePage
|
<ProductCreatePage
|
||||||
currency="USD"
|
|
||||||
disabled={false}
|
disabled={false}
|
||||||
errors={[]}
|
errors={[]}
|
||||||
header="Add product"
|
header="Add product"
|
||||||
|
@ -38,7 +37,6 @@ storiesOf("Views / Products / Create product", module)
|
||||||
))
|
))
|
||||||
.add("When loading", () => (
|
.add("When loading", () => (
|
||||||
<ProductCreatePage
|
<ProductCreatePage
|
||||||
currency="USD"
|
|
||||||
disabled={true}
|
disabled={true}
|
||||||
errors={[]}
|
errors={[]}
|
||||||
header="Add product"
|
header="Add product"
|
||||||
|
@ -59,7 +57,6 @@ storiesOf("Views / Products / Create product", module)
|
||||||
))
|
))
|
||||||
.add("form errors", () => (
|
.add("form errors", () => (
|
||||||
<ProductCreatePage
|
<ProductCreatePage
|
||||||
currency="USD"
|
|
||||||
disabled={false}
|
disabled={false}
|
||||||
errors={(["name", "productType", "category", "sku"] as Array<
|
errors={(["name", "productType", "category", "sku"] as Array<
|
||||||
keyof ProductCreatePageSubmitData
|
keyof ProductCreatePageSubmitData
|
||||||
|
|
|
@ -112,7 +112,6 @@ storiesOf("Views / Products / Product edit", module)
|
||||||
<ProductUpdatePage
|
<ProductUpdatePage
|
||||||
{...props}
|
{...props}
|
||||||
errors={([
|
errors={([
|
||||||
"basePrice",
|
|
||||||
"category",
|
"category",
|
||||||
"chargeTaxes",
|
"chargeTaxes",
|
||||||
"collections",
|
"collections",
|
||||||
|
|
Loading…
Reference in a new issue