Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add dropzone to product details view
dominik-zeglen383b7e72f8c9
diff --git a/package-lock.json b/package-lock.jsonindex e45118048d..084d00e67f 100644--- a/package-lock.json+++ b/package-lock.json@@ -12794,12 +12794,14 @@"balanced-match": {"version": "1.0.0","bundled": true,- "dev": true+ "dev": true,+ "optional": true},"brace-expansion": {"version": "1.1.11","bundled": true,"dev": true,+ "optional": true,"requires": {"balanced-match": "^1.0.0","concat-map": "0.0.1"@@ -12814,17 +12816,20 @@"code-point-at": {"version": "1.1.0","bundled": true,- "dev": true+ "dev": true,+ "optional": true},"concat-map": {"version": "0.0.1","bundled": true,- "dev": true+ "dev": true,+ "optional": true},"console-control-strings": {"version": "1.1.0","bundled": true,- "dev": true+ "dev": true,+ "optional": true},"core-util-is": {"version": "1.0.2",@@ -12941,7 +12946,8 @@"inherits": {"version": "2.0.3","bundled": true,- "dev": true+ "dev": true,+ "optional": true},"ini": {"version": "1.3.5",@@ -12953,6 +12959,7 @@"version": "1.0.0","bundled": true,"dev": true,+ "optional": true,"requires": {"number-is-nan": "^1.0.0"}@@ -12967,6 +12974,7 @@"version": "3.0.4","bundled": true,"dev": true,+ "optional": true,"requires": {"brace-expansion": "^1.1.7"}@@ -12974,12 +12982,14 @@"minimist": {"version": "0.0.8","bundled": true,- "dev": true+ "dev": true,+ "optional": true},"minipass": {"version": "2.2.4","bundled": true,"dev": true,+ "optional": true,"requires": {"safe-buffer": "^5.1.1","yallist": "^3.0.0"@@ -12998,6 +13008,7 @@"version": "0.5.1","bundled": true,"dev": true,+ "optional": true,"requires": {"minimist": "0.0.8"}@@ -13078,7 +13089,8 @@"number-is-nan": {"version": "1.0.1","bundled": true,- "dev": true+ "dev": true,+ "optional": true},"object-assign": {"version": "4.1.1",@@ -13090,6 +13102,7 @@"version": "1.4.0","bundled": true,"dev": true,+ "optional": true,"requires": {"wrappy": "1"}@@ -13211,6 +13224,7 @@"version": "1.0.2","bundled": true,"dev": true,+ "optional": true,"requires": {"code-point-at": "^1.0.0","is-fullwidth-code-point": "^1.0.0",diff --git a/saleor/static/dashboard-next/components/Dropzone.tsx b/saleor/static/dashboard-next/components/Dropzone.tsxnew file mode 100644index 0000000000..1a8c621144--- /dev/null+++ b/saleor/static/dashboard-next/components/Dropzone.tsx@@ -0,0 +1,3 @@+/* tslint:disable:no-submodule-imports */+import * as Dropzone from "react-dropzone/dist/index";+export default Dropzone;diff --git a/saleor/static/dashboard-next/components/ImageUpload/ImageUpload.tsx b/saleor/static/dashboard-next/components/ImageUpload/ImageUpload.tsxindex 41a2c08dba..f7f24a53d9 100644--- a/saleor/static/dashboard-next/components/ImageUpload/ImageUpload.tsx+++ b/saleor/static/dashboard-next/components/ImageUpload/ImageUpload.tsx@@ -9,11 +9,21 @@ import Typography from "@material-ui/core/Typography";import AddPhotoIcon from "@material-ui/icons/AddAPhoto";import classNames from "classnames";import * as React from "react";-/* tslint:disable:no-submodule-imports */-import * as Dropzone from "react-dropzone/dist/index";+import i18n from "../../i18n";+import Dropzone from "../Dropzone";interface ImageUploadProps {+ children?: (+ props: {+ isDragActive: boolean;+ }+ ) => React.ReactNode;+ className?: string;+ disableClick?: boolean;+ isActiveClassName?: string;+ iconContainerClassName?: string;+ iconContainerActiveClassName?: string;onImageUpload: (file: File) => void;}@@ -55,26 +65,48 @@ const styles = (theme: Theme) =>export const ImageUpload = withStyles(styles, { name: "ImageUpload" })(({+ children,classes,+ className,+ disableClick,+ isActiveClassName,+ iconContainerActiveClassName,+ iconContainerClassName,onImageUpload}: ImageUploadProps & WithStyles<typeof styles>) => (- <Dropzone onDrop={files => onImageUpload(files[0])}>+ <Dropzone+ disableClick={disableClick}+ onDrop={files => onImageUpload(files[0])}+ >{({ isDragActive, getInputProps, getRootProps }) => (- <div- {...getRootProps()}- className={classNames({- [classes.photosIconContainer]: true,- [classes.containerDragActive]: isDragActive- })}- >- <input {...getInputProps()} className={classes.fileField} />- <AddPhotoIcon className={classes.photosIcon} />- <Typography className={classes.uploadText} variant="body2">- {i18n.t("Drop here to upload", {- context: "image upload"+ <>+ <div+ {...getRootProps()}+ className={classNames({+ [classes.photosIconContainer]: true,+ [classes.containerDragActive]: isDragActive,+ [className]: !!className,+ [isActiveClassName]: !!isActiveClassName && isDragActive})}- </Typography>- </div>+ >+ <div+ className={classNames({+ [iconContainerClassName]: !!iconContainerClassName,+ [iconContainerActiveClassName]:+ !!iconContainerActiveClassName && isDragActive+ })}+ >+ <input {...getInputProps()} className={classes.fileField} />+ <AddPhotoIcon className={classes.photosIcon} />+ <Typography className={classes.uploadText} variant="body2">+ {i18n.t("Drop here to upload", {+ context: "image upload"+ })}+ </Typography>+ </div>+ </div>+ {children({ isDragActive })}+ </>)}</Dropzone>)diff --git a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsxindex 699f3582c9..81d9e3a0ec 100644--- a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx+++ b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx@@ -1,6 +1,7 @@import Button from "@material-ui/core/Button";import Card from "@material-ui/core/Card";import CardContent from "@material-ui/core/CardContent";+import classNames from "classnames";import {createStyles,@@ -8,12 +9,11 @@ import {withStyles,WithStyles} from "@material-ui/core/styles";-import Typography from "@material-ui/core/Typography";-import AddPhotoIcon from "@material-ui/icons/AddAPhoto";import * as React from "react";import { SortableContainer, SortableElement } from "react-sortable-hoc";import CardTitle from "../../../components/CardTitle";import ImageTile from "../../../components/ImageTile";+import ImageUpload from "../../../components/ImageUpload";import i18n from "../../../i18n";import { ProductDetails_product_images } from "../../types/ProductDetails";@@ -53,6 +53,9 @@ const styles = (theme: Theme) =>position: "relative",width: 140},+ imageGridContainer: {+ position: "relative"+ },imageOverlay: {background: "rgba(0, 0, 0, 0.6)",cursor: "move",@@ -71,19 +74,21 @@ const styles = (theme: Theme) =>right: -theme.spacing.unit * 3,top: -theme.spacing.unit * 2},- noPhotosIcon: {- height: theme.spacing.unit * 8,- margin: "0 auto",- width: theme.spacing.unit * 8+ imageUpload: {+ height: "100%",+ left: 0,+ position: "absolute",+ top: 0,+ width: "100%"+ },+ imageUploadActive: {+ zIndex: 1},- noPhotosIconContainer: {- margin: `${theme.spacing.unit * 5}px 0`,- textAlign: "center"+ imageUploadIcon: {+ display: "none"},- noPhotosIconText: {- fontSize: "1rem",- fontWeight: 600,- marginTop: theme.spacing.unit+ imageUploadIconActive: {+ display: "block"},root: {display: "grid",@@ -96,6 +101,9 @@ const styles = (theme: Theme) =>[theme.breakpoints.down("xs")]: {gridTemplateColumns: "repeat(2, 1fr)"}+ },+ rootDragActive: {+ opacity: 0.2}});@@ -105,7 +113,7 @@ interface ProductImagesProps extends WithStyles<typeof styles> {loading?: boolean;onImageDelete: (id: string) => () => void;onImageEdit: (id: string) => () => void;- onImageUpload?(event: React.ChangeEvent<any>);+ onImageUpload(file: File);onImageReorder?(event: { oldIndex: number; newIndex: number });}@@ -178,40 +186,55 @@ const ProductImages = withStyles(styles, { name: "ProductImages" })(<inputclassName={classes.fileField}id="fileUpload"- onChange={onImageUpload}+ onChange={event => onImageUpload(event.target.files[0])}type="file"ref={ref => (this.upload = ref)}/></>}/>- <CardContent>+ <div className={classes.imageGridContainer}>{images === undefined ? (- <div className={classes.root}>- <div className={classes.imageContainer}>- <img className={classes.image} src={placeholderImage} />+ <CardContent>+ <div className={classes.root}>+ <div className={classes.imageContainer}>+ <img className={classes.image} src={placeholderImage} />+ </div></div>- </div>+ </CardContent>) : images.length > 0 ? (- <ImageListContainer- distance={20}- helperClass="dragged"- axis="xy"- items={images}- onSortEnd={onImageReorder}- className={classes.root}- onImageDelete={onImageDelete}- onImageEdit={onImageEdit}- />+ <>+ <ImageUpload+ className={classes.imageUpload}+ isActiveClassName={classes.imageUploadActive}+ disableClick={true}+ iconContainerClassName={classes.imageUploadIcon}+ iconContainerActiveClassName={classes.imageUploadIconActive}+ onImageUpload={onImageUpload}+ >+ {({ isDragActive }) => (+ <CardContent>+ <ImageListContainer+ distance={20}+ helperClass="dragged"+ axis="xy"+ items={images}+ onSortEnd={onImageReorder}+ className={classNames({+ [classes.root]: true,+ [classes.rootDragActive]: isDragActive+ })}+ onImageDelete={onImageDelete}+ onImageEdit={onImageEdit}+ />+ </CardContent>+ )}+ </ImageUpload>+ </>) : (- <div className={classes.noPhotosIconContainer}>- <AddPhotoIcon className={classes.noPhotosIcon} />- <Typography className={classes.noPhotosIconText}>- {i18n.t("Drop images to upload")}- </Typography>- </div>+ <ImageUpload onImageUpload={onImageUpload} />)}- </CardContent>+ </div></Card>));diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsxindex ac421994e0..46cbd445c7 100644--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx@@ -79,7 +79,7 @@ interface ProductUpdateProps extends WithStyles<typeof styles> {onDelete();onImageEdit?(id: string);onImageReorder?(event: { oldIndex: number; newIndex: number });- onImageUpload?(event: React.ChangeEvent<any>);+ onImageUpload(file: File);onProductShow?();onSeoClick?();onSubmit?(data: any);diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsxindex f899693e05..7a84997f6f 100644--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx@@ -262,11 +262,11 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({variantId))}- onImageUpload={event => {+ onImageUpload={file => {if (product) {createProductImage.mutate({alt: "",- image: event.target.files[0],+ image: file,product: product.id});}