Skip to content

Commit 88b46a8

Browse files
committed
refactor(Header): add shouldIncludeSignInButton prop to control sign-in button visibility
1 parent bcbddc2 commit 88b46a8

File tree

7 files changed

+26
-28
lines changed

7 files changed

+26
-28
lines changed

apps/frontend/src/app/[locale]/(auth)/login/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default async function LoginPage({ params }: Readonly<Props>) {
9999
<body>
100100
<GlobalProvider config={init} labels={init.labels} locale={locale} themes={init.themes}>
101101
<div className="flex flex-col min-h-dvh">
102-
<Header data={init.common.header} />
102+
<Header data={init.common.header} shouldIncludeSignInButton={false} />
103103
<div className="flex flex-col grow">
104104
<AuthLayout>
105105
<SignInForm

apps/frontend/src/containers/Header/DesktopNavigation/DesktopNavigation.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { useSession } from 'next-auth/react';
34
import React from 'react';
45

56
import { Models } from '@o2s/framework/modules';
@@ -20,7 +21,7 @@ import { Separator } from '@o2s/ui/elements/separator';
2021
import { Typography } from '@o2s/ui/elements/typography';
2122

2223
import { Link as NextLink, usePathname } from '@/i18n';
23-
import { LOGIN_PATH, routing } from '@/i18n/routing';
24+
import { LOGIN_PATH } from '@/i18n/routing';
2425

2526
import { DesktopNavigationProps } from './DesktopNavigation.types';
2627

@@ -32,19 +33,14 @@ export function DesktopNavigation({
3233
userSlot,
3334
items,
3435
signInLabel,
35-
isSignedIn,
36+
shouldIncludeSignInButton = true,
3637
}: DesktopNavigationProps) {
38+
const session = useSession();
39+
const isSignedIn = !!session.data?.user;
3740
const pathname = usePathname();
3841

39-
// Check if we're on login page
40-
const normalizedPathname = pathname?.split('?')[0] || '';
41-
const loginPaths = [LOGIN_PATH, ...Object.values(routing.pathnames[LOGIN_PATH] || {})];
42-
const isLoginPage = loginPaths.some(
43-
(loginPath) => normalizedPathname === loginPath || normalizedPathname.startsWith(`${loginPath}/`),
44-
);
45-
46-
// Show sign in button if user is not signed in, not on login page, and signInLabel is available
47-
const showSignInButton = !isSignedIn && !isLoginPage && signInLabel;
42+
// Show sign in button if user is not signed in, container allows it, and signInLabel is available
43+
const showSignInButton = shouldIncludeSignInButton && !isSignedIn && signInLabel;
4844

4945
const activeNavigationGroup = items.find((item) => {
5046
if (item.__typename === 'NavigationGroup') {

apps/frontend/src/containers/Header/DesktopNavigation/DesktopNavigation.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export interface DesktopNavigationProps {
1010
userSlot?: ReactNode;
1111
items: CMS.Model.Header.Header['items'];
1212
signInLabel?: CMS.Model.Header.Header['signInLabel'];
13-
isSignedIn?: boolean;
13+
shouldIncludeSignInButton?: boolean;
1414
}

apps/frontend/src/containers/Header/Header.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import { MobileNavigation } from './MobileNavigation/MobileNavigation';
2020
import { NotificationInfo } from './NotificationInfo/NotificationInfo';
2121
import { UserInfo } from './UserInfo/UserInfo';
2222

23-
export const Header: React.FC<HeaderProps> = ({ data, alternativeUrls, children }) => {
23+
export const Header: React.FC<HeaderProps> = ({
24+
data,
25+
alternativeUrls,
26+
children,
27+
shouldIncludeSignInButton = true,
28+
}) => {
2429
const session = useSession();
2530
const isSignedIn = !!session.data?.user;
2631

@@ -83,7 +88,7 @@ export const Header: React.FC<HeaderProps> = ({ data, alternativeUrls, children
8388
userSlot={UserSlot}
8489
items={data.items}
8590
signInLabel={data.signInLabel}
86-
isSignedIn={isSignedIn}
91+
shouldIncludeSignInButton={shouldIncludeSignInButton}
8792
/>
8893
</div>
8994
<div className="md:hidden">
@@ -97,7 +102,7 @@ export const Header: React.FC<HeaderProps> = ({ data, alternativeUrls, children
97102
title={data.title}
98103
mobileMenuLabel={data.mobileMenuLabel}
99104
signInLabel={data.signInLabel}
100-
isSignedIn={isSignedIn}
105+
shouldIncludeSignInButton={shouldIncludeSignInButton}
101106
/>
102107
</div>
103108
</>

apps/frontend/src/containers/Header/Header.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export interface HeaderProps {
88
alternativeUrls?: {
99
[key: string]: string;
1010
};
11+
shouldIncludeSignInButton?: boolean;
1112
}

apps/frontend/src/containers/Header/MobileNavigation/MobileNavigation.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import { Menu, X } from 'lucide-react';
4+
import { useSession } from 'next-auth/react';
45
import React, { useEffect, useState } from 'react';
56

67
import { Models } from '@o2s/framework/modules';
@@ -16,7 +17,7 @@ import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from '@o2s
1617
import { Typography } from '@o2s/ui/elements/typography';
1718

1819
import { Link as NextLink, usePathname } from '@/i18n';
19-
import { LOGIN_PATH, routing } from '@/i18n/routing';
20+
import { LOGIN_PATH } from '@/i18n/routing';
2021

2122
import { MobileNavigationProps } from './MobileNavigation.types';
2223

@@ -30,19 +31,14 @@ export function MobileNavigation({
3031
title,
3132
mobileMenuLabel,
3233
signInLabel,
33-
isSignedIn,
34+
shouldIncludeSignInButton = true,
3435
}: MobileNavigationProps) {
36+
const session = useSession();
37+
const isSignedIn = !!session.data?.user;
3538
const pathname = usePathname();
3639

37-
// Check if we're on login page
38-
const normalizedPathname = pathname?.split('?')[0] || '';
39-
const loginPaths = [LOGIN_PATH, ...Object.values(routing.pathnames[LOGIN_PATH] || {})];
40-
const isLoginPage = loginPaths.some(
41-
(loginPath) => normalizedPathname === loginPath || normalizedPathname.startsWith(`${loginPath}/`),
42-
);
43-
44-
// Show sign in button if user is not signed in, not on login page, and signInLabel is available
45-
const showSignInButton = !isSignedIn && !isLoginPage && signInLabel;
40+
// Show sign in button if user is not signed in, container allows it, and signInLabel is available
41+
const showSignInButton = shouldIncludeSignInButton && !isSignedIn && signInLabel;
4642

4743
const [isMenuOpen, setIsMenuOpen] = useState(false);
4844

apps/frontend/src/containers/Header/MobileNavigation/MobileNavigation.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export interface MobileNavigationProps {
1212
title?: CMS.Model.Header.Header['title'];
1313
mobileMenuLabel: CMS.Model.Header.Header['mobileMenuLabel'];
1414
signInLabel?: CMS.Model.Header.Header['signInLabel'];
15-
isSignedIn?: boolean;
15+
shouldIncludeSignInButton?: boolean;
1616
}

0 commit comments

Comments
 (0)