Skip to content

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

Add collection image

dominik-zeglen4d9f8c888b72
diff --git a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
index dfb44af1ce..19883acccc 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
@@ -6,9 +6,8 @@ import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import AddPhotoIcon from "@material-ui/icons/AddAPhoto";
-import CategoryBackgroundImage from "./CategoryBackgroundImage";
-
import CardTitle from "../../../components/CardTitle";
+import ImageTile from "../../../components/ImageTile";
import i18n from "../../../i18n";
interface CategoryBackgroundProps {
@@ -22,9 +21,9 @@ interface CategoryBackgroundProps {
const decorate = withStyles(theme => ({
PhotosIcon: {
- height: "64px",
+ height: 64,
margin: "0 auto",
- width: "64px"
+ width: 64
},
PhotosIconContainer: {
margin: `${theme.spacing.unit * 5}px 0`,
@@ -111,9 +110,9 @@ export const CategoryBackground = decorate(
<AddPhotoIcon className={classes.PhotosIcon} />
</div>
) : (
- <CategoryBackgroundImage
+ <ImageTile
+ image={backgroundImage}
onImageDelete={onImageDelete}
- backgroundImage={backgroundImage}
/>
)}
</CardContent>
diff --git a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackgroundImage.tsx b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackgroundImage.tsx
deleted file mode 100644
index 92f9cc6b5f..0000000000
--- a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackgroundImage.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import { withStyles } from "@material-ui/core/styles";
-import * as React from "react";
-
-import ImageTile from "../../../components/ImageTile";
-
-const decorate = withStyles({});
-
-interface CategoryBackgroundImageProps {
- onImageDelete: () => void;
- backgroundImage: {
- url: string;
- };
-}
-
-const CategoryBackgroundImage = decorate<CategoryBackgroundImageProps>(
- ({ onImageDelete, backgroundImage }) => (
- <ImageTile
- tile={backgroundImage}
- onImageDelete={onImageDelete}
- deleteIcon={true}
- editIcon={false}
- />
- )
-);
-
-export default CategoryBackgroundImage;
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
index 75112164b6..2a3b7b7d1a 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
@@ -10,6 +10,7 @@ import { maybe } from "../../../misc";
import { CollectionDetails_collection } from "../../types/CollectionDetails";
import CollectionDetails from "../CollectionDetails/CollectionDetails";
import CollectionProducts from "../CollectionProducts/CollectionProducts";
+import { CollectionImage } from "../CollectionImage/CollectionImage";
export interface CollectionDetailsPageFormData {
name: string;
@@ -22,6 +23,7 @@ export interface CollectionDetailsPageProps extends PageListProps {
collection: CollectionDetails_collection;
onBack: () => void;
onCollectionRemove: () => void;
+ onImageDelete: () => void;
onImageUpload: () => void;
onSubmit: (data: CollectionDetailsPageFormData) => void;
}
@@ -40,6 +42,8 @@ const CollectionDetailsPage = decorate<CollectionDetailsPageProps>(
disabled,
onBack,
onCollectionRemove,
+ onImageDelete,
+ onImageUpload,
onSubmit,
...pageListProps
}) => (
@@ -64,6 +68,12 @@ const CollectionDetailsPage = decorate<CollectionDetailsPageProps>(
onChange={change}
/>
<CardSpacer />
+ <CollectionImage
+ image={maybe(() => collection.backgroundImage)}
+ onImageDelete={onImageDelete}
+ onImageUpload={onImageUpload}
+ />
+ <CardSpacer />
<CollectionProducts
disabled={disabled}
collection={collection}
diff --git a/saleor/static/dashboard-next/collections/components/CollectionImage/CollectionImage.tsx b/saleor/static/dashboard-next/collections/components/CollectionImage/CollectionImage.tsx
new file mode 100644
index 0000000000..90b7ad9d2b
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/components/CollectionImage/CollectionImage.tsx
@@ -0,0 +1,113 @@
+import { withStyles, WithStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import AddPhotoIcon from "@material-ui/icons/AddAPhoto";
+import CardTitle from "../../../components/CardTitle";
+import ImageTile from "../../../components/ImageTile";
+import Skeleton from "../../../components/Skeleton";
+import i18n from "../../../i18n";
+import { CollectionDetails_collection_backgroundImage } from "../../types/CollectionDetails";
+
+export interface CollectionImageProps {
+ image: CollectionDetails_collection_backgroundImage;
+ onImageDelete: () => void;
+ onImageUpload: (event: React.ChangeEvent<any>) => void;
+}
+
+const decorate = withStyles(theme => ({
+ PhotosIcon: {
+ height: "64px",
+ margin: "0 auto",
+ width: "64px"
+ },
+ PhotosIconContainer: {
+ margin: `${theme.spacing.unit * 5}px 0`,
+ textAlign: "center" as "center"
+ },
+ fileField: {
+ display: "none"
+ },
+ image: {
+ height: "100%",
+ objectFit: "contain" as "contain",
+ userSelect: "none" as "none",
+ width: "100%"
+ },
+ imageContainer: {
+ background: "#ffffff",
+ border: "1px solid #eaeaea",
+ borderRadius: theme.spacing.unit,
+ height: 148,
+ justifySelf: "start",
+ overflow: "hidden" as "hidden",
+ padding: theme.spacing.unit * 2,
+ position: "relative" as "relative",
+ width: 148
+ }
+}));
+export const CollectionImage = decorate(
+ class CollectionImageComponent extends React.Component<
+ CollectionImageProps &
+ WithStyles<
+ | "PhotosIcon"
+ | "PhotosIconContainer"
+ | "fileField"
+ | "image"
+ | "imageContainer"
+ >,
+ {}
+ > {
+ imgInputAnchor = React.createRef<HTMLInputElement>();
+
+ clickImgInput = () => this.imgInputAnchor.current.click();
+
+ render() {
+ const { classes, onImageUpload, image, onImageDelete } = this.props;
+ return (
+ <Card>
+ <CardTitle
+ title={i18n.t("Background image (optional)")}
+ toolbar={
+ <>
+ <Button
+ variant="flat"
+ color="secondary"
+ onClick={this.clickImgInput}
+ >
+ {i18n.t("Upload image")}
+ </Button>
+ <input
+ className={classes.fileField}
+ id="fileUpload"
+ onChange={onImageUpload}
+ type="file"
+ ref={this.imgInputAnchor}
+ />
+ </>
+ }
+ />
+ <CardContent>
+ {image === undefined ? (
+ <div>
+ <div className={classes.imageContainer}>
+ <Skeleton />
+ </div>
+ </div>
+ ) : image === null ? (
+ <div className={classes.PhotosIconContainer}>
+ <AddPhotoIcon className={classes.PhotosIcon} />
+ </div>
+ ) : (
+ <ImageTile image={image} onImageDelete={onImageDelete} />
+ )}
+ </CardContent>
+ </Card>
+ );
+ }
+ }
+);
+
+export default CollectionImage;
diff --git a/saleor/static/dashboard-next/collections/components/CollectionImage/index.ts b/saleor/static/dashboard-next/collections/components/CollectionImage/index.ts
new file mode 100644
index 0000000000..1d18c66cc6
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/components/CollectionImage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CollectionImage";
+export * from "./CollectionImage";
diff --git a/saleor/static/dashboard-next/collections/fixtures.ts b/saleor/static/dashboard-next/collections/fixtures.ts
index 6237c7849c..dce2f7e560 100644
--- a/saleor/static/dashboard-next/collections/fixtures.ts
+++ b/saleor/static/dashboard-next/collections/fixtures.ts
@@ -24,13 +24,16 @@ export const collections: CollectionList_collections_edges_node[] = [
}
];
export const collection: (
- placeholderImage: string
-) => CollectionDetails_collection = placeholderImage => ({
+ placeholderCollectionImage: string,
+ placeholderProductImage: string
+) => CollectionDetails_collection = (
+ placeholderCollectionImage,
+ placeholderImage
+) => ({
__typename: "Collection",
backgroundImage: {
__typename: "Image",
- url:
- "/media/collection-backgrounds/saleor/static/placeholders/products-list/summer_drbDitj.jpg"
+ url: placeholderCollectionImage
},
id: "Q29sbGVjdGlvbjox",
isPublished: true,
diff --git a/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx b/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx
index a85c7c60d2..99ad6a7245 100644
--- a/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx
+++ b/saleor/static/dashboard-next/components/ImageTile/ImageTile.tsx
@@ -4,7 +4,6 @@ import * as React from "react";
import IconButton from "@material-ui/core/IconButton";
import DeleteIcon from "@material-ui/icons/Delete";
import EditIcon from "@material-ui/icons/Edit";
-import { ProductDetails_product_images_edges_node } from "../../products/types/ProductDetails";
const decorate = withStyles(theme => ({
image: {
@@ -45,24 +44,25 @@ const decorate = withStyles(theme => ({
}));
interface ImageTileProps {
- image: ProductDetails_product_images_edges_node;
- deleteIcon: boolean;
- editIcon: boolean;
+ image: {
+ alt?: string;
+ url: string;
+ };
onImageDelete?: () => void;
- onImageEdit: (event: React.ChangeEvent<any>) => void;
+ onImageEdit?: (event: React.ChangeEvent<any>) => void;
}
const ImageTile = decorate<ImageTileProps>(
- ({ classes, onImageDelete, onImageEdit, image, editIcon, deleteIcon }) => (
+ ({ classes, onImageDelete, onImageEdit, image }) => (
<div className={classes.imageContainer}>
<div className={classes.imageOverlay}>
<div className={classes.imageOverlayToolbar}>
- {editIcon && (
+ {onImageEdit && (
<IconButton color="secondary" onClick={onImageEdit}>
<EditIcon />
</IconButton>
)}
- {deleteIcon && (
+ {onImageDelete && (
<IconButton color="secondary" onClick={onImageDelete}>
<DeleteIcon />
</IconButton>
diff --git a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
index 68bf597ab4..1d7a97501c 100644
--- a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
@@ -115,8 +115,6 @@ const decorate = withStyles(theme => ({
const SortableImage = SortableElement(({ image, onImageEdit, toggle }) => (
<ImageTile
image={image}
- deleteIcon={true}
- editIcon={true}
onImageEdit={onImageEdit ? () => onImageEdit(image.id) : undefined}
onImageDelete={toggle}
/>
diff --git a/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
index ef49b83709..1062d41fb6 100644
--- a/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
@@ -1,7 +1,8 @@
import { storiesOf } from "@storybook/react";
import * as React from "react";
-import * as placeholderImage from "../../../../images/placeholder60x60.png";
+import * as placeholderCollectionImage from "../../../../images/block1.jpg";
+import * as placeholderProductImage from "../../../../images/placeholder60x60.png";
import CollectionDetailsPage, {
CollectionDetailsPageProps
} from "../../../collections/components/CollectionDetailsPage";
@@ -9,7 +10,10 @@ import { collection as collectionFixture } from "../../../collections/fixtures";
import { pageListProps } from "../../../fixtures";
import Decorator from "../../Decorator";
-const collection = collectionFixture(placeholderImage);
+const collection = collectionFixture(
+ placeholderCollectionImage,
+ placeholderProductImage
+);
const props: CollectionDetailsPageProps = {
...pageListProps.default,
@@ -17,6 +21,7 @@ const props: CollectionDetailsPageProps = {
disabled: false,
onBack: () => undefined,
onCollectionRemove: () => undefined,
+ onImageDelete: () => undefined,
onImageUpload: () => undefined,
onSubmit: () => undefined
};