From 123a31a775bd6112165c71cc057cbd9f70f4f794 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Wed, 4 Sep 2019 13:50:34 +0200 Subject: [PATCH 1/4] Save after toggling "has variants" --- .../ProductTypeDetailsPage.tsx | 10 +- .../views/ProductTypeUpdate/index.tsx | 10 + .../__snapshots__/Stories.test.ts.snap | 172 +++++++++++++----- 3 files changed, 142 insertions(+), 50 deletions(-) diff --git a/src/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/src/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx index 2b4bfb9af..d1150695c 100644 --- a/src/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx +++ b/src/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx @@ -5,7 +5,7 @@ import AppHeader from "@saleor/components/AppHeader"; import CardSpacer from "@saleor/components/CardSpacer"; import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton"; import Container from "@saleor/components/Container"; -import { ControlledCheckbox } from "@saleor/components/ControlledCheckbox"; +import ControlledSwitch from "@saleor/components/ControlledSwitch"; import Form from "@saleor/components/Form"; import Grid from "@saleor/components/Grid"; import PageHeader from "@saleor/components/PageHeader"; @@ -56,6 +56,7 @@ export interface ProductTypeDetailsPageProps { onAttributeUnassign: (id: string) => void; onBack: () => void; onDelete: () => void; + onHasVariantsToggle: (hasVariants: boolean) => void; onSubmit: (data: ProductTypeForm) => void; } @@ -89,6 +90,7 @@ const ProductTypeDetailsPage: React.StatelessComponent< onAttributeClick, onBack, onDelete, + onHasVariantsToggle, onSubmit }) => { const intl = useIntl(); @@ -172,15 +174,15 @@ const ProductTypeDetailsPage: React.StatelessComponent< {...productAttributeList} /> - onHasVariantsToggle(event.target.value)} /> {data.hasVariants && ( <> diff --git a/src/productTypes/views/ProductTypeUpdate/index.tsx b/src/productTypes/views/ProductTypeUpdate/index.tsx index 67f94a381..73510adbd 100644 --- a/src/productTypes/views/ProductTypeUpdate/index.tsx +++ b/src/productTypes/views/ProductTypeUpdate/index.tsx @@ -151,6 +151,15 @@ export const ProductTypeUpdate: React.FC = ({ } }); }; + const handleProductTypeVariantsToggle = ( + hasVariants: boolean + ) => + updateProductType.mutate({ + id, + input: { + hasVariants + } + }); const handleAssignAttribute = () => assignAttribute.mutate({ id, @@ -266,6 +275,7 @@ export const ProductTypeUpdate: React.FC = ({ }) ) } + onHasVariantsToggle={handleProductTypeVariantsToggle} onSubmit={handleProductTypeUpdate} productAttributeList={{ isChecked: productAttributeListActions.isSelected, diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index 3df89fe0d..eda2d6d28 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -76998,22 +76998,42 @@ exports[`Storyshots Views / Product types / Product type details default 1`] = `