Skip to content

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

Change window title in category views

dominik-zeglence5f2585f15b
diff --git a/saleor/static/dashboard-next/categories/index.tsx b/saleor/static/dashboard-next/categories/index.tsx
index ee3db149e1..b0c0b60513 100644
--- a/saleor/static/dashboard-next/categories/index.tsx
+++ b/saleor/static/dashboard-next/categories/index.tsx
@@ -1,6 +1,8 @@
import { parse as parseQs } from "qs";
import * as React from "react";
import { Route, RouteComponentProps, Switch } from "react-router-dom";
+import { WindowTitle } from "../components/WindowTitle";
+import i18n from "../i18n";
import { CategoryCreateView } from "./views/CategoryCreate";
import CategoryDetailsView, {
CategoryDetailsQueryParams
@@ -42,12 +44,15 @@ const CategoryCreate: React.StatelessComponent<
};
const Component = ({ match }) => (
- <Switch>
- <Route exact path={match.url} component={CategoryList} />
- <Route exact path={`${match.url}/add/`} component={CategoryCreate} />
- <Route exact path={`${match.url}/:id/add/`} component={CategoryCreate} />
- <Route path={`${match.url}/:id/`} component={CategoryDetails} />
- </Switch>
+ <>
+ <WindowTitle title={i18n.t("Categories")} />
+ <Switch>
+ <Route exact path={match.url} component={CategoryList} />
+ <Route exact path={`${match.url}/add/`} component={CategoryCreate} />
+ <Route exact path={`${match.url}/:id/add/`} component={CategoryCreate} />
+ <Route path={`${match.url}/:id/`} component={CategoryDetails} />
+ </Switch>
+ </>
);
export const categoryListUrl = "/categories/";
diff --git a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
index a1e29afc38..011018cdbd 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx
@@ -3,6 +3,7 @@ import * as React from "react";
import { categoryUrl } from "../";
import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
+import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
import { maybe } from "../../misc";
import CategoryCreatePage from "../components/CategoryCreatePage";
@@ -31,28 +32,31 @@ export const CategoryCreateView: React.StatelessComponent<
return (
<TypedCategoryCreateMutation onCompleted={handleSuccess}>
{(mutate, { data, loading }) => (
- <CategoryCreatePage
- errors={maybe(() => data.categoryCreate.errors, [])}
- disabled={loading}
- onBack={() =>
- navigate(categoryUrl(encodeURIComponent(parentId)))
- }
- onSubmit={formData =>
- mutate({
- variables: {
- input: {
- description: formData.description,
- name: formData.name,
- seo: {
- description: formData.seoDescription,
- title: formData.seoTitle
- }
- },
- parent: parentId
- }
- })
- }
- />
+ <>
+ <WindowTitle title={i18n.t("Create category")} />
+ <CategoryCreatePage
+ errors={maybe(() => data.categoryCreate.errors, [])}
+ disabled={loading}
+ onBack={() =>
+ navigate(categoryUrl(encodeURIComponent(parentId)))
+ }
+ onSubmit={formData =>
+ mutate({
+ variables: {
+ input: {
+ description: formData.description,
+ name: formData.name,
+ seo: {
+ description: formData.seoDescription,
+ title: formData.seoTitle
+ }
+ },
+ parent: parentId
+ }
+ })
+ }
+ />
+ </>
)}
</TypedCategoryCreateMutation>
);
diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
index 5e32667441..48a35a7d19 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
@@ -10,6 +10,7 @@ import {
createPaginationState,
Paginator
} from "../../../components/Paginator";
+import { WindowTitle } from "../../../components/WindowTitle";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { productAddUrl, productUrl } from "../../../products";
@@ -82,6 +83,9 @@ export const CategoryDetails: React.StatelessComponent<
>
{({ data, loading }) => (
<>
+ <WindowTitle
+ title={maybe(() => data.category.name)}
+ />
<Paginator
pageInfo={maybe(
() => data.category.products.pageInfo
diff --git a/saleor/static/dashboard-next/components/Shop/Shop.tsx b/saleor/static/dashboard-next/components/Shop/index.tsx
similarity index 72%
rename from saleor/static/dashboard-next/components/Shop/Shop.tsx
rename to saleor/static/dashboard-next/components/Shop/index.tsx
index 12d257bc86..264aa82350 100644
--- a/saleor/static/dashboard-next/components/Shop/Shop.tsx
+++ b/saleor/static/dashboard-next/components/Shop/index.tsx
@@ -1,6 +1,5 @@
import * as React from "react";
-import { maybe } from "../../misc";
import { TypedShopInfoQuery } from "./query";
import { ShopInfo_shop } from "./types/ShopInfo";
@@ -11,12 +10,11 @@ export const shopContext = React.createContext<ShopContext>(undefined);
export const ShopProvider: React.StatelessComponent<{}> = ({ children }) => (
<TypedShopInfoQuery>
{({ data }) =>
- maybe(
- () => (
- <shopContext.Provider value={data.shop}>
- {children}
- </shopContext.Provider>
- ),
+ data && data.shop !== undefined ? (
+ <shopContext.Provider value={data.shop}>
+ {children}
+ </shopContext.Provider>
+ ) : (
children
)
}
diff --git a/saleor/static/dashboard-next/components/Shop/query.tsx b/saleor/static/dashboard-next/components/Shop/query.ts
similarity index 94%
rename from saleor/static/dashboard-next/components/Shop/query.tsx
rename to saleor/static/dashboard-next/components/Shop/query.ts
index 44d8e0ce9c..7076ec6610 100644
--- a/saleor/static/dashboard-next/components/Shop/query.tsx
+++ b/saleor/static/dashboard-next/components/Shop/query.ts
@@ -1,5 +1,4 @@
import gql from "graphql-tag";
-import * as React from "react";
import { TypedQuery } from "../../queries";
import { ShopInfo } from "./types/ShopInfo";
diff --git a/saleor/static/dashboard-next/components/WindowTitle/index.tsx b/saleor/static/dashboard-next/components/WindowTitle/index.tsx
new file mode 100644
index 0000000000..c1b54adf97
--- /dev/null
+++ b/saleor/static/dashboard-next/components/WindowTitle/index.tsx
@@ -0,0 +1,22 @@
+import * as React from "react";
+import { Helmet } from "react-helmet";
+
+import Shop from "../Shop";
+
+interface WindowTitleProps {
+ title: string;
+}
+
+export const WindowTitle: React.StatelessComponent<WindowTitleProps> = ({
+ title
+}) => (
+ <Shop>
+ {shop =>
+ shop === undefined || !title ? null : (
+ <Helmet>
+ <title>{`${title} | ${shop.name}`}</title>
+ </Helmet>
+ )
+ }
+ </Shop>
+);
diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsx
index a488eb0efc..ffcadfb2de 100644
--- a/saleor/static/dashboard-next/index.tsx
+++ b/saleor/static/dashboard-next/index.tsx
@@ -21,7 +21,7 @@ import CollectionSection from "./collections";
import { DateProvider } from "./components/DateFormatter";
import { LocaleProvider } from "./components/Locale";
import { MessageManager } from "./components/messages";
-import { ShopProvider } from "./components/Shop/Shop";
+import { ShopProvider } from "./components/Shop";
import ConfigurationSection, { configurationMenu } from "./configuration";
import { CustomerSection } from "./customers";
import HomePage from "./home";