Skip to content

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

add category details form

Łukasz Szewczykda54ddac81b0
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
new file mode 100644
index 0000000000..618ad93fb1
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/CategoryCreatePage.tsx
@@ -0,0 +1,56 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+import Form from "../../../components/Form";
+import Container from "../../../components/Container";
+import PageHeader from "../../../components/PageHeader";
+import { UserError } from "../../../";
+
+import CategoryDetailsForm from "../../components/CategoryDetailsForm";
+
+interface FormData {
+ //CategoryDetailsForm
+ description: string;
+ name: string;
+}
+
+interface CategoryCreatePageProps {
+ errors: UserError[];
+ header: string;
+
+ disabled: boolean;
+
+ onSubmit?(data: FormData);
+}
+
+const decorate = withStyles(theme => ({
+ root: {
+ display: "grid",
+ marginTop: theme.spacing.unit * 2
+ }
+}));
+
+export const CategoryCreatePage = decorate<CategoryCreatePageProps>(
+ ({ header, disabled, onSubmit, errors: userErrors }) => {
+ const initialData: FormData = {
+ name: "",
+ description: ""
+ };
+ return (
+ <Form onSubmit={onSubmit} initial={initialData} errors={userErrors}>
+ {({ data, change, errors }) => (
+ <Container width="lg">
+ <PageHeader title={header} />
+ <CategoryDetailsForm
+ disabled={disabled}
+ data={data}
+ onChange={change}
+ errors={errors}
+ />
+ </Container>
+ )}
+ </Form>
+ );
+ }
+);
+export default CategoryCreatePage;
diff --git a/saleor/static/dashboard-next/categories/components/CategoryCreatePage/index.ts b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/index.ts
new file mode 100644
index 0000000000..1624a6ddbd
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/components/CategoryCreatePage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CategoryCreatePage";
+export * from "./CategoryCreatePage";
diff --git a/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx b/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
new file mode 100644
index 0000000000..ba18dd091d
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/CategoryDetailsForm.tsx
@@ -0,0 +1,69 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import TextField from "@material-ui/core/TextField";
+
+import CardTitle from "../../../components/CardTitle";
+import FormSpacer from "../../../components/FormSpacer";
+import { RichTextEditor } from "../../../components/RichTextEditor";
+
+import i18n from "../../../i18n";
+
+interface CategoryDetailsFormProps {
+ data: {
+ name: string;
+ description: string;
+ };
+ disabled: boolean;
+ errors: { [key: string]: string };
+ onChange(event: any);
+}
+
+const decorate = withStyles(theme => ({
+ root: {
+ display: "grid",
+ gridColumnGap: theme.spacing.unit * 2 + "px",
+ gridTemplateColumns: `1fr 1fr`
+ }
+}));
+
+export const CategoryDetailsForm = decorate<CategoryDetailsFormProps>(
+ ({ classes, disabled, data, onChange, errors }) => {
+ 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}
+ />
+ </CardContent>
+ </Card>
+ );
+ }
+);
+export default CategoryDetailsForm;
diff --git a/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/index.ts b/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/index.ts
new file mode 100644
index 0000000000..33c5482ba0
--- /dev/null
+++ b/saleor/static/dashboard-next/categories/components/CategoryDetailsForm/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CategoryDetailsForm";
+export * from "./CategoryDetailsForm";
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 46c9fcc101..414e814420 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -37,6 +37,7 @@ function loadStories() {
require("./stories/categories/CategoryDetailsPage");
require("./stories/categories/CategoryEditPage");
require("./stories/categories/CategoryProducts");
+ require("./stories/categories/CategoryCreatePage");
// Collections
require("./stories/collections/CollectionDetailsPage");
@@ -51,8 +52,8 @@ function loadStories() {
require("./stories/customers/CustomerListPage");
// Staff
- require("./stories/staff/StaffListPage")
- require("./stories/staff/StaffDetailsPage")
+ require("./stories/staff/StaffListPage");
+ require("./stories/staff/StaffDetailsPage");
// Pages
require("./stories/pages/PageContent");
diff --git a/saleor/static/dashboard-next/storybook/stories/categories/CategoryCreatePage.tsx b/saleor/static/dashboard-next/storybook/stories/categories/CategoryCreatePage.tsx
new file mode 100644
index 0000000000..296fe722c6
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/categories/CategoryCreatePage.tsx
@@ -0,0 +1,14 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import CategoryCreatePage from "../../../categories/components/CategoryCreatePage";
+import Decorator from "../../Decorator";
+
+storiesOf("Views / Categories / Create category", module)
+ .addDecorator(Decorator)
+ .add("default", () => (
+ <CategoryCreatePage header="Add category" disabled={false} errors={[]} />
+ ))
+ .add("When loading", () => (
+ <CategoryCreatePage header="Add category" disabled={true} errors={[]} />
+ ));