Skip to content

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

Add create product page

dominik-zeglen1fe813116312
diff --git a/package-lock.json b/package-lock.json
index 0f5cab8e5e..c74b6aa4b2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3840,6 +3840,11 @@
"@types/webpack-env": "1.13.6"
}
},
+ "@types/string-similarity": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/@types/string-similarity/-/string-similarity-1.2.0.tgz",
+ "integrity": "sha512-zrUNNlpw29TES8RF5EbdjlyLQduy9rh0b+xgx3RuPl0Qb6KMcQ3CI+cNKejpU3TEbLEfq6l627WxDIXS+Ebj/Q=="
+ },
"@types/webpack-env": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.13.6.tgz",
@@ -22740,6 +22745,14 @@
}
}
},
+ "string-similarity": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-1.2.0.tgz",
+ "integrity": "sha1-11FTyzg4RjGLejmo2SkrtNtOnDA=",
+ "requires": {
+ "lodash": "4.17.10"
+ }
+ },
"string-template": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/string-template/-/string-template-0.2.1.tgz",
diff --git a/package.json b/package.json
index 7599bb3d7f..5c411e479f 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
"@material-ui/icons": "^1.1.0",
"@types/storybook__addon-storyshots": "^3.4.3",
"@types/storybook__react": "^3.0.8",
+ "@types/string-similarity": "^1.2.0",
"apollo": "^0.2.2",
"apollo-cache-inmemory": "^1.1.12",
"apollo-client": "^2.2.8",
@@ -69,6 +70,7 @@
"react-svg": "^2.2.11",
"select2": "^4.0.5",
"sortablejs": "^1.5.0-rc1",
+ "string-similarity": "^1.2.0",
"svg-injector-2": "^2.0.35",
"typescript": "^2.9.1",
"universal-cookie": "^2.1.2"
diff --git a/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx b/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx
new file mode 100644
index 0000000000..c9e0de2ea9
--- /dev/null
+++ b/saleor/static/dashboard-next/components/AppLayout/AppLayout.tsx
@@ -0,0 +1,28 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+interface AppLayoutProps {}
+
+const decorate = withStyles(theme => ({
+ root: {
+ height: theme.spacing.unit * 7
+ },
+ navbarAside: {
+ backgroundColor: theme.palette.primary.dark
+ },
+ navbarMain: {
+ backgroundColor: theme.palette.primary.main
+ }
+}));
+const AppLayout = decorate<AppLayoutProps>(({ classes, children }) => (
+ <>
+ <div className={classes.root}>
+ <div className={classes.navbarAside}>asd</div>
+ <div className={classes.navbarMain}>asd</div>
+ </div>
+ <aside>asd</aside>
+ <main>{children}</main>
+ </>
+));
+AppLayout.displayName = "AppLayout";
+export default AppLayout;
diff --git a/saleor/static/dashboard-next/components/AppLayout/index.ts b/saleor/static/dashboard-next/components/AppLayout/index.ts
new file mode 100644
index 0000000000..990e3e03de
--- /dev/null
+++ b/saleor/static/dashboard-next/components/AppLayout/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./AppLayout";
+export * from "./AppLayout";
diff --git a/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx b/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx
new file mode 100644
index 0000000000..73a3482007
--- /dev/null
+++ b/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx
@@ -0,0 +1,9 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+interface ImageTileProps {}
+
+const decorate = withStyles(theme => ({ root: {} }));
+const ImageTile = decorate<ImageTileProps>(({ classes }) => <div />);
+ImageTile.displayName = "ImageTile";
+export default ImageTile;
diff --git a/saleor/static/dashboard-next/components/ImageTile/index.ts b/saleor/static/dashboard-next/components/ImageTile/index.ts
new file mode 100644
index 0000000000..56297f8849
--- /dev/null
+++ b/saleor/static/dashboard-next/components/ImageTile/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ImageTile";
+export * from "./ImageTile";
diff --git a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
index 23d4dfd3c8..a20f592af8 100644
--- a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
+++ b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
@@ -57,7 +57,7 @@ export const ProductList = decorate<ProductListProps>(
}) => (
<Table>
<TableHead>
- <TableRow>
+ <TableRow hover>
<TableCell />
<TableCell className={classes.textLeft}>
{i18n.t("Name", { context: "object" })}
@@ -68,7 +68,7 @@ export const ProductList = decorate<ProductListProps>(
</TableRow>
</TableHead>
<TableFooter>
- <TableRow>
+ <TableRow hover>
<TablePagination
colSpan={5}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
@@ -82,7 +82,7 @@ export const ProductList = decorate<ProductListProps>(
</TableFooter>
<TableBody>
{products === undefined ? (
- <TableRow>
+ <TableRow hover>
<TableCellAvatar />
<TableCell>
<Skeleton />
@@ -99,7 +99,7 @@ export const ProductList = decorate<ProductListProps>(
</TableRow>
) : products !== null && products.length > 0 ? (
products.map(product => (
- <TableRow key={product.id}>
+ <TableRow hover key={product.id}>
<TableCellAvatar thumbnail={product.thumbnailUrl} />
<TableCell className={classes.textLeft}>
<span
@@ -142,7 +142,7 @@ export const ProductList = decorate<ProductListProps>(
</TableRow>
))
) : (
- <TableRow>
+ <TableRow hover>
<TableCell colSpan={5}>{i18n.t("No products found")}</TableCell>
</TableRow>
)}
diff --git a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
index c9f3201ddd..fb6c706622 100644
--- a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
+++ b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
@@ -4,6 +4,7 @@ import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import Downshift from "downshift";
import * as React from "react";
+import { compareTwoStrings } from "string-similarity";
import i18n from "../../i18n";
@@ -11,21 +12,29 @@ interface SingleAutocompleteSelectFieldProps {
name: string;
choices: Array<{
label: string;
- value: string;
+ value: any;
}>;
value?: {
label: string;
- value: string;
+ value: any;
};
+ disabled?: boolean;
loading?: boolean;
placeholder?: string;
custom?: boolean;
helperText?: string;
label?: string;
- fetchChoices(value: string);
+ fetchChoices?(value: string);
onChange(event);
}
+interface SingleAutocompleteSelectFieldState {
+ choices: Array<{
+ label: string;
+ value: string;
+ }>;
+}
+
const decorate = withStyles(theme => ({
container: {
flexGrow: 1,
@@ -43,13 +52,14 @@ const decorate = withStyles(theme => ({
}
}));
-export const SingleAutocompleteSelectField = decorate<
+const SingleAutocompleteSelectFieldComponent = decorate<
SingleAutocompleteSelectFieldProps
>(
({
choices,
classes,
custom,
+ disabled,
helperText,
label,
loading,
@@ -91,6 +101,7 @@ export const SingleAutocompleteSelectField = decorate<
placeholder
})
}}
+ disabled={disabled}
helperText={helperText}
label={label}
fullWidth={true}
@@ -103,9 +114,9 @@ export const SingleAutocompleteSelectField = decorate<
</MenuItem>
) : (
<>
- {choices.map((suggestion, index) => (
+ {choices.map(suggestion => (
<MenuItem
- key={suggestion.value}
+ key={JSON.stringify(suggestion)}
selected={
selectedItem
? suggestion.value === selectedItem.value
@@ -140,4 +151,39 @@ export const SingleAutocompleteSelectField = decorate<
);
}
);
+export class SingleAutocompleteSelectField extends React.Component<
+ SingleAutocompleteSelectFieldProps,
+ SingleAutocompleteSelectFieldState
+> {
+ state = { choices: this.props.choices };
+
+ handleInputChange = (value: string) => {
+ this.setState({
+ choices: this.props.choices.sort((a, b) => {
+ const ratingA = compareTwoStrings(value || "", a.label);
+ const ratingB = compareTwoStrings(value || "", b.label);
+ if (ratingA > ratingB) {
+ return -1;
+ }
+ if (ratingA < ratingB) {
+ return 1;
+ }
+ return 0;
+ })
+ });
+ };
+
+ render() {
+ if (!!this.props.fetchChoices) {
+ return <SingleAutocompleteSelectFieldComponent {...this.props} />;
+ }
+ return (
+ <SingleAutocompleteSelectFieldComponent
+ {...this.props}
+ choices={this.state.choices}
+ fetchChoices={this.handleInputChange}
+ />
+ );
+ }
+}
export default SingleAutocompleteSelectField;
diff --git a/saleor/static/dashboard-next/components/TabSwitch/TabSwitch.tsx b/saleor/static/dashboard-next/components/TabSwitch/TabSwitch.tsx
new file mode 100644
index 0000000000..b97c35533c
--- /dev/null
+++ b/saleor/static/dashboard-next/components/TabSwitch/TabSwitch.tsx
@@ -0,0 +1,40 @@
+import * as React from "react";
+
+interface TabSwitchProps {
+ children:
+ | ((
+ props: {
+ currentTab: string;
+ handleChange: (event: React.ChangeEvent<any>, value: string) => void;
+ }
+ ) => React.ReactElement<any>)
+ | React.ReactNode;
+ initial: string;
+}
+interface TabSwitchState {
+ value: string;
+}
+
+class TabSwitch extends React.Component<TabSwitchProps, TabSwitchState> {
+ constructor(props) {
+ super(props);
+ this.state = {
+ value: this.props.initial
+ };
+ }
+
+ handleChange = (event: React.ChangeEvent<any>, value: string) =>
+ this.setState({ value });
+
+ render() {
+ const { children } = this.props;
+ if (typeof children === "function") {
+ return children({
+ currentTab: this.state.value,
+ handleChange: this.handleChange
+ });
+ }
+ return children;
+ }
+}
+export default TabSwitch;
diff --git a/saleor/static/dashboard-next/components/TabSwitch/index.ts b/saleor/static/dashboard-next/components/TabSwitch/index.ts
new file mode 100644
index 0000000000..db3ead829e
--- /dev/null
+++ b/saleor/static/dashboard-next/components/TabSwitch/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./TabSwitch";
+export * from "./TabSwitch";
diff --git a/saleor/static/dashboard-next/components/TableCellAvatar/TableCellAvatar.tsx b/saleor/static/dashboard-next/components/TableCellAvatar/TableCellAvatar.tsx
index d987041d03..1225b3f61e 100644
--- a/saleor/static/dashboard-next/components/TableCellAvatar/TableCellAvatar.tsx
+++ b/saleor/static/dashboard-next/components/TableCellAvatar/TableCellAvatar.tsx
@@ -4,7 +4,10 @@ import TableCell from "@material-ui/core/TableCell";
import Cached from "@material-ui/icons/Cached";
import * as React from "react";
+import NoPhoto from "../../icons/NoPhoto";
+
interface TableCellAvatarProps {
+ className?: string;
thumbnail?: string;
}
@@ -23,15 +26,15 @@ const decorate = withStyles(theme => ({
}
}));
const TableCellAvatar = decorate<TableCellAvatarProps>(
- ({ classes, thumbnail }) => (
- <TableCell className={classes.root}>
+ ({ classes, className, thumbnail }) => (
+ <TableCell className={[classes.root, className].join(" ")}>
{thumbnail === undefined ? (
<Avatar className={classes.avatar}>
<Cached />
</Avatar>
) : thumbnail === null ? (
<Avatar className={classes.avatar}>
- <Cached />
+ <NoPhoto />
</Avatar>
) : (
<Avatar className={classes.avatar} src={thumbnail} />
diff --git a/saleor/static/dashboard-next/gql-types.ts b/saleor/static/dashboard-next/gql-types.ts
index d8ee4969e9..d7e9d42bd8 100644
--- a/saleor/static/dashboard-next/gql-types.ts
+++ b/saleor/static/dashboard-next/gql-types.ts
@@ -762,6 +762,7 @@ export interface VariantUpdateMutation {
// The ID of the object.
id: string,
name: string,
+ sku: string,
},
} >,
} | null,
@@ -1098,6 +1099,7 @@ export interface ProductVariantDetailsQuery {
// The ID of the object.
id: string,
name: string,
+ sku: string,
},
} >,
} | null,
@@ -1376,6 +1378,7 @@ export interface ProductVariantFragment {
// The ID of the object.
id: string,
name: string,
+ sku: string,
},
} >,
} | null,
diff --git a/saleor/static/dashboard-next/icons/NoPhoto.tsx b/saleor/static/dashboard-next/icons/NoPhoto.tsx
new file mode 100644
index 0000000000..5d0b3ef39c
--- /dev/null
+++ b/saleor/static/dashboard-next/icons/NoPhoto.tsx
@@ -0,0 +1,10 @@
+import createSvgIcon from "@material-ui/icons/utils/createSvgIcon";
+import * as React from "react";
+
+export const NoPhoto = createSvgIcon(
+ <g style={{fillRule: 'evenodd'}}>
+ <path d="M 22.418358,23.933955 23.941248,22.416861 1.505286,0.06622212 -0.01756434,1.5833815 2.3945365,3.98626 c -0.00402,0.054209 -0.00609,0.1089561 -0.00609,0.1641949 l 0,15.5654231 c 0,1.223034 1.0044565,2.223746 2.232151,2.223746 l 15.6251379,0 c 0.05533,0 0.110242,-0.0021 0.164611,-0.0061 l 2.008007,2.000405 z m -4.234188,-4.218065 -2.232782,-2.224284 -10.2147024,0 3.3482328,-4.291641 2.3883966,2.879541 1.336535,-1.717557 -8.1892465,-8.1579753 0,13.5119163 13.5635665,0 z m 4.293682,-15.5654234 0,13.8585934 -2.232111,-2.223614 0,-11.6349794 -11.6793779,0 -2.232218,-2.2237479 13.9115959,0 c 1.227708,0 2.232111,1.0007001 2.232111,2.2237479 z" />
+ </g>
+);
+NoPhoto.displayName = "NoPhoto";
+export default NoPhoto;
diff --git a/saleor/static/dashboard-next/productTypes/fixtures.ts b/saleor/static/dashboard-next/productTypes/fixtures.ts
index d91567bea9..a539adb28b 100644
--- a/saleor/static/dashboard-next/productTypes/fixtures.ts
+++ b/saleor/static/dashboard-next/productTypes/fixtures.ts
@@ -1,18 +1,50 @@
export const productTypes = [
{
- id: "pt48490",
- name: "Wooden",
+ id: "pt44865",
+ name: "Steel",
hasVariants: true,
productAttributes: {
totalCount: 2,
edges: [
- { node: { id: "pta92235", sortNumber: 0, name: "Iowa", slug: "Iowa" } },
{
node: {
- id: "pta51633",
- sortNumber: 1,
- name: "e-commerce",
- slug: "e-commerce"
+ id: "pta55837",
+ sortOrder: 0,
+ name: "virtual",
+ slug: "virtual",
+ values: [
+ {
+ id: "ptav37754",
+ sortOrder: 0,
+ name: "turquoise",
+ slug: "turquoise"
+ },
+ {
+ id: "ptav60615",
+ sortOrder: 1,
+ name: "Credit Card Account",
+ slug: "Credit-Card-Account"
+ },
+ { id: "ptav86191", sortOrder: 2, name: "Pants", slug: "Pants" },
+ {
+ id: "ptav14831",
+ sortOrder: 3,
+ name: "maximize",
+ slug: "maximize"
+ },
+ { id: "ptav15280", sortOrder: 4, name: "Movies", slug: "Movies" }
+ ]
+ }
+ },
+ {
+ node: {
+ id: "pta64310",
+ sortOrder: 1,
+ name: "Shoes",
+ slug: "Shoes",
+ values: [
+ { id: "ptav55703", sortOrder: 0, name: "feed", slug: "feed" }
+ ]
}
}
]
@@ -22,18 +54,65 @@ export const productTypes = [
edges: [
{
node: {
- id: "pta32369",
- sortNumber: 0,
- name: "target",
- slug: "target"
+ id: "pta35234",
+ sortOrder: 0,
+ name: "experiences",
+ slug: "experiences",
+ values: [
+ { id: "ptav25787", sortOrder: 0, name: "ADP", slug: "ADP" },
+ {
+ id: "ptav40095",
+ sortOrder: 1,
+ name: "action-items",
+ slug: "action-items"
+ },
+ {
+ id: "ptav85585",
+ sortOrder: 2,
+ name: "collaboration",
+ slug: "collaboration"
+ }
+ ]
}
},
{
node: {
- id: "pta89798",
- sortNumber: 1,
- name: "Incredible",
- slug: "Incredible"
+ id: "pta27033",
+ sortOrder: 1,
+ name: "Visionary",
+ slug: "Visionary",
+ values: [
+ {
+ id: "ptav22663",
+ sortOrder: 0,
+ name: "Argentine Peso",
+ slug: "Argentine-Peso"
+ },
+ {
+ id: "ptav89180",
+ sortOrder: 1,
+ name: "Clothing",
+ slug: "Clothing"
+ },
+ {
+ id: "ptav83896",
+ sortOrder: 2,
+ name: "Customer",
+ slug: "Customer"
+ },
+ {
+ id: "ptav79395",
+ sortOrder: 3,
+ name: "multimedia",
+ slug: "multimedia"
+ },
+ {
+ id: "ptav49687",
+ sortOrder: 4,
+ name: "interactive",
+ slug: "interactive"
+ }
+ ]
}
}
]
@@ -42,63 +121,123 @@ export const productTypes = [
taxRate: "standard"
},
{
- id: "pt6851",
- name: "Steel",
+ id: "pt27252",
+ name: "Steel two",
hasVariants: false,
productAttributes: {
totalCount: 1,
edges: [
{
node: {
- id: "pta99872",
- sortNumber: 0,
- name: "Facilitator",
- slug: "Facilitator"
+ id: "pta67389",
+ sortOrder: 0,
+ name: "array",
+ slug: "array",
+ values: [
+ {
+ id: "ptav23966",
+ sortOrder: 0,
+ name: "Strategist",
+ slug: "Strategist"
+ },
+ {
+ id: "ptav34403",
+ sortOrder: 1,
+ name: "even-keeled",
+ slug: "even-keeled"
+ }
+ ]
}
}
]
},
variantAttributes: { totalCount: 0, edges: [] },
- isShippingRequired: false,
+ isShippingRequired: true,
taxRate: "standard"
},
{
- id: "pt39537",
- name: "Metal",
+ id: "pt68725",
+ name: "Frozen",
hasVariants: true,
productAttributes: {
totalCount: 4,
edges: [
{
node: {
- id: "pta76662",
- sortNumber: 0,
- name: "Liaison",
- slug: "Liaison"
+ id: "pta28666",
+ sortOrder: 0,
+ name: "Computers",
+ slug: "Computers",
+ values: [
+ { id: "ptav51546", sortOrder: 0, name: "black", slug: "black" }
+ ]
}
},
{
node: {
- id: "pta96362",
- sortNumber: 1,
- name: "virtual",
- slug: "virtual"
+ id: "pta77888",
+ sortOrder: 1,
+ name: "Parkway",
+ slug: "Parkway",
+ values: [
+ {
+ id: "ptav79471",
+ sortOrder: 0,
+ name: "unleash",
+ slug: "unleash"
+ },
+ {
+ id: "ptav52436",
+ sortOrder: 1,
+ name: "Investment Account",
+ slug: "Investment-Account"
+ },
+ {
+ id: "ptav3413",
+ sortOrder: 2,
+ name: "eyeballs",
+ slug: "eyeballs"
+ },
+ {
+ id: "ptav17339",
+ sortOrder: 3,
+ name: "Investment Account",
+ slug: "Investment-Account"
+ },
+ {
+ id: "ptav2231",
+ sortOrder: 4,
+ name: "California",
+ slug: "California"
+ }
+ ]
}
},
{
node: {
- id: "pta47776",
- sortNumber: 2,
- name: "override",
- slug: "override"
+ id: "pta19754",
+ sortOrder: 2,
+ name: "bypass",
+ slug: "bypass",
+ values: [
+ {
+ id: "ptav68887",
+ sortOrder: 0,
+ name: "calculate",
+ slug: "calculate"
+ }
+ ]
}
},
{
node: {
- id: "pta2475",
- sortNumber: 3,
- name: "frictionless",
- slug: "frictionless"
+ id: "pta69254",
+ sortOrder: 3,
+ name: "Lead",
+ slug: "Lead",
+ values: [
+ { id: "ptav1674", sortOrder: 0, name: "orchid", slug: "orchid" }
+ ]
}
}
]
@@ -108,18 +247,48 @@ export const productTypes = [
edges: [
{
node: {
- id: "pta95446",
- sortNumber: 0,
- name: "Re-engineered",
- slug: "Re-engineered"
+ id: "pta52751",
+ sortOrder: 0,
+ name: "Burkina Faso",
+ slug: "Burkina-Faso",
+ values: [
+ {
+ id: "ptav51410",
+ sortOrder: 0,
+ name: "Andorra",
+ slug: "Andorra"
+ },
+ {
+ id: "ptav38446",
+ sortOrder: 1,
+ name: "Concrete",
+ slug: "Concrete"
+ },
+ { id: "ptav62830", sortOrder: 2, name: "Guyana", slug: "Guyana" },
+ {
+ id: "ptav35266",
+ sortOrder: 3,
+ name: "Reduced",
+ slug: "Reduced"
+ }
+ ]
}
},
{
node: {
- id: "pta37902",
- sortNumber: 1,
- name: "real-time",
- slug: "real-time"
+ id: "pta81728",
+ sortOrder: 1,
+ name: "bluetooth",
+ slug: "bluetooth",
+ values: [
+ {
+ id: "ptav85090",
+ sortOrder: 0,
+ name: "Colorado",
+ slug: "Colorado"
+ },
+ { id: "ptav84747", sortOrder: 1, name: "Riel", slug: "Riel" }
+ ]
}
}
]
@@ -128,26 +297,38 @@ export const productTypes = [
taxRate: "standard"
},
{
- id: "pt67914",
+ id: "pt44961",
name: "Fresh",
hasVariants: true,
productAttributes: {
- totalCount: 2,
+ totalCount: 1,
edges: [
{
node: {
- id: "pta47954",
- sortNumber: 0,
- name: "payment",
- slug: "payment"
- }
- },
- {
- node: {
- id: "pta29219",
- sortNumber: 1,
- name: "transform",
- slug: "transform"
+ id: "pta48630",
+ sortOrder: 0,
+ name: "Jordanian Dinar",
+ slug: "Jordanian-Dinar",
+ values: [
+ {
+ id: "ptav42680",
+ sortOrder: 0,
+ name: "discrete",
+ slug: "discrete"
+ },
+ {
+ id: "ptav20274",
+ sortOrder: 1,
+ name: "Assurance",
+ slug: "Assurance"
+ },
+ {
+ id: "ptav11748",
+ sortOrder: 2,
+ name: "Unbranded Cotton Soap",
+ slug: "Unbranded-Cotton-Soap"
+ }
+ ]
}
}
]
@@ -157,10 +338,25 @@ export const productTypes = [
edges: [
{
node: {
- id: "pta69599",
- sortNumber: 0,
- name: "embrace",
- slug: "embrace"
+ id: "pta94377",
+ sortOrder: 0,
+ name: "payment",
+ slug: "payment",
+ values: [
+ {
+ id: "ptav83614",
+ sortOrder: 0,
+ name: "disintermediate",
+ slug: "disintermediate"
+ },
+ { id: "ptav63941", sortOrder: 1, name: "online", slug: "online" },
+ {
+ id: "ptav99833",
+ sortOrder: 2,
+ name: "payment",
+ slug: "payment"
+ }
+ ]
}
}
]
@@ -169,116 +365,209 @@ export const productTypes = [
taxRate: "standard"
},
{
- id: "pt11666",
- name: "Cotton",
+ id: "pt18337",
+ name: "Concrete",
hasVariants: true,
productAttributes: {
totalCount: 1,
edges: [
{
node: {
- id: "pta19059",
- sortNumber: 0,
- name: "Macedonia",
- slug: "Macedonia"
+ id: "pta92580",
+ sortOrder: 0,
+ name: "Concrete",
+ slug: "Concrete",
+ values: [
+ { id: "ptav4277", sortOrder: 0, name: "Refined", slug: "Refined" }
+ ]
}
}
]
},
variantAttributes: {
- totalCount: 2,
+ totalCount: 1,
edges: [
{
node: {
- id: "pta24510",
- sortNumber: 0,
- name: "bypassing",
- slug: "bypassing"
- }
- },
- {
- node: {
- id: "pta60488",
- sortNumber: 1,
- name: "encryption",
- slug: "encryption"
+ id: "pta24190",
+ sortOrder: 0,
+ name: "Ergonomic Granite Bike",
+ slug: "Ergonomic-Granite-Bike",
+ values: [
+ {
+ id: "ptav15347",
+ sortOrder: 0,
+ name: "District",
+ slug: "District"
+ },
+ {
+ id: "ptav11413",
+ sortOrder: 1,
+ name: "calculate",
+ slug: "calculate"
+ },
+ { id: "ptav302", sortOrder: 2, name: "TCP", slug: "TCP" },
+ { id: "ptav48581", sortOrder: 3, name: "SDD", slug: "SDD" }
+ ]
}
}
]
},
- isShippingRequired: false,
+ isShippingRequired: true,
taxRate: "standard"
},
{
- id: "pt23017",
- name: "Granite",
+ id: "pt18750",
+ name: "Cotton",
hasVariants: false,
productAttributes: {
- totalCount: 3,
+ totalCount: 1,
edges: [
{
node: {
- id: "pta82779",
- sortNumber: 0,
- name: "Extensions",
- slug: "Extensions"
- }
- },
- {
- node: {
- id: "pta27412",
- sortNumber: 1,
- name: "Automotive",
- slug: "Automotive"
- }
- },
- {
- node: {
- id: "pta32543",
- sortNumber: 2,
- name: "Massachusetts",
- slug: "Massachusetts"
+ id: "pta21014",
+ sortOrder: 0,
+ name: "Iraq",
+ slug: "Iraq",
+ values: [
+ {
+ id: "ptav5033",
+ sortOrder: 0,
+ name: "one-to-one",
+ slug: "one-to-one"
+ }
+ ]
}
}
]
},
variantAttributes: { totalCount: 0, edges: [] },
- isShippingRequired: false,
+ isShippingRequired: true,
taxRate: "standard"
},
{
- id: "pt74648",
- name: "Fresh",
+ id: "pt48335",
+ name: "Steel three",
hasVariants: true,
productAttributes: {
totalCount: 4,
edges: [
{
node: {
- id: "pta5202",
- sortNumber: 0,
- name: "Optional",
- slug: "Optional"
+ id: "pta65049",
+ sortOrder: 0,
+ name: "Taiwan",
+ slug: "Taiwan",
+ values: [
+ {
+ id: "ptav22004",
+ sortOrder: 0,
+ name: "Unbranded",
+ slug: "Unbranded"
+ },
+ { id: "ptav60504", sortOrder: 1, name: "AGP", slug: "AGP" },
+ { id: "ptav51168", sortOrder: 2, name: "Sleek", slug: "Sleek" },
+ {
+ id: "ptav10708",
+ sortOrder: 3,
+ name: "Handcrafted Fresh Sausages",
+ slug: "Handcrafted-Fresh-Sausages"
+ },
+ {
+ id: "ptav99626",
+ sortOrder: 4,
+ name: "Implementation",
+ slug: "Implementation"
+ }
+ ]
}
},
{
node: {
- id: "pta31989",
- sortNumber: 1,
- name: "Wyoming",
- slug: "Wyoming"
+ id: "pta71171",
+ sortOrder: 1,
+ name: "maroon",
+ slug: "maroon",
+ values: [
+ { id: "ptav38842", sortOrder: 0, name: "Frozen", slug: "Frozen" },
+ {
+ id: "ptav51110",
+ sortOrder: 1,
+ name: "open system",
+ slug: "open-system"
+ },
+ { id: "ptav7718", sortOrder: 2, name: "matrix", slug: "matrix" },
+ {
+ id: "ptav67123",
+ sortOrder: 3,
+ name: "Orchard",
+ slug: "Orchard"
+ },
+ {
+ id: "ptav33391",
+ sortOrder: 4,
+ name: "incentivize",
+ slug: "incentivize"
+ }
+ ]
}
},
{
node: {
- id: "pta702",
- sortNumber: 2,
- name: "hardware",
- slug: "hardware"
+ id: "pta42793",
+ sortOrder: 2,
+ name: "Chair",
+ slug: "Chair",
+ values: [
+ {
+ id: "ptav92542",
+ sortOrder: 0,
+ name: "frictionless",
+ slug: "frictionless"
+ },
+ {
+ id: "ptav18990",
+ sortOrder: 1,
+ name: "compress",
+ slug: "compress"
+ },
+ {
+ id: "ptav58568",
+ sortOrder: 2,
+ name: "Proactive",
+ slug: "Proactive"
+ },
+ {
+ id: "ptav95231",
+ sortOrder: 3,
+ name: "Program",
+ slug: "Program"
+ },
+ { id: "ptav93771", sortOrder: 4, name: "Web", slug: "Web" }
+ ]
}
},
{
- node: { id: "pta81699", sortNumber: 3, name: "Idaho", slug: "Idaho" }
+ node: {
+ id: "pta54549",
+ sortOrder: 3,
+ name: "client-driven",
+ slug: "client-driven",
+ values: [
+ {
+ id: "ptav42835",
+ sortOrder: 0,
+ name: "Quality",
+ slug: "Quality"
+ },
+ {
+ id: "ptav68828",
+ sortOrder: 1,
+ name: "Ergonomic Concrete Fish",
+ slug: "Ergonomic-Concrete-Fish"
+ }
+ ]
+ }
}
]
},
@@ -287,75 +576,137 @@ export const productTypes = [
edges: [
{
node: {
- id: "pta18263",
- sortNumber: 0,
- name: "Personal Loan Account",
- slug: "Personal-Loan-Account"
+ id: "pta74620",
+ sortOrder: 0,
+ name: "online",
+ slug: "online",
+ values: [
+ {
+ id: "ptav91332",
+ sortOrder: 0,
+ name: "Engineer",
+ slug: "Engineer"
+ },
+ {
+ id: "ptav74475",
+ sortOrder: 1,
+ name: "approach",
+ slug: "approach"
+ }
+ ]
}
}
]
},
- isShippingRequired: false,
+ isShippingRequired: true,
taxRate: "standard"
},
{
- id: "pt8102",
- name: "Frozen",
- hasVariants: false,
+ id: "pt51010",
+ name: "Cotton two",
+ hasVariants: true,
productAttributes: {
- totalCount: 3,
+ totalCount: 1,
edges: [
{
node: {
- id: "pta31363",
- sortNumber: 0,
- name: "parsing",
- slug: "parsing"
- }
- },
- {
- node: {
- id: "pta1588",
- sortNumber: 1,
- name: "payment",
- slug: "payment"
+ id: "pta20254",
+ sortOrder: 0,
+ name: "next generation",
+ slug: "next-generation",
+ values: [
+ {
+ id: "ptav60750",
+ sortOrder: 0,
+ name: "Azerbaijanian Manat",
+ slug: "Azerbaijanian-Manat"
+ },
+ {
+ id: "ptav64861",
+ sortOrder: 1,
+ name: "navigating",
+ slug: "navigating"
+ },
+ {
+ id: "ptav51862",
+ sortOrder: 2,
+ name: "Incredible Wooden Car",
+ slug: "Incredible-Wooden-Car"
+ },
+ {
+ id: "ptav9749",
+ sortOrder: 3,
+ name: "disintermediate",
+ slug: "disintermediate"
+ }
+ ]
}
- },
+ }
+ ]
+ },
+ variantAttributes: {
+ totalCount: 1,
+ edges: [
{
node: {
- id: "pta45552",
- sortNumber: 2,
- name: "Optimization",
- slug: "Optimization"
+ id: "pta83800",
+ sortOrder: 0,
+ name: "Representative",
+ slug: "Representative",
+ values: [
+ {
+ id: "ptav21139",
+ sortOrder: 0,
+ name: "solid state",
+ slug: "solid-state"
+ }
+ ]
}
}
]
},
- variantAttributes: { totalCount: 0, edges: [] },
- isShippingRequired: false,
+ isShippingRequired: true,
taxRate: "standard"
},
{
- id: "pt66738",
- name: "Rubber",
+ id: "pt62770",
+ name: "Frozen two",
hasVariants: true,
productAttributes: {
- totalCount: 2,
+ totalCount: 1,
edges: [
{
node: {
- id: "pta59482",
- sortNumber: 0,
- name: "Azerbaijan",
- slug: "Azerbaijan"
- }
- },
- {
- node: {
- id: "pta18958",
- sortNumber: 1,
- name: "primary",
- slug: "primary"
+ id: "pta25934",
+ sortOrder: 0,
+ name: "Chile",
+ slug: "Chile",
+ values: [
+ {
+ id: "ptav79149",
+ sortOrder: 0,
+ name: "overriding",
+ slug: "overriding"
+ },
+ {
+ id: "ptav27362",
+ sortOrder: 1,
+ name: "invoice",
+ slug: "invoice"
+ },
+ {
+ id: "ptav94654",
+ sortOrder: 2,
+ name: "deposit",
+ slug: "deposit"
+ },
+ {
+ id: "ptav53571",
+ sortOrder: 3,
+ name: "3rd generation",
+ slug: "3rd-generation"
+ }
+ ]
}
}
]
@@ -365,10 +716,18 @@ export const productTypes = [
edges: [
{
node: {
- id: "pta55738",
- sortNumber: 0,
- name: "silver",
- slug: "silver"
+ id: "pta68227",
+ sortOrder: 0,
+ name: "Balanced",
+ slug: "Balanced",
+ values: [
+ {
+ id: "ptav99727",
+ sortOrder: 0,
+ name: "infomediaries",
+ slug: "infomediaries"
+ }
+ ]
}
}
]
@@ -377,36 +736,180 @@ export const productTypes = [
taxRate: "standard"
},
{
- id: "pt98611",
- name: "Granite",
+ id: "pt43019",
+ name: "Soft",
hasVariants: true,
productAttributes: {
- totalCount: 1,
+ totalCount: 4,
edges: [
{
node: {
- id: "pta18523",
- sortNumber: 0,
- name: "implementation",
- slug: "implementation"
+ id: "pta45280",
+ sortOrder: 0,
+ name: "drive",
+ slug: "drive",
+ values: [
+ {
+ id: "ptav28113",
+ sortOrder: 0,
+ name: "web-readiness",
+ slug: "web-readiness"
+ },
+ {
+ id: "ptav61757",
+ sortOrder: 1,
+ name: "Pitcairn Islands",
+ slug: "Pitcairn-Islands"
+ },
+ { id: "ptav22934", sortOrder: 2, name: "sensor", slug: "sensor" },
+ {
+ id: "ptav39736",
+ sortOrder: 3,
+ name: "multi-tasking",
+ slug: "multi-tasking"
+ },
+ {
+ id: "ptav89720",
+ sortOrder: 4,
+ name: "disintermediate",
+ slug: "disintermediate"
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ id: "pta93764",
+ sortOrder: 1,
+ name: "needs-based",
+ slug: "needs-based",
+ values: [
+ {
+ id: "ptav97013",
+ sortOrder: 0,
+ name: "firewall",
+ slug: "firewall"
+ },
+ {
+ id: "ptav50856",
+ sortOrder: 1,
+ name: "Plastic",
+ slug: "Plastic"
+ },
+ { id: "ptav21173", sortOrder: 2, name: "Towels", slug: "Towels" },
+ { id: "ptav80307", sortOrder: 3, name: "matrix", slug: "matrix" },
+ {
+ id: "ptav74059",
+ sortOrder: 4,
+ name: "hacking",
+ slug: "hacking"
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ id: "pta65268",
+ sortOrder: 2,
+ name: "hard drive",
+ slug: "hard-drive",
+ values: [
+ {
+ id: "ptav27466",
+ sortOrder: 0,
+ name: "Unbranded Metal Soap",
+ slug: "Unbranded-Metal-Soap"
+ },
+ { id: "ptav88596", sortOrder: 1, name: "Small", slug: "Small" },
+ {
+ id: "ptav84969",
+ sortOrder: 2,
+ name: "Awesome",
+ slug: "Awesome"
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ id: "pta43186",
+ sortOrder: 3,
+ name: "Pants",
+ slug: "Pants",
+ values: [
+ {
+ id: "ptav54874",
+ sortOrder: 0,
+ name: "seamless",
+ slug: "seamless"
+ },
+ {
+ id: "ptav59316",
+ sortOrder: 1,
+ name: "Awesome Metal Fish",
+ slug: "Awesome-Metal-Fish"
+ }
+ ]
}
}
]
},
variantAttributes: {
- totalCount: 1,
+ totalCount: 2,
edges: [
{
node: {
- id: "pta54877",
- sortNumber: 0,
- name: "silver",
- slug: "silver"
+ id: "pta95449",
+ sortOrder: 0,
+ name: "interface",
+ slug: "interface",
+ values: [
+ {
+ id: "ptav65660",
+ sortOrder: 0,
+ name: "calculating",
+ slug: "calculating"
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ id: "pta93300",
+ sortOrder: 1,
+ name: "Kroon",
+ slug: "Kroon",
+ values: [
+ {
+ id: "ptav73125",
+ sortOrder: 0,
+ name: "functionalities",
+ slug: "functionalities"
+ },
+ {
+ id: "ptav77865",
+ sortOrder: 1,
+ name: "architectures",
+ slug: "architectures"
+ },
+ {
+ id: "ptav64084",
+ sortOrder: 2,
+ name: "functionalities",
+ slug: "functionalities"
+ },
+ {
+ id: "ptav38597",
+ sortOrder: 3,
+ name: "Officer",
+ slug: "Officer"
+ }
+ ]
}
}
]
},
- isShippingRequired: true,
+ isShippingRequired: false,
taxRate: "standard"
}
];
diff --git a/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx b/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx
new file mode 100644
index 0000000000..94ebbdeb5b
--- /dev/null
+++ b/saleor/static/dashboard-next/products/components/ProductCreatePage/ProductCreatePage.tsx
@@ -0,0 +1,206 @@
+import DialogContentText from "@material-ui/core/DialogContentText";
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+import { AttributeType, AttributeValueType, MoneyType } from "../../";
+import { UserError } from "../../../";
+import ActionDialog from "../../../components/ActionDialog";
+import Container from "../../../components/Container";
+import Form from "../../../components/Form";
+import PageHeader from "../../../components/PageHeader";
+import SaveButtonBar, {
+ SaveButtonBarState
+} from "../../../components/SaveButtonBar/SaveButtonBar";
+import SeoForm from "../../../components/SeoForm";
+import Toggle from "../../../components/Toggle";
+import i18n from "../../../i18n";
+import ProductAvailabilityForm from "../ProductAvailabilityForm";
+import ProductDetailsForm from "../ProductDetailsForm";
+import ProductImages from "../ProductImages";
+import ProductOrganization from "../ProductOrganization";
+import ProductPricing from "../ProductPricing";
+import ProductStock from "../ProductStock";
+import ProductVariants from "../ProductVariants";
+
+interface ProductCreatePageProps {
+ errors: UserError[];
+ collections?: Array<{
+ id: string;
+ name: string;
+ }>;
+ categories?: Array<{
+ id: string;
+ name: string;
+ }>;
+ disabled?: boolean;
+ productTypes?: Array<{
+ id: string;
+ name: string;
+ hasVariants: boolean;
+ productAttributes: {
+ edges: Array<{
+ node: AttributeType;
+ }>;
+ };
+ }>;
+ header: string;
+ saveButtonBarState?: SaveButtonBarState;
+ onAttributesEdit: () => void;
+ onBack?();
+ onSubmit?(data: any);
+}
+
+const decorate = withStyles(theme => ({
+ cardContainer: {
+ marginTop: theme.spacing.unit * 2,
+ [theme.breakpoints.down("sm")]: {
+ marginTop: theme.spacing.unit
+ }
+ },
+ root: {
+ display: "grid",
+ gridGap: theme.spacing.unit * 2 + "px",
+ gridTemplateColumns: "2.25fr 1fr",
+ marginTop: theme.spacing.unit * 2,
+ [theme.breakpoints.down("sm")]: {
+ gridGap: theme.spacing.unit + "px",
+ gridTemplateColumns: "1fr",
+ marginTop: theme.spacing.unit
+ }
+ }
+}));
+
+export const ProductCreatePage = decorate<ProductCreatePageProps>(
+ ({
+ classes,
+ disabled,
+ categories,
+ collections,
+ errors: userErrors,
+ header,
+ productTypes,
+ saveButtonBarState,
+ onAttributesEdit,
+ onBack,
+ onSubmit
+ }) => {
+ const initialData = {
+ attributes: [],
+ available: false,
+ availableOn: "",
+ category: "",
+ chargeTaxes: false,
+ collections: [],
+ description: "",
+ featured: false,
+ name: "",
+ price: 0,
+ productType: {
+ label: "",
+ value: {
+ hasVariants: false,
+ id: "",
+ name: "",
+ productAttributes: {
+ edges: [] as Array<{ node: AttributeType }>
+ }
+ }
+ },
+ seoDescription: "",
+ seoTitle: "",
+ sku: null,
+ stockQuantity: null
+ };
+ return (
+ <Toggle>
+ {(openedDeleteDialog, { toggle: toggleDeleteDialog }) => (
+ <Form onSubmit={onSubmit} errors={userErrors} initial={initialData}>
+ {({ change, data, errors, hasChanged, submit }) => (
+ <Container width="md">
+ <PageHeader title={header} onBack={onBack} />
+ <div className={classes.root}>
+ <div>
+ <ProductDetailsForm
+ data={data}
+ disabled={disabled}
+ errors={errors}
+ onChange={change}
+ />
+ <div className={classes.cardContainer}>
+ <ProductPricing
+ // FIXME: this should be fetched from API
+ currency="USD"
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
+ </div>
+ <div className={classes.cardContainer}>
+ <SeoForm
+ helperText={i18n.t(
+ "Add search engine title and description to make this product easier to find"
+ )}
+ title={data.seoTitle}
+ titlePlaceholder={data.name}
+ description={data.seoDescription}
+ descriptionPlaceholder={data.description}
+ loading={disabled}
+ onChange={change}
+ />
+ </div>
+ </div>
+ <div>
+ <ProductOrganization
+ category={data.category}
+ categories={
+ categories !== undefined && categories !== null
+ ? categories.map(category => ({
+ label: category.name,
+ value: category.id
+ }))
+ : []
+ }
+ errors={errors}
+ productCollections={data.collections}
+ collections={
+ collections !== undefined && collections !== null
+ ? collections.map(collection => ({
+ label: collection.name,
+ value: collection.id
+ }))
+ : []
+ }
+ productTypes={productTypes}
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
+ <div className={classes.cardContainer}>
+ <ProductAvailabilityForm
+ data={data}
+ errors={errors}
+ loading={disabled}
+ onChange={change}
+ />
+ </div>
+ </div>
+ </div>
+ <SaveButtonBar
+ labels={{
+ delete: i18n.t("Remove product"),
+ save: i18n.t("Save product")
+ }}
+ onDelete={toggleDeleteDialog}
+ onSave={submit}
+ state={saveButtonBarState}
+ disabled={disabled || !onSubmit || !hasChanged}
+ />
+ </Container>
+ )}
+ </Form>
+ )}
+ </Toggle>
+ );
+ }
+);
+export default ProductCreatePage;
diff --git a/saleor/static/dashboard-next/products/components/ProductCreatePage/index.ts b/saleor/static/dashboard-next/products/components/ProductCreatePage/index.ts
new file mode 100644
index 0000000000..7174a4e9d5
--- /dev/null
+++ b/saleor/static/dashboard-next/products/components/ProductCreatePage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ProductCreatePage";
+export * from "./ProductCreatePage";
diff --git a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
index a1cc811171..1385c8a136 100644
--- a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
@@ -1,9 +1,12 @@
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 { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import AddPhotoIcon from "@material-ui/icons/AddAPhoto";
+import DeleteIcon from "@material-ui/icons/Delete";
+import EditIcon from "@material-ui/icons/Edit";
import * as React from "react";
import { SortableContainer, SortableElement } from "react-sortable-hoc";
@@ -53,17 +56,42 @@ const decorate = withStyles(theme => ({
color: "rgba(255, 255, 255, 0.54)"
},
image: {
- cursor: "move",
height: "100%",
- maxHeight: theme.spacing.unit * 15,
- maxWidth: theme.spacing.unit * 15,
+ objectFit: "contain" as "contain",
userSelect: "none" as "none",
width: "100%"
},
imageContainer: {
+ "&:hover, &.dragged": {
+ "& $imageOverlay": {
+ display: "block" as "block"
+ }
+ },
+ background: "#ffffff",
border: "1px solid #eaeaea",
borderRadius: theme.spacing.unit,
- padding: theme.spacing.unit * 2
+ height: theme.spacing.unit * 17.5,
+ overflow: "hidden" as "hidden",
+ padding: theme.spacing.unit * 2,
+ position: "relative" as "relative"
+ },
+ imageOverlay: {
+ background: "rgba(0, 0, 0, 0.6)",
+ cursor: "move",
+ display: "none" as "none",
+ height: theme.spacing.unit * 17.5,
+ left: 0,
+ padding: theme.spacing.unit * 2,
+ position: "absolute" as "absolute",
+ top: 0,
+ width: theme.spacing.unit * 17.5
+ },
+ imageOverlayToolbar: {
+ alignContent: "flex-end",
+ display: "flex" as "flex",
+ position: "relative" as "relative",
+ right: -theme.spacing.unit * 3,
+ top: -theme.spacing.unit * 2
},
noPhotosIcon: {
height: theme.spacing.unit * 8,
@@ -80,36 +108,28 @@ const decorate = withStyles(theme => ({
marginTop: theme.spacing.unit
},
root: {
- display: "grid",
- gridColumnGap: `${theme.spacing.unit * 2}px`,
- gridRowGap: `${theme.spacing.unit * 2}px`,
- gridTemplateColumns: "repeat(4, 1fr)",
- [theme.breakpoints.down("sm")]: {
- gridTemplateColumns: "repeat(2, 1fr)"
- }
+ display: "grid" as "grid",
+ gridColumnGap: theme.spacing.unit * 2 + "px",
+ gridRowGap: theme.spacing.unit * 2 + "px",
+ gridTemplateColumns: "repeat(4, 1fr)"
}
}));
const ImageListElement = SortableElement(
decorate<ImageListElementProps>(({ classes, onImageEdit, tile }) => (
<div className={classes.imageContainer}>
+ <div className={classes.imageOverlay}>
+ <div className={classes.imageOverlayToolbar}>
+ <IconButton color="secondary" onClick={onImageEdit}>
+ <EditIcon />
+ </IconButton>
+ <IconButton color="secondary">
+ <DeleteIcon />
+ </IconButton>
+ </div>
+ </div>
<img className={classes.image} src={tile.url} alt={tile.alt} />
</div>
- // <GridListTile key={tile.id} component="div" className={classes.gridElement}>
- // <img src={tile.url} alt={tile.alt} />
- // <GridListTileBar
- // title={tile.alt || i18n.t("No description")}
- // actionIcon={
- // onImageEdit ? (
- // <IconButton className={classes.icon} onClick={onImageEdit}>
- // <ModeEditIcon />
- // </IconButton>
- // ) : (
- // ""
- // )
- // }
- // />
- // </GridListTile>
))
);
@@ -169,11 +189,13 @@ const ProductImages = decorate<ProductImagesProps>(
{images === undefined ? (
<div className={classes.root}>
<div className={classes.imageContainer}>
- <img src={placeholderImage} />
+ <img className={classes.image} src={placeholderImage} />
</div>
</div>
) : images.length > 0 ? (
<ImageListContainer
+ distance={20}
+ helperClass="dragged"
axis="xy"
items={images}
onSortEnd={onImageReorder}
diff --git a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
index 02ed2eaac1..9b0bab7878 100644
--- a/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductOrganization/ProductOrganization.tsx
@@ -8,21 +8,40 @@ import { AttributeType, AttributeValueType } from "../..";
import CardTitle from "../../../components/CardTitle";
import { FormSpacer } from "../../../components/FormSpacer";
import MultiSelectField from "../../../components/MultiSelectField";
+import SingleAutocompleteSelectField from "../../../components/SingleAutocompleteSelectField";
import SingleSelectField from "../../../components/SingleSelectField";
import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
+interface ProductType {
+ hasVariants: boolean;
+ id: string;
+ name: string;
+ productAttributes: {
+ edges: Array<{ node: AttributeType }>;
+ };
+}
interface ProductOrganizationProps {
categories?: Array<{ value: string; label: string }>;
collections?: Array<{ value: string; label: string }>;
- attributes?: Array<{
- attribute: AttributeType;
- value: AttributeValueType;
- }>;
category: string;
productCollections: string[];
data: {
- [key: string]: string;
+ attributes: Array<{
+ slug: string;
+ value: string;
+ }>;
+ productType: {
+ label: string;
+ value: {
+ hasVariants: boolean;
+ id: string;
+ name: string;
+ productAttributes: {
+ edges: Array<{ node: AttributeType }>;
+ };
+ };
+ };
};
disabled: boolean;
errors: { [key: string]: string };
@@ -32,6 +51,7 @@ interface ProductOrganizationProps {
name?: string;
};
};
+ productTypes?: ProductType[];
onChange: (event: React.ChangeEvent<any>) => void;
}
@@ -49,7 +69,6 @@ const decorate = withStyles(theme => ({
}));
const ProductOrganization = decorate<ProductOrganizationProps>(
({
- attributes,
category,
categories,
classes,
@@ -59,93 +78,158 @@ const ProductOrganization = decorate<ProductOrganizationProps>(
errors,
product,
productCollections,
+ productTypes,
onChange
- }) => (
- <Card>
- <CardTitle title={i18n.t("Organize Product")} />
- <CardContent>
- {product &&
- product.productType &&
- product.productType.name !== undefined ? (
- <SingleSelectField
- disabled={true}
+ }) => {
+ const unrolledAttributes =
+ data.productType &&
+ data.productType.value &&
+ data.productType.value.productAttributes
+ ? data.productType.value.productAttributes.edges.map(edge => edge.node)
+ : [];
+ const getAttributeName = (slug: string) =>
+ unrolledAttributes.filter(a => a.slug === slug)[0].slug;
+ const getAttributeValue = (slug: string) =>
+ data.attributes.filter(a => a.slug === slug)[0].value;
+ const getAttributeValues = (slug: string) =>
+ unrolledAttributes.filter(a => a.slug === slug)[0].values;
+ const handleProductTypeSelect = (
+ event: React.ChangeEvent<{
+ name: string;
+ value: {
+ label: string;
+ value: ProductType;
+ };
+ }>
+ ) => {
+ onChange(event);
+ onChange({
+ ...event,
+ target: {
+ ...event.target,
+ name: "attributes",
+ value: event.target.value.value.productAttributes.edges.map(edge => ({
+ slug: edge.node.slug,
+ value: ""
+ }))
+ }
+ });
+ };
+ const handleProductAttributeValueSelect = (
+ event: React.ChangeEvent<{
+ name: string;
+ value: {
+ label: string;
+ value: string;
+ };
+ }>
+ ) =>
+ onChange({
+ ...event,
+ target: {
+ ...event.target,
+ name: "attributes",
+ value: data.attributes.map(
+ a =>
+ a.slug === event.target.name
+ ? { slug: a.slug, value: event.target.value }
+ : a
+ )
+ }
+ });
+ return (
+ <Card>
+ <CardTitle title={i18n.t("Organize Product")} />
+ <CardContent>
+ <SingleAutocompleteSelectField
+ name="productType"
+ disabled={!!product || disabled}
label={i18n.t("Product Type")}
- choices={[{ label: product.productType.name, value: "1" }]}
- value={"1"}
- onChange={() => {}}
+ choices={
+ product &&
+ product.productType &&
+ product.productType.name !== undefined
+ ? [{ label: product.productType.name, value: "1" }]
+ : productTypes
+ ? productTypes.map(pt => ({ label: pt.name, value: pt }))
+ : []
+ }
+ value={data.productType}
+ onChange={handleProductTypeSelect}
/>
- ) : (
- <Skeleton />
- )}
- <FormSpacer />
- {product &&
- product.productType &&
- product.productType.hasVariants !== undefined ? (
+ <FormSpacer />
<SingleSelectField
disabled={true}
+ name="hasVariants"
label={i18n.t("Is it configurable?")}
choices={[
{ label: i18n.t("Yes"), value: "true" },
{ label: i18n.t("No"), value: "false" }
]}
- value={product.productType.hasVariants + ""}
- onChange={() => {}}
+ value={
+ product &&
+ product.productType &&
+ product.productType.hasVariants !== undefined
+ ? product.productType.hasVariants + ""
+ : data.productType
+ ? data.productType.value.hasVariants + ""
+ : false + ""
+ }
+ onChange={onChange}
+ />
+ <Typography className={classes.cardSubtitle}>
+ {i18n.t("Attributes")}
+ </Typography>
+ {data.attributes ? (
+ data.attributes.map((item, index) => {
+ return (
+ <React.Fragment key={index}>
+ <SingleSelectField
+ disabled={disabled}
+ name={item.slug}
+ label={getAttributeName(item.slug)}
+ onChange={handleProductAttributeValueSelect}
+ value={getAttributeValue(item.slug)}
+ choices={getAttributeValues(item.slug).map(v => ({
+ label: v.name,
+ value: v.slug
+ }))}
+ key={index}
+ />
+ <FormSpacer />
+ </React.Fragment>
+ );
+ })
+ ) : (
+ <Skeleton />
+ )}
+ <hr className={classes.hr} />
+ <SingleSelectField
+ disabled={disabled}
+ error={!!errors.category}
+ hint={errors.category}
+ label={i18n.t("Category")}
+ choices={disabled ? [] : categories}
+ name="category"
+ value={category}
+ onChange={onChange}
/>
- ) : (
- <Skeleton />
- )}
- <Typography className={classes.cardSubtitle}>
- {i18n.t("Attributes")}
- </Typography>
- {attributes ? (
- attributes.map((item, index) => {
- return (
- <React.Fragment key={index}>
- <SingleSelectField
- disabled={disabled}
- name={item.attribute.slug}
- label={item.attribute.name}
- onChange={onChange}
- value={data[item.attribute.slug]}
- choices={item.attribute.values.map(choice => ({
- label: choice.name,
- value: choice.slug
- }))}
- key={index}
- />
- <FormSpacer />
- </React.Fragment>
- );
- })
- ) : (
- <Skeleton />
- )}
- <hr className={classes.hr} />
- <SingleSelectField
- disabled={disabled}
- error={!!errors.category}
- hint={errors.category}
- label={i18n.t("Category")}
- choices={disabled ? [] : categories}
- name="category"
- value={category}
- onChange={onChange}
- />
- <FormSpacer />
- <hr className={classes.hr} />
- <MultiSelectField
- disabled={disabled}
- error={!!errors.collections}
- hint={errors.collections}
- label={i18n.t("Collections")}
- choices={disabled ? [] : collections}
- name="collections"
- value={productCollections}
- onChange={onChange}
- />
- </CardContent>
- </Card>
- )
+ <FormSpacer />
+ <hr className={classes.hr} />
+ <MultiSelectField
+ disabled={disabled}
+ error={!!errors.collections}
+ hint={errors.collections}
+ label={i18n.t("Collections")}
+ choices={disabled ? [] : collections}
+ name="collections"
+ value={productCollections}
+ onChange={onChange}
+ />
+ </CardContent>
+ </Card>
+ );
+ }
);
ProductOrganization.displayName = "ProductOrganization";
export default ProductOrganization;
diff --git a/saleor/static/dashboard-next/products/components/ProductPrice/ProductPrice.tsx b/saleor/static/dashboard-next/products/components/ProductPrice/ProductPrice.tsx
index 32692f5847..10b03e4d78 100644
--- a/saleor/static/dashboard-next/products/components/ProductPrice/ProductPrice.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductPrice/ProductPrice.tsx
@@ -42,7 +42,7 @@ const ProductPrice = decorate<ProductPriceProps>(
<PageHeader title={i18n.t("Pricing")} />
<Table className={classes.root}>
<TableBody>
- <TableRow>
+ <TableRow hover>
<TableCell>{i18n.t("Purchase cost")}</TableCell>
<TableCell className={classes.textRight}>
{purchaseCost ? (
@@ -81,7 +81,7 @@ const ProductPrice = decorate<ProductPriceProps>(
)}
</TableCell>
</TableRow>
- <TableRow>
+ <TableRow hover>
<TableCell>{i18n.t("Margin")}</TableCell>
<TableCell className={classes.textRight}>
{margin ? `${margin.start} % - ${margin.stop}%` : <Skeleton />}
diff --git a/saleor/static/dashboard-next/products/components/ProductPricing/ProductPricing.tsx b/saleor/static/dashboard-next/products/components/ProductPricing/ProductPricing.tsx
index 3656fb2878..6578acc9ef 100644
--- a/saleor/static/dashboard-next/products/components/ProductPricing/ProductPricing.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductPricing/ProductPricing.tsx
@@ -40,6 +40,7 @@ const ProductPricing = decorate<ProductPricingProps>(
<CardContent>
<div className={classes.root}>
<PriceField
+ disabled={disabled}
label={i18n.t("Price")}
name="price"
value={data.price}
diff --git a/saleor/static/dashboard-next/products/components/ProductStock/ProductStock.tsx b/saleor/static/dashboard-next/products/components/ProductStock/ProductStock.tsx
new file mode 100644
index 0000000000..530e18a9ab
--- /dev/null
+++ b/saleor/static/dashboard-next/products/components/ProductStock/ProductStock.tsx
@@ -0,0 +1,53 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import { withStyles } from "@material-ui/core/styles";
+import TextField from "@material-ui/core/TextField";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import i18n from "../../../i18n";
+
+interface ProductStockProps {
+ data: {
+ sku: string;
+ stockQuantity: number;
+ };
+ disabled: boolean;
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+
+const decorate = withStyles(theme => ({
+ root: {
+ display: "grid",
+ gridColumnGap: theme.spacing.unit * 2 + "px",
+ gridTemplateColumns: "1fr 1fr"
+ }
+}));
+const ProductStock = decorate<ProductStockProps>(
+ ({ classes, data, disabled, onChange }) => (
+ <Card>
+ <CardTitle title={i18n.t("Inventory")} />
+ <CardContent>
+ <div className={classes.root}>
+ <TextField
+ disabled={disabled}
+ name="sku"
+ label={i18n.t("SKU (Stock Keeping Unit)")}
+ value={data.sku}
+ onChange={onChange}
+ />
+ <TextField
+ disabled={disabled}
+ name="stockInventory"
+ label={i18n.t("Inventory")}
+ value={data.stockQuantity}
+ type="number"
+ onChange={onChange}
+ />
+ </div>
+ </CardContent>
+ </Card>
+ )
+);
+ProductStock.displayName = "ProductStock";
+export default ProductStock;
diff --git a/saleor/static/dashboard-next/products/components/ProductStock/index.ts b/saleor/static/dashboard-next/products/components/ProductStock/index.ts
new file mode 100644
index 0000000000..f98d67440e
--- /dev/null
+++ b/saleor/static/dashboard-next/products/components/ProductStock/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ProductStock";
+export * from "./ProductStock";
diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
index 055ff8f219..108c3a4025 100644
--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
@@ -1,8 +1,5 @@
import DialogContentText from "@material-ui/core/DialogContentText";
-import IconButton from "@material-ui/core/IconButton";
import { withStyles } from "@material-ui/core/styles";
-import DeleteIcon from "@material-ui/icons/Delete";
-import VisibilityIcon from "@material-ui/icons/Visibility";
import * as React from "react";
import { AttributeType, AttributeValueType, MoneyType } from "../../";
@@ -17,14 +14,12 @@ import SaveButtonBar, {
import SeoForm from "../../../components/SeoForm";
import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
-import ProductAttributesForm from "../ProductAttributesForm";
import ProductAvailabilityForm from "../ProductAvailabilityForm";
-import ProductCategoryAndCollectionsForm from "../ProductCategoryAndCollectionsForm";
import ProductDetailsForm from "../ProductDetailsForm";
import ProductImages from "../ProductImages";
import ProductOrganization from "../ProductOrganization";
-import ProductPrice from "../ProductPrice/ProductPrice";
import ProductPricing from "../ProductPricing";
+import ProductStock from "../ProductStock";
import ProductVariants from "../ProductVariants";
interface ProductUpdateProps {
@@ -94,7 +89,9 @@ interface ProductUpdateProps {
};
url: string;
};
+ header: string;
saveButtonBarState?: SaveButtonBarState;
+ onVariantShow: (id: string) => () => void;
onAttributesEdit: () => void;
onBack?();
onDelete?(id: string);
@@ -105,7 +102,6 @@ interface ProductUpdateProps {
onSeoClick?();
onSubmit?(data: any);
onVariantAdd?();
- onVariantShow?(id: string);
}
const decorate = withStyles(theme => ({
@@ -136,6 +132,7 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
collections,
errors: userErrors,
images,
+ header,
placeholderImage,
product,
productCollections,
@@ -154,6 +151,13 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
onVariantShow
}) => {
const initialData = {
+ attributes:
+ product && product.attributes
+ ? product.attributes.map(a => ({
+ slug: a.attribute.slug,
+ value: a.value.slug
+ }))
+ : undefined,
available: product ? product.isPublished : undefined,
availableOn: product ? product.availableOn : "",
category: product && product.category ? product.category.id : undefined,
@@ -167,14 +171,35 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
name: product ? product.name : "",
price:
product && product.price ? product.price.amount.toString() : undefined,
+ productType:
+ product && product.productType && product.attributes
+ ? {
+ label: product.productType.name,
+ value: {
+ hasVariants: product.productType.hasVariants,
+ id: product.productType.id,
+ name: product.productType.name,
+ productAttributes: {
+ edges: product.attributes.map(a => ({ node: a.attribute }))
+ }
+ }
+ }
+ : undefined,
seoDescription: product ? product.seoDescription : "",
- seoTitle: product && product.seoTitle ? product.seoTitle : ""
+ seoTitle: product && product.seoTitle ? product.seoTitle : "",
+ sku:
+ product && product.productType && product.productType.hasVariants
+ ? undefined
+ : variants && variants[0]
+ ? variants[0].sku
+ : undefined,
+ stockQuantity:
+ product && product.productType && product.productType.hasVariants
+ ? undefined
+ : variants && variants[0]
+ ? variants[0].stockQuantity
+ : undefined
};
- if (product && product.attributes) {
- product.attributes.forEach(item => {
- initialData[item.attribute.slug] = item.value.slug;
- });
- }
return (
<Toggle>
{(openedDeleteDialog, { toggle: toggleDeleteDialog }) => (
@@ -186,24 +211,7 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
>
{({ change, data, errors, hasChanged, submit }) => (
<Container width="md">
- <PageHeader
- title={product ? product.name : undefined}
- onBack={onBack}
- >
- {!!onProductShow && (
- <IconButton onClick={onProductShow} disabled={disabled}>
- <VisibilityIcon />
- </IconButton>
- )}
- {!!onDelete && (
- <IconButton
- onClick={toggleDeleteDialog}
- disabled={disabled}
- >
- <DeleteIcon />
- </IconButton>
- )}
- </PageHeader>
+ <PageHeader title={header} onBack={onBack} />
{product &&
onDelete &&
product.name && (
@@ -258,13 +266,23 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
/>
</div>
<div className={classes.cardContainer}>
- <ProductVariants
- variants={variants}
- fallbackPrice={product ? product.price : undefined}
- onAttributesEdit={onAttributesEdit}
- onRowClick={onVariantShow}
- onVariantAdd={onVariantAdd}
- />
+ {product &&
+ product.productType &&
+ product.productType.hasVariants ? (
+ <ProductVariants
+ variants={variants}
+ fallbackPrice={product ? product.price : undefined}
+ onAttributesEdit={onAttributesEdit}
+ onRowClick={onVariantShow}
+ onVariantAdd={onVariantAdd}
+ />
+ ) : (
+ <ProductStock
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
+ )}
</div>
<div className={classes.cardContainer}>
<SeoForm
@@ -284,7 +302,6 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
</div>
<div>
<ProductOrganization
- attributes={product ? product.attributes : undefined}
category={data.category}
categories={
categories !== undefined && categories !== null
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx b/saleor/static/dashboard-next/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx
index 3d9ee31eed..6a0354aa69 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantAttributes/ProductVariantAttributes.tsx
@@ -1,12 +1,12 @@
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import { withStyles } from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
import * as React from "react";
-import { debug } from "util";
import { AttributeType, AttributeValueType } from "../..";
-import PageHeader from "../../../components/PageHeader";
-import SingleSelectField from "../../../components/SingleSelectField";
+import CardTitle from "../../../components/CardTitle";
+import SingleAutocompleteSelectField from "../../../components/SingleAutocompleteSelectField";
import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
@@ -16,51 +16,66 @@ interface ProductVariantAttributesProps {
value: AttributeValueType;
}>;
data: {
- [key: string]: string;
+ [key: string]: {
+ label: string;
+ value: string;
+ };
};
- loading?: boolean;
+ disabled: boolean;
onChange(event: any);
}
const decorate = withStyles(theme => ({
+ card: {
+ overflow: "visible" as "visible"
+ },
grid: {
- display: "grid",
- gridGap: `${theme.spacing.unit * 2}px`,
- gridTemplateColumns: "1fr 1fr",
"& input": {
width: "100%"
- }
+ },
+ display: "grid",
+ gridGap: `${theme.spacing.unit * 2}px`,
+ gridTemplateColumns: "1fr 1fr"
}
}));
const ProductVariantAttributes = decorate<ProductVariantAttributesProps>(
- ({ attributes, classes, data, loading, onChange }) => (
- <Card>
- <PageHeader title={i18n.t("Attributes")} />
+ ({ attributes, classes, data, disabled, onChange }) => (
+ <Card className={classes.card}>
+ <CardTitle title={i18n.t("General Information")} />
<CardContent className={classes.grid}>
- {attributes ? (
+ {attributes === undefined ? (
+ <Skeleton />
+ ) : attributes.length > 0 ? (
attributes.map(item => {
const { attribute } = item;
return (
- <SingleSelectField
- choices={
- attribute.values
- ? attribute.values.map(value => ({
- label: value.name,
- value: value.slug
- }))
- : []
- }
- onChange={onChange}
- value={data[attribute.slug]}
- label={attribute.name}
- name={attribute.slug}
- key={attribute.slug}
- />
+ <>
+ <SingleAutocompleteSelectField
+ choices={
+ attribute.values
+ ? attribute.values.map(value => ({
+ label: value.name,
+ value: value.slug
+ }))
+ : []
+ }
+ disabled={disabled}
+ label={attribute.name}
+ name={attribute.slug}
+ value={data[attribute.slug]}
+ onChange={onChange}
+ custom
+ key={attribute.slug}
+ />
+ <div />
+ </>
);
})
) : (
- <Skeleton />
+ <Typography>
+ {i18n.t("This product type has no variant attributes.")}
+ </Typography>
)}
</CardContent>
</Card>
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantImageSelectDialog/ProductVariantImageSelectDialog.tsx b/saleor/static/dashboard-next/products/components/ProductVariantImageSelectDialog/ProductVariantImageSelectDialog.tsx
index 3044de2d8d..340f09290e 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantImageSelectDialog/ProductVariantImageSelectDialog.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantImageSelectDialog/ProductVariantImageSelectDialog.tsx
@@ -11,36 +11,50 @@ import { withStyles, WithStyles } from "@material-ui/core/styles";
import CheckCircleIcon from "@material-ui/icons/CheckCircle";
import * as React from "react";
-import i18n from "../../../i18n";
import { ProductImageType } from "../..";
+import i18n from "../../../i18n";
const decorate = withStyles(theme => ({
+ gridElement: {
+ "& img": {
+ width: "100%"
+ }
+ },
+ image: {
+ height: "100%",
+ objectFit: "contain" as "contain",
+ userSelect: "none" as "none",
+ width: "100%"
+ },
+ imageContainer: {
+ "&.selected": {
+ borderColor: theme.palette.primary.main
+ },
+ background: "#ffffff",
+ border: "1px solid #eaeaea",
+ borderRadius: theme.spacing.unit,
+ cursor: "pointer" as "pointer",
+ height: theme.spacing.unit * 21.5,
+ overflow: "hidden" as "hidden",
+ padding: theme.spacing.unit * 2,
+ position: "relative" as "relative",
+ transitionDuration: theme.transitions.duration.standard + "ms"
+ },
root: {
display: "grid",
- gridTemplateColumns: "repeat(3, 1fr)",
gridColumnGap: `${theme.spacing.unit * 2}px`,
gridRowGap: `${theme.spacing.unit * 2}px`,
- width: theme.breakpoints.values.lg,
+ gridTemplateColumns: "repeat(3, 1fr)",
maxWidth: "100%",
+ width: theme.breakpoints.values.lg,
[theme.breakpoints.down("sm")]: {
gridTemplateColumns: "repeat(2, 1fr)"
}
- },
- gridElement: {
- "& img": {
- width: "100%"
- }
- },
- icon: {
- color: "white"
- },
- iconChecked: {
- color: theme.palette.secondary.main
}
}));
interface ProductVariantImageSelectDialogProps {
- images?: Array<ProductImageType>;
+ images?: ProductImageType[];
selectedImages?: Array<{
id: string;
}>;
@@ -58,7 +72,7 @@ const ProductVariantImageSelectDialog = decorate<
>(
class ProductVariantImageSelectDialogComponent extends React.Component<
ProductVariantImageSelectDialogProps &
- WithStyles<"root" | "gridElement" | "icon" | "iconChecked">,
+ WithStyles<"root" | "gridElement" | "image" | "imageContainer">,
ProductVariantImageSelectDialogState
> {
constructor(props) {
@@ -70,7 +84,7 @@ const ProductVariantImageSelectDialog = decorate<
};
}
- handleConfirm = () => this.state.images;
+ handleConfirm = () => this.props.onConfirm(this.state.images);
handleImageSelect = id => () =>
this.state.images.indexOf(id) === -1
? this.setState(prevState => ({ images: [...prevState.images, id] }))
@@ -79,47 +93,34 @@ const ProductVariantImageSelectDialog = decorate<
}));
render() {
- const {
- children,
- classes,
- images,
- open,
- onConfirm,
- onClose
- } = this.props;
+ const { classes, images, open, onClose } = this.props;
return (
<Dialog open={open}>
<DialogTitle>
{i18n.t("Image selection", { context: "title" })}
</DialogTitle>
<DialogContent>
- <DialogContentText>{i18n.t("Select images")}</DialogContentText>
<div className={classes.root}>
{images
- .sort((prev, next) => (prev.sortOrder > next.sortOrder ? 1 : -1))
+ .sort(
+ (prev, next) => (prev.sortOrder > next.sortOrder ? 1 : -1)
+ )
.map(tile => (
- <GridListTile
- key={tile.id}
- className={classes.gridElement}
- component="div"
+ <div
+ className={[
+ classes.imageContainer,
+ this.state.images.indexOf(tile.id) === -1
+ ? undefined
+ : "selected"
+ ].join(" ")}
onClick={this.handleImageSelect(tile.id)}
>
- <img src={tile.url} alt={tile.alt} />
- <GridListTileBar
- title={tile.alt || i18n.t("No description")}
- actionIcon={
- <IconButton
- className={
- this.state.images.indexOf(tile.id) !== -1
- ? classes.iconChecked
- : classes.icon
- }
- >
- <CheckCircleIcon />
- </IconButton>
- }
+ <img
+ className={classes.image}
+ src={tile.url}
+ alt={tile.alt}
/>
- </GridListTile>
+ </div>
))}
</div>
</DialogContent>
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantImages/ProductVariantImages.tsx b/saleor/static/dashboard-next/products/components/ProductVariantImages/ProductVariantImages.tsx
index e7c51d3bf0..241fd9e29f 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantImages/ProductVariantImages.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantImages/ProductVariantImages.tsx
@@ -1,37 +1,23 @@
+import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
-import GridListTile from "@material-ui/core/GridListTile";
-import GridListTileBar from "@material-ui/core/GridListTileBar";
-import IconButton from "@material-ui/core/IconButton";
import { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
-import AddIcon from "@material-ui/icons/Add";
import * as React from "react";
-import PageHeader from "../../../components/PageHeader";
-import i18n from "../../../i18n";
import { ProductImageType } from "../..";
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import i18n from "../../../i18n";
interface ProductVariantImagesProps {
- images?: Array<ProductImageType>;
+ images?: ProductImageType[];
placeholderImage?: string;
- loading?: boolean;
+ disabled: boolean;
onImageAdd();
}
const decorate = withStyles(theme => ({
- root: {
- display: "grid",
- gridTemplateColumns: "repeat(4, 1fr)",
- gridColumnGap: `${theme.spacing.unit * 2}px`,
- gridRowGap: `${theme.spacing.unit * 2}px`,
- [theme.breakpoints.down("md")]: {
- gridTemplateColumns: "repeat(3, 1fr)"
- },
- [theme.breakpoints.down("sm")]: {
- gridTemplateColumns: "repeat(2, 1fr)"
- }
- },
card: {
marginTop: theme.spacing.unit * 2,
[theme.breakpoints.down("sm")]: {
@@ -42,45 +28,62 @@ const decorate = withStyles(theme => ({
"& img": {
width: "100%"
}
+ },
+ image: {
+ height: "100%",
+ objectFit: "contain" as "contain",
+ width: "100%"
+ },
+ imageContainer: {
+ background: "#ffffff",
+ border: "1px solid #eaeaea",
+ borderRadius: theme.spacing.unit,
+ height: theme.spacing.unit * 17.5,
+ marginBottom: theme.spacing.unit * 2,
+ padding: theme.spacing.unit * 2
+ },
+ root: {
+ display: "grid" as "grid",
+ gridColumnGap: theme.spacing.unit * 2 + "px",
+ gridTemplateColumns: "repeat(4, 1fr)"
}
}));
export const ProductVariantImages = decorate<ProductVariantImagesProps>(
- ({ classes, images, placeholderImage, loading, onImageAdd }) => (
+ ({ classes, images, placeholderImage, disabled, onImageAdd }) => (
<Card className={classes.card}>
- <PageHeader title={i18n.t("Images")}>
- <IconButton
- onClick={loading ? () => { } : onImageAdd}
- disabled={loading}
- >
- <AddIcon />
- </IconButton>
- </PageHeader>
+ <CardTitle
+ title={i18n.t("Images")}
+ toolbar={
+ <Button
+ color="secondary"
+ variant="flat"
+ disabled={disabled}
+ onClick={onImageAdd}
+ >
+ {i18n.t("Choose photos")}
+ </Button>
+ }
+ />
<CardContent>
<div className={classes.root}>
{images === undefined || images === null ? (
- <GridListTile className={classes.gridElement} component="div">
- <img src={placeholderImage} />
- <GridListTileBar title={i18n.t("Loading...")} />
- </GridListTile>
+ <Skeleton />
) : images.length > 0 ? (
images
.sort((prev, next) => (prev.sortOrder > next.sortOrder ? 1 : -1))
.map(tile => (
- <GridListTile
- key={tile.id}
- className={classes.gridElement}
- component="div"
- >
- <img src={tile.url} alt={tile.alt} />
- <GridListTileBar
- title={tile.alt || i18n.t("No description")}
+ <div className={classes.imageContainer}>
+ <img
+ className={classes.image}
+ src={tile.url}
+ alt={tile.alt}
/>
- </GridListTile>
+ </div>
))
) : (
- <Typography>{i18n.t("No images available")}</Typography>
- )}
+ <Typography>{i18n.t("No images available")}</Typography>
+ )}
</div>
</CardContent>
</Card>
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantNavigation/ProductVariantNavigation.tsx b/saleor/static/dashboard-next/products/components/ProductVariantNavigation/ProductVariantNavigation.tsx
index b8674cb4a1..7f301ea6c3 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantNavigation/ProductVariantNavigation.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantNavigation/ProductVariantNavigation.tsx
@@ -1,5 +1,4 @@
import Card from "@material-ui/core/Card";
-import blue from "@material-ui/core/colors/blue";
import { withStyles } from "@material-ui/core/styles";
import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
@@ -7,56 +6,91 @@ import TableCell from "@material-ui/core/TableCell";
import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
-import PageHeader from "../../../components/PageHeader";
+import CardTitle from "../../../components/CardTitle";
import Skeleton from "../../../components/Skeleton";
+import TableCellAvatar from "../../../components/TableCellAvatar";
import i18n from "../../../i18n";
interface ProductVariantNavigationProps {
- current?: string;
- loading?: boolean;
- productId?: string;
+ current: string;
variants?: Array<{
id: string;
name: string;
+ sku: string;
+ images?: {
+ edges?: Array<{
+ node?: {
+ image;
+ };
+ }>;
+ };
}>;
- onRowClick(variantId: string);
+ onRowClick: (variantId: string) => void;
}
const decorate = withStyles(theme => ({
- card: {
- marginTop: theme.spacing.unit * 2,
- [theme.breakpoints.down("sm")]: {
- marginTop: theme.spacing.unit
- }
- },
link: {
- color: blue[500],
cursor: "pointer"
+ },
+ tabActive: {
+ "&:before": {
+ background: theme.palette.primary.main,
+ content: '""',
+ height: "100%",
+ left: 0,
+ position: "absolute" as "absolute",
+ top: 0,
+ width: 2
+ },
+ position: "relative" as "relative"
+ },
+ textLeft: {
+ textAlign: [["left"], "!important"] as any
}
}));
const ProductVariantNavigation = decorate<ProductVariantNavigationProps>(
- ({ classes, current, loading, productId, variants, onRowClick }) => (
- <Card className={classes.card}>
- <PageHeader title={i18n.t("Variants")} />
+ ({ classes, current, variants, onRowClick }) => (
+ <Card>
+ <CardTitle title={i18n.t("Variants")} />
<Table>
<TableBody>
- {loading ? (
- <TableRow>
+ {variants === undefined ? (
+ <TableRow hover>
<TableCell>
<Skeleton />
</TableCell>
</TableRow>
) : variants.length > 0 ? (
variants.map(variant => (
- <TableRow key={variant.id}>
- <TableCell className={classes.link} onClick={() => onRowClick(variant.id)}>
- {variant.name}
+ <TableRow
+ hover
+ key={variant.id}
+ className={classes.link}
+ onClick={() => onRowClick(variant.id)}
+ >
+ <TableCellAvatar
+ className={
+ variant.id === current ? classes.tabActive : undefined
+ }
+ thumbnail={
+ variant &&
+ variant.images &&
+ variant.images.edges &&
+ variant.images.edges[0] &&
+ variant.images.edges[0].node &&
+ variant.images.edges[0].node.image
+ ? variant.images.edges[0].node.image
+ : null
+ }
+ />
+ <TableCell className={classes.textLeft}>
+ {variant.name || variant.sku}
</TableCell>
</TableRow>
))
) : (
- <TableRow>
+ <TableRow hover>
<TableCell>{i18n.t("This product has no variants")}</TableCell>
</TableRow>
)}
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx b/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx
index 3370370642..bb37e73acd 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantPage/ProductVariantPage.tsx
@@ -1,7 +1,4 @@
-import IconButton from "@material-ui/core/IconButton";
import { withStyles } from "@material-ui/core/styles";
-import DeleteIcon from "@material-ui/icons/Delete";
-import * as CRC from "crc-32";
import * as React from "react";
import {
@@ -18,13 +15,13 @@ import SaveButtonBar, {
SaveButtonBarState
} from "../../../components/SaveButtonBar";
import Toggle from "../../../components/Toggle";
+import i18n from "../../../i18n";
import ProductVariantAttributes from "../ProductVariantAttributes";
import ProductVariantDeleteDialog from "../ProductVariantDeleteDialog";
import ProductVariantImages from "../ProductVariantImages";
import ProductVariantImageSelectDialog from "../ProductVariantImageSelectDialog";
import ProductVariantNavigation from "../ProductVariantNavigation";
import ProductVariantPrice from "../ProductVariantPrice";
-import ProductVariantProduct from "../ProductVariantProduct";
import ProductVariantStock from "../ProductVariantStock";
interface ProductVariantPageProps {
@@ -58,6 +55,7 @@ interface ProductVariantPageProps {
node: {
id: string;
name: string;
+ sku: string;
};
}>;
totalCount: number;
@@ -71,6 +69,7 @@ interface ProductVariantPageProps {
saveButtonBarState?: SaveButtonBarState;
loading?: boolean;
placeholderImage?: string;
+ header: string;
onBack();
onDelete();
onSubmit(data: any);
@@ -85,7 +84,7 @@ const decorate = withStyles(theme => ({
},
display: "grid",
gridGap: `${theme.spacing.unit * 2}px`,
- gridTemplateColumns: "1fr 2fr",
+ gridTemplateColumns: "1fr 2.25fr",
[theme.breakpoints.down("sm")]: {
gridGap: `${theme.spacing.unit}px`,
gridTemplateColumns: "1fr"
@@ -98,6 +97,7 @@ const ProductVariantPage = decorate<ProductVariantPageProps>(
classes,
errors: formErrors,
loading,
+ header,
placeholderImage,
saveButtonBarState,
variant,
@@ -109,7 +109,10 @@ const ProductVariantPage = decorate<ProductVariantPageProps>(
}) => {
const attributes = variant
? variant.attributes.reduce((prev, curr) => {
- prev[curr.attribute.slug] = curr.value.slug;
+ prev[curr.attribute.slug] = {
+ label: curr.value.name,
+ value: curr.value.slug
+ };
return prev;
}, {})
: {};
@@ -134,14 +137,7 @@ const ProductVariantPage = decorate<ProductVariantPageProps>(
{(isImageSelectModalActive, { toggle: toggleImageSelectModal }) => (
<>
<Container width="md">
- <PageHeader
- title={variant ? variant.name : undefined}
- onBack={onBack}
- >
- <IconButton onClick={toggleDeleteModal} disabled={loading}>
- <DeleteIcon />
- </IconButton>
- </PageHeader>
+ <PageHeader title={header} onBack={onBack} />
<Form
initial={{
costPrice:
@@ -159,23 +155,14 @@ const ProductVariantPage = decorate<ProductVariantPageProps>(
}}
errors={formErrors}
onSubmit={onSubmit}
- key={variant ? CRC.str(JSON.stringify(variant)) : "loading"}
+ key={variant ? JSON.stringify(variant) : "novariant"}
>
{({ change, data, errors, hasChanged, submit }) => (
<>
<div className={classes.root}>
<div>
- <ProductVariantProduct
- product={variant ? variant.product : undefined}
- loading={loading}
- placeholderImage={placeholderImage}
- />
<ProductVariantNavigation
current={variant ? variant.id : undefined}
- loading={loading}
- productId={
- variant ? variant.product.id : undefined
- }
variants={
variant
? variant.product.variants.edges.map(
@@ -196,8 +183,14 @@ const ProductVariantPage = decorate<ProductVariantPageProps>(
variant ? variant.attributes : undefined
}
data={data}
+ disabled={loading}
onChange={change}
- loading={loading}
+ />
+ <ProductVariantImages
+ disabled={loading}
+ images={images}
+ placeholderImage={placeholderImage}
+ onImageAdd={toggleImageSelectModal}
/>
<ProductVariantPrice
errors={errors}
@@ -221,17 +214,17 @@ const ProductVariantPage = decorate<ProductVariantPageProps>(
loading={loading}
onChange={change}
/>
- <ProductVariantImages
- images={images}
- placeholderImage={placeholderImage}
- onImageAdd={toggleImageSelectModal}
- loading={loading}
- />
</div>
</div>
<SaveButtonBar
disabled={loading || !onSubmit || !hasChanged}
+ labels={{
+ delete: i18n.t("Remove variant"),
+ save: i18n.t("Save variant")
+ }}
state={saveButtonBarState}
+ onCancel={onBack}
+ onDelete={toggleDeleteModal}
onSave={submit}
/>
</>
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantPrice/ProductVariantPrice.tsx b/saleor/static/dashboard-next/products/components/ProductVariantPrice/ProductVariantPrice.tsx
index 7ade85b912..eef75c4642 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantPrice/ProductVariantPrice.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantPrice/ProductVariantPrice.tsx
@@ -3,8 +3,7 @@ import CardContent from "@material-ui/core/CardContent";
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
-import { FormSpacer } from "../../../components/FormSpacer";
-import PageHeader from "../../../components/PageHeader";
+import CardTitle from "../../../components/CardTitle";
import PriceField from "../../../components/PriceField";
import i18n from "../../../i18n";
@@ -18,16 +17,16 @@ interface ProductVariantPriceProps {
}
const decorate = withStyles(theme => ({
+ grid: {
+ display: "grid",
+ gridColumnGap: `${theme.spacing.unit * 2}px`,
+ gridTemplateColumns: "1fr 1fr"
+ },
root: {
marginTop: theme.spacing.unit * 2,
[theme.breakpoints.down("sm")]: {
marginTop: theme.spacing.unit
}
- },
- grid: {
- display: "grid",
- gridColumnGap: `${theme.spacing.unit * 2}px`,
- gridTemplateColumns: "1fr 1fr"
}
}));
const ProductVariantPrice = decorate<ProductVariantPriceProps>(
@@ -41,7 +40,7 @@ const ProductVariantPrice = decorate<ProductVariantPriceProps>(
onChange
}) => (
<Card className={classes.root}>
- <PageHeader title={i18n.t("Pricing")} />
+ <CardTitle title={i18n.t("Pricing")} />
<CardContent>
<div className={classes.grid}>
<div>
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantProduct/ProductVariantProduct.tsx b/saleor/static/dashboard-next/products/components/ProductVariantProduct/ProductVariantProduct.tsx
deleted file mode 100644
index d7a8dea696..0000000000
--- a/saleor/static/dashboard-next/products/components/ProductVariantProduct/ProductVariantProduct.tsx
+++ /dev/null
@@ -1,55 +0,0 @@
-import Card from "@material-ui/core/Card";
-import CardContent from "@material-ui/core/CardContent";
-import { withStyles } from "@material-ui/core/styles";
-import Typography from "@material-ui/core/Typography";
-import * as React from "react";
-
-import Skeleton from "../../../components/Skeleton";
-import i18n from "../../../i18n";
-
-interface ProductVariantProductProps {
- product?: {
- id: string;
- name: string;
- thumbnailUrl: string;
- variants: {
- totalCount: number;
- };
- };
- loading?: boolean;
- placeholderImage?: string;
-}
-
-const decorate = withStyles(theme => ({
- root: {
- display: "grid",
- gridColumnGap: `${theme.spacing.unit * 2}px`,
- gridTemplateColumns: "60px 1fr",
- },
- thumbnail: {
- maxWidth: "60px"
- }
-}));
-
-const ProductVariantProduct = decorate<ProductVariantProductProps>(
- ({ classes, product, loading, placeholderImage }) => (
- <Card>
- <CardContent>
- <div className={classes.root}>
- <img className={classes.thumbnail} src={product ? product.thumbnailUrl : placeholderImage } />
- <div>
- <Typography>{product ? product.name : <Skeleton /> }</Typography>
- <Typography variant="caption">
- {product ? (
- i18n.t("Variants:") + " " + product.variants.totalCount
- ) : (
- <Skeleton />
- )}
- </Typography>
- </div>
- </div>
- </CardContent>
- </Card>
- )
-);
-export default ProductVariantProduct;
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantProduct/index.ts b/saleor/static/dashboard-next/products/components/ProductVariantProduct/index.ts
deleted file mode 100644
index b0b819429e..0000000000
--- a/saleor/static/dashboard-next/products/components/ProductVariantProduct/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from "./ProductVariantProduct";
-export * from "./ProductVariantProduct";
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantStock/ProductVariantStock.tsx b/saleor/static/dashboard-next/products/components/ProductVariantStock/ProductVariantStock.tsx
index 39bbaa2293..6119b518a2 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantStock/ProductVariantStock.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantStock/ProductVariantStock.tsx
@@ -4,8 +4,7 @@ import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import * as React from "react";
-import { FormSpacer } from "../../../components/FormSpacer";
-import PageHeader from "../../../components/PageHeader";
+import CardTitle from "../../../components/CardTitle";
import i18n from "../../../i18n";
interface ProductVariantStockProps {
@@ -18,26 +17,26 @@ interface ProductVariantStockProps {
}
const decorate = withStyles(theme => ({
+ grid: {
+ "& input": {
+ width: "100%"
+ },
+ display: "grid",
+ gridColumnGap: `${theme.spacing.unit * 2}px`,
+ gridTemplateColumns: "1fr 1fr"
+ },
root: {
marginTop: theme.spacing.unit * 2,
[theme.breakpoints.down("sm")]: {
marginTop: theme.spacing.unit
}
- },
- grid: {
- display: "grid",
- gridColumnGap: `${theme.spacing.unit * 2}px`,
- gridTemplateColumns: "1fr 1fr",
- "& input": {
- width: "100%"
- }
}
}));
const ProductVariantStock = decorate<ProductVariantStockProps>(
({ classes, errors, sku, stock, stockAllocated, loading, onChange }) => (
<Card className={classes.root}>
- <PageHeader title={i18n.t("Stock")} />
+ <CardTitle title={i18n.t("Stock")} />
<CardContent>
<div className={classes.grid}>
<div>
@@ -45,7 +44,7 @@ const ProductVariantStock = decorate<ProductVariantStockProps>(
error={!!errors.stock}
name="stock"
value={stock}
- label={i18n.t("In stock")}
+ label={i18n.t("Inventory")}
helperText={
errors.stock
? errors.stock
@@ -64,7 +63,7 @@ const ProductVariantStock = decorate<ProductVariantStockProps>(
helperText={errors.sku}
name="sku"
value={sku}
- label={i18n.t("SKU")}
+ label={i18n.t("SKU (Stock Keeping Unit)")}
onChange={onChange}
disabled={loading}
fullWidth
diff --git a/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx b/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
index 7560ece025..eae77491b2 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
@@ -1,9 +1,6 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
-import blue from "@material-ui/core/colors/blue";
-import green from "@material-ui/core/colors/green";
-import red from "@material-ui/core/colors/red";
import Hidden from "@material-ui/core/Hidden";
import { withStyles } from "@material-ui/core/styles";
import Table from "@material-ui/core/Table";
@@ -18,8 +15,8 @@ import { MoneyType } from "../..";
import CardTitle from "../../../components/CardTitle";
import Money from "../../../components/Money";
import Skeleton from "../../../components/Skeleton";
-import i18n from "../../../i18n";
import StatusLabel from "../../../components/StatusLabel";
+import i18n from "../../../i18n";
interface ProductVariantsProps {
disabled?: boolean;
@@ -33,7 +30,7 @@ interface ProductVariantsProps {
}>;
fallbackPrice?: MoneyType;
onAttributesEdit: () => void;
- onRowClick?(id: string);
+ onRowClick: (id: string) => () => void;
onVariantAdd?();
}
@@ -95,7 +92,7 @@ export const ProductVariants = decorate<ProductVariantsProps>(
</CardContent>
<Table className={classes.denseTable}>
<TableHead>
- <TableRow>
+ <TableRow hover>
<TableCell className={classes.textLeft}>{i18n.t("Name")}</TableCell>
<TableCell>{i18n.t("Status")}</TableCell>
<TableCell>{i18n.t("SKU")}</TableCell>
@@ -110,7 +107,7 @@ export const ProductVariants = decorate<ProductVariantsProps>(
{variants === undefined ||
variants === null ||
fallbackPrice === undefined ? (
- <TableRow>
+ <TableRow hover>
<TableCell>
<Skeleton />
</TableCell>
@@ -130,16 +127,12 @@ export const ProductVariants = decorate<ProductVariantsProps>(
variants.map(variant => {
const price = variant.priceOverride || fallbackPrice;
return (
- <TableRow key={variant.id}>
+ <TableRow hover key={variant.id}>
<TableCell
className={[classes.textLeft, classes.link].join(" ")}
- onClick={() => {
- if (onRowClick) {
- onRowClick(variant.id);
- }
- }}
+ onClick={onRowClick(variant.id)}
>
- {variant.name}
+ {variant.name || variant.sku}
</TableCell>
<TableCell>
<StatusLabel
@@ -161,7 +154,7 @@ export const ProductVariants = decorate<ProductVariantsProps>(
);
})
) : (
- <TableRow>
+ <TableRow hover>
<TableCell colSpan={2}>
{i18n.t("This product has no variants")}
</TableCell>
diff --git a/saleor/static/dashboard-next/products/fixtures.ts b/saleor/static/dashboard-next/products/fixtures.ts
index 9a9ca4a466..e27784cc4d 100644
--- a/saleor/static/dashboard-next/products/fixtures.ts
+++ b/saleor/static/dashboard-next/products/fixtures.ts
@@ -569,22 +569,32 @@ export const variant = (placeholderImage: string) => ({
variants: {
totalCount: 11,
edges: [
+ {
+ node: {
+ id: "var1",
+ name: "Extended Hard",
+ sku: "13-1337"
+ }
+ },
{
node: {
id: "var2",
- name: "Extended Soft"
+ name: "Extended Soft",
+ sku: "13-1338"
}
},
{
node: {
id: "var3",
- name: "Normal Hard"
+ name: "Normal Hard",
+ sku: "13-1339"
}
},
{
node: {
id: "var4",
- name: "Normal Soft"
+ name: "Normal Soft",
+ sku: "13-1340"
}
}
]
diff --git a/saleor/static/dashboard-next/products/queries.ts b/saleor/static/dashboard-next/products/queries.ts
index 06bec024e7..2eedeef643 100644
--- a/saleor/static/dashboard-next/products/queries.ts
+++ b/saleor/static/dashboard-next/products/queries.ts
@@ -178,6 +178,7 @@ export const fragmentVariant = gql`
node {
id
name
+ sku
}
}
}
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
index 270f501f54..20c6b64b3a 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
@@ -95,6 +95,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
errors={errors}
saveButtonBarState={formSubmitState}
images={images}
+ header={product ? product.name : undefined}
placeholderImage={placeholderImg}
product={product}
productCollections={
@@ -166,13 +167,10 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
}
}}
onVariantAdd={() => {}}
- onVariantShow={variantId => {
- if (product) {
- navigate(
- productVariantEditUrl(product.id, variantId)
- );
- }
- }}
+ onVariantShow={variantId => () =>
+ navigate(
+ productVariantEditUrl(product.id, variantId)
+ )}
onImageUpload={event => {
if (product) {
createProductImage.mutate({
diff --git a/saleor/static/dashboard-next/products/views/ProductVariant.tsx b/saleor/static/dashboard-next/products/views/ProductVariant.tsx
index 1d5054fdfe..2542fe7f3b 100644
--- a/saleor/static/dashboard-next/products/views/ProductVariant.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductVariant.tsx
@@ -73,6 +73,9 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
loading={disableFormSave}
placeholderImage={placeholderImg}
variant={variant}
+ header={
+ variant ? variant.name || variant.sku : undefined
+ }
onBack={handleBack}
onDelete={() => deleteVariant.mutate(variantId)}
onImageSelect={() => {}}
@@ -85,7 +88,7 @@ export const ProductVariant: React.StatelessComponent<ProductUpdateProps> = ({
values: item.attribute.values
}))
.map(({ slug, values }) => {
- const valueSlug = data[slug];
+ const valueSlug = data[slug].value;
const value = values.filter(
item => item.slug === valueSlug
);
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index bc922bc7aa..dc8912a0e2 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -54,6 +54,7 @@ function loadStories() {
require("./stories/pages/PageProperties");
// Products
+ require("./stories/products/ProductCreatePage");
require("./stories/products/ProductImagePage");
require("./stories/products/ProductListCard");
require("./stories/products/ProductUpdatePage");
diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductCreatePage.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductCreatePage.tsx
new file mode 100644
index 0000000000..2ee0144e9f
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductCreatePage.tsx
@@ -0,0 +1,24 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import ProductCreatePage from "../../../products/components/ProductCreatePage";
+import { product as productFixture } from "../../../products/fixtures";
+import { productTypes } from "../../../productTypes/fixtures";
+import Decorator from "../../Decorator";
+
+const product = productFixture("");
+
+storiesOf("Views / Products / Create product", module)
+ .addDecorator(Decorator)
+ .add("default", () => (
+ <ProductCreatePage
+ errors={[]}
+ header="Add product"
+ collections={product.collections.edges.map(edge => edge.node)}
+ productTypes={productTypes}
+ categories={[product.category]}
+ onAttributesEdit={() => {}}
+ onBack={() => {}}
+ onSubmit={() => {}}
+ />
+ ));
diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
index 410f9f1f7f..86f6b0c78d 100644
--- a/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
@@ -16,6 +16,7 @@ storiesOf("Views / Products / Product edit", module)
onBack={() => {}}
onSubmit={() => {}}
product={product}
+ header={product.name}
collections={product.collections.edges.map(edge => edge.node)}
categories={[product.category]}
placeholderImage={placeholderImage}
@@ -26,7 +27,7 @@ storiesOf("Views / Products / Product edit", module)
onDelete={() => {}}
onProductShow={() => {}}
onVariantAdd={() => {}}
- onVariantShow={() => {}}
+ onVariantShow={() => () => {}}
/>
))
.add("when product has no images", () => (
@@ -35,6 +36,7 @@ storiesOf("Views / Products / Product edit", module)
onBack={() => {}}
onSubmit={() => {}}
product={product}
+ header={product.name}
collections={product.collections.edges.map(edge => edge.node)}
categories={[product.category]}
placeholderImage={placeholderImage}
@@ -45,17 +47,44 @@ storiesOf("Views / Products / Product edit", module)
onDelete={() => {}}
onProductShow={() => {}}
onVariantAdd={() => {}}
- onVariantShow={() => {}}
+ onVariantShow={() => () => {}}
+ />
+ ))
+ .add("when product has no variants", () => (
+ <ProductUpdatePage
+ errors={[]}
+ onBack={() => {}}
+ onSubmit={() => {}}
+ product={
+ {
+ ...product,
+ productType: { ...product.productType, hasVariants: false }
+ } as any
+ }
+ header={product.name}
+ collections={product.collections.edges.map(edge => edge.node)}
+ categories={[product.category]}
+ placeholderImage={placeholderImage}
+ images={product.images.edges.map(edge => edge.node)}
+ variants={product.variants.edges.map(edge => edge.node)}
+ productCollections={product.collections.edges.map(edge => edge.node)}
+ onAttributesEdit={() => {}}
+ onDelete={() => {}}
+ onProductShow={() => {}}
+ onVariantAdd={() => {}}
+ onVariantShow={() => () => {}}
/>
))
.add("when loading data", () => (
<ProductUpdatePage
errors={[]}
+ header={undefined}
categories={[]}
onBack={() => {}}
onSubmit={() => {}}
disabled={true}
- onAttributesEdit={() => {}}
placeholderImage={placeholderImage}
+ onAttributesEdit={() => {}}
+ onVariantShow={() => () => {}}
/>
));
diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductVariantPage.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductVariantPage.tsx
index 57c5c5d040..d129110a77 100644
--- a/saleor/static/dashboard-next/storybook/stories/products/ProductVariantPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductVariantPage.tsx
@@ -12,6 +12,7 @@ storiesOf("Views / Products / Product variant details", module)
.addDecorator(Decorator)
.add("when loaded data", () => (
<ProductVariantPage
+ header={variant.name || variant.sku}
errors={[]}
variant={variant}
onBack={() => () => {}}
@@ -23,6 +24,7 @@ storiesOf("Views / Products / Product variant details", module)
))
.add("when loading data", () => (
<ProductVariantPage
+ header={undefined}
errors={[]}
loading={true}
onBack={() => () => {}}
diff --git a/saleor/static/dashboard-next/theme.ts b/saleor/static/dashboard-next/theme.ts
index 6595d50597..caeba71461 100644
--- a/saleor/static/dashboard-next/theme.ts
+++ b/saleor/static/dashboard-next/theme.ts
@@ -48,6 +48,8 @@ export default createMuiTheme({
},
MuiInputLabel: {
formControl: {
+ transform: "translate(0, 1.5px) scale(0.75)",
+ transformOrigin: "top left" as "top left",
width: "100%"
},
root: {
@@ -102,6 +104,23 @@ export default createMuiTheme({
paddingLeft: 0,
textAlign: "center" as "center"
}
+ },
+ MuiTableRow: {
+ footer: {
+ "$root$hover&:hover": {
+ background: "none"
+ }
+ },
+ head: {
+ "$root$hover&:hover": {
+ background: "none"
+ }
+ },
+ hover: {
+ "$root&:hover": {
+ backgroundColor: "rgba(90, 179, 120, .1)"
+ }
+ }
}
},
palette: {