Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add voucher details page
dominik-zeglen71786b3d5caf
diff --git a/saleor/static/dashboard-next/components/ControlledSwitch.tsx b/saleor/static/dashboard-next/components/ControlledSwitch.tsxindex fe9ca77cf0..b13a4b28ed 100644--- a/saleor/static/dashboard-next/components/ControlledSwitch.tsx+++ b/saleor/static/dashboard-next/components/ControlledSwitch.tsx@@ -13,9 +13,9 @@ const styles = (theme: Theme) =>interface ControlledSwitchProps extends WithStyles<typeof styles> {checked: boolean;disabled?: boolean;- label: string;+ label: string | React.ReactNode;name: string;- uncheckedLabel?: string;+ uncheckedLabel?: string | React.ReactNode;onChange?(event: React.ChangeEvent<any>);}diff --git a/saleor/static/dashboard-next/components/TextFieldWithChoice/Anchor.tsx b/saleor/static/dashboard-next/components/TextFieldWithChoice/Anchor.tsxnew file mode 100644index 0000000000..c2dd266009--- /dev/null+++ b/saleor/static/dashboard-next/components/TextFieldWithChoice/Anchor.tsx@@ -0,0 +1,14 @@+import * as React from "react";++export interface AnchorProps {+ children: (anchor: React.RefObject<HTMLDivElement>) => React.ReactNode;+}++class Anchor extends React.Component<AnchorProps> {+ anchor = React.createRef<HTMLDivElement>();++ render() {+ return this.anchor ? this.props.children(this.anchor) : null;+ }+}+export default Anchor;diff --git a/saleor/static/dashboard-next/components/TextFieldWithChoice/TextFieldWithChoice.tsx b/saleor/static/dashboard-next/components/TextFieldWithChoice/TextFieldWithChoice.tsxnew file mode 100644index 0000000000..22df622c6e--- /dev/null+++ b/saleor/static/dashboard-next/components/TextFieldWithChoice/TextFieldWithChoice.tsx@@ -0,0 +1,131 @@+import ClickAwayListener from "@material-ui/core/ClickAwayListener";+import Grow from "@material-ui/core/Grow";+import MenuItem from "@material-ui/core/MenuItem";+import Menu from "@material-ui/core/MenuList";+import Paper from "@material-ui/core/Paper";+import Popper from "@material-ui/core/Popper";+import { createStyles, WithStyles, withStyles } from "@material-ui/core/styles";+import TextField, { TextFieldProps } from "@material-ui/core/TextField";+import Typography from "@material-ui/core/Typography";+import DropdownIcon from "@material-ui/icons/ArrowDropDown";+import * as React from "react";+import MenuToggle from "../MenuToggle";+import Anchor from "./Anchor";++export type TextFieldWithChoiceProps<TValue = string> = TextFieldProps & {+ ChoiceProps: {+ name: string;+ label: string | React.ReactNode;+ values: Array<{+ label: string | React.ReactNode;+ value: TValue;+ }>;+ };+};++const styles = createStyles({+ adornment: {+ alignItems: "center",+ cursor: "pointer",+ display: "flex"+ },+ menu: {+ zIndex: 10+ }+});++const TextFieldWithChoice = withStyles(styles, {+ name: "TextFieldWithChoices"+})(+ ({+ ChoiceProps,+ InputProps,+ classes,+ name,+ onChange,+ ...props+ }: TextFieldWithChoiceProps & WithStyles<typeof styles>) => (+ <Anchor>+ {anchor => (+ <TextField+ {...props}+ InputProps={{+ ...InputProps,+ endAdornment: (+ <MenuToggle ariaOwns="user-menu">+ {({+ open: menuOpen,+ actions: { open: openMenu, close: closeMenu }+ }) => {+ const handleSelect = value => {+ onChange({+ target: {+ name: ChoiceProps.name,+ value+ }+ } as any);+ closeMenu();+ };++ return (+ <>+ <div+ className={classes.adornment}+ ref={anchor}+ onClick={!menuOpen ? openMenu : undefined}+ >+ <Typography component="span" variant="caption">+ {ChoiceProps.label}+ </Typography>+ <DropdownIcon />+ </div>+ <Popper+ open={menuOpen}+ anchorEl={anchor.current}+ transition+ disablePortal+ placement="bottom-end"+ className={classes.menu}+ >+ {({ TransitionProps, placement }) => (+ <Grow+ {...TransitionProps}+ style={{+ transformOrigin:+ placement === "bottom"+ ? "right top"+ : "right bottom"+ }}+ >+ <Paper>+ <ClickAwayListener+ onClickAway={closeMenu}+ mouseEvent="onClick"+ >+ <Menu>+ {ChoiceProps.values.map(choice => (+ <MenuItem+ onClick={() => handleSelect(choice.value)}+ >+ {choice.label}+ </MenuItem>+ ))}+ </Menu>+ </ClickAwayListener>+ </Paper>+ </Grow>+ )}+ </Popper>+ </>+ );+ }}+ </MenuToggle>+ )+ }}+ />+ )}+ </Anchor>+ )+);+TextFieldWithChoice.displayName = "TextFieldWithChoice";+export default TextFieldWithChoice;diff --git a/saleor/static/dashboard-next/components/TextFieldWithChoice/index.ts b/saleor/static/dashboard-next/components/TextFieldWithChoice/index.tsnew file mode 100644index 0000000000..064783078e--- /dev/null+++ b/saleor/static/dashboard-next/components/TextFieldWithChoice/index.ts@@ -0,0 +1,2 @@+export { default } from "./TextFieldWithChoice";+export * from "./TextFieldWithChoice";diff --git a/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx b/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsxsimilarity index 88%rename from saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsxrename to saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsxindex dc644ceed2..938a0d7f17 100644--- a/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx+++ b/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx@@ -16,9 +16,10 @@ import i18n from "../../../i18n";import { maybe, renderCollection } from "../../../misc";import { ListProps } from "../../../types";import { SaleDetails_sale } from "../../types/SaleDetails";+import { VoucherDetails_voucher } from "../../types/VoucherDetails";-export interface SaleCategoriesProps extends ListProps {- sale: SaleDetails_sale;+export interface DiscountCategoriesProps extends ListProps {+ discount: SaleDetails_sale | VoucherDetails_voucher;onCategoryAssign: () => void;}@@ -33,11 +34,11 @@ const styles = createStyles({width: "60%"}});-const SaleCategories = withStyles(styles, {- name: "SaleCategories"+const DiscountCategories = withStyles(styles, {+ name: "DiscountCategories"})(({- sale,+ discount: sale,classes,disabled,pageInfo,@@ -45,7 +46,7 @@ const SaleCategories = withStyles(styles, {onRowClick,onPreviousPage,onNextPage- }: SaleCategoriesProps & WithStyles<typeof styles>) => (+ }: DiscountCategoriesProps & WithStyles<typeof styles>) => (<Card><CardTitletitle={i18n.t("Categories assigned to {{ saleName }}", {@@ -115,5 +116,5 @@ const SaleCategories = withStyles(styles, {</Card>));-SaleCategories.displayName = "SaleCategories";-export default SaleCategories;+DiscountCategories.displayName = "DiscountCategories";+export default DiscountCategories;diff --git a/saleor/static/dashboard-next/discounts/components/DiscountCategories/index.ts b/saleor/static/dashboard-next/discounts/components/DiscountCategories/index.tsnew file mode 100644index 0000000000..00e781deb8--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/DiscountCategories/index.ts@@ -0,0 +1,2 @@+export { default } from "./DiscountCategories";+export * from "./DiscountCategories";diff --git a/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx b/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsxsimilarity index 88%rename from saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsxrename to saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsxindex 39d856f0f9..07c95f60e0 100644--- a/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx+++ b/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx@@ -16,9 +16,10 @@ import i18n from "../../../i18n";import { maybe, renderCollection } from "../../../misc";import { ListProps } from "../../../types";import { SaleDetails_sale } from "../../types/SaleDetails";+import { VoucherDetails_voucher } from "../../types/VoucherDetails";-export interface SaleCollectionsProps extends ListProps {- sale: SaleDetails_sale;+export interface DiscountCollectionsProps extends ListProps {+ discount: SaleDetails_sale | VoucherDetails_voucher;onCollectionAssign: () => void;}@@ -33,11 +34,11 @@ const styles = createStyles({width: "60%"}});-const SaleCollections = withStyles(styles, {- name: "SaleCollections"+const DiscountCollections = withStyles(styles, {+ name: "DiscountCollections"})(({- sale,+ discount: sale,classes,disabled,pageInfo,@@ -45,7 +46,7 @@ const SaleCollections = withStyles(styles, {onRowClick,onPreviousPage,onNextPage- }: SaleCollectionsProps & WithStyles<typeof styles>) => (+ }: DiscountCollectionsProps & WithStyles<typeof styles>) => (<Card><CardTitletitle={i18n.t("Collections assigned to {{ saleName }}", {@@ -115,5 +116,5 @@ const SaleCollections = withStyles(styles, {</Card>));-SaleCollections.displayName = "SaleCollections";-export default SaleCollections;+DiscountCollections.displayName = "DiscountCollections";+export default DiscountCollections;diff --git a/saleor/static/dashboard-next/discounts/components/DiscountCollections/index.ts b/saleor/static/dashboard-next/discounts/components/DiscountCollections/index.tsnew file mode 100644index 0000000000..5cd22c3a17--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/DiscountCollections/index.ts@@ -0,0 +1,2 @@+export { default } from "./DiscountCollections";+export * from "./DiscountCollections";diff --git a/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx b/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsxsimilarity index 93%rename from saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsxrename to saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsxindex c2e9f54eb2..7f1dedcea8 100644--- a/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx+++ b/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx@@ -18,9 +18,10 @@ import i18n from "../../../i18n";import { maybe, renderCollection } from "../../../misc";import { ListProps } from "../../../types";import { SaleDetails_sale } from "../../types/SaleDetails";+import { VoucherDetails_voucher } from "../../types/VoucherDetails";export interface SaleProductsProps extends ListProps {- sale: SaleDetails_sale;+ discount: SaleDetails_sale | VoucherDetails_voucher;onProductAssign: () => void;}@@ -35,11 +36,11 @@ const styles = createStyles({width: "40%"}});-const SaleProducts = withStyles(styles, {- name: "SaleProducts"+const DiscountProducts = withStyles(styles, {+ name: "DiscountProducts"})(({- sale,+ discount: sale,classes,disabled,pageInfo,@@ -138,5 +139,5 @@ const SaleProducts = withStyles(styles, {</Card>));-SaleProducts.displayName = "SaleProducts";-export default SaleProducts;+DiscountProducts.displayName = "DiscountProducts";+export default DiscountProducts;diff --git a/saleor/static/dashboard-next/discounts/components/DiscountProducts/index.ts b/saleor/static/dashboard-next/discounts/components/DiscountProducts/index.tsnew file mode 100644index 0000000000..acd26089af--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/DiscountProducts/index.ts@@ -0,0 +1,2 @@+export { default } from "./DiscountProducts";+export * from "./DiscountProducts";diff --git a/saleor/static/dashboard-next/discounts/components/SaleCategories/index.ts b/saleor/static/dashboard-next/discounts/components/SaleCategories/index.tsdeleted file mode 100644index f13d3fd8db..0000000000--- a/saleor/static/dashboard-next/discounts/components/SaleCategories/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { default } from "./SaleCategories";-export * from "./SaleCategories";diff --git a/saleor/static/dashboard-next/discounts/components/SaleCollections/index.ts b/saleor/static/dashboard-next/discounts/components/SaleCollections/index.tsdeleted file mode 100644index d2f259271c..0000000000--- a/saleor/static/dashboard-next/discounts/components/SaleCollections/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { default } from "./SaleCollections";-export * from "./SaleCollections";diff --git a/saleor/static/dashboard-next/discounts/components/SaleContent/SaleContent.tsx b/saleor/static/dashboard-next/discounts/components/SaleContent/SaleContent.tsxdeleted file mode 100644index adb6fb39fd..0000000000--- a/saleor/static/dashboard-next/discounts/components/SaleContent/SaleContent.tsx+++ /dev/null@@ -1,9 +0,0 @@-import { withStyles } from "@material-ui/core/styles";-import * as React from "react";--export interface SaleContentProps {}--const decorate = withStyles(theme => ({ root: {} }));-const SaleContent = decorate<SaleContentProps>(({ classes }) => <div />);-SaleContent.displayName = "SaleContent";-export default SaleContent;diff --git a/saleor/static/dashboard-next/discounts/components/SaleContent/index.ts b/saleor/static/dashboard-next/discounts/components/SaleContent/index.tsdeleted file mode 100644index 7cfec4feb7..0000000000--- a/saleor/static/dashboard-next/discounts/components/SaleContent/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { default } from "./SaleContent";-export * from "./SaleContent";diff --git a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsxindex 8e6b93d3f8..32b9eaed41 100644--- a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx+++ b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx@@ -14,11 +14,11 @@ import { maybe } from "../../../misc";import { ListProps, UserError } from "../../../types";import { SaleType } from "../../../types/globalTypes";import { SaleDetails_sale } from "../../types/SaleDetails";-import SaleCategories from "../SaleCategories";-import SaleCollections from "../SaleCollections";+import DiscountCategories from "../DiscountCategories";+import DiscountCollections from "../DiscountCollections";+import DiscountProducts from "../DiscountProducts";import SaleInfo from "../SaleInfo";import SalePricing from "../SalePricing";-import SaleProducts from "../SaleProducts";import SaleSummary from "../SaleSummary";export interface FormData {@@ -137,34 +137,34 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({</TabContainer><CardSpacer />{activeTab === SaleDetailsPageTab.categories ? (- <SaleCategories+ <DiscountCategoriesdisabled={disabled}onCategoryAssign={onCategoryAssign}onNextPage={onNextPage}onPreviousPage={onPreviousPage}onRowClick={onCategoryClick}pageInfo={pageInfo}- sale={sale}+ discount={sale}/>) : activeTab === SaleDetailsPageTab.collections ? (- <SaleCollections+ <DiscountCollectionsdisabled={disabled}onCollectionAssign={onCollectionAssign}onNextPage={onNextPage}onPreviousPage={onPreviousPage}onRowClick={onCollectionClick}pageInfo={pageInfo}- sale={sale}+ discount={sale}/>) : (- <SaleProducts+ <DiscountProductsdisabled={disabled}onNextPage={onNextPage}onPreviousPage={onPreviousPage}onProductAssign={onProductAssign}onRowClick={onProductClick}pageInfo={pageInfo}- sale={sale}+ discount={sale}/>)}</div>diff --git a/saleor/static/dashboard-next/discounts/components/SalePricing/SalePricing.tsx b/saleor/static/dashboard-next/discounts/components/SalePricing/SalePricing.tsxindex f0433db1e6..670a0dec12 100644--- a/saleor/static/dashboard-next/discounts/components/SalePricing/SalePricing.tsx+++ b/saleor/static/dashboard-next/discounts/components/SalePricing/SalePricing.tsx@@ -1,11 +1,5 @@import Card from "@material-ui/core/Card";import CardContent from "@material-ui/core/CardContent";-import ClickAwayListener from "@material-ui/core/ClickAwayListener";-import Grow from "@material-ui/core/Grow";-import MenuItem from "@material-ui/core/MenuItem";-import Menu from "@material-ui/core/MenuList";-import Paper from "@material-ui/core/Paper";-import Popper from "@material-ui/core/Popper";import {createStyles,Theme,@@ -14,12 +8,11 @@ import {} from "@material-ui/core/styles";import TextField from "@material-ui/core/TextField";import Typography from "@material-ui/core/Typography";-import DropdownIcon from "@material-ui/icons/ArrowDropDown";import * as React from "react";import CardTitle from "../../../components/CardTitle";import Hr from "../../../components/Hr";-import MenuToggle from "../../../components/MenuToggle";+import TextFieldWithChoice from "../../../components/TextFieldWithChoice";import i18n from "../../../i18n";import { SaleType } from "../../../types/globalTypes";import { FormData } from "../SaleDetailsPage";@@ -38,14 +31,6 @@ export interface SalePricingProps {const styles = (theme: Theme) =>createStyles({- adornment: {- alignItems: "center",- cursor: "pointer",- display: "flex"- },- menu: {- zIndex: 10- },root: {display: "grid",gridColumnGap: theme.spacing.unit * 2 + "px",@@ -60,153 +45,76 @@ const styles = (theme: Theme) =>const SalePricing = withStyles(styles, {name: "SalePricing"})(- class SalePricingComponent extends React.Component<- SalePricingProps & WithStyles<typeof styles>- > {- anchor = React.createRef<HTMLDivElement>();-- render() {- const {- classes,- data,- defaultCurrency,- disabled,- errors,- onChange- } = this.props;-- return (- <Card>- <CardTitle title={i18n.t("Pricing")} />- <CardContent className={classes.root}>- <TextField- disabled={disabled}- error={!!errors.value}- helperText={errors.value}- name={"value" as keyof FormData}- onChange={onChange}- label={i18n.t("Discount Value")}- value={data.value}- type="number"- fullWidth- inputProps={{- min: 0- }}- InputProps={{- endAdornment: (- <MenuToggle ariaOwns="user-menu">- {({- open: menuOpen,- actions: { open: openMenu, close: closeMenu }- }) => {- const handleSelect = (value: SaleType) => {- onChange({- target: {- name: "type",- value- }- } as any);- closeMenu();- };-- return (- <>- <div- className={classes.adornment}- ref={this.anchor}- onClick={!menuOpen ? openMenu : undefined}- >- <Typography component="span" variant="caption">- {data.type === SaleType.FIXED- ? defaultCurrency- : "%"}- </Typography>- <DropdownIcon />- </div>- <Popper- open={menuOpen}- anchorEl={this.anchor.current}- transition- disablePortal- placement="bottom-end"- className={classes.menu}- >- {({ TransitionProps, placement }) => (- <Grow- {...TransitionProps}- style={{- transformOrigin:- placement === "bottom"- ? "right top"- : "right bottom"- }}- >- <Paper>- <ClickAwayListener- onClickAway={closeMenu}- mouseEvent="onClick"- >- <Menu>- <MenuItem- onClick={() =>- handleSelect(SaleType.FIXED)- }- >- {defaultCurrency}- </MenuItem>- <MenuItem- onClick={() =>- handleSelect(SaleType.PERCENTAGE)- }- >- %- </MenuItem>- </Menu>- </ClickAwayListener>- </Paper>- </Grow>- )}- </Popper>- </>- );- }}- </MenuToggle>- )- }}- />- </CardContent>- <Hr />- <CardContent className={classes.root}>- <Typography className={classes.subheading} variant="subheading">- {i18n.t("Time Frame")}- </Typography>- <TextField- disabled={disabled}- error={!!errors.startDate}- helperText={errors.startDate}- name={"startDate" as keyof FormData}- onChange={onChange}- label={i18n.t("Start Date")}- value={data.startDate}- type="date"- fullWidth- />- <TextField- disabled={disabled}- error={!!errors.endDate}- helperText={errors.endDate}- name={"endDate" as keyof FormData}- onChange={onChange}- label={i18n.t("End Date")}- value={data.endDate}- type="date"- fullWidth- />- </CardContent>- </Card>- );- }- }+ ({+ classes,+ data,+ defaultCurrency,+ disabled,+ errors,+ onChange+ }: SalePricingProps & WithStyles<typeof styles>) => (+ <Card>+ <CardTitle title={i18n.t("Pricing")} />+ <CardContent className={classes.root}>+ <TextFieldWithChoice+ disabled={disabled}+ ChoiceProps={{+ label: data.type === SaleType.FIXED ? defaultCurrency : "%",+ name: "type",+ values: [+ {+ label: defaultCurrency,+ value: SaleType.FIXED+ },+ {+ label: "%",+ value: SaleType.PERCENTAGE+ }+ ]+ }}+ error={!!errors.value}+ helperText={errors.value}+ name={"value" as keyof FormData}+ onChange={onChange}+ label={i18n.t("Discount Value")}+ value={data.value}+ type="number"+ fullWidth+ inputProps={{+ min: 0+ }}+ />+ </CardContent>+ <Hr />+ <CardContent className={classes.root}>+ <Typography className={classes.subheading} variant="subheading">+ {i18n.t("Time Frame")}+ </Typography>+ <TextField+ disabled={disabled}+ error={!!errors.startDate}+ helperText={errors.startDate}+ name={"startDate" as keyof FormData}+ onChange={onChange}+ label={i18n.t("Start Date")}+ value={data.startDate}+ type="date"+ fullWidth+ />+ <TextField+ disabled={disabled}+ error={!!errors.endDate}+ helperText={errors.endDate}+ name={"endDate" as keyof FormData}+ onChange={onChange}+ label={i18n.t("End Date")}+ value={data.endDate}+ type="date"+ fullWidth+ />+ </CardContent>+ </Card>+ ));SalePricing.displayName = "SalePricing";export default SalePricing;diff --git a/saleor/static/dashboard-next/discounts/components/SaleProducts/index.ts b/saleor/static/dashboard-next/discounts/components/SaleProducts/index.tsdeleted file mode 100644index b3905aca28..0000000000--- a/saleor/static/dashboard-next/discounts/components/SaleProducts/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { default } from "./SaleProducts";-export * from "./SaleProducts";diff --git a/saleor/static/dashboard-next/discounts/components/VoucherCountries/VoucherCountries.tsx b/saleor/static/dashboard-next/discounts/components/VoucherCountries/VoucherCountries.tsxnew file mode 100644index 0000000000..5896a8d970--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/VoucherCountries/VoucherCountries.tsx@@ -0,0 +1,135 @@+import Button from "@material-ui/core/Button";+import Card from "@material-ui/core/Card";+import IconButton from "@material-ui/core/IconButton";+import {+ createStyles,+ Theme,+ withStyles,+ WithStyles+} from "@material-ui/core/styles";+import Table from "@material-ui/core/Table";+import TableBody from "@material-ui/core/TableBody";+import TableCell from "@material-ui/core/TableCell";+import TableRow from "@material-ui/core/TableRow";+import ArrowDropDownIcon from "@material-ui/icons/ArrowDropDown";+import CloseIcon from "@material-ui/icons/Close";+import classNames from "classnames";+import * as React from "react";++import CardTitle from "../../../components/CardTitle";+import Skeleton from "../../../components/Skeleton";+import Toggle from "../../../components/Toggle";+import i18n from "../../../i18n";+import { maybe, renderCollection } from "../../../misc";+import { VoucherDetails_voucher } from "../../types/VoucherDetails";++export interface VoucherCountriesProps {+ disabled: boolean;+ voucher: VoucherDetails_voucher;+ onCountryAssign: () => void;+ onCountryUnassign: (country: string) => void;+}++const styles = (theme: Theme) =>+ createStyles({+ arrow: {+ marginRight: theme.spacing.unit * 1.5+ },+ pointer: {+ cursor: "pointer"+ },+ rotate: {+ transform: "rotate(180deg)"+ },+ textRight: {+ textAlign: "right"+ },+ wideColumn: {+ width: "100%"+ }+ });++const VoucherCountries = withStyles(styles, {+ name: "VoucherCountries"+})(+ ({+ classes,+ disabled,+ voucher,+ onCountryAssign,+ onCountryUnassign+ }: VoucherCountriesProps & WithStyles<typeof styles>) => (+ <Toggle>+ {(isCollapsed, { toggle: toggleCollapse }) => (+ <Card>+ <CardTitle+ title={i18n.t("Countries assigned to {{ voucherName }}", {+ voucherName: maybe(() => voucher.name)+ })}+ toolbar={+ <Button+ variant="flat"+ color="secondary"+ onClick={onCountryAssign}+ >+ {i18n.t("Assign countries")}+ </Button>+ }+ />+ <Table>+ <TableBody>+ {maybe(() => (+ <TableRow className={classes.pointer} onClick={toggleCollapse}>+ <TableCell className={classes.wideColumn}>+ {i18n.t("{{ number }} Countries", {+ context: "number of countries",+ number: voucher.countries.length+ })}+ </TableCell>+ <TableCell className={classes.textRight}>+ <ArrowDropDownIcon+ className={classNames({+ [classes.arrow]: true,+ [classes.rotate]: !isCollapsed+ })}+ />+ </TableCell>+ </TableRow>+ ))}+ {!isCollapsed &&+ renderCollection(+ maybe(() => voucher.countries),+ country => (+ <TableRow key={country ? country.code : "skeleton"}>+ <TableCell>+ {maybe<React.ReactNode>(+ () => country.country,+ <Skeleton />+ )}+ </TableCell>+ <TableCell className={classes.textRight}>+ <IconButton+ disabled={!country || disabled}+ onClick={() => onCountryUnassign(country.code)}+ >+ <CloseIcon />+ </IconButton>+ </TableCell>+ </TableRow>+ ),+ () => (+ <TableRow>+ <TableCell colSpan={2}>+ {i18n.t("No categories found")}+ </TableCell>+ </TableRow>+ )+ )}+ </TableBody>+ </Table>+ </Card>+ )}+ </Toggle>+ )+);+export default VoucherCountries;diff --git a/saleor/static/dashboard-next/discounts/components/VoucherCountries/index.ts b/saleor/static/dashboard-next/discounts/components/VoucherCountries/index.tsnew file mode 100644index 0000000000..503b300d5d--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/VoucherCountries/index.ts@@ -0,0 +1,2 @@+export { default } from "./VoucherCountries";+export * from "./VoucherCountries";diff --git a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsxindex de915cfd16..ffb7f28374 100644--- a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx+++ b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx@@ -1,27 +1,55 @@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 { maybe } from "../../../misc";import { ListProps } from "../../../types";-import { VoucherType } from "../../../types/globalTypes";+import {+ VoucherDiscountValueType,+ VoucherType+} from "../../../types/globalTypes";import { VoucherDetails_voucher } from "../../types/VoucherDetails";+import DiscountCategories from "../DiscountCategories";+import DiscountCollections from "../DiscountCollections";+import DiscountProducts from "../DiscountProducts";+import VoucherCountries from "../VoucherCountries";import VoucherInfo from "../VoucherInfo";+import VoucherOptions from "../VoucherOptions";import VoucherSummary from "../VoucherSummary";export interface FormData {+ applyOncePerOrder: boolean;code: string;+ discountType: VoucherDiscountValueType;+ endDate: string;+ minAmountSpent: number;name: string;+ startDate: string;type: VoucherType;+ usageLimit: number;+ value: number;}export interface VoucherDetailsPagePropsextends Pick<ListProps, Exclude<keyof ListProps, "onRowClick">> {defaultCurrency: string;+ saveButtonBarState: ConfirmButtonTransitionState;voucher: VoucherDetails_voucher;onBack: () => void;+ onCategoryAssign: () => void;+ onCategoryClick: (id: string) => () => void;+ onCountryAssign: () => void;+ onCountryUnassign: (code: string) => () => void;+ onCollectionAssign: () => void;+ onCollectionClick: (id: string) => () => void;+ onProductAssign: () => void;+ onProductClick: (id: string) => () => void;+ onRemove: () => void;onSubmit: (data: FormData) => void;}@@ -29,26 +57,93 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({defaultCurrency,disabled,pageInfo,+ saveButtonBarState,voucher,onBack,+ onCategoryAssign,+ onCategoryClick,+ onCountryAssign,+ onCountryUnassign,+ onCollectionAssign,+ onCollectionClick,onNextPage,onPreviousPage,+ onProductAssign,+ onProductClick,+ onRemove,onSubmit}) => {const initialForm: FormData = {- code: maybe(() => voucher.code),- name: maybe(() => voucher.name),- type: maybe(() => voucher.type)+ applyOncePerOrder: maybe(() => voucher.applyOncePerOrder, false),+ code: maybe(() => voucher.code, ""),+ discountType: maybe(+ () => voucher.discountValueType,+ VoucherDiscountValueType.FIXED+ ),+ endDate: maybe(() => voucher.endDate, ""),+ minAmountSpent: maybe(() => voucher.minAmountSpent.amount, 0),+ name: maybe(() => voucher.name, ""),+ startDate: maybe(() => voucher.startDate, ""),+ type: maybe(() => voucher.type, VoucherType.VALUE),+ usageLimit: maybe(() => voucher.usageLimit || 0, 0),+ value: maybe(() => voucher.discountValue, 0)};return (<Form initial={initialForm} onSubmit={onSubmit}>- {({ change, data, errors, hasChanged, submit }) => (+ {({ change, data, errors: formErrors, hasChanged, submit }) => (<Container width="md"><PageHeader title={maybe(() => voucher.name)} onBack={onBack} /><Grid><div><VoucherInfo data={data} disabled={disabled} onChange={change} />+ <CardSpacer />+ <VoucherOptions+ data={data}+ disabled={disabled}+ defaultCurrency={defaultCurrency}+ errors={formErrors}+ 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.SHIPPING ? (+ <VoucherCountries+ disabled={disabled}+ onCountryAssign={onCountryAssign}+ onCountryUnassign={onCountryUnassign}+ voucher={voucher}+ />+ ) : null}</div><div><VoucherSummary@@ -57,6 +152,13 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({/></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/VoucherOptions/VoucherOptions.tsx b/saleor/static/dashboard-next/discounts/components/VoucherOptions/VoucherOptions.tsxnew file mode 100644index 0000000000..4ac5eab70b--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/VoucherOptions/VoucherOptions.tsx@@ -0,0 +1,176 @@+import Card from "@material-ui/core/Card";+import CardContent from "@material-ui/core/CardContent";+import {+ createStyles,+ Theme,+ withStyles,+ WithStyles+} from "@material-ui/core/styles";+import TextField from "@material-ui/core/TextField";+import Typography from "@material-ui/core/Typography";+import * as React from "react";++import CardTitle from "../../../components/CardTitle";+import ControlledSwitch from "../../../components/ControlledSwitch";+import FormSpacer from "../../../components/FormSpacer";+import Hr from "../../../components/Hr";+import TextFieldWithChoice from "../../../components/TextFieldWithChoice";+import i18n from "../../../i18n";+import { VoucherDiscountValueType } from "../../../types/globalTypes";+import { FormData } from "../VoucherDetailsPage";++interface VoucherOptionsProps {+ data: FormData;+ defaultCurrency: string;+ disabled: boolean;+ errors: Partial<{+ discountType: string;+ endDate: string;+ minAmountSpent: string;+ startDate: string;+ usageLimit: string;+ value: string;+ }>;+ onChange: (event: React.ChangeEvent<any>) => void;+}++const styles = (theme: Theme) =>+ createStyles({+ root: {+ display: "grid",+ gridColumnGap: theme.spacing.unit * 2 + "px",+ gridTemplateColumns: "1fr 1fr"+ }+ });++const VoucherOptions = withStyles(styles, {+ name: "VoucherOptions"+})(+ ({+ classes,+ data,+ defaultCurrency,+ disabled,+ errors,+ onChange+ }: VoucherOptionsProps & WithStyles<typeof styles>) => (+ <Card>+ <CardTitle title={i18n.t("Detailed Informations")} />+ <CardContent className={classes.root}>+ <TextFieldWithChoice+ disabled={disabled}+ ChoiceProps={{+ label:+ data.discountType === VoucherDiscountValueType.FIXED+ ? defaultCurrency+ : "%",+ name: "discountType" as keyof FormData,+ values: [+ {+ label: defaultCurrency,+ value: VoucherDiscountValueType.FIXED+ },+ {+ label: "%",+ value: VoucherDiscountValueType.PERCENTAGE+ }+ ]+ }}+ error={!!errors.value}+ helperText={errors.value}+ name={"value" as keyof FormData}+ onChange={onChange}+ label={i18n.t("Discount Value")}+ value={data.value}+ type="number"+ fullWidth+ inputProps={{+ min: 0+ }}+ />+ <TextField+ disabled={disabled}+ error={!!errors.usageLimit}+ helperText={errors.usageLimit || i18n.t("Optional")}+ name={"usageLimit" as keyof FormData}+ value={data.usageLimit}+ onChange={onChange}+ label={i18n.t("Usage Limit")}+ type="number"+ inputProps={{+ min: 0+ }}+ fullWidth+ />+ </CardContent>+ <Hr />+ <CardContent>+ <Typography variant="subheading">+ {i18n.t("Discount Specific Information")}+ </Typography>+ <FormSpacer />+ <div className={classes.root}>+ <TextField+ disabled={disabled}+ error={!!errors.minAmountSpent}+ helperText={errors.minAmountSpent || i18n.t("Optional")}+ name={"minAmountSpent" as keyof FormData}+ value={data.minAmountSpent}+ onChange={onChange}+ label={i18n.t("Minimum order value")}+ fullWidth+ />+ </div>+ <FormSpacer />+ <ControlledSwitch+ checked={data.applyOncePerOrder}+ label={+ <>+ {i18n.t("Only once per order", {+ context: "voucher application"+ })}+ <Typography variant="caption">+ {i18n.t(+ "If this option is disabled, discount will be counted for every eligible product"+ )}+ </Typography>+ </>+ }+ onChange={onChange}+ name={"applyOncePerOrder" as keyof FormData}+ disabled={disabled}+ />+ </CardContent>+ <Hr />+ <CardContent>+ <Typography variant="subheading">{i18n.t("Time Frame")}</Typography>+ <FormSpacer />+ <div className={classes.root}>+ <TextField+ disabled={disabled}+ error={!!errors.startDate}+ helperText={errors.startDate}+ name={"startDate" as keyof FormData}+ onChange={onChange}+ label={i18n.t("Start Date")}+ value={data.startDate}+ type="date"+ fullWidth+ />+ <TextField+ disabled={disabled}+ error={!!errors.endDate}+ helperText={errors.endDate}+ name={"endDate" as keyof FormData}+ onChange={onChange}+ label={i18n.t("End Date")}+ value={data.endDate}+ type="date"+ fullWidth+ />+ </div>+ </CardContent>+ </Card>+ )+);+export default VoucherOptions;diff --git a/saleor/static/dashboard-next/discounts/components/VoucherOptions/index.ts b/saleor/static/dashboard-next/discounts/components/VoucherOptions/index.tsnew file mode 100644index 0000000000..3b2411d350--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/VoucherOptions/index.ts@@ -0,0 +1,2 @@+export { default } from "./VoucherOptions";+export * from "./VoucherOptions";diff --git a/saleor/static/dashboard-next/discounts/fixtures.ts b/saleor/static/dashboard-next/discounts/fixtures.tsindex 048b4c65e4..bb2bab755f 100644--- a/saleor/static/dashboard-next/discounts/fixtures.ts+++ b/saleor/static/dashboard-next/discounts/fixtures.ts@@ -257,7 +257,13 @@ export const voucherDetails: VoucherDetails_voucher = {},totalCount: 0},- countries: VoucherCountries.DE,+ countries: [+ {+ __typename: "CountryDisplay",+ code: "DE",+ country: "Germany"+ }+ ],discountValue: 25,discountValueType: VoucherDiscountValueType.FIXED,endDate: null,diff --git a/saleor/static/dashboard-next/discounts/mutations.ts b/saleor/static/dashboard-next/discounts/mutations.tsnew file mode 100644index 0000000000..97e93aca8d--- /dev/null+++ b/saleor/static/dashboard-next/discounts/mutations.ts@@ -0,0 +1,23 @@+import gql from "graphql-tag";++import { TypedMutation } from "../mutations";+import { saleFragment } from "./queries";+import { SaleUpdate, SaleUpdateVariables } from "./types/SaleUpdate";++const saleUpdate = gql`+ ${saleFragment}+ mutation SaleUpdate($input: SaleInput!, $id: ID!) {+ saleUpdate(id: $id, input: $input) {+ errors {+ field+ message+ }+ sale {+ ...SaleFragment+ }+ }+ }+`;+export const TypedSaleUpdate = TypedMutation<SaleUpdate, SaleUpdateVariables>(+ saleUpdate+);diff --git a/saleor/static/dashboard-next/discounts/queries.ts b/saleor/static/dashboard-next/discounts/queries.tsindex bb2863b4b9..d5f32f1da0 100644--- a/saleor/static/dashboard-next/discounts/queries.ts+++ b/saleor/static/dashboard-next/discounts/queries.ts@@ -9,6 +9,72 @@ import {} from "./types/VoucherDetails";import { VoucherList, VoucherListVariables } from "./types/VoucherList";+export const saleFragment = gql`+ fragment SaleFragment on Sale {+ id+ name+ type+ startDate+ endDate+ value+ }+`;++export const saleDetailsFragment = gql`+ ${pageInfoFragment}+ ${saleFragment}+ fragment SaleDetailsFragment on Sale {+ ...SaleFragment+ products(after: $after, before: $before, first: $first, last: $last) {+ edges {+ node {+ id+ name+ isPublished+ productType {+ id+ name+ }+ thumbnail {+ url+ }+ }+ }+ pageInfo {+ ...PageInfoFragment+ }+ }+ categories(after: $after, before: $before, first: $first, last: $last) {+ edges {+ node {+ id+ name+ products {+ totalCount+ }+ }+ }+ pageInfo {+ ...PageInfoFragment+ }+ }+ collections(after: $after, before: $before, first: $first, last: $last) {+ edges {+ node {+ id+ name+ products {+ totalCount+ }+ }+ }+ pageInfo {+ ...PageInfoFragment+ }+ }+ }+`;+export const voucherFragment = gql`fragment VoucherFragment on Voucher {id@@ -85,22 +151,21 @@ export const voucherDetailsFragment = gql`...PageInfoFragment}}- countries+ countries {+ code+ country+ }}`;export const saleList = gql`${pageInfoFragment}+ ${saleFragment}query SaleList($after: String, $before: String, $first: Int, $last: Int) {sales(after: $after, before: $before, first: $first, last: $last) {edges {node {- id- name- type- startDate- endDate- value+ ...SaleFragment}}pageInfo {@@ -132,7 +197,7 @@ export const TypedVoucherList = TypedQuery<VoucherList, VoucherListVariables>();export const saleDetails = gql`- ${pageInfoFragment}+ ${saleDetailsFragment}query SaleDetails($id: ID!$after: String@@ -141,59 +206,7 @@ export const saleDetails = gql`$last: Int) {sale(id: $id) {- id- name- type- value- products(after: $after, before: $before, first: $first, last: $last) {- edges {- node {- id- name- isPublished- productType {- id- name- }- thumbnail {- url- }- }- }- pageInfo {- ...PageInfoFragment- }- }- categories(after: $after, before: $before, first: $first, last: $last) {- edges {- node {- id- name- products {- totalCount- }- }- }- pageInfo {- ...PageInfoFragment- }- }- collections(after: $after, before: $before, first: $first, last: $last) {- edges {- node {- id- name- products {- totalCount- }- }- }- pageInfo {- ...PageInfoFragment- }- }- startDate- endDate+ ...SaleDetailsFragment}}`;diff --git a/saleor/static/dashboard-next/discounts/types/SaleDetails.ts b/saleor/static/dashboard-next/discounts/types/SaleDetails.tsindex b5bdf8c717..0e9a0dc9c3 100644--- a/saleor/static/dashboard-next/discounts/types/SaleDetails.ts+++ b/saleor/static/dashboard-next/discounts/types/SaleDetails.ts@@ -113,12 +113,12 @@ export interface SaleDetails_sale {id: string;name: string;type: SaleType;+ startDate: any;+ endDate: any | null;value: number;products: SaleDetails_sale_products | null;categories: SaleDetails_sale_categories | null;collections: SaleDetails_sale_collections | null;- startDate: any;- endDate: any | null;}export interface SaleDetails {diff --git a/saleor/static/dashboard-next/discounts/types/SaleDetailsFragment.ts b/saleor/static/dashboard-next/discounts/types/SaleDetailsFragment.tsnew file mode 100644index 0000000000..67c14f212c--- /dev/null+++ b/saleor/static/dashboard-next/discounts/types/SaleDetailsFragment.ts@@ -0,0 +1,122 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { SaleType } from "./../../types/globalTypes";++// ====================================================+// GraphQL fragment: SaleDetailsFragment+// ====================================================++export interface SaleDetailsFragment_products_edges_node_productType {+ __typename: "ProductType";+ id: string;+ name: string;+}++export interface SaleDetailsFragment_products_edges_node_thumbnail {+ __typename: "Image";+ url: string;+}++export interface SaleDetailsFragment_products_edges_node {+ __typename: "Product";+ id: string;+ name: string;+ isPublished: boolean;+ productType: SaleDetailsFragment_products_edges_node_productType;+ thumbnail: SaleDetailsFragment_products_edges_node_thumbnail | null;+}++export interface SaleDetailsFragment_products_edges {+ __typename: "ProductCountableEdge";+ node: SaleDetailsFragment_products_edges_node;+}++export interface SaleDetailsFragment_products_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface SaleDetailsFragment_products {+ __typename: "ProductCountableConnection";+ edges: SaleDetailsFragment_products_edges[];+ pageInfo: SaleDetailsFragment_products_pageInfo;+}++export interface SaleDetailsFragment_categories_edges_node_products {+ __typename: "ProductCountableConnection";+ totalCount: number | null;+}++export interface SaleDetailsFragment_categories_edges_node {+ __typename: "Category";+ id: string;+ name: string;+ products: SaleDetailsFragment_categories_edges_node_products | null;+}++export interface SaleDetailsFragment_categories_edges {+ __typename: "CategoryCountableEdge";+ node: SaleDetailsFragment_categories_edges_node;+}++export interface SaleDetailsFragment_categories_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface SaleDetailsFragment_categories {+ __typename: "CategoryCountableConnection";+ edges: SaleDetailsFragment_categories_edges[];+ pageInfo: SaleDetailsFragment_categories_pageInfo;+}++export interface SaleDetailsFragment_collections_edges_node_products {+ __typename: "ProductCountableConnection";+ totalCount: number | null;+}++export interface SaleDetailsFragment_collections_edges_node {+ __typename: "Collection";+ id: string;+ name: string;+ products: SaleDetailsFragment_collections_edges_node_products | null;+}++export interface SaleDetailsFragment_collections_edges {+ __typename: "CollectionCountableEdge";+ node: SaleDetailsFragment_collections_edges_node;+}++export interface SaleDetailsFragment_collections_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface SaleDetailsFragment_collections {+ __typename: "CollectionCountableConnection";+ edges: SaleDetailsFragment_collections_edges[];+ pageInfo: SaleDetailsFragment_collections_pageInfo;+}++export interface SaleDetailsFragment {+ __typename: "Sale";+ id: string;+ name: string;+ type: SaleType;+ startDate: any;+ endDate: any | null;+ value: number;+ products: SaleDetailsFragment_products | null;+ categories: SaleDetailsFragment_categories | null;+ collections: SaleDetailsFragment_collections | null;+}diff --git a/saleor/static/dashboard-next/discounts/types/SaleFragment.ts b/saleor/static/dashboard-next/discounts/types/SaleFragment.tsnew file mode 100644index 0000000000..73064dea3c--- /dev/null+++ b/saleor/static/dashboard-next/discounts/types/SaleFragment.ts@@ -0,0 +1,18 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { SaleType } from "./../../types/globalTypes";++// ====================================================+// GraphQL fragment: SaleFragment+// ====================================================++export interface SaleFragment {+ __typename: "Sale";+ id: string;+ name: string;+ type: SaleType;+ startDate: any;+ endDate: any | null;+ value: number;+}diff --git a/saleor/static/dashboard-next/discounts/types/SaleUpdate.ts b/saleor/static/dashboard-next/discounts/types/SaleUpdate.tsnew file mode 100644index 0000000000..a3ea580009--- /dev/null+++ b/saleor/static/dashboard-next/discounts/types/SaleUpdate.ts@@ -0,0 +1,39 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { SaleInput, SaleType } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: SaleUpdate+// ====================================================++export interface SaleUpdate_saleUpdate_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface SaleUpdate_saleUpdate_sale {+ __typename: "Sale";+ id: string;+ name: string;+ type: SaleType;+ startDate: any;+ endDate: any | null;+ value: number;+}++export interface SaleUpdate_saleUpdate {+ __typename: "SaleUpdate";+ errors: SaleUpdate_saleUpdate_errors[] | null;+ sale: SaleUpdate_saleUpdate_sale | null;+}++export interface SaleUpdate {+ saleUpdate: SaleUpdate_saleUpdate | null;+}++export interface SaleUpdateVariables {+ input: SaleInput;+ id: string;+}diff --git a/saleor/static/dashboard-next/discounts/types/VoucherDetails.ts b/saleor/static/dashboard-next/discounts/types/VoucherDetails.tsindex c76c986d39..0d9bcec683 100644--- a/saleor/static/dashboard-next/discounts/types/VoucherDetails.ts+++ b/saleor/static/dashboard-next/discounts/types/VoucherDetails.ts@@ -1,7 +1,7 @@/* tslint:disable */// This file was automatically generated and should not be edited.-import { VoucherDiscountValueType, VoucherType, VoucherCountries } from "./../../types/globalTypes";+import { VoucherDiscountValueType, VoucherType } from "./../../types/globalTypes";// ====================================================// GraphQL query operation: VoucherDetails@@ -117,6 +117,12 @@ export interface VoucherDetails_voucher_categories {pageInfo: VoucherDetails_voucher_categories_pageInfo;}+export interface VoucherDetails_voucher_countries {+ __typename: "CountryDisplay";+ code: string;+ country: string;+}+export interface VoucherDetails_voucher {__typename: "Voucher";id: string;@@ -134,7 +140,7 @@ export interface VoucherDetails_voucher {products: VoucherDetails_voucher_products | null;collections: VoucherDetails_voucher_collections | null;categories: VoucherDetails_voucher_categories | null;- countries: VoucherCountries;+ countries: (VoucherDetails_voucher_countries | null)[] | null;}export interface VoucherDetails {diff --git a/saleor/static/dashboard-next/discounts/types/VoucherDetailsFragment.ts b/saleor/static/dashboard-next/discounts/types/VoucherDetailsFragment.tsindex 37ce2f95ad..b763a8d6d8 100644--- a/saleor/static/dashboard-next/discounts/types/VoucherDetailsFragment.ts+++ b/saleor/static/dashboard-next/discounts/types/VoucherDetailsFragment.ts@@ -1,7 +1,7 @@/* tslint:disable */// This file was automatically generated and should not be edited.-import { VoucherDiscountValueType, VoucherType, VoucherCountries } from "./../../types/globalTypes";+import { VoucherDiscountValueType, VoucherType } from "./../../types/globalTypes";// ====================================================// GraphQL fragment: VoucherDetailsFragment@@ -117,6 +117,12 @@ export interface VoucherDetailsFragment_categories {pageInfo: VoucherDetailsFragment_categories_pageInfo;}+export interface VoucherDetailsFragment_countries {+ __typename: "CountryDisplay";+ code: string;+ country: string;+}+export interface VoucherDetailsFragment {__typename: "Voucher";id: string;@@ -134,5 +140,5 @@ export interface VoucherDetailsFragment {products: VoucherDetailsFragment_products | null;collections: VoucherDetailsFragment_collections | null;categories: VoucherDetailsFragment_categories | null;- countries: VoucherCountries;+ countries: (VoucherDetailsFragment_countries | null)[] | null;}diff --git a/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx b/saleor/static/dashboard-next/discounts/views/SaleDetails.tsxindex 8a168158be..60a737ca6a 100644--- a/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx+++ b/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx@@ -8,11 +8,13 @@ import { createPaginationState, Paginator } from "../../components/Paginator";import Shop from "../../components/Shop";import { WindowTitle } from "../../components/WindowTitle";import i18n from "../../i18n";-import { maybe } from "../../misc";+import { getMutationState, maybe } from "../../misc";import { productUrl } from "../../products/urls";+import { DiscountValueTypeEnum, SaleType } from "../../types/globalTypes";import SaleDetailsPage, {SaleDetailsPageTab} from "../components/SaleDetailsPage";+import { TypedSaleUpdate } from "../mutations";import { TypedSaleDetails } from "../queries";import { saleListUrl } from "../urls";@@ -29,6 +31,12 @@ interface SaleDetailsProps {params: SaleDetailsQueryParams;}+function discountValueTypeEnum(type: SaleType): DiscountValueTypeEnum {+ return type.toString() === DiscountValueTypeEnum.FIXED+ ? DiscountValueTypeEnum.FIXED+ : DiscountValueTypeEnum.PERCENTAGE;+}+export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({id,params@@ -48,46 +56,78 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({}));return (- <TypedSaleDetails- displayLoader- variables={{ id, ...paginationState }}- >- {({ data, loading }) => {- const pageInfo =- params.tab === SaleDetailsPageTab.categories- ? maybe(() => data.sale.categories.pageInfo)- : params.tab === SaleDetailsPageTab.collections- ? maybe(() => data.sale.collections.pageInfo)- : maybe(() => data.sale.products.pageInfo);+ <TypedSaleUpdate>+ {(saleUpdate, saleUpdateOpts) => (+ <TypedSaleDetails+ displayLoader+ variables={{ id, ...paginationState }}+ >+ {({ data, loading }) => {+ const pageInfo =+ params.tab === SaleDetailsPageTab.categories+ ? maybe(() => data.sale.categories.pageInfo)+ : params.tab === SaleDetailsPageTab.collections+ ? maybe(() => data.sale.collections.pageInfo)+ : maybe(() => data.sale.products.pageInfo);+ const formTransitionState = getMutationState(+ saleUpdateOpts.called,+ saleUpdateOpts.loading,+ maybe(() => saleUpdateOpts.data.saleUpdate.errors)+ );- return (- <Paginator- pageInfo={pageInfo}- paginationState={paginationState}- queryString={params}- >- {({ loadNextPage, loadPreviousPage, pageInfo }) => (- <SaleDetailsPage- defaultCurrency={maybe(() => shop.defaultCurrency)}- sale={data.sale}- disabled={loading}+ return (+ <PaginatorpageInfo={pageInfo}- onNextPage={loadNextPage}- onPreviousPage={loadPreviousPage}- onCategoryClick={id => () =>- navigate(categoryUrl(id))}- onCollectionClick={id => () =>- navigate(collectionUrl(id))}- onProductClick={id => () => navigate(productUrl(id))}- activeTab={params.tab}- onBack={() => navigate(saleListUrl)}- onTabClick={changeTab}- />- )}- </Paginator>- );- }}- </TypedSaleDetails>+ paginationState={paginationState}+ queryString={params}+ >+ {({ loadNextPage, loadPreviousPage, pageInfo }) => (+ <SaleDetailsPage+ defaultCurrency={maybe(+ () => shop.defaultCurrency+ )}+ sale={maybe(() => data.sale)}+ disabled={loading}+ pageInfo={pageInfo}+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ onCategoryClick={id => () =>+ navigate(categoryUrl(id))}+ onCollectionClick={id => () =>+ navigate(collectionUrl(id))}+ onProductClick={id => () =>+ navigate(productUrl(id))}+ activeTab={params.tab}+ onBack={() => navigate(saleListUrl)}+ onTabClick={changeTab}+ onSubmit={formData =>+ saleUpdate({+ variables: {+ id,+ input: {+ endDate:+ formData.endDate === ""+ ? null+ : new Date(formData.endDate),+ name: formData.name,+ startDate: new Date(formData.startDate),+ type: discountValueTypeEnum(+ formData.type+ ),+ value: formData.value+ }+ }+ })+ }+ saveButtonBarState={formTransitionState}+ />+ )}+ </Paginator>+ );+ }}+ </TypedSaleDetails>+ )}+ </TypedSaleUpdate>);}}</Navigator>diff --git a/saleor/static/dashboard-next/storybook/stories/discounts/VoucherDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/discounts/VoucherDetailsPage.tsxindex 7a8e655019..bdd86ac5f7 100644--- a/saleor/static/dashboard-next/storybook/stories/discounts/VoucherDetailsPage.tsx+++ b/saleor/static/dashboard-next/storybook/stories/discounts/VoucherDetailsPage.tsx@@ -12,10 +12,21 @@ const props: VoucherDetailsPageProps = {...pageListProps.default,defaultCurrency: "USD",onBack: () => undefined,+ onCategoryAssign: () => undefined,+ onCategoryClick: () => undefined,+ onCollectionAssign: () => undefined,+ onCollectionClick: () => undefined,+ onCountryAssign: () => undefined,+ onCountryUnassign: () => undefined,+ onProductAssign: () => undefined,+ onProductClick: () => undefined,+ onRemove: () => undefined,+ onSubmit: () => undefined,+ saveButtonBarState: "default",voucher: voucherDetails};-storiesOf("Views / Discounts / Voucher Details", module)+storiesOf("Views / Discounts / Voucher details", module).addDecorator(Decorator).add("default", () => <VoucherDetailsPage {...props} />).add("loading", () => (diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.tsindex 90e7209a5a..1f99bf92f8 100644--- a/saleor/static/dashboard-next/types/globalTypes.ts+++ b/saleor/static/dashboard-next/types/globalTypes.ts@@ -15,6 +15,11 @@ export enum AuthorizationKeyType {GOOGLE_OAUTH2 = "GOOGLE_OAUTH2",}+export enum DiscountValueTypeEnum {+ FIXED = "FIXED",+ PERCENTAGE = "PERCENTAGE",+}+export enum FulfillmentStatus {CANCELED = "CANCELED",FULFILLED = "FULFILLED",@@ -124,259 +129,6 @@ export enum TaxRateType {WINE = "WINE",}-export enum VoucherCountries {- AD = "AD",- AE = "AE",- AF = "AF",- AG = "AG",- AI = "AI",- AL = "AL",- AM = "AM",- AO = "AO",- AQ = "AQ",- AR = "AR",- AS = "AS",- AT = "AT",- AU = "AU",- AW = "AW",- AX = "AX",- AZ = "AZ",- BA = "BA",- BB = "BB",- BD = "BD",- BE = "BE",- BF = "BF",- BG = "BG",- BH = "BH",- BI = "BI",- BJ = "BJ",- BL = "BL",- BM = "BM",- BN = "BN",- BO = "BO",- BQ = "BQ",- BR = "BR",- BS = "BS",- BT = "BT",- BV = "BV",- BW = "BW",- BY = "BY",- BZ = "BZ",- CA = "CA",- CC = "CC",- CD = "CD",- CF = "CF",- CG = "CG",- CH = "CH",- CI = "CI",- CK = "CK",- CL = "CL",- CM = "CM",- CN = "CN",- CO = "CO",- CR = "CR",- CU = "CU",- CV = "CV",- CW = "CW",- CX = "CX",- CY = "CY",- CZ = "CZ",- DE = "DE",- DJ = "DJ",- DK = "DK",- DM = "DM",- DO = "DO",- DZ = "DZ",- EC = "EC",- EE = "EE",- EG = "EG",- EH = "EH",- ER = "ER",- ES = "ES",- ET = "ET",- EU = "EU",- FI = "FI",- FJ = "FJ",- FK = "FK",- FM = "FM",- FO = "FO",- FR = "FR",- GA = "GA",- GB = "GB",- GD = "GD",- GE = "GE",- GF = "GF",- GG = "GG",- GH = "GH",- GI = "GI",- GL = "GL",- GM = "GM",- GN = "GN",- GP = "GP",- GQ = "GQ",- GR = "GR",- GS = "GS",- GT = "GT",- GU = "GU",- GW = "GW",- GY = "GY",- HK = "HK",- HM = "HM",- HN = "HN",- HR = "HR",- HT = "HT",- HU = "HU",- ID = "ID",- IE = "IE",- IL = "IL",- IM = "IM",- IN = "IN",- IO = "IO",- IQ = "IQ",- IR = "IR",- IS = "IS",- IT = "IT",- JE = "JE",- JM = "JM",- JO = "JO",- JP = "JP",- KE = "KE",- KG = "KG",- KH = "KH",- KI = "KI",- KM = "KM",- KN = "KN",- KP = "KP",- KR = "KR",- KW = "KW",- KY = "KY",- KZ = "KZ",- LA = "LA",- LB = "LB",- LC = "LC",- LI = "LI",- LK = "LK",- LR = "LR",- LS = "LS",- LT = "LT",- LU = "LU",- LV = "LV",- LY = "LY",- MA = "MA",- MC = "MC",- MD = "MD",- ME = "ME",- MF = "MF",- MG = "MG",- MH = "MH",- MK = "MK",- ML = "ML",- MM = "MM",- MN = "MN",- MO = "MO",- MP = "MP",- MQ = "MQ",- MR = "MR",- MS = "MS",- MT = "MT",- MU = "MU",- MV = "MV",- MW = "MW",- MX = "MX",- MY = "MY",- MZ = "MZ",- NA = "NA",- NC = "NC",- NE = "NE",- NF = "NF",- NG = "NG",- NI = "NI",- NL = "NL",- NO = "NO",- NP = "NP",- NR = "NR",- NU = "NU",- NZ = "NZ",- OM = "OM",- PA = "PA",- PE = "PE",- PF = "PF",- PG = "PG",- PH = "PH",- PK = "PK",- PL = "PL",- PM = "PM",- PN = "PN",- PR = "PR",- PS = "PS",- PT = "PT",- PW = "PW",- PY = "PY",- QA = "QA",- RE = "RE",- RO = "RO",- RS = "RS",- RU = "RU",- RW = "RW",- SA = "SA",- SB = "SB",- SC = "SC",- SD = "SD",- SE = "SE",- SG = "SG",- SH = "SH",- SI = "SI",- SJ = "SJ",- SK = "SK",- SL = "SL",- SM = "SM",- SN = "SN",- SO = "SO",- SR = "SR",- SS = "SS",- ST = "ST",- SV = "SV",- SX = "SX",- SY = "SY",- SZ = "SZ",- TC = "TC",- TD = "TD",- TF = "TF",- TG = "TG",- TH = "TH",- TJ = "TJ",- TK = "TK",- TL = "TL",- TM = "TM",- TN = "TN",- TO = "TO",- TR = "TR",- TT = "TT",- TV = "TV",- TW = "TW",- TZ = "TZ",- UA = "UA",- UG = "UG",- UM = "UM",- US = "US",- UY = "UY",- UZ = "UZ",- VA = "VA",- VC = "VC",- VE = "VE",- VG = "VG",- VI = "VI",- VN = "VN",- VU = "VU",- WF = "WF",- WS = "WS",- YE = "YE",- YT = "YT",- ZA = "ZA",- ZM = "ZM",- ZW = "ZW",-}-export enum VoucherDiscountValueType {FIXED = "FIXED",PERCENTAGE = "PERCENTAGE",@@ -552,6 +304,17 @@ export interface ProductVariantInput {weight?: any | null;}+export interface SaleInput {+ name?: string | null;+ type?: DiscountValueTypeEnum | null;+ value?: any | null;+ products?: (string | null)[] | null;+ categories?: (string | null)[] | null;+ collections?: (string | null)[] | null;+ startDate?: any | null;+ endDate?: any | null;+}+export interface SeoInput {title?: string | null;description?: string | null;