generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Real-Dev-Squad/feat/add-navbar
Feat: Add navbar
- Loading branch information
Showing
10 changed files
with
178 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
VITE_REACT_RDS_BACKEND_BASE_URL='https://staging-api.realdevsquad.com' | ||
VITE_REACT_STATUS_SITE_URL='https://staging-status.realdevsquad.com' | ||
VITE_REACT_MEMBERS_SITE_URL='https://staging-members.realdevsquad.com' | ||
VITE_REACT_WELCOME_SITE_URL='https://welcome.realdevsquad.com' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ yarn-error.log* | |
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
.env | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useEffect } from 'react'; | ||
import { getConfig, validateEnv } from '../config'; | ||
|
||
const Navbar: React.FC = () => { | ||
const { welcomeSiteUrl, membersSiteUrl, statusSiteUrl } = getConfig(); | ||
|
||
useEffect(() => { | ||
try { | ||
validateEnv(); | ||
} catch (error) { | ||
console.error('Environment validation error:', error); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<nav | ||
className="fixed left-0 top-0 w-full border-b border-gray-100 bg-primary p-2" | ||
aria-label="Main Navigation" | ||
data-testid="navbar" | ||
> | ||
<div className="mx-auto flex h-14 w-full max-w-screen-2xl items-center gap-6 px-6"> | ||
<a | ||
href="/" | ||
className="flex items-center" | ||
aria-label="Home" | ||
data-testid="navbar-home-link" | ||
> | ||
<img | ||
src="/assets/rds-logo.svg" | ||
alt="RDS Logo" | ||
className="h-12 w-12" | ||
/> | ||
</a> | ||
|
||
<div className="flex items-center space-x-6"> | ||
<a | ||
href={welcomeSiteUrl} | ||
className="text-white hover:text-accent" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
aria-label="Go to Welcome site" | ||
data-testid="navbar-welcome-link" | ||
> | ||
Welcome | ||
</a> | ||
<a | ||
href={membersSiteUrl} | ||
className="text-white hover:text-accent" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
aria-label="Go to Members site" | ||
data-testid="navbar-members-link" | ||
> | ||
Members | ||
</a> | ||
<a | ||
href={statusSiteUrl} | ||
className="text-white hover:text-accent" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
aria-label="Go to Status site" | ||
data-testid="navbar-status-link" | ||
> | ||
Status | ||
</a> | ||
</div> | ||
|
||
<div className="ml-auto"> | ||
<button | ||
className="rounded bg-secondary px-4 py-2 text-white hover:bg-accent" | ||
aria-label="Sign In" | ||
data-testid="navbar-signin-btn" | ||
> | ||
Sign In | ||
</button> | ||
</div> | ||
</div> | ||
</nav> | ||
); | ||
}; | ||
|
||
export default Navbar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// config.ts | ||
const config = { | ||
appEnv: import.meta.env.VITE_REACT_ENV, | ||
welcomeSiteUrl: import.meta.env.VITE_REACT_WELCOME_SITE_URL, | ||
membersSiteUrl: import.meta.env.VITE_REACT_MEMBERS_SITE_URL, | ||
statusSiteUrl: import.meta.env.VITE_REACT_STATUS_SITE_URL, | ||
}; | ||
|
||
export const getConfig = () => { | ||
return config; | ||
}; | ||
|
||
export const validateEnv = () => { | ||
const requiredVars = [ | ||
'appEnv', | ||
'welcomeSiteUrl', | ||
'membersSiteUrl', | ||
'statusSiteUrl', | ||
]; | ||
for (const key of requiredVars) { | ||
if (!config[key]) { | ||
throw new Error(`Missing required environment variable: ${key}`); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import Navbar from '../../src/components/navbar'; | ||
import { describe, it, expect, vi } from 'vitest'; | ||
|
||
vi.mock('../../src/config', () => ({ | ||
getConfig: () => ({ | ||
welcomeSiteUrl: 'https://welcome.example.com', | ||
membersSiteUrl: 'https://members.example.com', | ||
statusSiteUrl: 'https://status.example.com', | ||
}), | ||
validateEnv: () => {}, | ||
})); | ||
|
||
describe('Navbar Component', () => { | ||
it('should render the navbar with correct links', () => { | ||
render(<Navbar />); | ||
|
||
expect(screen.getByLabelText(/Home/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Go to Welcome site/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Go to Members site/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Go to Status site/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should have links opening in a new tab', () => { | ||
render(<Navbar />); | ||
|
||
expect(screen.getByTestId('navbar-home-link')).toBeInTheDocument(); | ||
expect(screen.getByTestId('navbar-welcome-link')).toBeInTheDocument(); | ||
expect(screen.getByTestId('navbar-members-link')).toBeInTheDocument(); | ||
expect(screen.getByTestId('navbar-status-link')).toBeInTheDocument(); | ||
expect(screen.getByTestId('navbar-signin-btn')).toBeInTheDocument(); | ||
|
||
expect(screen.getByLabelText(/Go to Welcome site/i)).toHaveAttribute( | ||
'rel', | ||
'noopener noreferrer', | ||
); | ||
expect(screen.getByLabelText(/Go to Members site/i)).toHaveAttribute( | ||
'rel', | ||
'noopener noreferrer', | ||
); | ||
expect(screen.getByLabelText(/Go to Status site/i)).toHaveAttribute( | ||
'rel', | ||
'noopener noreferrer', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters