Skip to content

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

Add site settings page

dominik-zeglen4c744dd0992c
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsDetails/SiteSettingsDetails.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsDetails/SiteSettingsDetails.tsx
new file mode 100644
index 0000000000..1d006b8139
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsDetails/SiteSettingsDetails.tsx
@@ -0,0 +1,75 @@
+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 { SiteSettingsPageFormData } from "../SiteSettingsPage";
+
+interface SiteSettingsDetailsProps {
+ data: SiteSettingsPageFormData;
+ disabled: boolean;
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+
+const SiteSettingsDetails: React.StatelessComponent<
+ SiteSettingsDetailsProps
+> = ({ data, disabled, onChange }) => (
+ <Card>
+ <CardTitle
+ title={i18n.t("General Information", {
+ context: "card title"
+ })}
+ />
+ <CardContent>
+ <TextField
+ disabled={disabled}
+ fullWidth
+ name="name"
+ label={i18n.t("Store Name", {
+ context: "field label"
+ })}
+ helperText={i18n.t("Store Name is shown on taskbar in web browser", {
+ context: "help text"
+ })}
+ value={data.name}
+ onChange={onChange}
+ />
+ <FormSpacer />
+ <TextField
+ disabled={disabled}
+ fullWidth
+ name="domain"
+ label={i18n.t("Domain", {
+ context: "field label"
+ })}
+ helperText={i18n.t("Domain is your store URL", {
+ context: "help text"
+ })}
+ value={data.domain}
+ onChange={onChange}
+ />
+ <FormSpacer />
+ <TextField
+ disabled={disabled}
+ fullWidth
+ name="description"
+ label={i18n.t("Store Description", {
+ context: "field label"
+ })}
+ helperText={i18n.t(
+ "Store description is shown on taskbar after your store name",
+ {
+ context: "help text"
+ }
+ )}
+ value={data.description}
+ onChange={onChange}
+ />
+ </CardContent>
+ </Card>
+);
+SiteSettingsDetails.displayName = "SiteSettingsDetails";
+export default SiteSettingsDetails;
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsDetails/index.ts b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsDetails/index.ts
new file mode 100644
index 0000000000..ae552a229b
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsDetails/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./SiteSettingsDetails";
+export * from "./SiteSettingsDetails";
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/SiteSettingsKeys.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/SiteSettingsKeys.tsx
new file mode 100644
index 0000000000..aa6f833237
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/SiteSettingsKeys.tsx
@@ -0,0 +1,93 @@
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import { withStyles } from "@material-ui/core/styles";
+import Table from "@material-ui/core/Table";
+import TableBody from "@material-ui/core/TableBody";
+import TableCell from "@material-ui/core/TableCell";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { SiteSettings_shop_authorizationKeys } from "../../types/SiteSettings";
+
+interface SiteSettingsKeysProps {
+ disabled: boolean;
+ keys: SiteSettings_shop_authorizationKeys[];
+ onAdd: () => void;
+ onRemove: (name: string) => void;
+ onRowClick: (name: string) => void;
+}
+
+const decorate = withStyles({
+ row: {
+ cursor: "pointer" as "pointer"
+ }
+});
+const SiteSettingsKeys = decorate<SiteSettingsKeysProps>(
+ ({ classes, disabled, keys, onAdd, onRowClick }) => (
+ <Card>
+ <CardTitle
+ title={i18n.t("Authentication Keys", {
+ context: "card title"
+ })}
+ toolbar={
+ <Button
+ color="secondary"
+ disabled={disabled}
+ variant="flat"
+ onClick={onAdd}
+ >
+ {i18n.t("Add key", {
+ context: "button"
+ })}
+ </Button>
+ }
+ />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell>
+ {i18n.t("Authentication Type", { context: "table header" })}
+ </TableCell>
+ <TableCell>{i18n.t("Key", { context: "table header" })}</TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {renderCollection(
+ keys,
+ key => (
+ <TableRow
+ className={classes.row}
+ hover={!(disabled || !key)}
+ key={maybe(() => key.name)}
+ onClick={
+ !disabled && maybe(() => key.name)
+ ? () => onRowClick(key.name)
+ : undefined
+ }
+ >
+ <TableCell>
+ {maybe(() => key.name) ? key.name : <Skeleton />}
+ </TableCell>
+ <TableCell>
+ {maybe(() => key.key) ? key.key : <Skeleton />}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={2}>{i18n.t("No keys")}</TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
+SiteSettingsKeys.displayName = "SiteSettingsKeys";
+export default SiteSettingsKeys;
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/index.ts b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/index.ts
new file mode 100644
index 0000000000..cb3400edf6
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsKeys/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./SiteSettingsKeys";
+export * from "./SiteSettingsKeys";
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
new file mode 100644
index 0000000000..4458130089
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
@@ -0,0 +1,102 @@
+import { withStyles } from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+import * as React from "react";
+
+import Container from "../../../components/Container";
+import Form from "../../../components/Form";
+import PageHeader from "../../../components/PageHeader";
+import SaveButtonBar from "../../../components/SaveButtonBar";
+import i18n from "../../../i18n";
+import { maybe } from "../../../misc";
+import { SiteSettings_shop } from "../../types/SiteSettings";
+import SiteSettingsDetails from "../SiteSettingsDetails/SiteSettingsDetails";
+import SiteSettingsKeys from "../SiteSettingsKeys/SiteSettingsKeys";
+
+export interface SiteSettingsPageFormData {
+ description: string;
+ domain: string;
+ name: string;
+}
+
+export interface SiteSettingsPageProps {
+ disabled: boolean;
+ shop: SiteSettings_shop;
+ onKeyAdd: () => void;
+ onKeyClick: (name: string) => void;
+ onKeyRemove: (name: string) => void;
+ onSubmit: (data: SiteSettingsPageFormData) => void;
+}
+
+const decorate = withStyles(theme => ({
+ root: {
+ display: "grid" as "grid",
+ gridColumnGap: theme.spacing.unit * 2 + "px",
+ gridRowGap: theme.spacing.unit * 3 + "px",
+ gridTemplateColumns: "4fr 9fr"
+ }
+}));
+const SiteSettingsPage = decorate<SiteSettingsPageProps>(
+ ({
+ classes,
+ disabled,
+ shop,
+ onKeyAdd,
+ onKeyClick,
+ onKeyRemove,
+ onSubmit
+ }) => {
+ const initialForm: SiteSettingsPageFormData = {
+ description: maybe(() => shop.description, ""),
+ domain: maybe(() => shop.domain.host, ""),
+ name: maybe(() => shop.name, "")
+ };
+ return (
+ <Form
+ initial={initialForm}
+ onSubmit={onSubmit}
+ key={JSON.stringify(shop)}
+ >
+ {({ change, data, hasChanged, submit }) => (
+ <Container width="md">
+ <PageHeader
+ title={i18n.t("General Information", {
+ context: "page header"
+ })}
+ />
+ <div className={classes.root}>
+ <Typography variant="title">
+ {i18n.t("Site Settings", {
+ context: "section name"
+ })}
+ </Typography>
+ <SiteSettingsDetails
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
+ <Typography variant="title">
+ {i18n.t("Authentication keys", {
+ context: "section name"
+ })}
+ </Typography>
+ <SiteSettingsKeys
+ disabled={disabled}
+ keys={maybe(() => shop.authorizationKeys)}
+ onAdd={onKeyAdd}
+ onRowClick={onKeyClick}
+ onRemove={onKeyRemove}
+ />
+ </div>
+ <SaveButtonBar
+ disabled={disabled || !hasChanged}
+ onCancel={() => undefined}
+ onSave={submit}
+ />
+ </Container>
+ )}
+ </Form>
+ );
+ }
+);
+SiteSettingsPage.displayName = "SiteSettingsPage";
+export default SiteSettingsPage;
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/index.ts b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/index.ts
new file mode 100644
index 0000000000..d10967cb4e
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./SiteSettingsPage";
+export * from "./SiteSettingsPage";
diff --git a/saleor/static/dashboard-next/siteSettings/fixtures.ts b/saleor/static/dashboard-next/siteSettings/fixtures.ts
new file mode 100644
index 0000000000..95e2c02f33
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/fixtures.ts
@@ -0,0 +1,18 @@
+import { SiteSettings_shop } from "./types/SiteSettings";
+
+export const shop: SiteSettings_shop = {
+ __typename: "Shop",
+ authorizationKeys: [
+ {
+ __typename: "AuthorizationKey",
+ key: "n1n62jkn2123:123n",
+ name: "facebook"
+ }
+ ],
+ description: "Lorem ipsum dolor sit amet",
+ domain: {
+ __typename: "Domain",
+ host: "localhost:8000"
+ },
+ name: "Saleor e-commerce"
+};
diff --git a/saleor/static/dashboard-next/siteSettings/queries.ts b/saleor/static/dashboard-next/siteSettings/queries.ts
new file mode 100644
index 0000000000..07128b8739
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/queries.ts
@@ -0,0 +1,28 @@
+import gql from "graphql-tag";
+import { TypedQuery } from "../queries";
+import { SiteSettings } from "./types/SiteSettings";
+
+export const shopFragment = gql`
+ fragment ShopFragment on Shop {
+ authorizationKeys {
+ key
+ name
+ }
+ description
+ domain {
+ host
+ }
+ name
+ }
+`;
+const siteSettings = gql`
+ ${shopFragment}
+ query SiteSettings {
+ shop {
+ ...ShopFragment
+ }
+ }
+`;
+export const TypedSiteSettingsQuery = TypedQuery<SiteSettings, {}>(
+ siteSettings
+);
diff --git a/saleor/static/dashboard-next/siteSettings/types/ShopFragment.ts b/saleor/static/dashboard-next/siteSettings/types/ShopFragment.ts
new file mode 100644
index 0000000000..46533b1b57
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/types/ShopFragment.ts
@@ -0,0 +1,25 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL fragment: ShopFragment
+// ====================================================
+
+export interface ShopFragment_authorizationKeys {
+ __typename: "AuthorizationKey";
+ key: string;
+ name: string;
+}
+
+export interface ShopFragment_domain {
+ __typename: "Domain";
+ host: string;
+}
+
+export interface ShopFragment {
+ __typename: "Shop";
+ authorizationKeys: (ShopFragment_authorizationKeys | null)[];
+ description: string | null;
+ domain: ShopFragment_domain;
+ name: string;
+}
diff --git a/saleor/static/dashboard-next/siteSettings/types/SiteSettings.ts b/saleor/static/dashboard-next/siteSettings/types/SiteSettings.ts
new file mode 100644
index 0000000000..a588c4104e
--- /dev/null
+++ b/saleor/static/dashboard-next/siteSettings/types/SiteSettings.ts
@@ -0,0 +1,29 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL query operation: SiteSettings
+// ====================================================
+
+export interface SiteSettings_shop_authorizationKeys {
+ __typename: "AuthorizationKey";
+ key: string;
+ name: string;
+}
+
+export interface SiteSettings_shop_domain {
+ __typename: "Domain";
+ host: string;
+}
+
+export interface SiteSettings_shop {
+ __typename: "Shop";
+ authorizationKeys: (SiteSettings_shop_authorizationKeys | null)[];
+ description: string | null;
+ domain: SiteSettings_shop_domain;
+ name: string;
+}
+
+export interface SiteSettings {
+ shop: SiteSettings_shop | null;
+}
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 134c7708b0..add87e21ef 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -97,6 +97,9 @@ function loadStories() {
// Product types
require("./stories/productTypes/ProductTypeListPage");
require("./stories/productTypes/ProductTypeDetailsPage");
+
+ // Site settings
+ require("./stories/siteSettings/SiteSettingsPage");
}
configure(loadStories, module);
diff --git a/saleor/static/dashboard-next/storybook/stories/siteSettings/SiteSettingsPage.tsx b/saleor/static/dashboard-next/storybook/stories/siteSettings/SiteSettingsPage.tsx
new file mode 100644
index 0000000000..ee6ad1ea41
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/siteSettings/SiteSettingsPage.tsx
@@ -0,0 +1,19 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import SiteSettingsPage, {
+ SiteSettingsPageProps
+} from "../../../siteSettings/components/SiteSettingsPage";
+import { shop } from "../../../siteSettings/fixtures";
+import Decorator from "../../Decorator";
+
+const props: SiteSettingsPageProps = {
+ disabled: false,
+ onSubmit: () => undefined,
+ shop
+};
+
+storiesOf("Views / Site settings / Page", module)
+ .addDecorator(Decorator)
+ .add("default", () => <SiteSettingsPage {...props} />)
+ .add("loading", () => <SiteSettingsPage {...props} disabled={true} />);