Skip to content

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

Add page details page component

dominik-zeglena42f0ffa70c1
diff --git a/saleor/static/dashboard-next/pages/components/PageAvailability/PageAvailability.tsx b/saleor/static/dashboard-next/pages/components/PageAvailability/PageAvailability.tsx
new file mode 100644
index 0000000000..de27158b7c
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageAvailability/PageAvailability.tsx
@@ -0,0 +1,96 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import TextField from "@material-ui/core/TextField";
+import Typography from "@material-ui/core/Typography";
+import * as moment from "moment-timezone";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import ControlledSwitch from "../../../components/ControlledSwitch";
+import FormSpacer from "../../../components/FormSpacer";
+import { LocaleConsumer } from "../../../components/Locale";
+import { TimezoneConsumer } from "../../../components/Timezone";
+import i18n from "../../../i18n";
+import { FormData } from "../PageDetailsPage";
+
+export interface PageAvailabilityProps {
+ data: FormData;
+ disabled: boolean;
+ errors: Partial<Record<"availableOn", string>>;
+ onChange: (event: React.ChangeEvent<any>, cb?: () => void) => void;
+}
+
+const PageAvailability: React.StatelessComponent<PageAvailabilityProps> = ({
+ data,
+ disabled,
+ errors,
+ onChange
+}) => (
+ <LocaleConsumer>
+ {locale => (
+ <TimezoneConsumer>
+ {tz => (
+ <Card>
+ <CardTitle title={i18n.t("Availability")} />
+ <CardContent>
+ <ControlledSwitch
+ checked={data.isVisible}
+ disabled={disabled}
+ label={
+ data.isVisible && !data.availableOn ? (
+ i18n.t("Published")
+ ) : !data.isVisible && data.availableOn ? (
+ <>
+ {i18n.t("Hidden")}
+ <Typography variant="caption">
+ {i18n.t("Will become visible on {{ date }}", {
+ context: "page",
+ date: moment(data.availableOn)
+ .locale(locale)
+ .tz(tz)
+ .format("ll")
+ })}
+ </Typography>
+ </>
+ ) : (
+ i18n.t("Hidden")
+ )
+ }
+ name={"isVisible" as keyof FormData}
+ onChange={event =>
+ onChange(
+ event,
+ () =>
+ event.target.value &&
+ onChange({
+ target: {
+ name: "availableOn",
+ value: ""
+ }
+ } as any)
+ )
+ }
+ />
+ {!data.isVisible && (
+ <>
+ <FormSpacer />
+ <TextField
+ disabled={disabled}
+ fullWidth
+ label={i18n.t("Publish page on")}
+ name={"availableOn" as keyof FormData}
+ type="date"
+ value={data.availableOn}
+ onChange={onChange}
+ />
+ </>
+ )}
+ </CardContent>
+ </Card>
+ )}
+ </TimezoneConsumer>
+ )}
+ </LocaleConsumer>
+);
+PageAvailability.displayName = "PageAvailability";
+export default PageAvailability;
diff --git a/saleor/static/dashboard-next/pages/components/PageAvailability/index.ts b/saleor/static/dashboard-next/pages/components/PageAvailability/index.ts
new file mode 100644
index 0000000000..411f0e7989
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageAvailability/index.ts
@@ -0,0 +1,2 @@
+export { default } from './PageAvailability';
+export * from './PageAvailability';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx b/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
new file mode 100644
index 0000000000..16f360e0a7
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
@@ -0,0 +1,105 @@
+import * as React from "react";
+
+import CardSpacer from "../../../components/CardSpacer";
+import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton";
+import Container from "../../../components/Container";
+import Form from "../../../components/Form";
+import Grid from "../../../components/Grid";
+import PageHeader from "../../../components/PageHeader";
+import SaveButtonBar from "../../../components/SaveButtonBar";
+import SeoForm from "../../../components/SeoForm";
+import { maybe } from "../../../misc";
+import { PageDetails_page } from "../../types/PageDetails";
+import PageAvailability from "../PageAvailability";
+import PageInfo from "../PageInfo";
+import PageSlug from "../PageSlug";
+
+export interface FormData {
+ availableOn: string;
+ content: string;
+ isVisible: boolean;
+ seoDescription: string;
+ seoTitle: string;
+ slug: string;
+ title: string;
+}
+
+export interface PageDetailsPageProps {
+ disabled: boolean;
+ page: PageDetails_page;
+ saveButtonBarState: ConfirmButtonTransitionState;
+ onBack: () => void;
+ onRemove: () => void;
+ onSubmit: (data: FormData) => void;
+}
+
+const PageDetailsPage: React.StatelessComponent<PageDetailsPageProps> = ({
+ disabled,
+ page,
+ saveButtonBarState,
+ onBack,
+ onRemove,
+ onSubmit
+}) => {
+ const initialForm: FormData = {
+ availableOn: maybe(() => page.availableOn, ""),
+ content: maybe(() => page.content, ""),
+ isVisible: maybe(() => page.isVisible, false),
+ seoDescription: maybe(() => page.seoDescription, ""),
+ seoTitle: maybe(() => page.seoTitle, ""),
+ slug: maybe(() => page.slug, ""),
+ title: maybe(() => page.title, "")
+ };
+ return (
+ <Form initial={initialForm} onSubmit={onSubmit}>
+ {({ change, data, errors: formErrors, hasChanged, submit }) => (
+ <Container width="md">
+ <PageHeader title={maybe(() => page.title)} onBack={onBack} />
+ <Grid>
+ <div>
+ <PageInfo
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <SeoForm
+ description={data.seoDescription}
+ disabled={disabled}
+ descriptionPlaceholder={data.title}
+ onChange={change}
+ title={data.seoTitle}
+ titlePlaceholder={data.title}
+ />
+ </div>
+ <div>
+ <PageSlug
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <PageAvailability
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ </div>
+ </Grid>
+ <SaveButtonBar
+ disabled={disabled || !hasChanged}
+ state={saveButtonBarState}
+ onCancel={onBack}
+ onDelete={onRemove}
+ onSave={submit}
+ />
+ </Container>
+ )}
+ </Form>
+ );
+};
+PageDetailsPage.displayName = "PageDetailsPage";
+export default PageDetailsPage;
diff --git a/saleor/static/dashboard-next/pages/components/PageDetailsPage/index.ts b/saleor/static/dashboard-next/pages/components/PageDetailsPage/index.ts
new file mode 100644
index 0000000000..c299df7ee1
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageDetailsPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from './PageDetailsPage';
+export * from './PageDetailsPage';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx b/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx
new file mode 100644
index 0000000000..d028a8f4ae
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx
@@ -0,0 +1,52 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import TextField from "@material-ui/core/TextField";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import FormSpacer from "../../../components/FormSpacer";
+import i18n from "../../../i18n";
+import { FormData } from "../PageDetailsPage";
+
+export interface PageInfoProps {
+ data: FormData;
+ disabled: boolean;
+ errors: Partial<Record<"title" | "content", string>>;
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+
+const PageInfo: React.StatelessComponent<PageInfoProps> = ({
+ data,
+ disabled,
+ errors,
+ onChange
+}) => (
+ <Card>
+ <CardTitle title={i18n.t("General Informations")} />
+ <CardContent>
+ <TextField
+ disabled={disabled}
+ error={!!errors.title}
+ fullWidth
+ helperText={errors.title}
+ label={i18n.t("Title")}
+ name={"title" as keyof FormData}
+ value={data.title}
+ onChange={onChange}
+ />
+ <FormSpacer />
+ <TextField
+ disabled={disabled}
+ error={!!errors.title}
+ fullWidth
+ helperText={errors.title}
+ label={i18n.t("Content")}
+ name={"title" as keyof FormData}
+ value={data.content}
+ onChange={onChange}
+ />
+ </CardContent>
+ </Card>
+);
+PageInfo.displayName = "PageInfo";
+export default PageInfo;
diff --git a/saleor/static/dashboard-next/pages/components/PageInfo/index.ts b/saleor/static/dashboard-next/pages/components/PageInfo/index.ts
new file mode 100644
index 0000000000..8bcf98a76f
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageInfo/index.ts
@@ -0,0 +1,2 @@
+export { default } from './PageInfo';
+export * from './PageInfo';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/pages/components/PageSlug/PageSlug.tsx b/saleor/static/dashboard-next/pages/components/PageSlug/PageSlug.tsx
new file mode 100644
index 0000000000..dd691f2749
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageSlug/PageSlug.tsx
@@ -0,0 +1,42 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import TextField from "@material-ui/core/TextField";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import i18n from "../../../i18n";
+import { FormData } from "../PageDetailsPage";
+
+export interface PageSlugProps {
+ data: FormData;
+ disabled: boolean;
+ errors: Partial<Record<"slug", string>>;
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+
+const PageSlug: React.StatelessComponent<PageSlugProps> = ({
+ data,
+ disabled,
+ errors,
+ onChange
+}) => (
+ <Card>
+ <CardTitle title={i18n.t("URL")} />
+ <CardContent>
+ <TextField
+ name={"slug" as keyof FormData}
+ disabled={disabled}
+ label={i18n.t("Slug")}
+ helperText={
+ errors.availableOn ||
+ i18n.t("If empty, URL will be autogenerated from Page Name")
+ }
+ placeholder={data.title.toLowerCase()}
+ value={data.slug}
+ onChange={onChange}
+ />
+ </CardContent>
+ </Card>
+);
+PageSlug.displayName = "PageSlug";
+export default PageSlug;
diff --git a/saleor/static/dashboard-next/pages/components/PageSlug/index.ts b/saleor/static/dashboard-next/pages/components/PageSlug/index.ts
new file mode 100644
index 0000000000..06056b307b
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/components/PageSlug/index.ts
@@ -0,0 +1,2 @@
+export { default } from './PageSlug';
+export * from './PageSlug';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/pages/fixtures.ts b/saleor/static/dashboard-next/pages/fixtures.ts
index f40ea09d83..92065ec4a2 100644
--- a/saleor/static/dashboard-next/pages/fixtures.ts
+++ b/saleor/static/dashboard-next/pages/fixtures.ts
@@ -1,3 +1,4 @@
+import { PageDetails_page } from "./types/PageDetails";
import { PageList_pages_edges_node } from "./types/PageList";
export const pageList: PageList_pages_edges_node[] = [
@@ -30,3 +31,14 @@ export const pageList: PageList_pages_edges_node[] = [
title: "About"
}
];
+export const page: PageDetails_page = {
+ __typename: "Page",
+ availableOn: "",
+ content: "",
+ id: "Kzx152sEm==",
+ isVisible: false,
+ seoDescription: "About",
+ seoTitle: "About",
+ slug: "about",
+ title: "About"
+};
diff --git a/saleor/static/dashboard-next/pages/queries.ts b/saleor/static/dashboard-next/pages/queries.ts
index 1233f48e01..efeb1a735e 100644
--- a/saleor/static/dashboard-next/pages/queries.ts
+++ b/saleor/static/dashboard-next/pages/queries.ts
@@ -1,6 +1,7 @@
import gql from "graphql-tag";
import { TypedQuery } from "../queries";
+import { PageDetails, PageDetailsVariables } from "./types/PageDetails";
import { PageList, PageListVariables } from "./types/PageList";
export const pageFragment = gql`
@@ -12,6 +13,17 @@ export const pageFragment = gql`
}
`;
+export const pageDetailsFragment = gql`
+ ${pageFragment}
+ fragment PageDetailsFragment on Page {
+ ...PageFragment
+ content
+ seoTitle
+ seoDescription
+ availableOn
+ }
+`;
+
const pageList = gql`
${pageFragment}
query PageList($first: Int, $after: String, $last: Int, $before: String) {
@@ -31,3 +43,15 @@ const pageList = gql`
}
`;
export const TypedPageList = TypedQuery<PageList, PageListVariables>(pageList);
+
+const pageDetails = gql`
+ ${pageDetailsFragment}
+ query PageDetails($id: ID!) {
+ page(id: $id) {
+ ...PageDetailsFragment
+ }
+ }
+`;
+export const TypedPageDetails = TypedQuery<PageDetails, PageDetailsVariables>(
+ pageDetails
+);
diff --git a/saleor/static/dashboard-next/pages/types/PageDetails.ts b/saleor/static/dashboard-next/pages/types/PageDetails.ts
new file mode 100644
index 0000000000..d5a52cf6b9
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/types/PageDetails.ts
@@ -0,0 +1,26 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL query operation: PageDetails
+// ====================================================
+
+export interface PageDetails_page {
+ __typename: "Page";
+ id: string;
+ title: string;
+ slug: string;
+ isVisible: boolean;
+ content: string;
+ seoTitle: string | null;
+ seoDescription: string | null;
+ availableOn: any | null;
+}
+
+export interface PageDetails {
+ page: PageDetails_page | null;
+}
+
+export interface PageDetailsVariables {
+ id: string;
+}
diff --git a/saleor/static/dashboard-next/pages/types/PageDetailsFragment.ts b/saleor/static/dashboard-next/pages/types/PageDetailsFragment.ts
new file mode 100644
index 0000000000..ee08aaec56
--- /dev/null
+++ b/saleor/static/dashboard-next/pages/types/PageDetailsFragment.ts
@@ -0,0 +1,18 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL fragment: PageDetailsFragment
+// ====================================================
+
+export interface PageDetailsFragment {
+ __typename: "Page";
+ id: string;
+ title: string;
+ slug: string;
+ isVisible: boolean;
+ content: string;
+ seoTitle: string | null;
+ seoDescription: string | null;
+ availableOn: any | null;
+}
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index bfac4846b1..1d8d308437 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -70,6 +70,7 @@ function loadStories() {
require("./stories/staff/StaffDetailsPage");
// Pages
+ require("./stories/pages/PageDetailsPage")
require("./stories/pages/PageListPage")
// Products
diff --git a/saleor/static/dashboard-next/storybook/stories/pages/PageDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/pages/PageDetailsPage.tsx
new file mode 100644
index 0000000000..0285d61930
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/pages/PageDetailsPage.tsx
@@ -0,0 +1,24 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import PageDetailsPage, {
+ PageDetailsPageProps
+} from "../../../pages/components/PageDetailsPage";
+import { page } from "../../../pages/fixtures";
+import Decorator from "../../Decorator";
+
+const props: PageDetailsPageProps = {
+ disabled: false,
+ onBack: () => undefined,
+ onRemove: () => undefined,
+ onSubmit: () => undefined,
+ page,
+ saveButtonBarState: "default"
+};
+
+storiesOf("Views / Pages / Page details", module)
+ .addDecorator(Decorator)
+ .add("default", () => <PageDetailsPage {...props} />)
+ .add("loading", () => (
+ <PageDetailsPage {...props} disabled={true} page={undefined} />
+ ));