Skip to content

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

Add crate page and basic update layout

Łukasz Szewczyk51ea4a66c5c7
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
index f0bec4554d..78253fdd1b 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
@@ -1,4 +1,5 @@
import { withStyles } from "@material-ui/core/styles";
+// import DialogContentText from "@material-ui/core/DialogContentText";
import * as React from "react";
import Form from "../../../components/Form";
@@ -10,11 +11,12 @@ import CategoryDetailsForm from "../../components/CategoryDetailsForm";
import SeoForm from "../../../components/SeoForm";
import CategoryBackground from "../CategoryBackground";
import CategoryCreateSubcategories from "../CategoryCreateSubcategories";
+import Toggle from "../../../components/Toggle";
+import CategoryDeleteDialog from "../../components/CategoryDeleteDialog";
-// import SaveButtonBar from "../../../components/SaveButtonBar/SaveButtonBar";
-// ,{
-// SaveButtonBarState
-// }
+import SaveButtonBar, {
+ SaveButtonBarState
+} from "../../../components/SaveButtonBar/SaveButtonBar";
interface FormData {
//CategoryDetailsForm
@@ -34,8 +36,11 @@ interface CategoryCreatePageProps {
onSubmit?(data: FormData);
onImageUpload?(event: React.ChangeEvent<any>);
-}
+ onBack?();
+ onDelete?();
+ saveButtonBarState?: SaveButtonBarState;
+}
const decorate = withStyles(theme => ({
root: {
display: "grid",
@@ -50,8 +55,11 @@ export const CategoryCreatePage = decorate<CategoryCreatePageProps>(
header,
disabled,
onSubmit,
+ onBack,
errors: userErrors,
- onImageUpload
+ onImageUpload,
+ onDelete,
+ saveButtonBarState
}) => {
const initialData: FormData = {
name: "",
@@ -61,37 +69,62 @@ export const CategoryCreatePage = decorate<CategoryCreatePageProps>(
// backgroundImage: ""
};
return (
- <Form onSubmit={onSubmit} initial={initialData} errors={userErrors}>
- {({ data, change, errors }) => (
- <Container width="lg">
- <PageHeader title={header} />
- <div className={classes.root}>
- <CategoryDetailsForm
- disabled={disabled}
- data={data}
- onChange={change}
- errors={errors}
- />
- <CategoryBackground
- onImageUpload={onImageUpload}
- disabled={disabled}
- />
- <CategoryCreateSubcategories />
- <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>
- </Container>
+ <Toggle>
+ {(openedDeleteDialog, { toggle: toggleDeleteDialog }) => (
+ <Form onSubmit={onSubmit} initial={initialData} errors={userErrors}>
+ {({ data, change, errors, submit, hasChanged }) => (
+ <>
+ <Container width="lg">
+ <PageHeader title={header} />
+ <div className={classes.root}>
+ <CategoryDetailsForm
+ disabled={disabled}
+ data={data}
+ onChange={change}
+ errors={errors}
+ />
+ <CategoryBackground
+ onImageUpload={onImageUpload}
+ disabled={disabled}
+ />
+ <CategoryCreateSubcategories 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={disabled}
+ onChange={change}
+ disabled={disabled}
+ />{" "}
+ <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>
+ <CategoryDeleteDialog
+ name={undefined}
+ open={openedDeleteDialog}
+ productCount={undefined}
+ onClose={toggleDeleteDialog}
+ onConfirm={onDelete}
+ />
+ </>
+ )}
+ </Form>
)}
- </Form>
+ </Toggle>
);
}
);
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/CategoryCreateSubcategories.tsx b/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/CategoryCreateSubcategories.tsx
index 457470d66f..c7bd152819 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/CategoryCreateSubcategories.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryCreateSubcategories/CategoryCreateSubcategories.tsx
@@ -18,7 +18,9 @@ import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
-interface CategoryCreateSubcategoriesProps {}
+interface CategoryCreateSubcategoriesProps {
+ disabled: boolean;
+}
const decorate = withStyles(theme => ({
root: {
@@ -47,7 +49,7 @@ const decorate = withStyles(theme => ({
export const CategoryCreateSubcategories = decorate<
CategoryCreateSubcategoriesProps
->(({ classes }) => {
+>(({ classes, disabled }) => {
return (
<Toggle>
{(toggled, { toggle }) => (
@@ -59,6 +61,7 @@ export const CategoryCreateSubcategories = decorate<
color={toggled ? "default" : "secondary"}
variant="flat"
onClick={toggle}
+ disabled={disabled}
>
{toggled ? i18n.t("Cancel") : i18n.t("Add subcategory")}
</Button>
diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
new file mode 100644
index 0000000000..4ddf430169
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
@@ -0,0 +1,73 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+import Container from "../../../components/Container";
+import PageHeader from "../../../components/PageHeader";
+
+import CategoryDetailsForm from "../../components/CategoryDetailsForm";
+import Form from "../../../components/Form";
+
+// 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";
+
+// import i18n from "../../../i18n";
+
+interface CategoryUpdatePageProps {
+ header: string;
+
+ //CategoryDetailsForm
+ category: {
+ SeoDescription: string;
+ SeoTitle: string;
+ name: string;
+ description: string;
+ };
+}
+
+const decorate = withStyles(theme => ({
+ root: {
+ display: "grid",
+ marginTop: theme.spacing.unit * 2,
+ gridGap: theme.spacing.unit * 4 + "px"
+ }
+}));
+
+export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(
+ ({ classes, header, category }) => {
+ const initialData = category
+ ? {
+ SeoDescription: category.SeoDescription,
+ SeoTitle: category.SeoTitle,
+ name: category.name,
+ description: category.description
+ }
+ : {
+ SeoDescription: "",
+ SeoTitle: "",
+ description: "",
+ name: ""
+ };
+ 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>
+ )}
+ </Form>
+ );
+ }
+);
+export default CategoryUpdatePage;
diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/index.ts b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/index.ts
new file mode 100644
index 0000000000..0b5755ef7d
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CategoryUpdatePage";
+export * from "./CategoryUpdatePage";
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 414e814420..a6bcdc7d8d 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -38,6 +38,7 @@ function loadStories() {
require("./stories/categories/CategoryEditPage");
require("./stories/categories/CategoryProducts");
require("./stories/categories/CategoryCreatePage");
+ require("./stories/categories/CategoryUpdatePage");
// Collections
require("./stories/collections/CollectionDetailsPage");
diff --git a/saleor/static/dashboard-next/storybook/stories/categories/CategoryCreatePage.tsx b/saleor/static/dashboard-next/storybook/stories/categories/CategoryCreatePage.tsx
index 296fe722c6..f7847f7457 100644
--- a/saleor/static/dashboard-next/storybook/stories/categories/CategoryCreatePage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/categories/CategoryCreatePage.tsx
@@ -7,8 +7,18 @@ import Decorator from "../../Decorator";
storiesOf("Views / Categories / Create category", module)
.addDecorator(Decorator)
.add("default", () => (
- <CategoryCreatePage header="Add category" disabled={false} errors={[]} />
+ <CategoryCreatePage
+ header="Add category"
+ disabled={false}
+ errors={[]}
+ onBack={() => undefined}
+ />
))
.add("When loading", () => (
- <CategoryCreatePage header="Add category" disabled={true} errors={[]} />
+ <CategoryCreatePage
+ header="Add category"
+ disabled={true}
+ errors={[]}
+ onBack={() => undefined}
+ />
));
diff --git a/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx
new file mode 100644
index 0000000000..efe41d612f
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx
@@ -0,0 +1,15 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import { category as categoryFixture } from "../../../categories/fixtures";
+
+import CategoryUpdatePage from "../../../categories/components/CategoryUpdatePage";
+import Decorator from "../../Decorator";
+
+const category = categoryFixture("");
+
+storiesOf("Views / Categories / Update category", module)
+ .addDecorator(Decorator)
+ .add("default", () => (
+ <CategoryUpdatePage header={category.name} category={category} />
+ ));