diff --git a/src/discounts/components/SaleCreatePage/SaleCreatePage.tsx b/src/discounts/components/SaleCreatePage/SaleCreatePage.tsx index 128ebe80f..1901e9a40 100644 --- a/src/discounts/components/SaleCreatePage/SaleCreatePage.tsx +++ b/src/discounts/components/SaleCreatePage/SaleCreatePage.tsx @@ -8,8 +8,10 @@ import Form from "@saleor/components/Form"; import Grid from "@saleor/components/Grid"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; +import { createSaleChannelsChangeHandler } from "@saleor/discounts/handlers"; import { DiscountErrorFragment } from "@saleor/fragments/types/DiscountErrorFragment"; import { sectionNames } from "@saleor/intl"; +import { validatePrice } from "@saleor/products/utils/validation"; import React from "react"; import { useIntl } from "react-intl"; @@ -17,6 +19,7 @@ import { SaleType as SaleTypeEnum } from "../../../types/globalTypes"; import DiscountDates from "../DiscountDates"; import SaleInfo from "../SaleInfo"; import SaleType from "../SaleType"; +import SaleValue from "../SaleValue"; export interface FormData { channelListings: ChannelSaleData[]; @@ -37,6 +40,7 @@ export interface SaleCreatePageProps { errors: DiscountErrorFragment[]; saveButtonBarState: ConfirmButtonTransitionState; onBack: () => void; + onChannelsChange: (data: ChannelSaleData[]) => void; openChannelsModal: () => void; onSubmit: (data: FormData) => void; } @@ -46,6 +50,7 @@ const SaleCreatePage: React.FC = ({ channelListings = [], disabled, errors, + onChannelsChange, onSubmit, openChannelsModal, saveButtonBarState, @@ -66,56 +71,73 @@ const SaleCreatePage: React.FC = ({ }; return (
- {({ change, data, hasChanged, submit }) => ( - - - {intl.formatMessage(sectionNames.sales)} - - - -
- - - - - -
-
- ({ - id: channel.id, - name: channel.name - }))} - disabled={disabled} - openModal={openChannelsModal} - /> -
-
- -
- )} + {({ change, data, hasChanged, submit, triggerChange }) => { + const handleChannelChange = createSaleChannelsChangeHandler( + data.channelListings, + onChannelsChange, + triggerChange + ); + const formDisabled = data.channelListings?.some(channel => + validatePrice(channel.discountValue) + ); + return ( + + + {intl.formatMessage(sectionNames.sales)} + + + +
+ + + + + + + +
+
+ ({ + id: channel.id, + name: channel.name + }))} + disabled={disabled} + openModal={openChannelsModal} + /> +
+
+ +
+ ); + }}
); }; diff --git a/src/discounts/components/SaleValue/SaleValue.tsx b/src/discounts/components/SaleValue/SaleValue.tsx index 73d84fc9c..007e8d1d5 100644 --- a/src/discounts/components/SaleValue/SaleValue.tsx +++ b/src/discounts/components/SaleValue/SaleValue.tsx @@ -89,7 +89,7 @@ const SaleValue: React.FC = ({ {listing?.name || } - + {listing ? ( { handleChannelsModalOpen, isChannelSelected, isChannelsModalOpen, + setCurrentChannels, toggleAllChannels } = useChannels(allChannels); @@ -45,6 +46,7 @@ export const SaleDetails: React.FC = () => { const handleSaleCreate = (data: SaleCreate) => { if (data.saleCreate.errors.length === 0) { pushMessage({ + status: "success", text: intl.formatMessage({ defaultMessage: "Successfully created sale" }) @@ -94,6 +96,7 @@ export const SaleDetails: React.FC = () => { onSubmit={handleSubmit} saveButtonBarState={saleCreateOpts.status} openChannelsModal={handleChannelsModalOpen} + onChannelsChange={setCurrentChannels} /> ); diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index 3bbc2edbd..d41f428d8 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -63385,6 +63385,458 @@ exports[`Storyshots Views / Discounts / Sale create default 1`] = `
+
+
+ + Value + +
+
+
+
+
+
+ Channels that don’t have assigned discounts will use their parent channel to define the price. Price will be converted to channel’s currency +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Channel name + + + + Value + +
+
+ Test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel +
+
+
+ +
+ + euro + +
+
+
+
+ Channel test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel USD +
+
+
+ +
+ + euro + +
+
+
+
+ Channel +
+
+
+ +
+ + euro + +
+
+
+
+ Channel test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel USD +
+
+
+ +
+ + euro + +
+
+
+
+
+
+
+
@@ -63929,6 +64381,458 @@ exports[`Storyshots Views / Discounts / Sale create form errors 1`] = `
+
+
+ + Value + +
+
+
+
+
+
+ Channels that don’t have assigned discounts will use their parent channel to define the price. Price will be converted to channel’s currency +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Channel name + + + + Value + +
+
+ Test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel +
+
+
+ +
+ + euro + +
+
+
+
+ Channel test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel USD +
+
+
+ +
+ + euro + +
+
+
+
+ Channel +
+
+
+ +
+ + euro + +
+
+
+
+ Channel test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel USD +
+
+
+ +
+ + euro + +
+
+
+
+
+
+
+
@@ -64483,6 +65387,465 @@ exports[`Storyshots Views / Discounts / Sale create loading 1`] = `
+
+
+ + Value + +
+
+
+
+
+
+ Channels that don’t have assigned discounts will use their parent channel to define the price. Price will be converted to channel’s currency +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Channel name + + + + Value + +
+
+ Test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel +
+
+
+ +
+ + euro + +
+
+
+
+ Channel test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel USD +
+
+
+ +
+ + euro + +
+
+
+
+ Channel +
+
+
+ +
+ + euro + +
+
+
+
+ Channel test +
+
+
+ +
+ + euro + +
+
+
+
+ Channel USD +
+
+
+ +
+ + euro + +
+
+
+
+
+
+
+
@@ -65102,7 +66465,7 @@ exports[`Storyshots Views / Discounts / Sale details collections 1`] = `
undefined, + onChannelsChange: () => undefined, onSubmit: () => undefined, openChannelsModal: () => undefined, saveButtonBarState: "default"