Skip to content

Commit

Permalink
Merge pull request #8 from atlp-rwanda/ch-setup-react-187584854
Browse files Browse the repository at this point in the history
Deliver - [ch-setup-react-router-#187584858]
  • Loading branch information
key-joshua authored Jul 2, 2024
2 parents 1deaad2 + 328dd6e commit ff1539f
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 11 deletions.
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-redux": "^9.1.2",
"react-router-dom": "^6.24.0",
"sass": "^1.77.6",
"save-dev": "0.0.1-security"
},
Expand Down
12 changes: 7 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable linebreak-style */
import React from 'react';
import LandingPage from './pages/LandingPage';
import { BrowserRouter as Router } from 'react-router-dom';
import AppRouter from './router';

const App: React.FC = () => (
<div>
<LandingPage />
</div>
<Router>
<AppRouter />
</Router>
);

export default App;
export default App;
17 changes: 17 additions & 0 deletions src/components/layout/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable linebreak-style */
import React from 'react';

const getYear = (): number => new Date().getFullYear();

const Footer: React.FC = () => (
<footer>
<p>
&copy;
{getYear()}
{' '}
Ninja E-Commerce Store
</p>
</footer>
);

export default Footer;
17 changes: 17 additions & 0 deletions src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable linebreak-style */
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import { Link } from 'react-router-dom';

const Header: React.FC = () => (
<header>
<nav>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/login">Login</Link></li>
</ul>
</nav>
</header>
);

export default Header;
7 changes: 6 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/* eslint-disable linebreak-style */
import React from 'react';
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import { store } from './store/store';
import App from './App';

const root = createRoot(document.getElementById('root')!);
root.render(<Provider store={store}><App /></Provider>);
root.render(
<Provider store={store}>
<App />
</Provider>
);
16 changes: 11 additions & 5 deletions src/pages/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useEffect } from 'react';
import { useAppDispatch, useAppSelector } from '../store/store';
import { loadWelcomeMessage } from '../store/features/welcomeSlice';
import { IWelcomeMessage } from '../utils/types/store';
import Header from '../components/layout/Header';
import Footer from '../components/layout/Footer';
import '../styles/LandingPage.scss';

const LandingPage: React.FC = () => {
Expand All @@ -13,11 +15,15 @@ const LandingPage: React.FC = () => {
}, [dispatch]);

return (
<div className="landingPage">
<h1>
{welcomeMessage.message}
</h1>
</div>
<>
<Header />
<div className="landingPage">
<h1>
{welcomeMessage.message}
</h1>
</div>
<Footer />
</>
);
};

Expand Down
14 changes: 14 additions & 0 deletions src/pages/Login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import Header from '../components/layout/Header';

const Login: React.FC = () => (
<>
<Header />
<main>
<h2>Login Page</h2>
<p>Please login to continue.</p>
</main>
</>
);

export default Login;
10 changes: 10 additions & 0 deletions src/pages/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

const NotFound: React.FC = () => (
<main>
<h1> 404 -Not found </h1>
<p> The page you are looking for does not exist. </p>
</main>
);

export default NotFound;
21 changes: 21 additions & 0 deletions src/router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable linebreak-style */
/* eslint-disable arrow-body-style */
import React from 'react';
import { Route, Routes } from 'react-router-dom';
import LandingPage from './pages/LandingPage';
import Login from './pages/Login';
import NotFound from './pages/NotFound';

const AppRouter: React.FC = () => {
return (
<div>
<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/login" element={<Login />} />
<Route path="*" element={<NotFound />} />
</Routes>
</div>
);
};

export default AppRouter;

0 comments on commit ff1539f

Please sign in to comment.