Skip to content

Commit 8ed202b

Browse files
committed
feat: enhance CTABlock and HeroSection components with dynamic button links based on authentication status
- Integrate authentication context to determine user session state. - Update CTABlock to conditionally redirect logged-in users to documentation and non-logged-in users to the sign-up page. - Modify HeroSection to handle "Get Started" button clicks similarly, ensuring a seamless user experience based on authentication status. These changes improve navigation and user flow for authenticated and unauthenticated users.
1 parent d2f34da commit 8ed202b

File tree

2 files changed

+29
-3
lines changed
  • robolearn-interface/src/components/HomepageComponents

2 files changed

+29
-3
lines changed

robolearn-interface/src/components/HomepageComponents/CTABlock/index.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import Link from '@docusaurus/Link';
33
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
4+
import { useAuth } from '@/contexts/AuthContext';
5+
import { getHomeUrl } from '@/lib/url-utils';
46
import { useScrollReveal } from '../../../hooks/useScrollReveal';
57
import styles from './styles.module.css';
68

@@ -45,8 +47,22 @@ export function CTABlock({
4547
buttonLink,
4648
}: CTABlockProps): React.ReactElement {
4749
const { siteConfig } = useDocusaurusContext();
50+
const { session } = useAuth();
4851
const authUrl = (siteConfig.customFields?.authUrl as string) || 'http://localhost:3001';
49-
const finalButtonLink = buttonLink || `${authUrl}/auth/sign-up`;
52+
53+
// Determine button link based on auth status
54+
const getButtonLink = () => {
55+
if (buttonLink) return buttonLink;
56+
// If user is logged in, redirect to docs
57+
if (session?.user) {
58+
const homeUrl = getHomeUrl();
59+
return `${homeUrl}docs/preface-agent-native`;
60+
}
61+
// If not logged in, go to sign-up
62+
return `${authUrl}/auth/sign-up`;
63+
};
64+
65+
const finalButtonLink = getButtonLink();
5066

5167
const { ref, isVisible } = useScrollReveal<HTMLElement>();
5268

robolearn-interface/src/components/HomepageComponents/HeroSection/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useEffect, useState, useRef } from 'react';
22
import Link from '@docusaurus/Link';
33
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
44
import { getOAuthAuthorizationUrl } from '@/lib/auth-client';
5+
import { useAuth } from '@/contexts/AuthContext';
6+
import { getHomeUrl } from '@/lib/url-utils';
57
import styles from './styles.module.css';
68

79
/**
@@ -14,6 +16,7 @@ import styles from './styles.module.css';
1416
*/
1517
export function HeroSection(): React.ReactElement {
1618
const { siteConfig } = useDocusaurusContext();
19+
const { session, isLoading } = useAuth();
1720
const authUrl = (siteConfig.customFields?.authUrl as string) || 'http://localhost:3001';
1821
const oauthClientId = (siteConfig.customFields?.oauthClientId as string) || 'robolearn-interface';
1922

@@ -23,9 +26,16 @@ export function HeroSection(): React.ReactElement {
2326
clientId: oauthClientId,
2427
};
2528

26-
// Handle OAuth sign up flow
29+
// Handle Get Started button click
2730
const handleGetStarted = async () => {
28-
// Go to sign-up page, then redirect to OAuth flow
31+
// If user is already logged in, redirect to docs
32+
if (session?.user) {
33+
const homeUrl = getHomeUrl();
34+
window.location.href = `${homeUrl}docs/preface-agent-native`;
35+
return;
36+
}
37+
38+
// If not logged in, go to sign-up page, then redirect to OAuth flow
2939
const oauthUrl = await getOAuthAuthorizationUrl('signup', oauthConfig);
3040
const signupUrl = `${authUrl}/auth/sign-up?redirect=${encodeURIComponent(oauthUrl)}`;
3141
window.location.href = signupUrl;

0 commit comments

Comments
 (0)