Skip to content

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

Add sale create component

dominik-zeglen79864dd3307e
diff --git a/saleor/static/dashboard-next/discounts/components/SaleCreatePage/SaleCreatePage.tsx b/saleor/static/dashboard-next/discounts/components/SaleCreatePage/SaleCreatePage.tsx
new file mode 100644
index 0000000000..29e72cc631
--- /dev/null
+++ b/saleor/static/dashboard-next/discounts/components/SaleCreatePage/SaleCreatePage.tsx
@@ -0,0 +1,83 @@
+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 i18n from "../../../i18n";
+import { UserError } from "../../../types";
+import { SaleType } from "../../../types/globalTypes";
+import SaleInfo from "../SaleInfo";
+import SalePricing from "../SalePricing";
+
+export interface FormData {
+ name: string;
+ startDate: string;
+ endDate: string;
+ value: string;
+ type: SaleType;
+}
+
+export interface SaleCreatePageProps {
+ defaultCurrency: string;
+ disabled: boolean;
+ errors: UserError[];
+ saveButtonBarState: ConfirmButtonTransitionState;
+ onBack: () => void;
+ onSubmit: (data: FormData) => void;
+}
+
+const SaleCreatePage: React.StatelessComponent<SaleCreatePageProps> = ({
+ defaultCurrency,
+ disabled,
+ errors,
+ onSubmit,
+ saveButtonBarState,
+ onBack
+}) => {
+ const initialForm: FormData = {
+ endDate: "",
+ name: "",
+ startDate: "",
+ type: SaleType.FIXED,
+ value: ""
+ };
+ return (
+ <Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
+ {({ change, data, errors: formErrors, hasChanged, submit }) => (
+ <Container width="md">
+ <PageHeader title={i18n.t("Create Sale")} onBack={onBack} />
+ <Grid>
+ <div>
+ <SaleInfo
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <SalePricing
+ data={data}
+ defaultCurrency={defaultCurrency}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ </div>
+ </Grid>
+ <SaveButtonBar
+ disabled={disabled || !hasChanged}
+ onCancel={onBack}
+ onSave={submit}
+ state={saveButtonBarState}
+ />
+ </Container>
+ )}
+ </Form>
+ );
+};
+SaleCreatePage.displayName = "SaleCreatePage";
+export default SaleCreatePage;
diff --git a/saleor/static/dashboard-next/discounts/components/SaleCreatePage/index.ts b/saleor/static/dashboard-next/discounts/components/SaleCreatePage/index.ts
new file mode 100644
index 0000000000..5621f967ae
--- /dev/null
+++ b/saleor/static/dashboard-next/discounts/components/SaleCreatePage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./SaleCreatePage";
+export * from "./SaleCreatePage";
diff --git a/saleor/static/dashboard-next/discounts/mutations.ts b/saleor/static/dashboard-next/discounts/mutations.ts
index 1dea22fd00..ce5241b73f 100644
--- a/saleor/static/dashboard-next/discounts/mutations.ts
+++ b/saleor/static/dashboard-next/discounts/mutations.ts
@@ -6,6 +6,7 @@ import {
SaleCataloguesAdd,
SaleCataloguesAddVariables
} from "./types/SaleCataloguesAdd";
+import { SaleCreate, SaleCreateVariables } from "./types/SaleCreate";
import {
SaleCataloguesRemove,
SaleCataloguesRemoveVariables
@@ -81,3 +82,21 @@ export const TypedSaleCataloguesRemove = TypedMutation<
SaleCataloguesRemove,
SaleCataloguesRemoveVariables
>(saleCataloguesRemove);
+
+const saleCreate = gql`
+ ${saleFragment}
+ mutation SaleCreate($input: SaleInput!) {
+ saleCreate(input: $input) {
+ errors {
+ field
+ message
+ }
+ sale {
+ ...SaleFragment
+ }
+ }
+ }
+`;
+export const TypedSaleCreate = TypedMutation<SaleCreate, SaleCreateVariables>(
+ saleCreate
+);
diff --git a/saleor/static/dashboard-next/discounts/types/SaleCreate.ts b/saleor/static/dashboard-next/discounts/types/SaleCreate.ts
new file mode 100644
index 0000000000..70a9401ebc
--- /dev/null
+++ b/saleor/static/dashboard-next/discounts/types/SaleCreate.ts
@@ -0,0 +1,38 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+import { SaleInput, SaleType } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL mutation operation: SaleCreate
+// ====================================================
+
+export interface SaleCreate_saleCreate_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface SaleCreate_saleCreate_sale {
+ __typename: "Sale";
+ id: string;
+ name: string;
+ type: SaleType;
+ startDate: any;
+ endDate: any | null;
+ value: number;
+}
+
+export interface SaleCreate_saleCreate {
+ __typename: "SaleCreate";
+ errors: SaleCreate_saleCreate_errors[] | null;
+ sale: SaleCreate_saleCreate_sale | null;
+}
+
+export interface SaleCreate {
+ saleCreate: SaleCreate_saleCreate | null;
+}
+
+export interface SaleCreateVariables {
+ input: SaleInput;
+}
diff --git a/saleor/static/dashboard-next/discounts/views/SaleCreate.tsx b/saleor/static/dashboard-next/discounts/views/SaleCreate.tsx
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index c721718ae6..646ccdb2ab 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -54,6 +54,7 @@ function loadStories() {
require("./stories/customers/CustomerListPage");
// Discounts
+ require("./stories/discounts/SaleCreatePage");
require("./stories/discounts/SaleDetailsPage");
require("./stories/discounts/SaleListPage");
require("./stories/discounts/VoucherListPage");
diff --git a/saleor/static/dashboard-next/storybook/stories/discounts/SaleCreatePage.tsx b/saleor/static/dashboard-next/storybook/stories/discounts/SaleCreatePage.tsx
new file mode 100644
index 0000000000..51bbf35bca
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/discounts/SaleCreatePage.tsx
@@ -0,0 +1,28 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import SaleCreatePage, {
+ SaleCreatePageProps
+} from "../../../discounts/components/SaleCreatePage";
+import Decorator from "../../Decorator";
+import { formError } from "../../misc";
+
+const props: SaleCreatePageProps = {
+ defaultCurrency: "USD",
+ disabled: false,
+ errors: [],
+ onBack: () => undefined,
+ onSubmit: () => undefined,
+ saveButtonBarState: "default"
+};
+
+storiesOf("Views / Discounts / Sale create", module)
+ .addDecorator(Decorator)
+ .add("default", () => <SaleCreatePage {...props} />)
+ .add("loading", () => <SaleCreatePage {...props} disabled={true} />)
+ .add("form errors", () => (
+ <SaleCreatePage
+ {...props}
+ errors={["name", "startDate", "endDate", "value"].map(formError)}
+ />
+ ));
diff --git a/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
index 94ebe245d4..e493a79eb4 100644
--- a/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
@@ -17,12 +17,15 @@ const props: SaleDetailsPageProps = {
onBack: () => undefined,
onCategoryAssign: () => undefined,
onCategoryClick: () => undefined,
+ onCategoryUnassign: () => undefined,
onCollectionAssign: () => undefined,
onCollectionClick: () => undefined,
+ onCollectionUnassign: () => undefined,
onNextPage: () => undefined,
onPreviousPage: () => undefined,
onProductAssign: () => undefined,
onProductClick: () => undefined,
+ onProductUnassign: () => undefined,
onRemove: () => undefined,
onSubmit: () => undefined,
onTabClick: () => undefined,