Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add voucher details view
dominik-zeglen884f2979dbc0
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsxindex ffb7f28374..be0bc0d2e2 100644--- a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx+++ b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx@@ -7,8 +7,11 @@ 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";import { maybe } from "../../../misc";-import { ListProps } from "../../../types";+import { ListProps, UserError } from "../../../types";import {VoucherDiscountValueType,VoucherType@@ -22,6 +25,19 @@ import VoucherInfo from "../VoucherInfo";import VoucherOptions from "../VoucherOptions";import VoucherSummary from "../VoucherSummary";+export enum VoucherDetailsPageTab {+ categories = "categories",+ collections = "collections",+ products = "products"+}+export function voucherDetailsPageTab(tab: string): VoucherDetailsPageTab {+ return tab === VoucherDetailsPageTab.products+ ? VoucherDetailsPageTab.products+ : tab === VoucherDetailsPageTab.collections+ ? VoucherDetailsPageTab.collections+ : VoucherDetailsPageTab.categories;+}+export interface FormData {applyOncePerOrder: boolean;code: string;@@ -37,39 +53,55 @@ export interface FormData {export interface VoucherDetailsPagePropsextends Pick<ListProps, Exclude<keyof ListProps, "onRowClick">> {+ activeTab: VoucherDetailsPageTab;defaultCurrency: string;+ errors: UserError[];saveButtonBarState: ConfirmButtonTransitionState;voucher: VoucherDetails_voucher;onBack: () => void;onCategoryAssign: () => void;+ onCategoryUnassign: (id: string) => void;onCategoryClick: (id: string) => () => void;- onCountryAssign: () => void;- onCountryUnassign: (code: string) => () => void;onCollectionAssign: () => void;+ onCollectionUnassign: (id: string) => void;onCollectionClick: (id: string) => () => void;+ onCountryAssign: () => void;+ onCountryUnassign: (code: string) => void;onProductAssign: () => void;+ onProductUnassign: (id: string) => void;onProductClick: (id: string) => () => void;onRemove: () => void;onSubmit: (data: FormData) => void;+ onTabClick: (index: VoucherDetailsPageTab) => void;}+const CategoriesTab = Tab(VoucherDetailsPageTab.categories);+const CollectionsTab = Tab(VoucherDetailsPageTab.collections);+const ProductsTab = Tab(VoucherDetailsPageTab.products);+const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({+ activeTab,defaultCurrency,disabled,+ errors,pageInfo,saveButtonBarState,voucher,onBack,onCategoryAssign,onCategoryClick,+ onCategoryUnassign,onCountryAssign,onCountryUnassign,onCollectionAssign,onCollectionClick,+ onCollectionUnassign,onNextPage,onPreviousPage,onProductAssign,onProductClick,+ onProductUnassign,+ onTabClick,onRemove,onSubmit}) => {@@ -90,7 +122,7 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({};return (- <Form initial={initialForm} onSubmit={onSubmit}>+ <Form errors={errors} initial={initialForm} onSubmit={onSubmit}>{({ change, data, errors: formErrors, hasChanged, submit }) => (<Container width="md"><PageHeader title={maybe(() => voucher.name)} onBack={onBack} />@@ -106,36 +138,81 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({onChange={change}/><CardSpacer />- {data.type === VoucherType.CATEGORY ? (- <DiscountCategories- disabled={disabled}- onCategoryAssign={onCategoryAssign}- onNextPage={onNextPage}- onPreviousPage={onPreviousPage}- onRowClick={onCategoryClick}- pageInfo={pageInfo}- discount={voucher}- />- ) : data.type === VoucherType.COLLECTION ? (- <DiscountCollections- disabled={disabled}- onCollectionAssign={onCollectionAssign}- onNextPage={onNextPage}- onPreviousPage={onPreviousPage}- onRowClick={onCollectionClick}- pageInfo={pageInfo}- discount={voucher}- />- ) : data.type === VoucherType.PRODUCT ? (- <DiscountProducts- disabled={disabled}- onNextPage={onNextPage}- onPreviousPage={onPreviousPage}- onProductAssign={onProductAssign}- onRowClick={onProductClick}- pageInfo={pageInfo}- discount={voucher}- />+ {data.type === VoucherType.CATEGORY ||+ data.type === VoucherType.COLLECTION ||+ data.type === VoucherType.PRODUCT ? (+ <>+ <TabContainer>+ <CategoriesTab+ isActive={activeTab === VoucherDetailsPageTab.categories}+ changeTab={onTabClick}+ >+ {i18n.t("Categories ({{ number }})", {+ number: maybe(+ () => voucher.categories.totalCount.toString(),+ "…"+ )+ })}+ </CategoriesTab>+ <CollectionsTab+ isActive={activeTab === VoucherDetailsPageTab.collections}+ changeTab={onTabClick}+ >+ {i18n.t("Collections ({{ number }})", {+ number: maybe(+ () => voucher.collections.totalCount.toString(),+ "…"+ )+ })}+ </CollectionsTab>+ <ProductsTab+ isActive={activeTab === VoucherDetailsPageTab.products}+ changeTab={onTabClick}+ >+ {i18n.t("Products ({{ number }})", {+ number: maybe(+ () => voucher.products.totalCount.toString(),+ "…"+ )+ })}+ </ProductsTab>+ </TabContainer>+ <CardSpacer />+ {activeTab === VoucherDetailsPageTab.categories ? (+ <DiscountCategories+ disabled={disabled}+ onCategoryAssign={onCategoryAssign}+ onCategoryUnassign={onCategoryUnassign}+ onNextPage={onNextPage}+ onPreviousPage={onPreviousPage}+ onRowClick={onCategoryClick}+ pageInfo={pageInfo}+ discount={voucher}+ />+ ) : activeTab === VoucherDetailsPageTab.collections ? (+ <DiscountCollections+ disabled={disabled}+ onCollectionAssign={onCollectionAssign}+ onCollectionUnassign={onCollectionUnassign}+ onNextPage={onNextPage}+ onPreviousPage={onPreviousPage}+ onRowClick={onCollectionClick}+ pageInfo={pageInfo}+ discount={voucher}+ />+ ) : (+ <DiscountProducts+ disabled={disabled}+ onNextPage={onNextPage}+ onPreviousPage={onPreviousPage}+ onProductAssign={onProductAssign}+ onProductUnassign={onProductUnassign}+ onRowClick={onProductClick}+ pageInfo={pageInfo}+ discount={voucher}+ />+ )}+ </>) : data.type === VoucherType.SHIPPING ? (<VoucherCountriesdisabled={disabled}diff --git a/saleor/static/dashboard-next/discounts/index.tsx b/saleor/static/dashboard-next/discounts/index.tsxindex f2ed4eb1df..7aa977da7d 100644--- a/saleor/static/dashboard-next/discounts/index.tsx+++ b/saleor/static/dashboard-next/discounts/index.tsx@@ -5,12 +5,22 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";import { WindowTitle } from "../components/WindowTitle";import i18n from "../i18n";import { saleDetailsPageTab } from "./components/SaleDetailsPage";-import { saleAddPath, saleListPath, salePath, voucherListPath } from "./urls";+import { voucherDetailsPageTab } from "./components/VoucherDetailsPage";+import {+ saleAddPath,+ saleListPath,+ salePath,+ voucherListPath,+ voucherPath+} from "./urls";import SaleCreateView from "./views/SaleCreate";import SaleDetailsViewComponent, {SaleDetailsQueryParams} from "./views/SaleDetails";import SaleListViewComponent, { SaleListQueryParams } from "./views/SaleList";+import VoucherDetailsViewComponent, {+ VoucherDetailsQueryParams+} from "./views/VoucherDetails";import VoucherListViewComponent, {VoucherListQueryParams} from "./views/VoucherList";@@ -49,6 +59,18 @@ const VoucherListView: React.StatelessComponent<RouteComponentProps<{}>> = ({return <VoucherListViewComponent params={params} />;};+const VoucherDetailsView: React.StatelessComponent<+ RouteComponentProps<{ id: string }>+> = ({ match, location }) => {+ const qs = parseQs(location.search.substr(1));+ const params: VoucherDetailsQueryParams = {+ after: qs.after,+ before: qs.before,+ tab: voucherDetailsPageTab(qs.tab)+ };+ return <VoucherDetailsViewComponent id={match.params.id} params={params} />;+};+export const DiscountSection: React.StatelessComponent<{}> = () => (<><WindowTitle title={i18n.t("Discounts")} />@@ -57,6 +79,7 @@ export const DiscountSection: React.StatelessComponent<{}> = () => (<Route exact path={saleAddPath} component={SaleCreateView} /><Route path={salePath(":id")} component={SaleDetailsView} /><Route exact path={voucherListPath} component={VoucherListView} />+ <Route path={voucherPath(":id")} component={VoucherDetailsView} /></Switch></>);diff --git a/saleor/static/dashboard-next/discounts/mutations.ts b/saleor/static/dashboard-next/discounts/mutations.tsindex 9ad2a740d2..0a6a065c5c 100644--- a/saleor/static/dashboard-next/discounts/mutations.ts+++ b/saleor/static/dashboard-next/discounts/mutations.ts@@ -1,7 +1,12 @@import gql from "graphql-tag";import { TypedMutation } from "../mutations";-import { saleDetailsFragment, saleFragment } from "./queries";+import {+ saleDetailsFragment,+ saleFragment,+ voucherDetailsFragment,+ voucherFragment+} from "./queries";import {SaleCataloguesAdd,SaleCataloguesAddVariables@@ -13,6 +18,17 @@ import {import { SaleCreate, SaleCreateVariables } from "./types/SaleCreate";import { SaleDelete, SaleDeleteVariables } from "./types/SaleDelete";import { SaleUpdate, SaleUpdateVariables } from "./types/SaleUpdate";+import {+ VoucherCataloguesAdd,+ VoucherCataloguesAddVariables+} from "./types/VoucherCataloguesAdd";+import {+ VoucherCataloguesRemove,+ VoucherCataloguesRemoveVariables+} from "./types/VoucherCataloguesRemove";+import { VoucherCreate, VoucherCreateVariables } from "./types/VoucherCreate";+import { VoucherDelete, VoucherDeleteVariables } from "./types/VoucherDelete";+import { VoucherUpdate, VoucherUpdateVariables } from "./types/VoucherUpdate";const saleUpdate = gql`${saleFragment}@@ -115,3 +131,108 @@ const saleDelete = gql`export const TypedSaleDelete = TypedMutation<SaleDelete, SaleDeleteVariables>(saleDelete);++const voucherUpdate = gql`+ ${voucherFragment}+ mutation VoucherUpdate($input: VoucherInput!, $id: ID!) {+ voucherUpdate(id: $id, input: $input) {+ errors {+ field+ message+ }+ voucher {+ ...VoucherFragment+ }+ }+ }+`;+export const TypedVoucherUpdate = TypedMutation<+ VoucherUpdate,+ VoucherUpdateVariables+>(voucherUpdate);++const voucherCataloguesAdd = gql`+ ${voucherDetailsFragment}+ mutation VoucherCataloguesAdd(+ $input: CatalogueInput!+ $id: ID!+ $after: String+ $before: String+ $first: Int+ $last: Int+ ) {+ voucherCataloguesAdd(id: $id, input: $input) {+ errors {+ field+ message+ }+ voucher {+ ...VoucherDetailsFragment+ }+ }+ }+`;+export const TypedVoucherCataloguesAdd = TypedMutation<+ VoucherCataloguesAdd,+ VoucherCataloguesAddVariables+>(voucherCataloguesAdd);++const voucherCataloguesRemove = gql`+ ${voucherDetailsFragment}+ mutation VoucherCataloguesRemove(+ $input: CatalogueInput!+ $id: ID!+ $after: String+ $before: String+ $first: Int+ $last: Int+ ) {+ voucherCataloguesRemove(id: $id, input: $input) {+ errors {+ field+ message+ }+ voucher {+ ...VoucherDetailsFragment+ }+ }+ }+`;+export const TypedVoucherCataloguesRemove = TypedMutation<+ VoucherCataloguesRemove,+ VoucherCataloguesRemoveVariables+>(voucherCataloguesRemove);++const voucherCreate = gql`+ ${voucherFragment}+ mutation VoucherCreate($input: VoucherInput!) {+ voucherCreate(input: $input) {+ errors {+ field+ message+ }+ voucher {+ ...VoucherFragment+ }+ }+ }+`;+export const TypedVoucherCreate = TypedMutation<+ VoucherCreate,+ VoucherCreateVariables+>(voucherCreate);++const voucherDelete = gql`+ mutation VoucherDelete($id: ID!) {+ voucherDelete(id: $id) {+ errors {+ field+ message+ }+ }+ }+`;+export const TypedVoucherDelete = TypedMutation<+ VoucherDelete,+ VoucherDeleteVariables+>(voucherDelete);diff --git a/saleor/static/dashboard-next/discounts/types/VoucherCataloguesAdd.ts b/saleor/static/dashboard-next/discounts/types/VoucherCataloguesAdd.tsnew file mode 100644index 0000000000..29078c3f41--- /dev/null+++ b/saleor/static/dashboard-next/discounts/types/VoucherCataloguesAdd.ts@@ -0,0 +1,169 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { CatalogueInput, VoucherDiscountValueType, VoucherType } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: VoucherCataloguesAdd+// ====================================================++export interface VoucherCataloguesAdd_voucherCataloguesAdd_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_minAmountSpent {+ __typename: "Money";+ currency: string;+ amount: number;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_edges_node_productType {+ __typename: "ProductType";+ id: string;+ name: string;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_edges_node_thumbnail {+ __typename: "Image";+ url: string;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_edges_node {+ __typename: "Product";+ id: string;+ name: string;+ productType: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_edges_node_productType;+ isPublished: boolean;+ thumbnail: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_edges_node_thumbnail | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_edges {+ __typename: "ProductCountableEdge";+ node: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_edges_node;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products {+ __typename: "ProductCountableConnection";+ edges: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_edges[];+ totalCount: number | null;+ pageInfo: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products_pageInfo;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections_edges_node_products {+ __typename: "ProductCountableConnection";+ totalCount: number | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections_edges_node {+ __typename: "Collection";+ id: string;+ name: string;+ products: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections_edges_node_products | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections_edges {+ __typename: "CollectionCountableEdge";+ node: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections_edges_node;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections {+ __typename: "CollectionCountableConnection";+ edges: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections_edges[];+ totalCount: number | null;+ pageInfo: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections_pageInfo;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories_edges_node_products {+ __typename: "ProductCountableConnection";+ totalCount: number | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories_edges_node {+ __typename: "Category";+ id: string;+ name: string;+ products: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories_edges_node_products | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories_edges {+ __typename: "CategoryCountableEdge";+ node: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories_edges_node;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories {+ __typename: "CategoryCountableConnection";+ edges: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories_edges[];+ totalCount: number | null;+ pageInfo: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories_pageInfo;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher_countries {+ __typename: "CountryDisplay";+ code: string;+ country: string;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher {+ __typename: "Voucher";+ id: string;+ name: string | null;+ startDate: any;+ endDate: any | null;+ usageLimit: number | null;+ discountValueType: VoucherDiscountValueType;+ discountValue: number;+ minAmountSpent: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_minAmountSpent | null;+ type: VoucherType;+ code: string;+ used: number;+ applyOncePerOrder: boolean;+ products: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products | null;+ collections: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections | null;+ categories: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories | null;+ countries: (VoucherCataloguesAdd_voucherCataloguesAdd_voucher_countries | null)[] | null;+}++export interface VoucherCataloguesAdd_voucherCataloguesAdd {+ __typename: "VoucherAddCatalogues";+ errors: VoucherCataloguesAdd_voucherCataloguesAdd_errors[] | null;+ voucher: VoucherCataloguesAdd_voucherCataloguesAdd_voucher | null;+}++export interface VoucherCataloguesAdd {+ voucherCataloguesAdd: VoucherCataloguesAdd_voucherCataloguesAdd | null;+}++export interface VoucherCataloguesAddVariables {+ input: CatalogueInput;+ id: string;+ after?: string | null;+ before?: string | null;+ first?: number | null;+ last?: number | null;+}diff --git a/saleor/static/dashboard-next/discounts/types/VoucherCataloguesRemove.ts b/saleor/static/dashboard-next/discounts/types/VoucherCataloguesRemove.tsnew file mode 100644index 0000000000..920d7f664a--- /dev/null+++ b/saleor/static/dashboard-next/discounts/types/VoucherCataloguesRemove.ts@@ -0,0 +1,169 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { CatalogueInput, VoucherDiscountValueType, VoucherType } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: VoucherCataloguesRemove+// ====================================================++export interface VoucherCataloguesRemove_voucherCataloguesRemove_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_minAmountSpent {+ __typename: "Money";+ currency: string;+ amount: number;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_edges_node_productType {+ __typename: "ProductType";+ id: string;+ name: string;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_edges_node_thumbnail {+ __typename: "Image";+ url: string;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_edges_node {+ __typename: "Product";+ id: string;+ name: string;+ productType: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_edges_node_productType;+ isPublished: boolean;+ thumbnail: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_edges_node_thumbnail | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_edges {+ __typename: "ProductCountableEdge";+ node: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_edges_node;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products {+ __typename: "ProductCountableConnection";+ edges: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_edges[];+ totalCount: number | null;+ pageInfo: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products_pageInfo;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections_edges_node_products {+ __typename: "ProductCountableConnection";+ totalCount: number | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections_edges_node {+ __typename: "Collection";+ id: string;+ name: string;+ products: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections_edges_node_products | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections_edges {+ __typename: "CollectionCountableEdge";+ node: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections_edges_node;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections {+ __typename: "CollectionCountableConnection";+ edges: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections_edges[];+ totalCount: number | null;+ pageInfo: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections_pageInfo;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories_edges_node_products {+ __typename: "ProductCountableConnection";+ totalCount: number | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories_edges_node {+ __typename: "Category";+ id: string;+ name: string;+ products: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories_edges_node_products | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories_edges {+ __typename: "CategoryCountableEdge";+ node: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories_edges_node;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories {+ __typename: "CategoryCountableConnection";+ edges: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories_edges[];+ totalCount: number | null;+ pageInfo: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories_pageInfo;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher_countries {+ __typename: "CountryDisplay";+ code: string;+ country: string;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher {+ __typename: "Voucher";+ id: string;+ name: string | null;+ startDate: any;+ endDate: any | null;+ usageLimit: number | null;+ discountValueType: VoucherDiscountValueType;+ discountValue: number;+ minAmountSpent: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_minAmountSpent | null;+ type: VoucherType;+ code: string;+ used: number;+ applyOncePerOrder: boolean;+ products: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products | null;+ collections: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections | null;+ categories: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories | null;+ countries: (VoucherCataloguesRemove_voucherCataloguesRemove_voucher_countries | null)[] | null;+}++export interface VoucherCataloguesRemove_voucherCataloguesRemove {+ __typename: "VoucherRemoveCatalogues";+ errors: VoucherCataloguesRemove_voucherCataloguesRemove_errors[] | null;+ voucher: VoucherCataloguesRemove_voucherCataloguesRemove_voucher | null;+}++export interface VoucherCataloguesRemove {+ voucherCataloguesRemove: VoucherCataloguesRemove_voucherCataloguesRemove | null;+}++export interface VoucherCataloguesRemoveVariables {+ input: CatalogueInput;+ id: string;+ after?: string | null;+ before?: string | null;+ first?: number | null;+ last?: number | null;+}diff --git a/saleor/static/dashboard-next/discounts/types/VoucherCreate.ts b/saleor/static/dashboard-next/discounts/types/VoucherCreate.tsnew file mode 100644index 0000000000..96aca4abb9--- /dev/null+++ b/saleor/static/dashboard-next/discounts/types/VoucherCreate.ts@@ -0,0 +1,46 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { VoucherInput, VoucherDiscountValueType } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: VoucherCreate+// ====================================================++export interface VoucherCreate_voucherCreate_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface VoucherCreate_voucherCreate_voucher_minAmountSpent {+ __typename: "Money";+ currency: string;+ amount: number;+}++export interface VoucherCreate_voucherCreate_voucher {+ __typename: "Voucher";+ id: string;+ name: string | null;+ startDate: any;+ endDate: any | null;+ usageLimit: number | null;+ discountValueType: VoucherDiscountValueType;+ discountValue: number;+ minAmountSpent: VoucherCreate_voucherCreate_voucher_minAmountSpent | null;+}++export interface VoucherCreate_voucherCreate {+ __typename: "VoucherCreate";+ errors: VoucherCreate_voucherCreate_errors[] | null;+ voucher: VoucherCreate_voucherCreate_voucher | null;+}++export interface VoucherCreate {+ voucherCreate: VoucherCreate_voucherCreate | null;+}++export interface VoucherCreateVariables {+ input: VoucherInput;+}diff --git a/saleor/static/dashboard-next/discounts/types/VoucherDelete.ts b/saleor/static/dashboard-next/discounts/types/VoucherDelete.tsnew file mode 100644index 0000000000..2fa8455852--- /dev/null+++ b/saleor/static/dashboard-next/discounts/types/VoucherDelete.ts@@ -0,0 +1,25 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL mutation operation: VoucherDelete+// ====================================================++export interface VoucherDelete_voucherDelete_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface VoucherDelete_voucherDelete {+ __typename: "VoucherDelete";+ errors: VoucherDelete_voucherDelete_errors[] | null;+}++export interface VoucherDelete {+ voucherDelete: VoucherDelete_voucherDelete | null;+}++export interface VoucherDeleteVariables {+ id: string;+}diff --git a/saleor/static/dashboard-next/discounts/types/VoucherUpdate.ts b/saleor/static/dashboard-next/discounts/types/VoucherUpdate.tsnew file mode 100644index 0000000000..c850bfe3dd--- /dev/null+++ b/saleor/static/dashboard-next/discounts/types/VoucherUpdate.ts@@ -0,0 +1,47 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { VoucherInput, VoucherDiscountValueType } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: VoucherUpdate+// ====================================================++export interface VoucherUpdate_voucherUpdate_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface VoucherUpdate_voucherUpdate_voucher_minAmountSpent {+ __typename: "Money";+ currency: string;+ amount: number;+}++export interface VoucherUpdate_voucherUpdate_voucher {+ __typename: "Voucher";+ id: string;+ name: string | null;+ startDate: any;+ endDate: any | null;+ usageLimit: number | null;+ discountValueType: VoucherDiscountValueType;+ discountValue: number;+ minAmountSpent: VoucherUpdate_voucherUpdate_voucher_minAmountSpent | null;+}++export interface VoucherUpdate_voucherUpdate {+ __typename: "VoucherUpdate";+ errors: VoucherUpdate_voucherUpdate_errors[] | null;+ voucher: VoucherUpdate_voucherUpdate_voucher | null;+}++export interface VoucherUpdate {+ voucherUpdate: VoucherUpdate_voucherUpdate | null;+}++export interface VoucherUpdateVariables {+ input: VoucherInput;+ id: string;+}diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsx b/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsxnew file mode 100644index 0000000000..ebe32eaeaa--- /dev/null+++ b/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsx@@ -0,0 +1,560 @@+import DialogContentText from "@material-ui/core/DialogContentText";+import { stringify as stringifyQs } from "qs";+import * as React from "react";+import { Route } from "react-router-dom";++import { categoryUrl } from "../../../categories/urls";+import { collectionUrl } from "../../../collections/urls";+import ActionDialog from "../../../components/ActionDialog";+import AssignCategoriesDialog from "../../../components/AssignCategoryDialog";+import AssignCollectionDialog from "../../../components/AssignCollectionDialog";+import AssignProductDialog from "../../../components/AssignProductDialog";+import Messages from "../../../components/messages";+import Navigator from "../../../components/Navigator";+import {+ createPaginationState,+ Paginator+} from "../../../components/Paginator";+import Shop from "../../../components/Shop";+import { WindowTitle } from "../../../components/WindowTitle";+import { SearchCategoriesProvider } from "../../../containers/SearchCategories";+import { SearchCollectionsProvider } from "../../../containers/SearchCollections";+import { SearchProductsProvider } from "../../../containers/SearchProducts";+import i18n from "../../../i18n";+import { getMutationState, maybe } from "../../../misc";+import { productUrl } from "../../../products/urls";+import { DiscountValueTypeEnum, VoucherType } from "../../../types/globalTypes";+import VoucherDetailsPage, {+ VoucherDetailsPageTab+} from "../../components/VoucherDetailsPage";+import {+ TypedVoucherCataloguesAdd,+ TypedVoucherCataloguesRemove,+ TypedVoucherDelete,+ TypedVoucherUpdate+} from "../../mutations";+import { TypedVoucherDetails } from "../../queries";+import { VoucherDelete } from "../../types/VoucherDelete";+import { voucherListUrl, voucherUrl } from "../../urls";+import {+ voucherAssignCategoriesPath,+ voucherAssignCategoriesUrl,+ voucherAssignCollectionsPath,+ voucherAssignCollectionsUrl,+ voucherAssignCountriesUrl,+ voucherAssignProductsPath,+ voucherAssignProductsUrl,+ voucherDeletePath,+ voucherDeleteUrl+} from "./urls";++const PAGINATE_BY = 20;++export type VoucherDetailsQueryParams = Partial<{+ after: string;+ before: string;+ tab: VoucherDetailsPageTab;+}>;++interface VoucherDetailsProps {+ id: string;+ params: VoucherDetailsQueryParams;+}++function discountValueTypeEnum(type: VoucherType): DiscountValueTypeEnum {+ return type.toString() === DiscountValueTypeEnum.FIXED+ ? DiscountValueTypeEnum.FIXED+ : DiscountValueTypeEnum.PERCENTAGE;+}++export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({+ id,+ params+}) => (+ <>+ <WindowTitle title={i18n.t("Vouchers")} />+ <Shop>+ {shop => (+ <Messages>+ {pushMessage => (+ <Navigator>+ {navigate => {+ const paginationState = createPaginationState(+ PAGINATE_BY,+ params+ );+ const changeTab = (tab: VoucherDetailsPageTab) =>+ navigate(+ "?" ++ stringifyQs({+ tab+ })+ );++ const handleVoucherDelete = (data: VoucherDelete) => {+ if (data.voucherDelete.errors.length === 0) {+ pushMessage({+ text: i18n.t("Removed voucher", {+ context: "notification"+ })+ });+ navigate(voucherListUrl, true);+ }+ };++ return (+ <TypedVoucherCataloguesRemove>+ {(voucherCataloguesRemove, voucherCataloguesRemoveOpts) => (+ <TypedVoucherCataloguesAdd>+ {(voucherCataloguesAdd, voucherCataloguesAddOpts) => (+ <TypedVoucherUpdate>+ {(voucherUpdate, voucherUpdateOpts) => (+ <TypedVoucherDelete+ onCompleted={handleVoucherDelete}+ >+ {(voucherDelete, voucherDeleteOpts) => (+ <TypedVoucherDetails+ displayLoader+ variables={{ id, ...paginationState }}+ >+ {({ data, loading }) => {+ const pageInfo =+ params.tab ===+ VoucherDetailsPageTab.categories+ ? maybe(+ () =>+ data.voucher.categories.pageInfo+ )+ : params.tab ===+ VoucherDetailsPageTab.collections+ ? maybe(+ () =>+ data.voucher.collections+ .pageInfo+ )+ : maybe(+ () =>+ data.voucher.products.pageInfo+ );+ const formTransitionState = getMutationState(+ voucherUpdateOpts.called,+ voucherUpdateOpts.loading,+ maybe(+ () =>+ voucherUpdateOpts.data.voucherUpdate+ .errors+ )+ );+ const assignTransitionState = getMutationState(+ voucherCataloguesAddOpts.called,+ voucherCataloguesAddOpts.loading,+ maybe(+ () =>+ voucherCataloguesAddOpts.data+ .voucherCataloguesAdd.errors+ )+ );+ const removeTransitionState = getMutationState(+ voucherDeleteOpts.called,+ voucherDeleteOpts.loading,+ maybe(+ () =>+ voucherDeleteOpts.data.voucherDelete+ .errors+ )+ );++ return (+ <Paginator+ pageInfo={pageInfo}+ paginationState={paginationState}+ queryString={params}+ >+ {({+ loadNextPage,+ loadPreviousPage,+ pageInfo+ }) => (+ <>+ <VoucherDetailsPage+ defaultCurrency={maybe(+ () => shop.defaultCurrency+ )}+ voucher={maybe(+ () => data.voucher+ )}+ disabled={+ loading ||+ voucherCataloguesRemoveOpts.loading+ }+ errors={maybe(+ () =>+ voucherUpdateOpts.data+ .voucherUpdate.errors+ )}+ pageInfo={pageInfo}+ onNextPage={loadNextPage}+ onPreviousPage={+ loadPreviousPage+ }+ onCategoryAssign={() =>+ navigate(+ voucherAssignCategoriesUrl(+ id+ ),+ false,+ true+ )+ }+ onCategoryClick={id => () =>+ navigate(categoryUrl(id))}+ onCollectionAssign={() =>+ navigate(+ voucherAssignCollectionsUrl(+ id+ ),+ false,+ true+ )+ }+ onCollectionUnassign={collectionId =>+ voucherCataloguesRemove({+ variables: {+ ...paginationState,+ id,+ input: {+ collections: [+ collectionId+ ]+ }+ }+ })+ }+ onCountryAssign={() =>+ navigate(+ voucherAssignCountriesUrl(+ id+ ),+ false,+ true+ )+ }+ onCountryUnassign={countryCode =>+ voucherUpdate({+ variables: {+ ...paginationState,+ id,+ input: {+ countries: data.voucher.countries+ .filter(+ country =>+ country.code !==+ countryCode+ )+ .map(+ country =>+ country.code+ )+ }+ }+ })+ }+ onCategoryUnassign={categoryId =>+ voucherCataloguesRemove({+ variables: {+ ...paginationState,+ id,+ input: {+ categories: [categoryId]+ }+ }+ })+ }+ onCollectionClick={id => () =>+ navigate(collectionUrl(id))}+ onProductAssign={() =>+ navigate(+ voucherAssignProductsUrl(+ id+ ),+ false,+ true+ )+ }+ onProductUnassign={productId =>+ voucherCataloguesRemove({+ variables: {+ ...paginationState,+ id,+ input: {+ products: [productId]+ }+ }+ })+ }+ onProductClick={id => () =>+ navigate(productUrl(id))}+ activeTab={params.tab}+ onBack={() =>+ navigate(voucherListUrl)+ }+ onTabClick={changeTab}+ onSubmit={formData =>+ voucherUpdate({+ variables: {+ id,+ input: {+ endDate:+ formData.endDate ===+ ""+ ? null+ : formData.endDate,+ name: formData.name,+ startDate:+ formData.startDate,+ type: discountValueTypeEnum(+ formData.type+ ),+ value: formData.value+ }+ }+ })+ }+ onRemove={() =>+ navigate(voucherDeleteUrl(id))+ }+ saveButtonBarState={+ formTransitionState+ }+ />+ <Route+ path={voucherAssignProductsPath(+ ":id"+ )}+ render={({ match }) => (+ <SearchProductsProvider>+ {(+ searchProducts,+ searchProductsOpts+ ) => (+ <AssignProductDialog+ confirmButtonState={+ assignTransitionState+ }+ open={!!match}+ onFetch={searchProducts}+ loading={+ searchProductsOpts.loading+ }+ onClose={() =>+ navigate(+ voucherUrl(id),+ true,+ true+ )+ }+ onSubmit={formData =>+ voucherCataloguesAdd({+ variables: {+ ...paginationState,+ id,+ input: {+ products: formData.products.map(+ product =>+ product.id+ )+ }+ }+ })+ }+ products={maybe(() =>+ searchProductsOpts.data.products.edges+ .map(+ edge => edge.node+ )+ .filter(+ suggestedProduct =>+ suggestedProduct.id+ )+ )}+ />+ )}+ </SearchProductsProvider>+ )}+ />+ <Route+ path={voucherAssignCategoriesPath(+ ":id"+ )}+ render={({ match }) => (+ <SearchCategoriesProvider>+ {(+ searchCategories,+ searchCategoriesOpts+ ) => (+ <AssignCategoriesDialog+ categories={maybe(() =>+ searchCategoriesOpts.data.categories.edges+ .map(+ edge => edge.node+ )+ .filter(+ suggestedCategory =>+ suggestedCategory.id+ )+ )}+ confirmButtonState={+ assignTransitionState+ }+ open={!!match}+ onFetch={+ searchCategories+ }+ loading={+ searchCategoriesOpts.loading+ }+ onClose={() =>+ navigate(+ voucherUrl(id),+ true,+ true+ )+ }+ onSubmit={formData =>+ voucherCataloguesAdd({+ variables: {+ ...paginationState,+ id,+ input: {+ categories: formData.categories.map(+ product =>+ product.id+ )+ }+ }+ })+ }+ />+ )}+ </SearchCategoriesProvider>+ )}+ />+ <Route+ path={voucherAssignCollectionsPath(+ ":id"+ )}+ render={({ match }) => (+ <SearchCollectionsProvider>+ {(+ searchCollections,+ searchCollectionsOpts+ ) => (+ <AssignCollectionDialog+ collections={maybe(() =>+ searchCollectionsOpts.data.collections.edges+ .map(+ edge => edge.node+ )+ .filter(+ suggestedCategory =>+ suggestedCategory.id+ )+ )}+ confirmButtonState={+ assignTransitionState+ }+ open={!!match}+ onFetch={+ searchCollections+ }+ loading={+ searchCollectionsOpts.loading+ }+ onClose={() =>+ navigate(+ voucherUrl(id),+ true,+ true+ )+ }+ onSubmit={formData =>+ voucherCataloguesAdd({+ variables: {+ ...paginationState,+ id,+ input: {+ collections: formData.collections.map(+ product =>+ product.id+ )+ }+ }+ })+ }+ />+ )}+ </SearchCollectionsProvider>+ )}+ />+ <Route+ path={voucherDeletePath(":id")}+ render={({ match }) => (+ <ActionDialog+ open={!!match}+ title={i18n.t(+ "Remove Voucher"+ )}+ confirmButtonState={+ removeTransitionState+ }+ onClose={() =>+ navigate(voucherUrl(id))+ }+ variant="delete"+ onConfirm={() =>+ voucherDelete({+ variables: { id }+ })+ }+ >+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to remove <strong>{{ voucherName }}</strong>?",+ {+ voucherName: maybe(+ () =>+ data.voucher+ .name+ )+ }+ )+ }}+ />+ </ActionDialog>+ )}+ />+ </>+ )}+ </Paginator>+ );+ }}+ </TypedVoucherDetails>+ )}+ </TypedVoucherDelete>+ )}+ </TypedVoucherUpdate>+ )}+ </TypedVoucherCataloguesAdd>+ )}+ </TypedVoucherCataloguesRemove>+ );+ }}+ </Navigator>+ )}+ </Messages>+ )}+ </Shop>+ </>+);+export default VoucherDetails;diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails/urls.ts b/saleor/static/dashboard-next/discounts/views/VoucherDetails/urls.tsnew file mode 100644index 0000000000..668b7da87d--- /dev/null+++ b/saleor/static/dashboard-next/discounts/views/VoucherDetails/urls.ts@@ -0,0 +1,28 @@+import * as urlJoin from "url-join";++import { voucherPath } from "../../urls";++export const voucherAssignProductsPath = (id: string) =>+ urlJoin(voucherPath(id), "assign-products");+export const voucherAssignProductsUrl = (id: string) =>+ voucherAssignProductsPath(encodeURIComponent(id));++export const voucherAssignCategoriesPath = (id: string) =>+ urlJoin(voucherPath(id), "assign-categories");+export const voucherAssignCategoriesUrl = (id: string) =>+ voucherAssignCategoriesPath(encodeURIComponent(id));++export const voucherAssignCollectionsPath = (id: string) =>+ urlJoin(voucherPath(id), "assign-collections");+export const voucherAssignCollectionsUrl = (id: string) =>+ voucherAssignCollectionsPath(encodeURIComponent(id));++export const voucherAssignCountriesPath = (id: string) =>+ urlJoin(voucherPath(id), "assign-countries");+export const voucherAssignCountriesUrl = (id: string) =>+ voucherAssignCountriesPath(encodeURIComponent(id));++export const voucherDeletePath = (id: string) =>+ urlJoin(voucherPath(id), "delete");+export const voucherDeleteUrl = (id: string) =>+ voucherDeletePath(encodeURIComponent(id));diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.tsindex 37277ef818..115ed49d0e 100644--- a/saleor/static/dashboard-next/types/globalTypes.ts+++ b/saleor/static/dashboard-next/types/globalTypes.ts@@ -142,6 +142,14 @@ export enum VoucherType {VALUE = "VALUE",}+export enum VoucherTypeEnum {+ CATEGORY = "CATEGORY",+ COLLECTION = "COLLECTION",+ PRODUCT = "PRODUCT",+ SHIPPING = "SHIPPING",+ VALUE = "VALUE",+}+export enum WeightUnitsEnum {g = "g",kg = "kg",@@ -371,6 +379,21 @@ export interface UserCreateInput {sendPasswordEmail?: boolean | null;}+export interface VoucherInput {+ type?: VoucherTypeEnum | null;+ name?: string | null;+ code?: string | null;+ startDate?: any | null;+ endDate?: any | null;+ discountValueType?: DiscountValueTypeEnum | null;+ discountValue?: any | null;+ products?: (string | null)[] | null;+ collections?: (string | null)[] | null;+ categories?: (string | null)[] | null;+ minAmountSpent?: any | null;+ countries?: (string | null)[] | null;+}+//==============================================================// END Enums and Input Objects//==============================================================