Fix assign attribute for pages (#2843)
* Fix assign attribute for pages * Fix assign attribute for pages * Fix assign attribute for pages * Fix assign reference for edit page
This commit is contained in:
parent
e77c20722e
commit
550ef12ab2
3 changed files with 18 additions and 8 deletions
|
@ -35,7 +35,10 @@ import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
|
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
|
||||||
import ProductVariantPrice from "@saleor/products/components/ProductVariantPrice";
|
import ProductVariantPrice from "@saleor/products/components/ProductVariantPrice";
|
||||||
import { productListUrl } from "@saleor/products/urls";
|
import {
|
||||||
|
ProductCreateUrlQueryParams,
|
||||||
|
productListUrl,
|
||||||
|
} from "@saleor/products/urls";
|
||||||
import { getChoices } from "@saleor/products/utils/data";
|
import { getChoices } from "@saleor/products/utils/data";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
@ -92,7 +95,7 @@ interface ProductCreatePageProps {
|
||||||
fetchMoreReferencePages?: FetchMoreProps;
|
fetchMoreReferencePages?: FetchMoreProps;
|
||||||
fetchMoreReferenceProducts?: FetchMoreProps;
|
fetchMoreReferenceProducts?: FetchMoreProps;
|
||||||
onAttributeSelectBlur: () => void;
|
onAttributeSelectBlur: () => void;
|
||||||
onCloseDialog: () => void;
|
onCloseDialog: (currentParams?: ProductCreateUrlQueryParams) => void;
|
||||||
onSelectProductType: (productTypeId: string) => void;
|
onSelectProductType: (productTypeId: string) => void;
|
||||||
onSubmit?(data: ProductCreateData);
|
onSubmit?(data: ProductCreateData);
|
||||||
}
|
}
|
||||||
|
@ -142,6 +145,10 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
|
|
||||||
|
const closeDialog = () => {
|
||||||
|
onCloseDialog({ "product-type-id": selectedProductType.id });
|
||||||
|
};
|
||||||
|
|
||||||
// Display values
|
// Display values
|
||||||
const [selectedCategory, setSelectedCategory] = useStateFromProps(
|
const [selectedCategory, setSelectedCategory] = useStateFromProps(
|
||||||
initial?.category || "",
|
initial?.category || "",
|
||||||
|
@ -164,7 +171,8 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
value: taxClass.id,
|
value: taxClass.id,
|
||||||
})) ?? [];
|
})) ?? [];
|
||||||
|
|
||||||
const canOpenAssignReferencesAttributeDialog = !!assignReferencesAttributeId;
|
const canOpenAssignReferencesAttributeDialog =
|
||||||
|
!!assignReferencesAttributeId && !fetchMoreReferenceProducts.loading;
|
||||||
|
|
||||||
const handleAssignReferenceAttribute = (
|
const handleAssignReferenceAttribute = (
|
||||||
attributeValues: string[],
|
attributeValues: string[],
|
||||||
|
@ -179,7 +187,8 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
data.attributes,
|
data.attributes,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
onCloseDialog();
|
|
||||||
|
closeDialog();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -222,7 +231,6 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
const isSimpleProduct = data.productType?.hasVariants === false;
|
const isSimpleProduct = data.productType?.hasVariants === false;
|
||||||
|
|
||||||
const errors = [...apiErrors, ...validationErrors];
|
const errors = [...apiErrors, ...validationErrors];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Backlink href={productListUrl()}>
|
<Backlink href={productListUrl()}>
|
||||||
|
@ -393,7 +401,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
onFetch={handlers.fetchReferences}
|
onFetch={handlers.fetchReferences}
|
||||||
onFetchMore={handlers.fetchMoreReferences?.onFetchMore}
|
onFetchMore={handlers.fetchMoreReferences?.onFetchMore}
|
||||||
loading={handlers.fetchMoreReferences?.loading}
|
loading={handlers.fetchMoreReferences?.loading}
|
||||||
onClose={onCloseDialog}
|
onClose={closeDialog}
|
||||||
onSubmit={attributeValues =>
|
onSubmit={attributeValues =>
|
||||||
handleAssignReferenceAttribute(
|
handleAssignReferenceAttribute(
|
||||||
attributeValues,
|
attributeValues,
|
||||||
|
|
|
@ -199,7 +199,8 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
value: taxClass.id,
|
value: taxClass.id,
|
||||||
})) || [];
|
})) || [];
|
||||||
|
|
||||||
const canOpenAssignReferencesAttributeDialog = !!assignReferencesAttributeId;
|
const canOpenAssignReferencesAttributeDialog =
|
||||||
|
!!assignReferencesAttributeId && !fetchMoreReferenceProducts.loading;
|
||||||
|
|
||||||
const handleAssignReferenceAttribute = (
|
const handleAssignReferenceAttribute = (
|
||||||
attributeValues: string[],
|
attributeValues: string[],
|
||||||
|
|
|
@ -239,6 +239,7 @@ export const ProductCreateView: React.FC<ProductCreateProps> = ({ params }) => {
|
||||||
const handleAssignAttributeReferenceClick = (attribute: AttributeInput) =>
|
const handleAssignAttributeReferenceClick = (attribute: AttributeInput) =>
|
||||||
navigate(
|
navigate(
|
||||||
productAddUrl({
|
productAddUrl({
|
||||||
|
...params,
|
||||||
action: "assign-attribute-value",
|
action: "assign-attribute-value",
|
||||||
id: attribute.id,
|
id: attribute.id,
|
||||||
}),
|
}),
|
||||||
|
@ -373,7 +374,7 @@ export const ProductCreateView: React.FC<ProductCreateProps> = ({ params }) => {
|
||||||
fetchReferenceProducts={searchProducts}
|
fetchReferenceProducts={searchProducts}
|
||||||
fetchMoreReferenceProducts={fetchMoreReferenceProducts}
|
fetchMoreReferenceProducts={fetchMoreReferenceProducts}
|
||||||
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
fetchMoreAttributeValues={fetchMoreAttributeValues}
|
||||||
onCloseDialog={() => navigate(productAddUrl())}
|
onCloseDialog={currentParams => navigate(productAddUrl(currentParams))}
|
||||||
selectedProductType={selectedProductType?.productType}
|
selectedProductType={selectedProductType?.productType}
|
||||||
onSelectProductType={handleSelectProductType}
|
onSelectProductType={handleSelectProductType}
|
||||||
onAttributeSelectBlur={searchAttributeReset}
|
onAttributeSelectBlur={searchAttributeReset}
|
||||||
|
|
Loading…
Reference in a new issue