Skip to content

Saleor Core: the high performance, composable, headless commerce API.

wip

dominik-zeglene1cf5cdf53f0
diff --git a/saleor/static/dashboard-next/attributes/index.tsx b/saleor/static/dashboard-next/attributes/index.tsx
index 8c851c57e4..b98ce72ab1 100644
--- a/saleor/static/dashboard-next/attributes/index.tsx
+++ b/saleor/static/dashboard-next/attributes/index.tsx
@@ -34,7 +34,12 @@ const AttributeDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
}) => {
const qs = parseQs(location.search.substr(1));
const params: AttributeUrlQueryParams = qs;
- return <AttributeDetailsComponent id={match.params.id} params={params} />;
+ return (
+ <AttributeDetailsComponent
+ id={decodeURIComponent(match.params.id)}
+ params={params}
+ />
+ );
};
export const AttributeSection: React.FC = () => (
diff --git a/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx b/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx
index d2f8c8d90c..be4bb32ed5 100644
--- a/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx
@@ -8,7 +8,6 @@ import makeStyles from "@material-ui/styles/makeStyles";
import classNames from "classnames";
import * as React from "react";
-import CardSpacer from "@saleor/components/CardSpacer";
import CardTitle from "@saleor/components/CardTitle";
import Grid from "@saleor/components/Grid";
import Hr from "@saleor/components/Hr";
@@ -22,11 +21,15 @@ import { FormsetAtomicData } from "@saleor/hooks/useFormset";
import i18n from "@saleor/i18n";
import { ProductDetails_product_attributes_attribute_values } from "@saleor/products/types/ProductDetails";
import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";
+import { maybe } from "@saleor/misc";
-export type ProductAttributeInput = FormsetAtomicData<{
+export interface ProductAttributeInputData {
inputType: AttributeInputTypeEnum;
values: ProductDetails_product_attributes_attribute_values[];
-}>;
+}
+export type ProductAttributeInput = FormsetAtomicData<
+ ProductAttributeInputData
+>;
export interface ProductAttributesProps {
attributes: ProductAttributeInput[];
disabled: boolean;
@@ -135,11 +138,13 @@ const ProductAttributes: React.FC<ProductAttributesProps> = ({
<SingleAutocompleteSelectField
choices={getSingleChoices(attribute.data.values)}
disabled={disabled}
- displayValue={
- attribute.data.values.find(
- value => value.id === attribute.value
- ).name
- }
+ displayValue={maybe(
+ () =>
+ attribute.data.values.find(
+ value => value.id === attribute.value
+ ).name,
+ ""
+ )}
name={`attribute:${attribute.label}`}
label={i18n.t("Value")}
value={attribute.value}
@@ -147,8 +152,16 @@ const ProductAttributes: React.FC<ProductAttributesProps> = ({
onChange(attribute.id, event.target.value)
}
/>
- ) : // <MultiAutocompleteSelectField choices={getMultiChoices(attribute.data.values)} label={i18n.t("Values")} value={attribute.value}/>
- null}
+ ) : (
+ <MultiAutocompleteSelectField
+ choices={getMultiChoices(attribute.data.values)}
+ label={i18n.t("Values")}
+ value={attribute.value}
+ onChange={event =>
+ onChange(attribute.id, event.target.value)
+ }
+ />
+ )}
</div>
</Grid>
<Hr />
diff --git a/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx b/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx
index 9be4498715..88f9b96870 100644
--- a/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx
@@ -11,46 +11,48 @@ import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
import SeoForm from "@saleor/components/SeoForm";
import VisibilityCard from "@saleor/components/VisibilityCard";
+import useFormset from "@saleor/hooks/useFormset";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { UserError } from "../../../types";
import { ProductCreateData_productTypes_edges_node_productAttributes } from "../../types/ProductCreateData";
+import ProductAttributes, {
+ ProductAttributeInput,
+ ProductAttributeInputData
+} from "../ProductAttributes";
import ProductDetailsForm from "../ProductDetailsForm";
import ProductOrganization from "../ProductOrganization";
import ProductPricing from "../ProductPricing";
import ProductStock from "../ProductStock";
-interface ChoiceType {
+interface Collection {
+ id: string;
label: string;
- value: string;
}
-export interface FormData {
- attributes: Array<{
- slug: string;
- values: string[];
- }>;
+interface ProductType {
+ hasVariants: boolean;
+ id: string;
+ name: string;
+ productAttributes: ProductCreateData_productTypes_edges_node_productAttributes[];
+}
+interface FormData {
basePrice: number;
publicationDate: string;
- category: ChoiceType;
+ category: string;
chargeTaxes: boolean;
- collections: ChoiceType[];
+ collections: string[];
description: RawDraftContentState;
isPublished: boolean;
name: string;
- productType: {
- label: string;
- value: {
- hasVariants: boolean;
- id: string;
- name: string;
- productAttributes: ProductCreateData_productTypes_edges_node_productAttributes[];
- };
- };
+ productType: string;
seoDescription: string;
seoTitle: string;
sku: string;
stockQuantity: number;
}
+export interface ProductCreatePageSubmitData extends FormData {
+ attributes: ProductAttributeInput[];
+}
interface ProductCreatePageProps {
errors: UserError[];
@@ -76,7 +78,7 @@ interface ProductCreatePageProps {
fetchCollections: (data: string) => void;
onAttributesEdit: () => void;
onBack?();
- onSubmit?(data: FormData);
+ onSubmit?(data: ProductCreatePageSubmitData);
}
export const ProductCreatePage: React.StatelessComponent<
@@ -84,40 +86,52 @@ export const ProductCreatePage: React.StatelessComponent<
> = ({
currency,
disabled,
- categories,
- collections,
+ categories: categoryChoiceList,
+ collections: collectionChoiceList,
errors: userErrors,
fetchCategories,
fetchCollections,
header,
- productTypes,
+ productTypes: productTypeChoiceList,
saveButtonBarState,
onBack,
onSubmit
}: ProductCreatePageProps) => {
const initialDescription = convertToRaw(ContentState.createFromText(""));
+ const [selectedCategory, setSelectedCategory] = React.useState("");
+ const [productType, setProductType] = React.useState<ProductType>({
+ hasVariants: false,
+ id: "",
+ name: "",
+ productAttributes: [] as ProductCreateData_productTypes_edges_node_productAttributes[]
+ });
+ const [selectedCollections, setSelectedCollections] = React.useState<
+ Collection[]
+ >([]);
+ const { change: changeAttributeData, data: attributes } = useFormset<
+ ProductAttributeInputData
+ >(
+ productType.productAttributes.map(attribute => ({
+ data: {
+ inputType: attribute.inputType,
+ values: attribute.values
+ },
+ id: attribute.id,
+ label: attribute.name,
+ value: ""
+ }))
+ );
+
const initialData: FormData = {
- attributes: [],
basePrice: 0,
- category: {
- label: "",
- value: ""
- },
+ category: "",
chargeTaxes: false,
collections: [],
description: {} as any,
isPublished: false,
name: "",
- productType: {
- label: "",
- value: {
- hasVariants: false,
- id: "",
- name: "",
- productAttributes: [] as ProductCreateData_productTypes_edges_node_productAttributes[]
- }
- },
+ productType: "",
publicationDate: "",
seoDescription: "",
seoTitle: "",
@@ -125,16 +139,99 @@ export const ProductCreatePage: React.StatelessComponent<
stockQuantity: null
};
+ const categories = maybe(
+ () =>
+ categoryChoiceList.map(collection => ({
+ label: collection.name,
+ value: collection.id
+ })),
+ []
+ );
+ const collections = maybe(
+ () =>
+ collectionChoiceList.map(collection => ({
+ label: collection.name,
+ value: collection.id
+ })),
+ []
+ );
+ const productTypes = maybe(
+ () =>
+ productTypeChoiceList.map(pt => ({
+ label: pt.name,
+ value: pt.id
+ })),
+ []
+ );
+
+ const handleSubmit = (data: FormData) =>
+ onSubmit({
+ attributes,
+ ...data
+ });
+
return (
<Form
- onSubmit={onSubmit}
+ onSubmit={handleSubmit}
errors={userErrors}
initial={initialData}
confirmLeave
>
- {({ change, data, errors, hasChanged, set, submit }) => {
- const hasVariants =
- data.productType && data.productType.value.hasVariants;
+ {({ change, data, errors, hasChanged, submit }) => {
+ const handleCollectionSelect = (event: React.ChangeEvent<any>) => {
+ const id = event.target.value;
+ const collectionIndex = data.collections.indexOf(id);
+ const collectionList =
+ collectionIndex === -1
+ ? [
+ ...selectedCollections,
+ {
+ id,
+ label: collectionChoiceList.find(
+ collection => collection.id === id
+ ).name
+ }
+ ]
+ : [
+ ...selectedCollections.slice(0, collectionIndex),
+ ...selectedCollections.slice(collectionIndex + 1)
+ ];
+
+ setSelectedCollections(collectionList);
+ change({
+ target: {
+ name: "collections",
+ value: collectionList.map(collection => collection.id)
+ }
+ } as any);
+ };
+
+ const handleCategorySelect = (event: React.ChangeEvent<any>) => {
+ const id = event.target.value;
+ setSelectedCategory(
+ categoryChoiceList.find(category => category.id === id).name
+ );
+ change(event);
+ };
+
+ const handleProductTypeChange = (event: React.ChangeEvent<any>) => {
+ const id = event.target.value;
+ const selectedProductType = productTypeChoiceList.find(
+ productType => productType.id === id
+ );
+ setProductType(selectedProductType);
+ change(event);
+ change({
+ target: {
+ name: "attributes",
+ value: selectedProductType.productAttributes.map(attribute => ({
+ slug: attribute.slug,
+ value: ""
+ }))
+ }
+ } as any);
+ };
+
return (
<Container>
<AppHeader onBack={onBack}>{i18n.t("Products")}</AppHeader>
@@ -149,6 +246,12 @@ export const ProductCreatePage: React.StatelessComponent<
onChange={change}
/>
<CardSpacer />
+ <ProductAttributes
+ attributes={attributes}
+ disabled={disabled}
+ onChange={changeAttributeData}
+ />
+ <CardSpacer />
<ProductPricing
currency={currency}
data={data}
@@ -156,7 +259,7 @@ export const ProductCreatePage: React.StatelessComponent<
onChange={change}
/>
<CardSpacer />
- {!hasVariants && (
+ {!productType.hasVariants && (
<>
<ProductStock
data={data}
@@ -183,30 +286,23 @@ export const ProductCreatePage: React.StatelessComponent<
<div>
<ProductOrganization
canChangeType={true}
- categories={maybe(
- () =>
- categories.map(category => ({
- label: category.name,
- value: category.id
- })),
- []
- )}
+ categories={categories}
+ categoryInputDisplayValue={selectedCategory}
errors={errors}
fetchCategories={fetchCategories}
fetchCollections={fetchCollections}
- collections={maybe(
- () =>
- collections.map(collection => ({
- label: collection.name,
- value: collection.id
- })),
- []
- )}
+ collections={collections}
+ productTypeInputDisplayValue={productType.name}
productTypes={productTypes}
data={data}
+ productType={productType}
disabled={disabled}
- onChange={change}
- onSet={set}
+ collectionInputDisplayValue={selectedCollections
+ .map(collection => collection.label)
+ .join(", ")}
+ onCategoryChange={handleCategorySelect}
+ onCollectionChange={handleCollectionSelect}
+ onProductTypeChange={handleProductTypeChange}
/>
<CardSpacer />
<VisibilityCard
diff --git a/saleor/static/dashboard-next/products/components/ProductDetailsForm/ProductDetailsForm.tsx b/saleor/static/dashboard-next/products/components/ProductDetailsForm/ProductDetailsForm.tsx
index bf361d0d65..bcd06a90a2 100644
--- a/saleor/static/dashboard-next/products/components/ProductDetailsForm/ProductDetailsForm.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductDetailsForm/ProductDetailsForm.tsx
@@ -14,8 +14,6 @@ import CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer";
import RichTextEditor from "@saleor/components/RichTextEditor";
import i18n from "../../../i18n";
-import { FormData as CreateFormData } from "../ProductCreatePage";
-import { FormData as UpdateFormData } from "../ProductUpdatePage";
const styles = (theme: Theme) =>
createStyles({
@@ -27,7 +25,10 @@ const styles = (theme: Theme) =>
});
interface ProductDetailsFormProps extends WithStyles<typeof styles> {
- data: CreateFormData & UpdateFormData;
+ data: {
+ description: RawDraftContentState;
+ name: string;
+ };
disabled?: boolean;
errors: { [key: string]: string };
// Draftail isn't controlled - it needs only initial input
diff --git a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
index 033b4d6412..8000656b7c 100644
--- a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
@@ -19,7 +19,6 @@ import { ChangeEvent } from "@saleor/hooks/useForm";
import i18n from "@saleor/i18n";
import { maybe } from "@saleor/misc";
import { FormErrors } from "@saleor/types";
-import { ProductCreateData_productTypes_edges_node_productAttributes } from "../../types/ProductCreateData";
interface ChoiceType {
label: string;
@@ -29,7 +28,6 @@ interface ProductType {
hasVariants: boolean;
id: string;
name: string;
- productAttributes: ProductCreateData_productTypes_edges_node_productAttributes[];
}
const styles = (theme: Theme) =>
@@ -46,66 +44,34 @@ const styles = (theme: Theme) =>
}
});
-interface ProductOrganizationFormData {
- attributes: Array<{
- slug: string;
- values: string[];
- }>;
- category: ChoiceType;
- collections: ChoiceType[];
- productType: {
- label: string;
- value: {
- hasVariants: boolean;
- id: string;
- name: string;
- productAttributes: ProductCreateData_productTypes_edges_node_productAttributes[];
- };
- };
-}
-
interface ProductOrganizationProps extends WithStyles<typeof styles> {
canChangeType: boolean;
- categories?: Array<{ value: string; label: string }>;
- collections?: Array<{ value: string; label: string }>;
+ categories?: ChoiceType[];
+ categoryInputDisplayValue: string;
+ collections?: ChoiceType[];
collectionInputDisplayValue: string;
data: {
- attributes: Array<{
- slug: string;
- values: string[];
- }>;
- category: ChoiceType;
+ category: string;
collections: string[];
- productType: {
- label: string;
- value: {
- hasVariants: boolean;
- id: string;
- name: string;
- productAttributes: ProductCreateData_productTypes_edges_node_productAttributes[];
- };
- };
+ productType?: string;
};
disabled: boolean;
errors: FormErrors<"productType" | "category">;
- product?: {
- productType?: {
- hasVariants?: boolean;
- name?: string;
- };
- };
- productTypes?: ProductType[];
+ productType?: ProductType;
+ productTypeInputDisplayValue?: string;
+ productTypes?: ChoiceType[];
fetchCategories: (query: string) => void;
fetchCollections: (query: string) => void;
- onChange: (event: ChangeEvent<any>) => void;
- onCollectionChange: (event: ChangeEvent<any>) => void;
- onSet: (data: Partial<ProductOrganizationFormData>) => void;
+ onCategoryChange: (event: ChangeEvent) => void;
+ onCollectionChange: (event: ChangeEvent) => void;
+ onProductTypeChange?: (event: ChangeEvent) => void;
}
const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(
({
canChangeType,
categories,
+ categoryInputDisplayValue,
classes,
collections,
collectionInputDisplayValue,
@@ -114,106 +80,82 @@ const ProductOrganization = withStyles(styles, { name: "ProductOrganization" })(
errors,
fetchCategories,
fetchCollections,
- product,
+ productType,
+ productTypeInputDisplayValue,
productTypes,
- onChange,
+ onCategoryChange,
onCollectionChange,
- onSet
- }: ProductOrganizationProps) => {
- const handleProductTypeSelect = (
- event: ChangeEvent<
- string,
- {
- label: string;
- value: ProductType;
- }
- >
- ) => {
- onSet({
- attributes: event.target.value.value.productAttributes.map(
- attribute => ({
- slug: attribute.slug,
- values: [""]
- })
- ),
- productType: event.target.value
- });
- };
-
- return (
- <Card className={classes.card}>
- <CardTitle title={i18n.t("Organize Product")} />
- <CardContent>
- {canChangeType ? (
- <SingleAutocompleteSelectField
- error={!!errors.productType}
- helperText={errors.productType}
- name="productType"
- disabled={disabled}
- label={i18n.t("Product Type")}
- choices={maybe(
- () => productTypes.map(pt => ({ label: pt.name, value: pt })),
- []
- )}
- value={data.productType}
- onChange={handleProductTypeSelect}
- />
- ) : (
- <>
- <Typography className={classes.label} variant="caption">
- {i18n.t("Product Type")}
- </Typography>
- <Typography>
- {maybe(() => product.productType.name, "...")}
- </Typography>
- <CardSpacer />
- <Typography className={classes.label} variant="caption">
- {i18n.t("Product Type")}
- </Typography>
- <Typography>
- {maybe(
- () =>
- product.productType.hasVariants
- ? i18n.t("Configurable")
- : i18n.t("Simple"),
- "..."
- )}
- </Typography>
- </>
- )}
- <FormSpacer />
- <Hr />
- <FormSpacer />
+ onProductTypeChange
+ }: ProductOrganizationProps) => (
+ <Card className={classes.card}>
+ <CardTitle title={i18n.t("Organize Product")} />
+ <CardContent>
+ {canChangeType ? (
<SingleAutocompleteSelectField
- error={!!errors.category}
- helperText={errors.category}
+ displayValue={productTypeInputDisplayValue}
+ error={!!errors.productType}
+ helperText={errors.productType}
+ name="productType"
disabled={disabled}
- label={i18n.t("Category")}
- choices={disabled ? [] : categories}
- name="category"
- value={data.category}
- onChange={onChange}
- fetchChoices={fetchCategories}
- />
- <FormSpacer />
- <Hr />
- <FormSpacer />
- <MultiAutocompleteSelectField
- displayValue={collectionInputDisplayValue}
- label={i18n.t("Collections")}
- choices={disabled ? [] : collections}
- name="collections"
- value={data.collections}
- helperText={i18n.t(
- "*Optional. Adding product to collection helps users find it."
- )}
- onChange={onCollectionChange}
- fetchChoices={fetchCollections}
+ label={i18n.t("Product Type")}
+ choices={productTypes}
+ value={data.productType}
+ onChange={onProductTypeChange}
/>
- </CardContent>
- </Card>
- );
- }
+ ) : (
+ <>
+ <Typography className={classes.label} variant="caption">
+ {i18n.t("Product Type")}
+ </Typography>
+ <Typography>{maybe(() => productType.name, "...")}</Typography>
+ <CardSpacer />
+ <Typography className={classes.label} variant="caption">
+ {i18n.t("Product Type")}
+ </Typography>
+ <Typography>
+ {maybe(
+ () =>
+ productType.hasVariants
+ ? i18n.t("Configurable")
+ : i18n.t("Simple"),
+ "..."
+ )}
+ </Typography>
+ </>
+ )}
+ <FormSpacer />
+ <Hr />
+ <FormSpacer />
+ <SingleAutocompleteSelectField
+ displayValue={categoryInputDisplayValue}
+ error={!!errors.category}
+ helperText={errors.category}
+ disabled={disabled}
+ label={i18n.t("Category")}
+ choices={disabled ? [] : categories}
+ name="category"
+ value={data.category}
+ onChange={onCategoryChange}
+ fetchChoices={fetchCategories}
+ />
+ <FormSpacer />
+ <Hr />
+ <FormSpacer />
+ <MultiAutocompleteSelectField
+ displayValue={collectionInputDisplayValue}
+ label={i18n.t("Collections")}
+ choices={disabled ? [] : collections}
+ name="collections"
+ value={data.collections}
+ helperText={i18n.t(
+ "*Optional. Adding product to collection helps users find it."
+ )}
+ onChange={onCollectionChange}
+ fetchChoices={fetchCollections}
+ />
+ </CardContent>
+ </Card>
+ )
);
ProductOrganization.displayName = "ProductOrganization";
export default ProductOrganization;
diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
index e1e9306e70..2e07817466 100644
--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
@@ -19,11 +19,14 @@ import { maybe } from "@saleor/misc";
import { ListActions, UserError } from "@saleor/types";
import {
ProductDetails_product,
- ProductDetails_product_attributes_attribute,
+ ProductDetails_product_collections,
ProductDetails_product_images,
ProductDetails_product_variants
} from "../../types/ProductDetails";
-import ProductAttributes, { ProductAttributeInput } from "../ProductAttributes";
+import ProductAttributes, {
+ ProductAttributeInput,
+ ProductAttributeInputData
+} from "../ProductAttributes";
import ProductDetailsForm from "../ProductDetailsForm";
import ProductImages from "../ProductImages";
import ProductOrganization from "../ProductOrganization";
@@ -31,16 +34,18 @@ import ProductPricing from "../ProductPricing";
import ProductStock from "../ProductStock";
import ProductVariants from "../ProductVariants";
+interface Collection {
+ id: string;
+ label: string;
+}
+
interface ProductUpdateProps extends ListActions {
errors: UserError[];
placeholderImage: string;
collections: SearchCollections_collections_edges_node[];
categories: SearchCategories_categories_edges_node[];
disabled: boolean;
- productCollections: Array<{
- id: string;
- name: string;
- }>;
+ productCollections: ProductDetails_product_collections[];
variants: ProductDetails_product_variants[];
images: ProductDetails_product_images[];
product: ProductDetails_product;
@@ -58,37 +63,22 @@ interface ProductUpdateProps extends ListActions {
onImageUpload(file: File);
onProductShow?();
onSeoClick?();
- onSubmit?(data: any);
+ onSubmit?(data: FormData);
onVariantAdd?();
}
-interface ChoiceType {
- label: string;
- value: string;
-}
export interface FormData {
attributes: Array<{
slug: string;
values: string[];
}>;
basePrice: number;
- category: ChoiceType | null;
+ category: string | null;
chargeTaxes: boolean;
collections: string[];
description: RawDraftContentState;
isPublished: boolean;
name: string;
- productType: {
- label: string;
- value: {
- hasVariants: boolean;
- id: string;
- name: string;
- productAttributes: Array<
- Exclude<ProductDetails_product_attributes_attribute, "__typename">
- >;
- };
- } | null;
publicationDate: string;
seoDescription: string;
seoTitle: string;
@@ -127,7 +117,9 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
toggleAll,
toolbar
}) => {
- const { change: changeAttributeData, data: attributes } = useFormset(
+ const { change: changeAttributeData, data: attributes } = useFormset<
+ ProductAttributeInputData
+ >(
maybe(
(): ProductAttributeInput[] =>
product.attributes.map(attribute => ({
@@ -142,11 +134,9 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
[]
)
);
+ const [selectedCategory, setSelectedCategory] = React.useState("");
const [selectedCollections, setSelectedCollections] = React.useState<
- Array<{
- id: string;
- label: string;
- }>
+ Collection[]
>(
maybe(
() =>
@@ -172,10 +162,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
[]
),
basePrice: maybe(() => product.basePrice.amount, 0),
- category: {
- label: maybe(() => product.category.name, ""),
- value: maybe(() => product.category.id, "")
- },
+ category: maybe(() => product.category.id),
chargeTaxes: maybe(() => product.chargeTaxes, false),
collections: productCollections
? productCollections.map(collection => collection.id)
@@ -183,15 +170,6 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
description: initialDescription,
isPublished: maybe(() => product.isPublished, false),
name: maybe(() => product.name, ""),
- productType: maybe(() => ({
- label: product.productType.name,
- value: {
- hasVariants: product.productType.hasVariants,
- id: product.productType.id,
- name: product.productType.name,
- productAttributes: product.attributes.map(a => a.attribute)
- }
- })),
publicationDate: maybe(() => product.publicationDate, ""),
seoDescription: maybe(() => product.seoDescription, ""),
seoTitle: maybe(() => product.seoTitle, ""),
@@ -265,6 +243,16 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
} as any);
};
+ const handleCategorySelect = (event: React.ChangeEvent<any>) => {
+ const id = event.target.value;
+ setSelectedCategory(
+ categoryChoiceList.find(category => category.id === id).name
+ );
+ change(event);
+ };
+
+ const handleAttributeValueChange = (event: React.ChangeEvent) => {};
+
return (
<>
<Container>
@@ -291,6 +279,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
<CardSpacer />
<ProductAttributes
attributes={attributes}
+ disabled={disabled}
onChange={changeAttributeData}
/>
<CardSpacer />
@@ -343,6 +332,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
<ProductOrganization
canChangeType={false}
categories={categories}
+ categoryInputDisplayValue={selectedCategory}
collectionInputDisplayValue={selectedCollections
.map(c => c.label)
.join(", ")}
@@ -350,10 +340,10 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
fetchCategories={fetchCategories}
fetchCollections={fetchCollections}
collections={collections}
- product={product}
+ productType={maybe(() => product.productType)}
data={data}
disabled={disabled}
- onChange={change}
+ onCategoryChange={handleCategorySelect}
onCollectionChange={handleCollectionSelect}
/>
<CardSpacer />
diff --git a/saleor/static/dashboard-next/products/queries.ts b/saleor/static/dashboard-next/products/queries.ts
index 040de93344..3cc80e734b 100644
--- a/saleor/static/dashboard-next/products/queries.ts
+++ b/saleor/static/dashboard-next/products/queries.ts
@@ -275,6 +275,7 @@ const productCreateQuery = gql`
hasVariants
productAttributes {
id
+ inputType
slug
name
values {
diff --git a/saleor/static/dashboard-next/products/types/ProductCreateData.ts b/saleor/static/dashboard-next/products/types/ProductCreateData.ts
index a198653410..c99bebcc63 100644
--- a/saleor/static/dashboard-next/products/types/ProductCreateData.ts
+++ b/saleor/static/dashboard-next/products/types/ProductCreateData.ts
@@ -2,6 +2,8 @@
/* eslint-disable */
// This file was automatically generated and should not be edited.
+import { AttributeInputTypeEnum } from "./../../types/globalTypes";
+
// ====================================================
// GraphQL query operation: ProductCreateData
// ====================================================
@@ -17,6 +19,7 @@ export interface ProductCreateData_productTypes_edges_node_productAttributes_val
export interface ProductCreateData_productTypes_edges_node_productAttributes {
__typename: "Attribute";
id: string;
+ inputType: AttributeInputTypeEnum | null;
slug: string | null;
name: string | null;
values: (ProductCreateData_productTypes_edges_node_productAttributes_values | null)[] | null;
diff --git a/saleor/static/dashboard-next/products/views/ProductCreate.tsx b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
index b806e61bba..5a3e66f832 100644
--- a/saleor/static/dashboard-next/products/views/ProductCreate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductCreate.tsx
@@ -9,7 +9,9 @@ import SearchCategories from "../../containers/SearchCategories";
import SearchCollections from "../../containers/SearchCollections";
import i18n from "../../i18n";
import { decimal, getMutationState, maybe } from "../../misc";
-import ProductCreatePage, { FormData } from "../components/ProductCreatePage";
+import ProductCreatePage, {
+ ProductCreatePageSubmitData
+} from "../components/ProductCreatePage";
import { TypedProductCreateMutation } from "../mutations";
import { TypedProductCreateQuery } from "../queries";
import { ProductCreate } from "../types/ProductCreate";
@@ -55,22 +57,25 @@ export const ProductUpdate: React.StatelessComponent<
loading: productCreateDataLoading
}
) => {
- const handleSubmit = (formData: FormData) => {
+ const handleSubmit = (
+ formData: ProductCreatePageSubmitData
+ ) => {
productCreate({
variables: {
- attributes: formData.attributes,
+ attributes: formData.attributes.map(attribute => ({
+ id: attribute.id,
+ values: [attribute.value]
+ })),
basePrice: decimal(formData.basePrice),
- category: formData.category.value,
+ category: formData.category,
chargeTaxes: formData.chargeTaxes,
- collections: formData.collections.map(
- collection => collection.value
- ),
+ collections: formData.collections,
descriptionJson: JSON.stringify(
formData.description
),
isPublished: formData.isPublished,
name: formData.name,
- productType: formData.productType.value.id,
+ productType: formData.productType,
publicationDate:
formData.publicationDate !== ""
? formData.publicationDate
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
index 2f7741b286..00d9131962 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
@@ -121,7 +121,10 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
if (product) {
if (product.productType.hasVariants) {
updateProduct.mutate({
- attributes: data.attributes,
+ attributes: data.attributes.map(attribute => ({
+ slug: attribute.slug,
+ values: [attribute.value]
+ })),
basePrice: decimal(data.basePrice),
category: data.category.value,
chargeTaxes: data.chargeTaxes,
@@ -143,7 +146,10 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
});
} else {
updateSimpleProduct.mutate({
- attributes: data.attributes,
+ attributes: data.attributes.map(attribute => ({
+ slug: attribute.slug,
+ values: [attribute.value]
+ })),
basePrice: decimal(data.basePrice),
category: data.category.value,
chargeTaxes: data.chargeTaxes,