Skip to content

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

Get rid of <Toggle /> component

dominik-zeglen583543713214
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/CategoryCreateSubcategories.tsx b/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/CategoryCreateSubcategories.tsx
deleted file mode 100644
index ede2f6b9ce..0000000000
--- a/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/CategoryCreateSubcategories.tsx
+++ /dev/null
@@ -1,110 +0,0 @@
-import {
- createStyles,
- Theme,
- withStyles,
- WithStyles
-} from "@material-ui/core/styles";
-import * as classNames from "classnames";
-import * as React from "react";
-
-import Button from "@material-ui/core/Button";
-import Card from "@material-ui/core/Card";
-import CardContent from "@material-ui/core/CardContent";
-import IconButton from "@material-ui/core/IconButton";
-import TextField from "@material-ui/core/TextField";
-import Typography from "@material-ui/core/Typography";
-import AddIcon from "@material-ui/icons/Add";
-import DeleteIcon from "@material-ui/icons/Delete";
-import Hr from "../../../components/Hr";
-
-import CardTitle from "../../../components/CardTitle";
-import Toggle from "../../../components/Toggle";
-
-import i18n from "../../../i18n";
-
-const styles = (theme: Theme) =>
- createStyles({
- addSubCat: {
- marginTop: ".5rem",
- padding: "0"
- },
- deleteIcon: {
- alignSelf: "end",
- justifySelf: "center"
- },
- helperText: {
- marginBottom: theme.spacing.unit * 4
- },
- inputGrid: {
- display: "grid",
- gridColumnGap: theme.spacing.unit * 2 + "px",
- gridTemplateColumns: "5fr 8fr 30px",
- marginBottom: "1rem"
- },
- root: {
- "&:last-child": {
- paddingBottom: ".5rem"
- },
- paddingBottom: "0px"
- }
- });
-
-interface CategoryCreateSubcategoriesProps extends WithStyles<typeof styles> {
- disabled: boolean;
-}
-
-export const CategoryCreateSubcategories = withStyles(styles, {
- name: "CategoryCreateSubcategories"
-})(({ classes, disabled }: CategoryCreateSubcategoriesProps) => {
- return (
- <Toggle>
- {(toggled, { toggle }) => (
- <Card>
- <CardTitle
- title={i18n.t("Subcategories")}
- toolbar={
- <Button
- color={toggled ? "default" : "secondary"}
- variant="text"
- onClick={toggle}
- disabled={disabled}
- >
- {toggled ? i18n.t("Cancel") : i18n.t("Add subcategory")}
- </Button>
- }
- />
- <CardContent className={classNames({ [classes.root]: toggled })}>
- <Typography
- className={classNames({ [classes.helperText]: toggled })}
- >
- {i18n.t("Add subcategories to help you organize your products")}
- </Typography>
- {toggled && (
- <>
- <div className={classes.inputGrid}>
- <TextField label={i18n.t("Category Name")} />
- <TextField label={i18n.t("Category Description")} />
- <IconButton className={classes.deleteIcon} color="primary">
- <DeleteIcon />
- </IconButton>
- </div>
-
- <Hr />
- <Button
- variant="text"
- color="primary"
- className={classes.addSubCat}
- >
- {i18n.t("Add subcategory")}
- <AddIcon />
- </Button>
- </>
- )}
- </CardContent>
- </Card>
- )}
- </Toggle>
- );
-});
-CategoryCreateSubcategories.displayName = "CategoryCreateSubcategories";
-export default CategoryCreateSubcategories;
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/index.ts b/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/index.ts
deleted file mode 100644
index a7a7947bbc..0000000000
--- a/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from "./CategoryCreateSubcategories";
-export * from "./CategoryCreateSubcategories";
diff --git a/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx b/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx
index b286b51207..4d4a473bcb 100644
--- a/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx
+++ b/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx
@@ -227,12 +227,12 @@ const AppLayout = withStyles(styles, {
return (
<AppProgressProvider>
- {({ value: isProgressVisible }) => (
+ {({ isProgress }) => (
<AppHeaderContext.Provider value={appHeaderAnchor}>
<AppActionContext.Provider value={appActionAnchor}>
<LinearProgress
className={classNames(classes.appLoader, {
- [classes.hide]: !isProgressVisible
+ [classes.hide]: !isProgress
})}
color="primary"
/>
diff --git a/saleor/static/dashboard-next/components/AppLayout/MenuList.tsx b/saleor/static/dashboard-next/components/AppLayout/MenuList.tsx
index c1c4d88b01..7ea9ac2f46 100644
--- a/saleor/static/dashboard-next/components/AppLayout/MenuList.tsx
+++ b/saleor/static/dashboard-next/components/AppLayout/MenuList.tsx
@@ -15,7 +15,6 @@ import { User } from "../../auth/types/User";
import { configurationMenu, configurationMenuUrl } from "../../configuration";
import i18n from "../../i18n";
import { orderDraftListUrl, orderListUrl } from "../../orders/urls";
-import Toggle from "../Toggle";
import { IMenuItem } from "./menuStructure";
const styles = (theme: Theme) =>
@@ -97,101 +96,106 @@ const MenuList = withStyles(styles, { name: "MenuList" })(
user,
renderConfigure,
onMenuItemClick
- }: MenuListProps & WithStyles<typeof styles>) => (
- <div className={className}>
- {/* FIXME: this .split("?")[0] looks gross */}
- {menuItems.map(menuItem => {
- const isActive = (menuItem: IMenuItem) =>
- location.split("?")[0] === orderDraftListUrl().split("?")[0] &&
- menuItem.url.split("?")[0] === orderListUrl().split("?")[0]
- ? false
- : !!matchPath(location.split("?")[0], {
- exact: menuItem.url.split("?")[0] === "/",
- path: menuItem.url.split("?")[0]
- });
+ }: MenuListProps & WithStyles<typeof styles>) => {
+ const [isOpened, setOpenStatus] = React.useState(false);
- if (
- menuItem.permission &&
- !user.permissions.map(perm => perm.code).includes(menuItem.permission)
- ) {
- return null;
- }
+ return (
+ <div className={className}>
+ {/* FIXME: this .split("?")[0] looks gross */}
+ {menuItems.map(menuItem => {
+ const isActive = (menuItem: IMenuItem) =>
+ location.split("?")[0] === orderDraftListUrl().split("?")[0] &&
+ menuItem.url.split("?")[0] === orderListUrl().split("?")[0]
+ ? false
+ : !!matchPath(location.split("?")[0], {
+ exact: menuItem.url.split("?")[0] === "/",
+ path: menuItem.url.split("?")[0]
+ });
- if (!menuItem.url) {
- const isAnyChildActive = menuItem.children.reduce(
- (acc, child) => acc || isActive(child),
- false
- );
- return (
- <Toggle key={menuItem.label} initial={isAnyChildActive}>
- {(openedMenu, { toggle: toggleMenu }) => (
- <>
- <div
- onClick={toggleMenu}
- className={classNames(classes.menuListItem, {
- [classes.menuListItemActive]: isAnyChildActive
- })}
+ if (
+ menuItem.permission &&
+ !user.permissions
+ .map(perm => perm.code)
+ .includes(menuItem.permission)
+ ) {
+ return null;
+ }
+
+ if (!menuItem.url) {
+ const isAnyChildActive = menuItem.children.reduce(
+ (acc, child) => acc || isActive(child),
+ false
+ );
+
+ return (
+ <>
+ <div
+ onClick={() => setOpenStatus(!isOpened)}
+ className={classNames(classes.menuListItem, {
+ [classes.menuListItemActive]: isAnyChildActive
+ })}
+ >
+ <Typography
+ aria-label={menuItem.ariaLabel}
+ className={classes.menuListItemText}
>
- <Typography
- aria-label={menuItem.ariaLabel}
- className={classes.menuListItemText}
- >
- {menuItem.label}
- </Typography>
- {openedMenu && (
- <div className={classes.menuListNested}>
- <MenuList
- menuItems={menuItem.children}
- location={location}
- user={user}
- renderConfigure={false}
- onMenuItemClick={onMenuItemClick}
- />
- </div>
- )}
- </div>
- </>
- )}
- </Toggle>
- );
- }
+ {menuItem.label}
+ </Typography>
+ {isOpened && (
+ <div className={classes.menuListNested}>
+ <MenuList
+ menuItems={menuItem.children}
+ location={location}
+ user={user}
+ renderConfigure={false}
+ onMenuItemClick={onMenuItemClick}
+ />
+ </div>
+ )}
+ </div>
+ </>
+ );
+ }
- return (
- <a
- className={classNames(classes.menuListItem, {
- [classes.menuListItemActive]: isActive(menuItem)
- })}
- href={urlJoin(appMountPoint, menuItem.url)}
- onClick={event => onMenuItemClick(menuItem.url, event)}
- key={menuItem.label}
- >
- <Typography
- aria-label={menuItem.ariaLabel}
- className={classes.menuListItemText}
+ return (
+ <a
+ className={classNames(classes.menuListItem, {
+ [classes.menuListItemActive]: isActive(menuItem)
+ })}
+ href={urlJoin(appMountPoint, menuItem.url)}
+ onClick={event => onMenuItemClick(menuItem.url, event)}
+ key={menuItem.label}
>
- {menuItem.label}
- </Typography>
- </a>
- );
- })}
- {renderConfigure &&
- configurationMenu.filter(menuItem =>
- user.permissions.map(perm => perm.code).includes(menuItem.permission)
- ).length > 0 && (
- <a
- className={classes.menuListItem}
- href={urlJoin(appMountPoint, configurationMenuUrl)}
- onClick={event => onMenuItemClick(configurationMenuUrl, event)}
- >
- <Typography
- aria-label="configure"
- className={classes.menuListItemText}
+ <Typography
+ aria-label={menuItem.ariaLabel}
+ className={classes.menuListItemText}
+ >
+ {menuItem.label}
+ </Typography>
+ </a>
+ );
+ })}
+ {renderConfigure &&
+ configurationMenu.filter(menuItem =>
+ user.permissions
+ .map(perm => perm.code)
+ .includes(menuItem.permission)
+ ).length > 0 && (
+ <a
+ className={classes.menuListItem}
+ href={urlJoin(appMountPoint, configurationMenuUrl)}
+ onClick={event => onMenuItemClick(configurationMenuUrl, event)}
>
- {i18n.t("Configure")}
- </Typography>
- </a>
- )}
- </div>
- )
+ <Typography
+ aria-label="configure"
+ className={classes.menuListItemText}
+ >
+ {i18n.t("Configure")}
+ </Typography>
+ </a>
+ )}
+ </div>
+ );
+ }
);
export default MenuList;
diff --git a/saleor/static/dashboard-next/components/AppProgress/index.tsx b/saleor/static/dashboard-next/components/AppProgress/index.tsx
index e9c6a2bfda..7be0c21321 100644
--- a/saleor/static/dashboard-next/components/AppProgress/index.tsx
+++ b/saleor/static/dashboard-next/components/AppProgress/index.tsx
@@ -1,10 +1,8 @@
import * as React from "react";
-import Toggle, { ToggleFuncs } from "../Toggle";
-
interface IAppProgressContext {
- value: boolean;
- funcs: ToggleFuncs;
+ isProgress: boolean;
+ setProgressState: (isOpened: boolean) => void;
}
export const AppProgressContext = React.createContext<IAppProgressContext>(
@@ -13,20 +11,20 @@ export const AppProgressContext = React.createContext<IAppProgressContext>(
export const AppProgressProvider: React.StatelessComponent<{}> = ({
children
-}) => (
- <Toggle>
- {(value, funcs) => (
- <AppProgressContext.Provider
- value={{
- funcs,
- value
- }}
- >
- {children}
- </AppProgressContext.Provider>
- )}
- </Toggle>
-);
+}) => {
+ const [isProgress, setProgressState] = React.useState(false);
+
+ return (
+ <AppProgressContext.Provider
+ value={{
+ isProgress,
+ setProgressState
+ }}
+ >
+ {children}
+ </AppProgressContext.Provider>
+ );
+};
export const AppProgress = AppProgressContext.Consumer;
export default AppProgress;
diff --git a/saleor/static/dashboard-next/components/CountryList/CountryList.tsx b/saleor/static/dashboard-next/components/CountryList/CountryList.tsx
index 0771973b39..c9220c251f 100644
--- a/saleor/static/dashboard-next/components/CountryList/CountryList.tsx
+++ b/saleor/static/dashboard-next/components/CountryList/CountryList.tsx
@@ -19,7 +19,6 @@ 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 { CountryFragment } from "../../taxes/types/CountryFragment";
@@ -90,98 +89,95 @@ const CountryList = withStyles(styles, {
title,
onCountryAssign,
onCountryUnassign
- }: CountryListProps & WithStyles<typeof styles>) => (
- <Toggle initial={true}>
- {(isCollapsed, { toggle: toggleCollapse }) => (
- <Card>
- <CardTitle
- title={title}
- toolbar={
- <Button
- variant="flat"
- color="primary"
- onClick={onCountryAssign}
- >
- {i18n.t("Assign countries")}
- </Button>
- }
- />
- <CardContent className={classes.root}>
- <Table>
- <TableBody>
- <TableRow className={classes.pointer} onClick={toggleCollapse}>
- <TableCell
- className={classNames(classes.wideColumn, classes.toLeft)}
- >
- {i18n.t("{{ number }} Countries", {
- context: "number of countries",
- number: maybe(() => countries.length.toString(), "...")
- })}
- </TableCell>
- <TableCell
- className={classNames(classes.textRight, classes.iconCell)}
- >
- <IconButton>
- <ArrowDropDownIcon
- className={classNames({
- [classes.rotate]: !isCollapsed
- })}
- />
- </IconButton>
- </TableCell>
- </TableRow>
- {!isCollapsed &&
- renderCollection(
- countries,
- (country, countryIndex) => (
- <TableRow key={country ? country.code : "skeleton"}>
- <TableCell className={classes.offsetCell}>
- {maybe<React.ReactNode>(
- () => (
- <>
- {(countryIndex === 0 ||
- countries[countryIndex].country[0] !==
- countries[countryIndex - 1].country[0]) && (
- <span className={classes.indicator}>
- {country.country[0]}
- </span>
- )}
- {country.country}
- </>
- ),
- <Skeleton />
- )}
- </TableCell>
- <TableCell
- className={classNames(
- classes.textRight,
- classes.iconCell
- )}
+ }: CountryListProps & WithStyles<typeof styles>) => {
+ const [isCollapsed, setCollapseStatus] = React.useState(true);
+ const toggleCollapse = () => setCollapseStatus(!isCollapsed);
+
+ return (
+ <Card>
+ <CardTitle
+ title={title}
+ toolbar={
+ <Button variant="flat" color="primary" onClick={onCountryAssign}>
+ {i18n.t("Assign countries")}
+ </Button>
+ }
+ />
+ <CardContent className={classes.root}>
+ <Table>
+ <TableBody>
+ <TableRow className={classes.pointer} onClick={toggleCollapse}>
+ <TableCell
+ className={classNames(classes.wideColumn, classes.toLeft)}
+ >
+ {i18n.t("{{ number }} Countries", {
+ context: "number of countries",
+ number: maybe(() => countries.length.toString(), "...")
+ })}
+ </TableCell>
+ <TableCell
+ className={classNames(classes.textRight, classes.iconCell)}
+ >
+ <IconButton>
+ <ArrowDropDownIcon
+ className={classNames({
+ [classes.rotate]: !isCollapsed
+ })}
+ />
+ </IconButton>
+ </TableCell>
+ </TableRow>
+ {!isCollapsed &&
+ renderCollection(
+ countries,
+ (country, countryIndex) => (
+ <TableRow key={country ? country.code : "skeleton"}>
+ <TableCell className={classes.offsetCell}>
+ {maybe<React.ReactNode>(
+ () => (
+ <>
+ {(countryIndex === 0 ||
+ countries[countryIndex].country[0] !==
+ countries[countryIndex - 1].country[0]) && (
+ <span className={classes.indicator}>
+ {country.country[0]}
+ </span>
+ )}
+ {country.country}
+ </>
+ ),
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell
+ className={classNames(
+ classes.textRight,
+ classes.iconCell
+ )}
+ >
+ <IconButton
+ color="primary"
+ disabled={!country || disabled}
+ onClick={() => onCountryUnassign(country.code)}
>
- <IconButton
- color="primary"
- disabled={!country || disabled}
- onClick={() => onCountryUnassign(country.code)}
- >
- <DeleteIcon />
- </IconButton>
- </TableCell>
- </TableRow>
- ),
- () => (
- <TableRow>
- <TableCell className={classes.toLeft} colSpan={2}>
- {emptyText}
- </TableCell>
- </TableRow>
- )
- )}
- </TableBody>
- </Table>
- </CardContent>
- </Card>
- )}
- </Toggle>
- )
+ <DeleteIcon />
+ </IconButton>
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell className={classes.toLeft} colSpan={2}>
+ {emptyText}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </CardContent>
+ </Card>
+ );
+ }
);
export default CountryList;
diff --git a/saleor/static/dashboard-next/components/EditableTableCell/EditableTableCell.tsx b/saleor/static/dashboard-next/components/EditableTableCell/EditableTableCell.tsx
index 9b8d77673a..326107d5a2 100644
--- a/saleor/static/dashboard-next/components/EditableTableCell/EditableTableCell.tsx
+++ b/saleor/static/dashboard-next/components/EditableTableCell/EditableTableCell.tsx
@@ -13,7 +13,6 @@ import * as classNames from "classnames";
import * as React from "react";
import Form from "../../components/Form";
-import Toggle from "../../components/Toggle";
const styles = (theme: Theme) =>
createStyles({
@@ -63,56 +62,51 @@ export const EditableTableCell = withStyles(styles, {
InputProps,
value,
onConfirm
- }: EditableTableCellProps) => (
- <TableCell className={classNames(classes.container, className)}>
- <Toggle initial={focused}>
- {(opened, { enable, disable }) => {
- const handleConfirm = (data: { value: string }) => {
- disable();
- onConfirm(data.value);
- };
- return (
+ }: EditableTableCellProps) => {
+ const [opened, setOpenStatus] = React.useState(focused);
+ const enable = () => setOpenStatus(true);
+ const disable = () => setOpenStatus(false);
+
+ const handleConfirm = (data: { value: string }) => {
+ disable();
+ onConfirm(data.value);
+ };
+
+ return (
+ <TableCell className={classNames(classes.container, className)}>
+ {opened && <div className={classes.overlay} onClick={disable} />}
+ <Form initial={{ value }} onSubmit={handleConfirm} useForm={false}>
+ {({ change, data }) => (
<>
- {opened && <div className={classes.overlay} onClick={disable} />}
- <Form
- initial={{ value }}
- onSubmit={handleConfirm}
- useForm={false}
+ <Typography
+ variant="caption"
+ onClick={enable}
+ className={classes.text}
>
- {({ change, data }) => (
- <>
- <Typography
- variant="caption"
- onClick={enable}
- className={classes.text}
- >
- {value || defaultValue}
- </Typography>
- {opened && (
- <div className={classes.root}>
- <Card>
- <CardContent>
- <TextField
- name="value"
- autoFocus
- fullWidth
- onChange={change}
- value={data.value}
- {...InputProps}
- />
- </CardContent>
- </Card>
- </div>
- )}
- </>
- )}
- </Form>
+ {value || defaultValue}
+ </Typography>
+ {opened && (
+ <div className={classes.root}>
+ <Card>
+ <CardContent>
+ <TextField
+ name="value"
+ autoFocus
+ fullWidth
+ onChange={change}
+ value={data.value}
+ {...InputProps}
+ />
+ </CardContent>
+ </Card>
+ </div>
+ )}
</>
- );
- }}
- </Toggle>
- </TableCell>
- )
+ )}
+ </Form>
+ </TableCell>
+ );
+ }
);
EditableTableCell.displayName = "EditableTableCell";
export default EditableTableCell;
diff --git a/saleor/static/dashboard-next/components/Link.tsx b/saleor/static/dashboard-next/components/Link.tsx
index cdcde018ad..d03ec4d009 100644
--- a/saleor/static/dashboard-next/components/Link.tsx
+++ b/saleor/static/dashboard-next/components/Link.tsx
@@ -40,6 +40,7 @@ const Link = withStyles(styles, { name: "Link" })(
children,
color = "primary",
underline = false,
+ onClick,
...linkProps
}: LinkProps) => (
<Typography
@@ -49,6 +50,10 @@ const Link = withStyles(styles, { name: "Link" })(
[classes[color]]: true,
[classes.underline]: underline
})}
+ onClick={event => {
+ event.preventDefault();
+ onClick(event as any);
+ }}
{...linkProps}
>
{children}
diff --git a/saleor/static/dashboard-next/components/SeoForm/SeoForm.tsx b/saleor/static/dashboard-next/components/SeoForm/SeoForm.tsx
index 9a4b78321a..c4af34cdc7 100644
--- a/saleor/static/dashboard-next/components/SeoForm/SeoForm.tsx
+++ b/saleor/static/dashboard-next/components/SeoForm/SeoForm.tsx
@@ -15,7 +15,6 @@ import * as React from "react";
import i18n from "../../i18n";
import CardTitle from "../CardTitle";
import FormSpacer from "../FormSpacer";
-import Toggle from "../Toggle";
const styles = (theme: Theme) =>
createStyles({
@@ -85,88 +84,89 @@ const SeoForm = withStyles(styles, { name: "SeoForm" })(
title,
titlePlaceholder,
onChange
- }: SeoFormProps) => (
- <Toggle>
- {(toggled, { toggle }) => (
- <Card>
- <CardTitle
- title={i18n.t("Search Engine Preview")}
- toolbar={
- <Button color="primary" variant="text" onClick={toggle}>
- {i18n.t("Edit website SEO")}
- </Button>
- }
- />
- <CardContent>
- {helperText && (
- <Typography
- className={classNames({ [classes.helperText]: toggled })}
- >
- {helperText}
- </Typography>
- )}
- {toggled && (
- <div className={classes.container}>
- <TextField
- name="seoTitle"
- label={
- <div className={classes.labelContainer}>
- <div className={classes.label}>
- {i18n.t("Search engine title")}
- </div>
- <span>
- {i18n.t(
- "{{ letters }} of {{ maxLetters }} characters",
- { letters: title.length, maxLetters: 70 }
- )}
- </span>
+ }: SeoFormProps) => {
+ const [expanded, setExpansionStatus] = React.useState(false);
+ const toggleExpansion = () => setExpansionStatus(!expanded);
+
+ return (
+ <Card>
+ <CardTitle
+ title={i18n.t("Search Engine Preview")}
+ toolbar={
+ <Button color="primary" variant="text" onClick={toggleExpansion}>
+ {i18n.t("Edit website SEO")}
+ </Button>
+ }
+ />
+ <CardContent>
+ {helperText && (
+ <Typography
+ className={classNames({ [classes.helperText]: expanded })}
+ >
+ {helperText}
+ </Typography>
+ )}
+ {expanded && (
+ <div className={classes.container}>
+ <TextField
+ name="seoTitle"
+ label={
+ <div className={classes.labelContainer}>
+ <div className={classes.label}>
+ {i18n.t("Search engine title")}
</div>
- }
- helperText={i18n.t(
- "If empty, the preview shows what will be autogenerated."
- )}
- value={title.slice(0, 69)}
- disabled={loading || disabled}
- InputLabelProps={{ shrink: true }}
- placeholder={titlePlaceholder}
- onChange={onChange}
- fullWidth
- />
- <FormSpacer />
- <TextField
- name="seoDescription"
- label={
- <div className={classes.labelContainer}>
- <div className={classes.label}>
- {i18n.t("Search engine description")}
- </div>
- <span>
- {i18n.t(
- "{{ letters }} of {{ maxLetters }} characters",
- { letters: description.length, maxLetters: 300 }
- )}
- </span>
+ <span>
+ {i18n.t("{{ letters }} of {{ maxLetters }} characters", {
+ letters: title.length,
+ maxLetters: 70
+ })}
+ </span>
+ </div>
+ }
+ helperText={i18n.t(
+ "If empty, the preview shows what will be autogenerated."
+ )}
+ value={title.slice(0, 69)}
+ disabled={loading || disabled}
+ InputLabelProps={{ shrink: true }}
+ placeholder={titlePlaceholder}
+ onChange={onChange}
+ fullWidth
+ />
+ <FormSpacer />
+ <TextField
+ name="seoDescription"
+ label={
+ <div className={classes.labelContainer}>
+ <div className={classes.label}>
+ {i18n.t("Search engine description")}
</div>
- }
- helperText={i18n.t(
- "If empty, the preview shows what will be autogenerated."
- )}
- value={description ? description.slice(0, 299) : undefined}
- onChange={onChange}
- disabled={loading || disabled}
- fullWidth
- multiline
- placeholder={descriptionPlaceholder}
- InputLabelProps={{ shrink: true }}
- rows={10}
- />
- </div>
- )}
- </CardContent>
- </Card>
- )}
- </Toggle>
- )
+ <span>
+ {i18n.t("{{ letters }} of {{ maxLetters }} characters", {
+ letters: description.length,
+ maxLetters: 300
+ })}
+ </span>
+ </div>
+ }
+ helperText={i18n.t(
+ "If empty, the preview shows what will be autogenerated."
+ )}
+ value={description ? description.slice(0, 299) : undefined}
+ onChange={onChange}
+ disabled={loading || disabled}
+ fullWidth
+ multiline
+ placeholder={descriptionPlaceholder}
+ InputLabelProps={{ shrink: true }}
+ rows={10}
+ />
+ </div>
+ )}
+ </CardContent>
+ </Card>
+ );
+ }
);
SeoForm.displayName = "SeoForm";
SeoForm.defaultProps = {
diff --git a/saleor/static/dashboard-next/components/Toggle.tsx b/saleor/static/dashboard-next/components/Toggle.tsx
deleted file mode 100644
index 354db81dd0..0000000000
--- a/saleor/static/dashboard-next/components/Toggle.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import * as React from "react";
-
-export interface ToggleFuncs {
- disable();
- enable();
- toggle();
-}
-export type ToggleChildren = (
- value: boolean,
- funcs: ToggleFuncs
-) => React.ReactElement<any>;
-
-interface ToggleProps {
- children: ToggleChildren;
- initial?: boolean;
-}
-
-interface ToggleState {
- value: boolean;
-}
-
-class Toggle extends React.Component<ToggleProps, ToggleState> {
- state = {
- value: this.props.initial !== undefined ? this.props.initial : false
- };
-
- disable = () => this.setState({ value: false });
- enable = () => this.setState({ value: true });
- toggle = () => this.setState(({ value }) => ({ value: !value }));
-
- render() {
- const { children } = this.props;
- return children(this.state.value, {
- disable: this.disable,
- enable: this.enable,
- toggle: this.toggle
- });
- }
-}
-
-export default Toggle;
diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.ts
index ed9c08117f..6940922c88 100644
--- a/saleor/static/dashboard-next/misc.ts
+++ b/saleor/static/dashboard-next/misc.ts
@@ -1,4 +1,7 @@
+import * as urlJoin from "url-join";
+
import { MutationFn, MutationResult } from "react-apollo";
+import { appMountPoint } from ".";
import { ConfirmButtonTransitionState } from "./components/ConfirmButton/ConfirmButton";
import { AddressType } from "./customers/types";
import i18n from "./i18n";
@@ -219,3 +222,7 @@ export function getUserInitials(user?: User) {
).toUpperCase()
: undefined;
}
+
+export function createHref(url: string) {
+ return urlJoin(appMountPoint, url);
+}
diff --git a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
index a265f8df33..37b7b006be 100644
--- a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
@@ -14,9 +14,10 @@ import CardTitle from "../../../components/CardTitle";
import ExternalLink from "../../../components/ExternalLink";
import Form from "../../../components/Form";
import Hr from "../../../components/Hr";
+import Link from "../../../components/Link";
import SingleAutocompleteSelectField from "../../../components/SingleAutocompleteSelectField";
import Skeleton from "../../../components/Skeleton";
-import Toggle from "../../../components/Toggle";
+import { customerUrl } from "../../../customers/urls";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { OrderDetails_order } from "../../types/OrderDetails";
@@ -51,12 +52,8 @@ export interface OrderCustomerProps extends WithStyles<typeof styles> {
canEditAddresses: boolean;
canEditCustomer: boolean;
fetchUsers?: (query: string) => void;
- onCustomerEdit?: (
- data: {
- user?: string;
- userEmail?: string;
- }
- ) => void;
+ onCustomerEdit?: (data: { user?: string; userEmail?: string }) => void;
+ onProfileView: () => void;
onBillingAddressEdit?: () => void;
onShippingAddressEdit?: () => void;
}
@@ -72,83 +69,88 @@ const OrderCustomer = withStyles(styles, { name: "OrderCustomer" })(
users,
onCustomerEdit,
onBillingAddressEdit,
+ onProfileView,
onShippingAddressEdit
}: OrderCustomerProps) => {
+ const [isInEditMode, setEditModeStatus] = React.useState(false);
+ const toggleEditMode = () => setEditModeStatus(!isInEditMode);
+
const billingAddress = maybe(() => order.billingAddress);
const shippingAddress = maybe(() => order.shippingAddress);
const user = maybe(() => order.user);
return (
<Card>
- <Toggle>
- {(editMode, { toggle: toggleEditMode }) => (
+ <CardTitle
+ title={i18n.t("Customer")}
+ toolbar={
+ !!canEditCustomer && (
+ <Button
+ color="primary"
+ variant="text"
+ disabled={!onCustomerEdit}
+ onClick={toggleEditMode}
+ >
+ {i18n.t("Edit")}
+ </Button>
+ )
+ }
+ />
+ <CardContent>
+ {user === undefined ? (
+ <Skeleton />
+ ) : isInEditMode && canEditCustomer ? (
+ <Form initial={{ query: { label: "", value: "" } }}>
+ {({ change, data }) => {
+ const handleChange = (event: React.ChangeEvent<any>) => {
+ change(event);
+ onCustomerEdit({
+ [event.target.value.value.includes("@")
+ ? "userEmail"
+ : "user"]: event.target.value.value
+ });
+ toggleEditMode();
+ };
+ return (
+ <SingleAutocompleteSelectField
+ custom={true}
+ choices={maybe(() => users, []).map(user => ({
+ label: user.email,
+ value: user.id
+ }))}
+ fetchChoices={fetchUsers}
+ loading={loading}
+ placeholder={i18n.t("Search Customers")}
+ onChange={handleChange}
+ name="query"
+ value={data.query}
+ />
+ );
+ }}
+ </Form>
+ ) : user === null ? (
+ <Typography>{i18n.t("Anonymous user")}</Typography>
+ ) : (
<>
- <CardTitle
- title={i18n.t("Customer")}
- toolbar={
- !!canEditCustomer && (
- <Button
- color="primary"
- variant="text"
- disabled={!onCustomerEdit}
- onClick={toggleEditMode}
- >
- {i18n.t("Edit")}
- </Button>
- )
- }
- />
- <CardContent>
- {user === undefined ? (
- <Skeleton />
- ) : editMode && canEditCustomer ? (
- <Form initial={{ query: { label: "", value: "" } }}>
- {({ change, data }) => {
- const handleChange = (event: React.ChangeEvent<any>) => {
- change(event);
- onCustomerEdit({
- [event.target.value.value.includes("@")
- ? "userEmail"
- : "user"]: event.target.value.value
- });
- toggleEditMode();
- };
- return (
- <SingleAutocompleteSelectField
- custom={true}
- choices={maybe(() => users, []).map(user => ({
- label: user.email,
- value: user.id
- }))}
- fetchChoices={fetchUsers}
- loading={loading}
- placeholder={i18n.t("Search Customers")}
- onChange={handleChange}
- name="query"
- value={data.query}
- />
- );
- }}
- </Form>
- ) : user === null ? (
- <Typography>{i18n.t("Anonymous user")}</Typography>
- ) : (
- <>
- <Typography className={classes.userEmail}>
- {user.email}
- </Typography>
- {/* TODO: uncomment after adding customer section */}
- {/* <div>
- <Link underline={false}>{i18n.t("View Profile")}</Link>
- </div>
- <div>
- <Link underline={false}>{i18n.t("View Orders")}</Link>
- </div> */}
- </>
- )}
- </CardContent>
+ <Typography className={classes.userEmail}>
+ {user.email}
+ </Typography>
+ <div>
+ <Link
+ underline={false}
+ href={customerUrl(user.id)}
+ onClick={onProfileView}
+ >
+ {i18n.t("View Profile")}
+ </Link>
+ </div>
+ {/* TODO: Uncomment it after adding ability to filter
+ orders by customer */}
+ {/* <div>
+ <Link underline={false} href={}>{i18n.t("View Orders")}</Link>
+ </div> */}
</>
)}
- </Toggle>
+ </CardContent>
<Hr />
<CardContent>
<div className={classes.sectionHeader}>
diff --git a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
index 704ee02d2e..4a6bdb720f 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
@@ -60,6 +60,7 @@ export interface OrderDetailsPageProps extends WithStyles<typeof styles> {
onShippingAddressEdit();
onOrderCancel();
onNoteAdd(data: HistoryFormData);
+ onProfileView();
}
const OrderDetailsPage = withStyles(styles, { name: "OrderDetailsPage" })(
@@ -77,7 +78,8 @@ const OrderDetailsPage = withStyles(styles, { name: "OrderDetailsPage" })(
onPaymentPaid,
onPaymentRefund,
onPaymentVoid,
- onShippingAddressEdit
+ onShippingAddressEdit,
+ onProfileView
}: OrderDetailsPageProps) => {
const canCancel = maybe(() => order.status) !== OrderStatus.CANCELED;
const canEditAddresses = maybe(() => order.status) !== OrderStatus.CANCELED;
@@ -162,6 +164,7 @@ const OrderDetailsPage = withStyles(styles, { name: "OrderDetailsPage" })(
order={order}
onBillingAddressEdit={onBillingAddressEdit}
onShippingAddressEdit={onShippingAddressEdit}
+ onProfileView={onProfileView}
/>
<CardSpacer />
<OrderCustomerNote note={maybe(() => order.customerNote)} />
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
index ef70acb19a..79d5b1f093 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
@@ -63,6 +63,7 @@ export interface OrderDraftPageProps extends WithStyles<typeof styles> {
onProductClick: (id: string) => void;
onShippingAddressEdit: () => void;
onShippingMethodEdit: () => void;
+ onProfileView: () => void;
}
const OrderDraftPage = withStyles(styles, { name: "OrderDraftPage" })(
@@ -82,6 +83,7 @@ const OrderDraftPage = withStyles(styles, { name: "OrderDraftPage" })(
onOrderLineRemove,
onShippingAddressEdit,
onShippingMethodEdit,
+ onProfileView,
order,
users,
usersLoading
@@ -135,6 +137,7 @@ const OrderDraftPage = withStyles(styles, { name: "OrderDraftPage" })(
onBillingAddressEdit={onBillingAddressEdit}
onCustomerEdit={onCustomerEdit}
onShippingAddressEdit={onShippingAddressEdit}
+ onProfileView={onProfileView}
/>
</div>
</Grid>
diff --git a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
index 7e1a9bade6..81a3c99a3f 100644
--- a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
+++ b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx
@@ -1,6 +1,7 @@
import * as React from "react";
import { WindowTitle } from "../../../components/WindowTitle";
+import { customerUrl } from "../../../customers/urls";
import useNavigator from "../../../hooks/useNavigator";
import { getMutationState, maybe, transformAddressToForm } from "../../../misc";
import { productUrl } from "../../../products/urls";
@@ -203,6 +204,9 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
openModal("edit-shipping-address")
}
onPaymentPaid={() => openModal("mark-paid")}
+ onProfileView={() =>
+ navigate(customerUrl(order.user.id))
+ }
/>
<OrderCancelDialog
confirmButtonState={getMutationState(
@@ -444,6 +448,9 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({
})
}
saveButtonBarState="default"
+ onProfileView={() =>
+ navigate(customerUrl(order.user.id))
+ }
/>
<OrderDraftCancelDialog
confirmButtonState={getMutationState(
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx b/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx
index 9d6c126868..a0c4b8ca7e 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx
@@ -8,7 +8,6 @@ import Form from "../../../components/Form";
import Grid from "../../../components/Grid";
import PageHeader from "../../../components/PageHeader";
import SaveButtonBar from "../../../components/SaveButtonBar";
-import Toggle from "../../../components/Toggle";
import { maybe } from "../../../misc";
import { UserError } from "../../../types";
import { ProductVariant } from "../../types/ProductVariant";
@@ -48,6 +47,9 @@ const ProductVariantPage: React.StatelessComponent<ProductVariantPageProps> = ({
onSubmit,
onVariantClick
}) => {
+ const [isModalOpened, setModalStatus] = React.useState(false);
+ const toggleModal = () => setModalStatus(!isModalOpened);
+
const variantImages = variant ? variant.images.map(image => image.id) : [];
const productImages = variant
? variant.product.images.sort((prev, next) =>
@@ -60,129 +62,121 @@ const ProductVariantPage: React.StatelessComponent<ProductVariantPageProps> = ({
.sort((prev, next) => (prev.sortOrder > next.sortOrder ? 1 : -1))
: undefined;
return (
- <Toggle>
- {(isImageSelectModalActive, { toggle: toggleImageSelectModal }) => (
- <>
- <Container>
- <AppHeader onBack={onBack}>
- {maybe(() => variant.product.name)}
- </AppHeader>
- <PageHeader title={header} />
- <Form
- initial={{
- attributes:
- variant && variant.attributes
- ? variant.attributes.map(a => ({
- slug: a.attribute.slug,
- value: a.value.slug
- }))
- : [],
- costPrice:
- variant && variant.costPrice
- ? variant.costPrice.amount.toString()
- : null,
- priceOverride:
- variant && variant.priceOverride
- ? variant.priceOverride.amount.toString()
- : null,
- quantity: variant && variant.quantity ? variant.quantity : "",
- sku: variant && variant.sku
- }}
- errors={formErrors}
- onSubmit={onSubmit}
- confirmLeave
- >
- {({ change, data, errors, hasChanged, submit }) => (
- <>
- <Grid variant="inverted">
- <div>
- <ProductVariantNavigation
- current={variant ? variant.id : undefined}
- fallbackThumbnail={maybe(
- () => variant.product.thumbnail.url
- )}
- variants={maybe(() => variant.product.variants)}
- onAdd={onAdd}
- onRowClick={(variantId: string) => {
- if (variant) {
- return onVariantClick(variantId);
- }
- }}
- />
- </div>
- <div>
- <ProductVariantAttributes
- attributes={
- variant && variant.attributes
- ? variant.attributes.map(a => a.attribute)
- : undefined
- }
- data={data}
- disabled={loading}
- onChange={change}
- />
- <CardSpacer />
- <ProductVariantImages
- disabled={loading}
- images={images}
- placeholderImage={placeholderImage}
- onImageAdd={toggleImageSelectModal}
- />
- <CardSpacer />
- <ProductVariantPrice
- errors={errors}
- priceOverride={data.priceOverride}
- currencySymbol={
- variant && variant.priceOverride
- ? variant.priceOverride.currency
- : variant && variant.costPrice
- ? variant.costPrice.currency
- : ""
- }
- costPrice={data.costPrice}
- loading={loading}
- onChange={change}
- />
- <CardSpacer />
- <ProductVariantStock
- errors={errors}
- sku={data.sku}
- quantity={data.quantity}
- stockAllocated={
- variant ? variant.quantityAllocated : undefined
- }
- loading={loading}
- onChange={change}
- />
- </div>
- </Grid>
- <SaveButtonBar
- disabled={loading || !hasChanged}
- state={saveButtonBarState}
- onCancel={onBack}
- onDelete={onDelete}
- onSave={submit}
- />
- </>
- )}
- </Form>
- </Container>
- {variant && (
+ <>
+ <Container>
+ <AppHeader onBack={onBack}>
+ {maybe(() => variant.product.name)}
+ </AppHeader>
+ <PageHeader title={header} />
+ <Form
+ initial={{
+ attributes:
+ variant && variant.attributes
+ ? variant.attributes.map(a => ({
+ slug: a.attribute.slug,
+ value: a.value.slug
+ }))
+ : [],
+ costPrice:
+ variant && variant.costPrice
+ ? variant.costPrice.amount.toString()
+ : null,
+ priceOverride:
+ variant && variant.priceOverride
+ ? variant.priceOverride.amount.toString()
+ : null,
+ quantity: variant && variant.quantity ? variant.quantity : "",
+ sku: variant && variant.sku
+ }}
+ errors={formErrors}
+ onSubmit={onSubmit}
+ confirmLeave
+ >
+ {({ change, data, errors, hasChanged, submit }) => (
<>
- <ProductVariantImageSelectDialog
- onClose={toggleImageSelectModal}
- onImageSelect={onImageSelect}
- open={isImageSelectModalActive}
- images={productImages}
- selectedImages={maybe(() =>
- variant.images.map(image => image.id)
- )}
+ <Grid variant="inverted">
+ <div>
+ <ProductVariantNavigation
+ current={variant ? variant.id : undefined}
+ fallbackThumbnail={maybe(
+ () => variant.product.thumbnail.url
+ )}
+ variants={maybe(() => variant.product.variants)}
+ onAdd={onAdd}
+ onRowClick={(variantId: string) => {
+ if (variant) {
+ return onVariantClick(variantId);
+ }
+ }}
+ />
+ </div>
+ <div>
+ <ProductVariantAttributes
+ attributes={
+ variant && variant.attributes
+ ? variant.attributes.map(a => a.attribute)
+ : undefined
+ }
+ data={data}
+ disabled={loading}
+ onChange={change}
+ />
+ <CardSpacer />
+ <ProductVariantImages
+ disabled={loading}
+ images={images}
+ placeholderImage={placeholderImage}
+ onImageAdd={toggleModal}
+ />
+ <CardSpacer />
+ <ProductVariantPrice
+ errors={errors}
+ priceOverride={data.priceOverride}
+ currencySymbol={
+ variant && variant.priceOverride
+ ? variant.priceOverride.currency
+ : variant && variant.costPrice
+ ? variant.costPrice.currency
+ : ""
+ }
+ costPrice={data.costPrice}
+ loading={loading}
+ onChange={change}
+ />
+ <CardSpacer />
+ <ProductVariantStock
+ errors={errors}
+ sku={data.sku}
+ quantity={data.quantity}
+ stockAllocated={
+ variant ? variant.quantityAllocated : undefined
+ }
+ loading={loading}
+ onChange={change}
+ />
+ </div>
+ </Grid>
+ <SaveButtonBar
+ disabled={loading || !hasChanged}
+ state={saveButtonBarState}
+ onCancel={onBack}
+ onDelete={onDelete}
+ onSave={submit}
/>
</>
)}
- </>
+ </Form>
+ </Container>
+ {variant && (
+ <ProductVariantImageSelectDialog
+ onClose={toggleModal}
+ onImageSelect={onImageSelect}
+ open={isModalOpened}
+ images={productImages}
+ selectedImages={maybe(() => variant.images.map(image => image.id))}
+ />
)}
- </Toggle>
+ </>
);
};
ProductVariantPage.displayName = "ProductVariantPage";
diff --git a/saleor/static/dashboard-next/queries.tsx b/saleor/static/dashboard-next/queries.tsx
index db0561ab99..e90fdda5ef 100644
--- a/saleor/static/dashboard-next/queries.tsx
+++ b/saleor/static/dashboard-next/queries.tsx
@@ -66,7 +66,7 @@ export function TypedQuery<TData, TVariables>(query: DocumentNode) {
return (
<AppProgress>
- {({ funcs: changeProgressState }) => {
+ {({ setProgressState }) => {
// Obviously, this is workaround to the problem described here:
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/32588
const {
@@ -135,8 +135,8 @@ export function TypedQuery<TData, TVariables>(query: DocumentNode) {
return (
<QueryProgress
loading={queryData.loading}
- onCompleted={changeProgressState.disable}
- onLoading={changeProgressState.enable}
+ onCompleted={() => setProgressState(true)}
+ onLoading={() => setProgressState(false)}
>
{childrenOrNotFound}
</QueryProgress>
diff --git a/saleor/static/dashboard-next/shipping/components/ShippingZoneCreatePage/ShippingZoneCreatePage.tsx b/saleor/static/dashboard-next/shipping/components/ShippingZoneCreatePage/ShippingZoneCreatePage.tsx
index 7729a37cd5..1a7ecb9553 100644
--- a/saleor/static/dashboard-next/shipping/components/ShippingZoneCreatePage/ShippingZoneCreatePage.tsx
+++ b/saleor/static/dashboard-next/shipping/components/ShippingZoneCreatePage/ShippingZoneCreatePage.tsx
@@ -9,7 +9,6 @@ import Form from "../../../components/Form";
import Grid from "../../../components/Grid";
import PageHeader from "../../../components/PageHeader";
import SaveButtonBar from "../../../components/SaveButtonBar";
-import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
import { CountryFragment } from "../../../taxes/types/CountryFragment";
import { UserError } from "../../../types";
@@ -34,104 +33,97 @@ export interface ShippingZoneCreatePageProps {
const ShippingZoneCreatePage: React.StatelessComponent<
ShippingZoneCreatePageProps
> = ({ countries, disabled, errors, onBack, onSubmit, saveButtonBarState }) => {
+ const [isModalOpened, setModalStatus] = React.useState(false);
+ const toggleModal = () => setModalStatus(!isModalOpened);
+
const initialForm: FormData = {
countries: [],
default: false,
name: ""
};
+
return (
- <Toggle>
- {(
- isCountrySelectionDialogOpened,
- { toggle: toggleCountrySelectionDialog }
- ) => (
- <Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
- {({ change, data, errors: formErrors, hasChanged, submit }) => (
- <>
- <Container>
- <AppHeader onBack={onBack}>{i18n.t("Shipping")}</AppHeader>
- <PageHeader title={i18n.t("Create New Shipping Zone")} />
- <Grid>
- <div>
- <ShippingZoneInfo
- data={data}
- errors={formErrors}
- onChange={change}
- />
- <CardSpacer />
- <CountryList
- countries={data.countries.map(selectedCountry =>
- countries.find(
- country => country.code === selectedCountry
+ <Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
+ {({ change, data, errors: formErrors, hasChanged, submit }) => (
+ <>
+ <Container>
+ <AppHeader onBack={onBack}>{i18n.t("Shipping")}</AppHeader>
+ <PageHeader title={i18n.t("Create New Shipping Zone")} />
+ <Grid>
+ <div>
+ <ShippingZoneInfo
+ data={data}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <CountryList
+ countries={data.countries.map(selectedCountry =>
+ countries.find(country => country.code === selectedCountry)
+ )}
+ disabled={disabled}
+ emptyText={
+ data.default
+ ? i18n.t(
+ "This is default shipping zone, which means that it covers all of the countries which are not assigned to other shipping zones"
+ )
+ : i18n.t(
+ "Currently, there are no countries assigned to this shipping zone"
+ )
+ }
+ onCountryAssign={toggleModal}
+ onCountryUnassign={countryCode =>
+ change({
+ target: {
+ name: "countries",
+ value: data.countries.filter(
+ country => country !== countryCode
)
- )}
- disabled={disabled}
- emptyText={
- data.default
- ? i18n.t(
- "This is default shipping zone, which means that it covers all of the countries which are not assigned to other shipping zones"
- )
- : i18n.t(
- "Currently, there are no countries assigned to this shipping zone"
- )
- }
- onCountryAssign={toggleCountrySelectionDialog}
- onCountryUnassign={countryCode =>
- change({
- target: {
- name: "countries",
- value: data.countries.filter(
- country => country !== countryCode
- )
- }
- } as any)
}
- title={i18n.t("Countries")}
- />
- </div>
- </Grid>
- <SaveButtonBar
- disabled={disabled || !hasChanged}
- onCancel={onBack}
- onSave={submit}
- state={saveButtonBarState}
+ } as any)
+ }
+ title={i18n.t("Countries")}
/>
- </Container>
- <ShippingZoneCountriesAssignDialog
- open={isCountrySelectionDialogOpened}
- onConfirm={formData =>
+ </div>
+ </Grid>
+ <SaveButtonBar
+ disabled={disabled || !hasChanged}
+ onCancel={onBack}
+ onSave={submit}
+ state={saveButtonBarState}
+ />
+ </Container>
+ <ShippingZoneCountriesAssignDialog
+ open={isModalOpened}
+ onConfirm={formData =>
+ change(
+ {
+ target: {
+ name: "default",
+ value: formData.restOfTheWorld
+ }
+ } as any,
+ () =>
change(
{
target: {
- name: "default",
- value: formData.restOfTheWorld
+ name: "countries",
+ value: formData.restOfTheWorld ? [] : formData.countries
}
} as any,
- () =>
- change(
- {
- target: {
- name: "countries",
- value: formData.restOfTheWorld
- ? []
- : formData.countries
- }
- } as any,
- toggleCountrySelectionDialog
- )
+ toggleModal
)
- }
- confirmButtonState="default"
- countries={countries}
- initial={data.countries}
- isDefault={data.default}
- onClose={toggleCountrySelectionDialog}
- />
- </>
- )}
- </Form>
+ )
+ }
+ confirmButtonState="default"
+ countries={countries}
+ initial={data.countries}
+ isDefault={data.default}
+ onClose={toggleModal}
+ />
+ </>
)}
- </Toggle>
+ </Form>
);
};
ShippingZoneCreatePage.displayName = "ShippingZoneCreatePage";
diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderCustomer.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderCustomer.tsx
index 0fa39e108c..20081af0e8 100644
--- a/saleor/static/dashboard-next/storybook/stories/orders/OrderCustomer.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderCustomer.tsx
@@ -16,6 +16,7 @@ const props: Omit<OrderCustomerProps, "classes"> = {
fetchUsers: () => undefined,
onBillingAddressEdit: undefined,
onCustomerEdit: undefined,
+ onProfileView: () => undefined,
onShippingAddressEdit: undefined,
order,
users: clients
diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderDetailsPage.tsx
index 4d453b6def..e284c6adc1 100644
--- a/saleor/static/dashboard-next/storybook/stories/orders/OrderDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderDetailsPage.tsx
@@ -30,6 +30,7 @@ const props: Omit<OrderDetailsPageProps, "classes"> = {
onPaymentRefund: undefined,
onPaymentVoid: undefined,
onProductClick: undefined,
+ onProfileView: () => undefined,
onShippingAddressEdit: undefined,
order
};
diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftPage.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftPage.tsx
index 8bea0d8d7b..f33e9bd2da 100644
--- a/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftPage.tsx
@@ -25,6 +25,7 @@ const props: Omit<OrderDraftPageProps, "classes"> = {
onOrderLineChange: () => undefined,
onOrderLineRemove: () => () => undefined,
onProductClick: undefined,
+ onProfileView: () => undefined,
onShippingAddressEdit: undefined,
onShippingMethodEdit: undefined,
order,