Skip to content

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

Handle assign button clicks

dominik-zeglend4b80c4c445b
diff --git a/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx b/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx
index 9d840dff89..dc644ceed2 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx
@@ -19,6 +19,7 @@ import { SaleDetails_sale } from "../../types/SaleDetails";
export interface SaleCategoriesProps extends ListProps {
sale: SaleDetails_sale;
+ onCategoryAssign: () => void;
}
const styles = createStyles({
@@ -40,6 +41,7 @@ const SaleCategories = withStyles(styles, {
classes,
disabled,
pageInfo,
+ onCategoryAssign,
onRowClick,
onPreviousPage,
onNextPage
@@ -50,7 +52,7 @@ const SaleCategories = withStyles(styles, {
saleName: maybe(() => sale.name)
})}
toolbar={
- <Button variant="flat" color="secondary">
+ <Button variant="flat" color="secondary" onClick={onCategoryAssign}>
{i18n.t("Assign categories")}
</Button>
}
diff --git a/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx b/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx
index a5514e78d1..39d856f0f9 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx
@@ -19,6 +19,7 @@ import { SaleDetails_sale } from "../../types/SaleDetails";
export interface SaleCollectionsProps extends ListProps {
sale: SaleDetails_sale;
+ onCollectionAssign: () => void;
}
const styles = createStyles({
@@ -40,6 +41,7 @@ const SaleCollections = withStyles(styles, {
classes,
disabled,
pageInfo,
+ onCollectionAssign,
onRowClick,
onPreviousPage,
onNextPage
@@ -50,7 +52,7 @@ const SaleCollections = withStyles(styles, {
saleName: maybe(() => sale.name)
})}
toolbar={
- <Button variant="flat" color="secondary">
+ <Button variant="flat" color="secondary" onClick={onCollectionAssign}>
{i18n.t("Assign collections")}
</Button>
}
diff --git a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
index 99b185ea53..3ab12468a2 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
@@ -1,10 +1,12 @@
import * as React from "react";
import CardSpacer from "../../../components/CardSpacer";
+import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton";
import Container from "../../../components/Container";
import Form from "../../../components/Form";
import Grid from "../../../components/Grid";
import PageHeader from "../../../components/PageHeader";
+import SaveButtonBar from "../../../components/SaveButtonBar";
import { Tab } from "../../../components/Tab";
import TabContainer from "../../../components/Tab/TabContainer";
import i18n from "../../../i18n";
@@ -33,12 +35,20 @@ export enum SaleDetailsPageTab {
"products"
}
-export interface SaleDetailsPageProps extends ListProps {
+export interface SaleDetailsPageProps
+ extends Pick<ListProps, Exclude<keyof ListProps, "onRowClick">> {
activeTab: SaleDetailsPageTab;
defaultCurrency: string;
errors: UserError[];
sale: SaleDetails_sale;
+ saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
+ onCategoryAssign: () => void;
+ onCategoryClick: (id: string) => () => void;
+ onCollectionAssign: () => void;
+ onCollectionClick: (id: string) => () => void;
+ onProductAssign: () => void;
+ onProductClick: (id: string) => () => void;
onRemove: () => void;
onSubmit: (data: FormData) => void;
onTabClick: (index: SaleDetailsPageTab) => void;
@@ -50,18 +60,24 @@ const ProductsTab = Tab(SaleDetailsPageTab.products);
const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
activeTab,
- onTabClick,
defaultCurrency,
disabled,
errors,
- sale,
+ onRemove,
+ onSubmit,
+ onTabClick,
pageInfo,
+ sale,
+ saveButtonBarState,
onBack,
+ onCategoryAssign,
+ onCategoryClick,
+ onCollectionAssign,
+ onCollectionClick,
onNextPage,
onPreviousPage,
- onRemove,
- onRowClick,
- onSubmit
+ onProductAssign,
+ onProductClick
}) => {
const initialForm: FormData = {
endDate: maybe(() => sale.endDate),
@@ -116,18 +132,20 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
{activeTab === SaleDetailsPageTab.categories ? (
<SaleCategories
disabled={disabled}
+ onCategoryAssign={onCategoryAssign}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
- onRowClick={onRowClick}
+ onRowClick={onCategoryClick}
pageInfo={pageInfo}
sale={sale}
/>
) : activeTab === SaleDetailsPageTab.collections ? (
<SaleCollections
disabled={disabled}
+ onCollectionAssign={onCollectionAssign}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
- onRowClick={onRowClick}
+ onRowClick={onCollectionClick}
pageInfo={pageInfo}
sale={sale}
/>
@@ -136,7 +154,8 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
disabled={disabled}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
- onRowClick={onRowClick}
+ onProductAssign={onProductAssign}
+ onRowClick={onProductClick}
pageInfo={pageInfo}
sale={sale}
/>
@@ -146,6 +165,13 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
<SaleSummary defaultCurrency={defaultCurrency} sale={sale} />
</div>
</Grid>
+ <SaveButtonBar
+ disabled={disabled || !hasChanged}
+ onCancel={onBack}
+ onDelete={onRemove}
+ onSave={submit}
+ state={saveButtonBarState}
+ />
</Container>
)}
</Form>
diff --git a/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx b/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx
index cb5dec42e7..c2e9f54eb2 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx
@@ -21,6 +21,7 @@ import { SaleDetails_sale } from "../../types/SaleDetails";
export interface SaleProductsProps extends ListProps {
sale: SaleDetails_sale;
+ onProductAssign: () => void;
}
const styles = createStyles({
@@ -44,6 +45,7 @@ const SaleProducts = withStyles(styles, {
pageInfo,
onRowClick,
onPreviousPage,
+ onProductAssign,
onNextPage
}: SaleProductsProps & WithStyles<typeof styles>) => (
<Card>
@@ -52,7 +54,7 @@ const SaleProducts = withStyles(styles, {
saleName: maybe(() => sale.name)
})}
toolbar={
- <Button variant="flat" color="secondary">
+ <Button variant="flat" color="secondary" onClick={onProductAssign}>
{i18n.t("Assign products")}
</Button>
}
diff --git a/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
index 9e86b00928..94ebe245d4 100644
--- a/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
@@ -15,17 +15,23 @@ const props: SaleDetailsPageProps = {
disabled: false,
errors: [],
onBack: () => undefined,
+ onCategoryAssign: () => undefined,
+ onCategoryClick: () => undefined,
+ onCollectionAssign: () => undefined,
+ onCollectionClick: () => undefined,
onNextPage: () => undefined,
onPreviousPage: () => undefined,
+ onProductAssign: () => undefined,
+ onProductClick: () => undefined,
onRemove: () => undefined,
- onRowClick: () => () => undefined,
onSubmit: () => undefined,
onTabClick: () => undefined,
pageInfo: {
hasNextPage: true,
hasPreviousPage: false
},
- sale
+ sale,
+ saveButtonBarState: "default"
};
storiesOf("Views / Discounts / Sale details", module)