Skip to content

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

Display user name if available

dominik-zeglen95b76ba5b1a9
diff --git a/saleor/static/dashboard-next/auth/mutations.ts b/saleor/static/dashboard-next/auth/mutations.ts
index 582f1fc52f..8d4007ba71 100644
--- a/saleor/static/dashboard-next/auth/mutations.ts
+++ b/saleor/static/dashboard-next/auth/mutations.ts
@@ -8,6 +8,8 @@ export const fragmentUser = gql`
fragment User on User {
id
email
+ firstName
+ lastName
isStaff
note
permissions {
diff --git a/saleor/static/dashboard-next/auth/types/TokenAuth.ts b/saleor/static/dashboard-next/auth/types/TokenAuth.ts
index 2a7da74c3d..a282edc472 100644
--- a/saleor/static/dashboard-next/auth/types/TokenAuth.ts
+++ b/saleor/static/dashboard-next/auth/types/TokenAuth.ts
@@ -24,6 +24,8 @@ export interface TokenAuth_tokenCreate_user {
__typename: "User";
id: string;
email: string;
+ firstName: string;
+ lastName: string;
isStaff: boolean;
note: string | null;
permissions: (TokenAuth_tokenCreate_user_permissions | null)[] | null;
diff --git a/saleor/static/dashboard-next/auth/types/User.ts b/saleor/static/dashboard-next/auth/types/User.ts
index 131fe2a113..6027f7f828 100644
--- a/saleor/static/dashboard-next/auth/types/User.ts
+++ b/saleor/static/dashboard-next/auth/types/User.ts
@@ -18,6 +18,8 @@ export interface User {
__typename: "User";
id: string;
email: string;
+ firstName: string;
+ lastName: string;
isStaff: boolean;
note: string | null;
permissions: (User_permissions | null)[] | null;
diff --git a/saleor/static/dashboard-next/auth/types/VerifyToken.ts b/saleor/static/dashboard-next/auth/types/VerifyToken.ts
index 8c722421fd..52dc496a41 100644
--- a/saleor/static/dashboard-next/auth/types/VerifyToken.ts
+++ b/saleor/static/dashboard-next/auth/types/VerifyToken.ts
@@ -18,6 +18,8 @@ export interface VerifyToken_tokenVerify_user {
__typename: "User";
id: string;
email: string;
+ firstName: string;
+ lastName: string;
isStaff: boolean;
note: string | null;
permissions: (VerifyToken_tokenVerify_user_permissions | null)[] | null;
diff --git a/saleor/static/dashboard-next/home/views/index.tsx b/saleor/static/dashboard-next/home/views/index.tsx
index 20726a2185..6aafa36815 100644
--- a/saleor/static/dashboard-next/home/views/index.tsx
+++ b/saleor/static/dashboard-next/home/views/index.tsx
@@ -1,67 +1,62 @@
import * as React from "react";
-import { UserContext } from "../../auth";
-import Navigator from "../../components/Navigator";
-import { maybe } from "../../misc";
+import useNavigator from "../../hooks/useNavigator";
+import useUser from "../../hooks/useUser";
+import { getUserName, maybe } from "../../misc";
import { orderListUrl } from "../../orders/urls";
import { productListUrl, productVariantEditUrl } from "../../products/urls";
import { OrderStatusFilter, StockAvailability } from "../../types/globalTypes";
import HomePage from "../components/HomePage";
import { HomePageQuery } from "../queries";
-const HomeSection = () => (
- <Navigator>
- {navigate => (
- <UserContext.Consumer>
- {({ user }) => (
- <HomePageQuery displayLoader>
- {({ data }) => (
- <HomePage
- activities={maybe(() =>
- data.activities.edges.map(edge => edge.node).reverse()
- )}
- orders={maybe(() => data.ordersToday.totalCount)}
- sales={maybe(() => data.salesToday.gross)}
- topProducts={maybe(() =>
- data.productTopToday.edges.map(edge => edge.node)
- )}
- onProductClick={(productId, variantId) =>
- navigate(productVariantEditUrl(productId, variantId))
- }
- onOrdersToCaptureClick={() =>
- navigate(
- orderListUrl({
- status: OrderStatusFilter.READY_TO_CAPTURE
- })
- )
- }
- onOrdersToFulfillClick={() =>
- navigate(
- orderListUrl({
- status: OrderStatusFilter.READY_TO_FULFILL
- })
- )
- }
- onProductsOutOfStockClick={() =>
- navigate(
- productListUrl({
- status: StockAvailability.OUT_OF_STOCK
- })
- )
- }
- ordersToCapture={maybe(() => data.ordersToCapture.totalCount)}
- ordersToFulfill={maybe(() => data.ordersToFulfill.totalCount)}
- productsOutOfStock={maybe(
- () => data.productsOutOfStock.totalCount
- )}
- userName={user.email}
- />
- )}
- </HomePageQuery>
- )}
- </UserContext.Consumer>
- )}
- </Navigator>
-);
+const HomeSection = () => {
+ const navigate = useNavigator();
+ const { user } = useUser();
+
+ return (
+ <HomePageQuery displayLoader>
+ {({ data }) => (
+ <HomePage
+ activities={maybe(() =>
+ data.activities.edges.map(edge => edge.node).reverse()
+ )}
+ orders={maybe(() => data.ordersToday.totalCount)}
+ sales={maybe(() => data.salesToday.gross)}
+ topProducts={maybe(() =>
+ data.productTopToday.edges.map(edge => edge.node)
+ )}
+ onProductClick={(productId, variantId) =>
+ navigate(productVariantEditUrl(productId, variantId))
+ }
+ onOrdersToCaptureClick={() =>
+ navigate(
+ orderListUrl({
+ status: OrderStatusFilter.READY_TO_CAPTURE
+ })
+ )
+ }
+ onOrdersToFulfillClick={() =>
+ navigate(
+ orderListUrl({
+ status: OrderStatusFilter.READY_TO_FULFILL
+ })
+ )
+ }
+ onProductsOutOfStockClick={() =>
+ navigate(
+ productListUrl({
+ status: StockAvailability.OUT_OF_STOCK
+ })
+ )
+ }
+ ordersToCapture={maybe(() => data.ordersToCapture.totalCount)}
+ ordersToFulfill={maybe(() => data.ordersToFulfill.totalCount)}
+ productsOutOfStock={maybe(() => data.productsOutOfStock.totalCount)}
+ userName={getUserName(user, true)}
+ />
+ )}
+ </HomePageQuery>
+ );
+};
export default HomeSection;