Skip to content

Commit

Permalink
DEVPROD-4779 Show GitHub username banner on all pages (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
khelif96 authored May 2, 2024
1 parent cc77cc1 commit 676f679
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions apps/spruce/src/components/Banners/GithubUsernameBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import { useQuery } from "@apollo/client";
import Banner from "@leafygreen-ui/banner";
import { matchPath, useLocation } from "react-router-dom";
import { StyledRouterLink } from "components/styles";
import {
getPreferencesRoute,
PreferencesTabRoutes,
routes,
} from "constants/routes";
import { getPreferencesRoute, PreferencesTabRoutes } from "constants/routes";
import { UserSettingsQuery } from "gql/generated/types";
import { USER_SETTINGS } from "gql/queries";

export const GithubUsernameBanner = () => {
const { pathname } = useLocation();
const matchedPath = matchPath(routes.user, pathname);
const isPatchesPage = !!matchedPath;

// USER SETTINGS QUERY
const { data: userSettingsData } = useQuery<UserSettingsQuery>(
USER_SETTINGS,
{ skip: !isPatchesPage },
);
const { data: userSettingsData } = useQuery<UserSettingsQuery>(USER_SETTINGS);
const { userSettings } = userSettingsData || {};
const { githubUser } = userSettings || {};
const { lastKnownAs } = githubUser || {};
const hasNoGithubUser = lastKnownAs === "";

return isPatchesPage && hasNoGithubUser ? (
return hasNoGithubUser ? (
<Banner data-cy="github-username-banner" variant="warning">
Please set your GitHub username on the{" "}
<StyledRouterLink to={getPreferencesRoute(PreferencesTabRoutes.Profile)}>
Expand Down

0 comments on commit 676f679

Please sign in to comment.