Skip to content

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

Add root page, update category

Łukasz Szewczyk586e58d0799e
diff --git a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
index 9deb4f50a0..dc08dd8983 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryBackground/CategoryBackground.tsx
@@ -5,7 +5,6 @@ import Card from "@material-ui/core/Card";
import Button from "@material-ui/core/Button";
import CardContent from "@material-ui/core/CardContent";
import AddPhotoIcon from "@material-ui/icons/AddAPhoto";
-import Typography from "@material-ui/core/Typography";
import CardTitle from "../../../components/CardTitle";
@@ -26,11 +25,6 @@ const decorate = withStyles(theme => ({
margin: `${theme.spacing.unit * 5}px 0`,
textAlign: "center" as "center"
},
- noPhotosIconText: {
- fontSize: "1rem",
- fontWeight: 600 as 600,
- marginTop: theme.spacing.unit
- },
fileField: {
display: "none"
}
@@ -65,9 +59,6 @@ export const CategoryBackground = decorate<CategoryBackgroundProps>(
<CardContent>
<div className={classes.noPhotosIconContainer}>
<AddPhotoIcon className={classes.noPhotosIcon} />
- <Typography className={classes.noPhotosIconText}>
- {i18n.t("Drop images to upload")}
- </Typography>
</div>
</CardContent>
</Card>
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
index 78253fdd1b..4bcb1fea80 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
@@ -82,6 +82,7 @@ export const CategoryCreatePage = decorate<CategoryCreatePageProps>(
data={data}
onChange={change}
errors={errors}
+ loading={false}
/>
<CategoryBackground
onImageUpload={onImageUpload}
diff --git a/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx b/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
index ba18dd091d..66e8a3a1e0 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
@@ -8,6 +8,7 @@ import TextField from "@material-ui/core/TextField";
import CardTitle from "../../../components/CardTitle";
import FormSpacer from "../../../components/FormSpacer";
import { RichTextEditor } from "../../../components/RichTextEditor";
+import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
@@ -19,6 +20,7 @@ interface CategoryDetailsFormProps {
disabled: boolean;
errors: { [key: string]: string };
onChange(event: any);
+ loading?: boolean;
}
const decorate = withStyles(theme => ({
@@ -30,37 +32,43 @@ const decorate = withStyles(theme => ({
}));
export const CategoryDetailsForm = decorate<CategoryDetailsFormProps>(
- ({ classes, disabled, data, onChange, errors }) => {
+ ({ classes, disabled, data, onChange, errors, loading }) => {
return (
<Card>
<CardTitle title={i18n.t("General information")} />
<CardContent>
- <div className={classes.root}>
- <TextField
- label={i18n.t("Name")}
- name="name"
- disabled={disabled}
- value={data.name}
- onChange={onChange}
- error={!!errors.name}
- helperText={errors.name}
- />
- </div>
- <FormSpacer />
- <RichTextEditor
- disabled={disabled}
- label={i18n.t("Description")}
- fullWidth
- helperText={
- errors.description
- ? errors.description
- : i18n.t("Select text to enable text-formatting tools.")
- }
- name="description"
- value={data.description}
- onChange={onChange}
- error={!!errors.description}
- />
+ {loading === true ? (
+ <Skeleton />
+ ) : (
+ <>
+ <div className={classes.root}>
+ <TextField
+ label={i18n.t("Name")}
+ name="name"
+ disabled={disabled}
+ value={data.name}
+ onChange={onChange}
+ error={!!errors.name}
+ helperText={errors.name}
+ />
+ </div>
+ <FormSpacer />
+ <RichTextEditor
+ disabled={disabled}
+ label={i18n.t("Description")}
+ fullWidth
+ helperText={
+ errors.description
+ ? errors.description
+ : i18n.t("Select text to enable text-formatting tools.")
+ }
+ name="description"
+ value={data.description}
+ onChange={onChange}
+ error={!!errors.description}
+ />
+ </>
+ )}
</CardContent>
</Card>
);
diff --git a/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx b/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
index baa6db60b5..e596420026 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryList/CategoryList.tsx
@@ -24,7 +24,7 @@ interface CategoryListProps {
totalCount: number;
};
}>;
- isRoot: boolean;
+ isRoot?: boolean;
onAdd?();
onRowClick?(id: string): () => void;
}
@@ -46,7 +46,7 @@ const CategoryList = decorate<CategoryListProps>(
<Card>
{!isRoot && (
<CardTitle
- title={i18n.t("Subcategories")}
+ title={i18n.t("All Subcategories")}
toolbar={
<Button color="secondary" variant="flat" onClick={onAdd}>
{i18n.t("Add subcategory")}
@@ -58,7 +58,7 @@ const CategoryList = decorate<CategoryListProps>(
<TableHead>
<TableRow>
<TableCell className={classes.wideColumn}>
- {i18n.t("Name", { context: "object" })}
+ {i18n.t("Category Name", { context: "object" })}
</TableCell>
<TableCell>
{i18n.t("Subcategories", { context: "object" })}
diff --git a/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx b/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
index 4bde646ae8..4f9e1de0a1 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryProducts/CategoryProducts.tsx
@@ -56,7 +56,7 @@ export const ProductList = decorate<ProductListProps>(
}) => (
<Card>
<CardTitle
- title={i18n.t("Products")}
+ title={i18n.t(`Products in`)}
toolbar={
<Button variant="flat" color="secondary" onClick={onAddProduct}>
{i18n.t("Add product")}
diff --git a/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx b/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx
new file mode 100644
index 0000000000..83bd2de4a0
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx
@@ -0,0 +1,58 @@
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import * as React from "react";
+
+import { MoneyType } from "../../../products";
+import { PageListProps } from "../../..";
+import CardTitle from "../../../components/CardTitle";
+import ProductList from "../../../components/ProductList";
+import i18n from "../../../i18n";
+
+interface CategoryProductsCardProps extends PageListProps {
+ products?: Array<{
+ id: string;
+ name: string;
+ productType: {
+ name: string;
+ };
+ thumbnailUrl: string;
+ availability: {
+ available: boolean;
+ };
+ price: MoneyType;
+ }>;
+ onAddProduct?();
+}
+
+export const CategoryProductsCard: React.StatelessComponent<
+ CategoryProductsCardProps
+> = ({
+ products,
+ disabled,
+ pageInfo,
+ onAddProduct,
+ onNextPage,
+ onPreviousPage,
+ onRowClick
+}) => (
+ <Card>
+ <CardTitle
+ title={i18n.t("Products")}
+ toolbar={
+ <Button color="secondary" variant="flat" onClick={onAddProduct}>
+ {i18n.t("Add product")}
+ </Button>
+ }
+ />
+ <ProductList
+ products={products}
+ disabled={disabled}
+ pageInfo={pageInfo}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ onRowClick={onRowClick}
+ />
+ </Card>
+);
+
+export default CategoryProductsCard;
diff --git a/saleor/static/dashboard-next/categories/components/CategoryProductsCard/index.ts b/saleor/static/dashboard-next/categories/components/CategoryProductsCard/index.ts
new file mode 100644
index 0000000000..741d2b7085
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/components/CategoryProductsCard/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CategoryProductsCard";
+export * from "./CategoryProductsCard";
diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
index 4ddf430169..a5b817f563 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
@@ -1,31 +1,92 @@
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
+import AddIcon from "@material-ui/icons/Add";
import Container from "../../../components/Container";
import PageHeader from "../../../components/PageHeader";
+import CategoryBackground from "../CategoryBackground";
+import CategoryList from "../../components/CategoryList";
+
import CategoryDetailsForm from "../../components/CategoryDetailsForm";
+import SeoForm from "../../../components/SeoForm";
import Form from "../../../components/Form";
+import CategoryProductsCard from "../CategoryProductsCard";
+import CategoryDeleteDialog from "../../components/CategoryDeleteDialog";
+import { MoneyType } from "../../../products";
+import Toggle from "../../../components/Toggle";
+import SaveButtonBar, {
+ SaveButtonBarState
+} from "../../../components/SaveButtonBar/SaveButtonBar";
+import { UserError } from "../../../";
// import Card from "@material-ui/core/Card";
-// import Button from "@material-ui/core/Button";
+import Button from "@material-ui/core/Button";
// import CardContent from "@material-ui/core/CardContent";
// import AddPhotoIcon from "@material-ui/icons/AddAPhoto";
// import Typography from "@material-ui/core/Typography";
// import CardTitle from "../../../components/CardTitle";
-// import i18n from "../../../i18n";
-
-interface CategoryUpdatePageProps {
- header: string;
+import i18n from "../../../i18n";
+interface FormData {
//CategoryDetailsForm
- category: {
- SeoDescription: string;
- SeoTitle: string;
+ description: string;
+ name: string;
+
+ // SeoForm
+ seoTitle: string;
+ seoDescription: string;
+}
+interface CategoryUpdatePageProps {
+ errors: UserError[];
+ disabled: boolean;
+ productCount?: number;
+ category?: {
+ SeoDescription?: string;
+ SeoTitle?: string;
+ name?: string;
+ description?: string;
+ };
+ products?: Array<{
+ id: string;
name: string;
- description: string;
+ productType: {
+ name: string;
+ };
+ thumbnailUrl: string;
+ availability: {
+ available: boolean;
+ };
+ price: MoneyType;
+ }>;
+ subcategories?: Array<{
+ id: string;
+ name: string;
+ children: {
+ totalCount: number;
+ };
+ products: {
+ totalCount: number;
+ };
+ }>;
+ pageInfo?: {
+ hasNextPage: boolean;
+ hasPreviousPage: boolean;
};
+ loading: boolean;
+ saveButtonBarState?: SaveButtonBarState;
+ onSubmit?(data: FormData);
+ onImageUpload?(event: React.ChangeEvent<any>);
+ onNextPage?();
+ onPreviousPage?();
+ onProductClick?(id: string): () => void;
+ onAddProduct?();
+ onBack?();
+ onDelete?();
+ onSubmit?(data: FormData);
+ onAddCategory?();
+ onCategoryClick?(id: string): () => void;
}
const decorate = withStyles(theme => ({
@@ -37,36 +98,143 @@ const decorate = withStyles(theme => ({
}));
export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(
- ({ classes, header, category }) => {
+ ({
+ classes,
+ disabled,
+ errors: userErrors,
+ category,
+ onImageUpload,
+ subcategories,
+ loading,
+ products,
+ pageInfo,
+ onNextPage,
+ onPreviousPage,
+ onProductClick,
+ onAddProduct,
+ onDelete,
+ saveButtonBarState,
+ onSubmit,
+ onBack,
+ productCount,
+ onAddCategory,
+ onCategoryClick
+ }) => {
const initialData = category
? {
- SeoDescription: category.SeoDescription,
- SeoTitle: category.SeoTitle,
name: category.name,
- description: category.description
+ description: category.description,
+ seoTitle: category.SeoTitle,
+ seoDescription: category.SeoTitle
}
: {
- SeoDescription: "",
- SeoTitle: "",
+ name: "",
description: "",
- name: ""
+ seoTitle: "",
+ seoDescription: ""
};
+ const isRoot = !loading && !products && !category;
return (
- <Form initial={initialData}>
- {({ data }) => (
- <Container width="lg">
- <PageHeader title={header} />
- <div className={classes.root}>
- <CategoryDetailsForm
- disabled={false}
- data={category}
- onChange={() => undefined}
- errors={undefined}
- />
- </div>
- </Container>
+ <Toggle>
+ {(openedDeleteDialog, { toggle: toggleDeleteDialog }) => (
+ <Form onSubmit={onSubmit} initial={initialData} errors={userErrors}>
+ {({ data, change, errors, submit, hasChanged }) => (
+ <>
+ <Container width="lg">
+ <PageHeader
+ title={
+ isRoot
+ ? i18n.t("Category")
+ : category
+ ? category.name
+ : undefined
+ }
+ >
+ {isRoot && (
+ <Button
+ color="secondary"
+ variant="contained"
+ onClick={onAddCategory}
+ >
+ {i18n.t("Add category")} <AddIcon />
+ </Button>
+ )}
+ </PageHeader>
+
+ <div className={classes.root}>
+ {!isRoot && (
+ <>
+ <CategoryDetailsForm
+ data={data}
+ disabled={disabled}
+ errors={errors}
+ onChange={change}
+ loading={loading}
+ />
+ <CategoryBackground
+ onImageUpload={onImageUpload}
+ disabled={disabled}
+ />
+ <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={loading}
+ onChange={change}
+ disabled={disabled}
+ />
+ </>
+ )}
+ <CategoryList
+ categories={subcategories}
+ isRoot={isRoot}
+ onAdd={onAddCategory}
+ onRowClick={onCategoryClick}
+ />
+ {!isRoot && (
+ <>
+ <CategoryProductsCard
+ products={products}
+ disabled={disabled}
+ pageInfo={pageInfo}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ onRowClick={onProductClick}
+ onAdd={onAddProduct}
+ />{" "}
+ <SaveButtonBar
+ onCancel={onBack}
+ onDelete={toggleDeleteDialog}
+ onSave={submit}
+ labels={{
+ save: i18n.t("Save category"),
+ delete: i18n.t("Delete category")
+ }}
+ state={saveButtonBarState}
+ disabled={disabled || !hasChanged}
+ />
+ </>
+ )}
+ </div>
+ </Container>
+ {!isRoot && (
+ <CategoryDeleteDialog
+ name={category.name}
+ open={openedDeleteDialog}
+ productCount={productCount}
+ onClose={toggleDeleteDialog}
+ onConfirm={onDelete}
+ />
+ )}
+ </>
+ )}
+ </Form>
)}
- </Form>
+ </Toggle>
);
}
);
diff --git a/saleor/static/dashboard-next/categories/fixtures.ts b/saleor/static/dashboard-next/categories/fixtures.ts
index e568fd9451..b65b3f8887 100644
--- a/saleor/static/dashboard-next/categories/fixtures.ts
+++ b/saleor/static/dashboard-next/categories/fixtures.ts
@@ -13,12 +13,52 @@ export const categories = [
},
{
children: {
- totalCount: 18
+ totalCount: 54
},
id: "876752",
name: "Mauris vehicula tortor vulputate",
products: {
+ totalCount: 3
+ }
+ },
+ {
+ children: {
totalCount: 2
+ },
+ id: "876542",
+ name: "Excepteur sint occaecat cupidatat non proident",
+ products: {
+ totalCount: 6
+ }
+ },
+ {
+ children: {
+ totalCount: 6
+ },
+ id: "875352",
+ name: "Ut enim ad minim veniam",
+ products: {
+ totalCount: 12
+ }
+ },
+ {
+ children: {
+ totalCount: 76
+ },
+ id: "865752",
+ name: "Duis aute irure dolor in reprehenderit",
+ products: {
+ totalCount: 43
+ }
+ },
+ {
+ children: {
+ totalCount: 11
+ },
+ id: "878752",
+ name: "Neque porro quisquam est",
+ products: {
+ totalCount: 21
}
}
];
diff --git a/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx
index efe41d612f..c61b46d5f5 100644
--- a/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx
@@ -11,5 +11,48 @@ const category = categoryFixture("");
storiesOf("Views / Categories / Update category", module)
.addDecorator(Decorator)
.add("default", () => (
- <CategoryUpdatePage header={category.name} category={category} />
+ <CategoryUpdatePage
+ subcategories={category.children}
+ disabled={false}
+ category={category}
+ errors={[]}
+ products={category.products}
+ loading={false}
+ pageInfo={{
+ hasNextPage: true,
+ hasPreviousPage: true
+ }}
+ onNextPage={undefined}
+ onPreviousPage={undefined}
+ onProductClick={() => undefined}
+ onAddProduct={undefined}
+ onCategoryClick={() => undefined}
+ onAddCategory={undefined}
+ />
+ ))
+ .add("When in root", () => (
+ <CategoryUpdatePage
+ subcategories={category.children}
+ disabled={false}
+ errors={[]}
+ loading={false}
+ category={undefined}
+ onNextPage={undefined}
+ onPreviousPage={undefined}
+ onProductClick={() => undefined}
+ onAddProduct={undefined}
+ onCategoryClick={() => undefined}
+ onAddCategory={undefined}
+ />
+ ))
+ .add("When loading", () => (
+ <CategoryUpdatePage
+ subcategories={category.children}
+ disabled={false}
+ category={category}
+ errors={[]}
+ // products={category.products}
+ loading={true}
+ onProductClick={() => undefined}
+ />
));