From ad861867ebc572f7b05374a7d6f0f81820d650b5 Mon Sep 17 00:00:00 2001 From: PrathamX595 Date: Mon, 10 Jun 2024 23:20:14 +0530 Subject: [PATCH] Frontend: Added Login Page with modifications to other components added a Login page with changes to input and button components. routes for login and signin pages were also added Fixes: #79 integrated AuthContext --- frontend/src/App.tsx | 3 + frontend/src/Navbar.tsx | 28 +++--- frontend/src/contexts/AuthContext.tsx | 14 +-- frontend/src/library/button.tsx | 3 + frontend/src/library/input.tsx | 2 +- frontend/src/pages/Home.tsx | 2 +- frontend/src/pages/Login.tsx | 122 ++++++++++++++++++++++++++ 7 files changed, 154 insertions(+), 20 deletions(-) create mode 100644 frontend/src/pages/Login.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 328ad8e..acb6315 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -6,6 +6,7 @@ import Error from './pages/Error'; import Game from './pages/Game'; import About from './pages/About'; import { AuthProvider } from './contexts/AuthContext'; +import Login from './pages/Login'; const router = createBrowserRouter([ { @@ -23,6 +24,8 @@ const router = createBrowserRouter([ }, { path: '/about', element: }, { path: '/error', element: }, + { path: '/login', element: }, + { path: '/signin', element: } ], }, ]); diff --git a/frontend/src/Navbar.tsx b/frontend/src/Navbar.tsx index dc2d9a7..faf7537 100644 --- a/frontend/src/Navbar.tsx +++ b/frontend/src/Navbar.tsx @@ -33,17 +33,23 @@ const Navbar: React.FC = ({ /> - {!isLoggedIn && ( -
-
- )} + {isLoggedIn ? ( + <> + + + ) : ( + <> +
+
+ + )} + {isOpen && (
diff --git a/frontend/src/contexts/AuthContext.tsx b/frontend/src/contexts/AuthContext.tsx index 78b6d25..4b34852 100644 --- a/frontend/src/contexts/AuthContext.tsx +++ b/frontend/src/contexts/AuthContext.tsx @@ -8,12 +8,12 @@ import { export type User = { name: string; - email: string; + pass: string; }; export type AuthContextProps = { getUser: () => User | null; - login: () => void; + login: (arg0: string, arg1: string) => void; logout: () => void; isLoggedIn: () => boolean; }; @@ -30,14 +30,14 @@ export function useAuth() { } export function AuthProvider({ children }: { children: ReactElement }) { - const [user, setUser] = useState(null); + const [user, setUser] = useState(null); - const login = useCallback(() => { + const login = useCallback((name: string, pass: string) => { setUser({ - name: 'John Doe', - email: '', + name: name, + pass: pass, }); - }, []); + }, [setUser]); const logout = useCallback(() => { setUser(null); diff --git a/frontend/src/library/button.tsx b/frontend/src/library/button.tsx index c9ba58a..af848eb 100644 --- a/frontend/src/library/button.tsx +++ b/frontend/src/library/button.tsx @@ -15,6 +15,7 @@ type ButtonProps = { fontSize?: string; rounded?: string; buttonSize?: string; + type?: "submit" | "reset" | "button" borderColor?: string; hoverColor?: string; hoverScale?: boolean; @@ -36,11 +37,13 @@ const Button: React.FC = ({ borderColor = 'border-black', hoverColor = 'hover:bg-lime-600', hoverScale = true, + type = 'button', onClick, className = '', }) => { return (
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+ Don't have an account? Sign in +
+
+
+ + + + + + ); +}; + +export default Login; \ No newline at end of file