Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Josef/admin log in page #65

Merged
merged 6 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions web/src/app/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SponsorSignUp } from './pages/Sponsor/SponsorSignup.page';
import { AlumniSignUp } from './pages/Alumni/AlumniSignup.page';
import { AdminSignUp } from './pages/Admin/AdminSignup.page';
import SignupSwitcher from './pages/General/SignupSwitcher.page';
import { AdminLogin } from './pages/Admin/AdminLogin.page';

// Protected route is currently commented out. To be enabled once the Authentication Logic has been implemented
const router = createBrowserRouter([
Expand All @@ -37,6 +38,14 @@ const router = createBrowserRouter([
</AppLayout>
),
},
{
path: '/fsae-administrator-login',
element: (
<AppLayout>
<AdminLogin />
</AppLayout>
),
},
{
path: '/signup',
element: (
Expand Down
76 changes: 76 additions & 0 deletions web/src/app/components/AuthForms/AdminLoginForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
Flex,
TextInput,
PasswordInput,
Checkbox,
Button,
Title,
useMantineTheme,
} from '@mantine/core';
import styles from './authform.module.css';
import { NavLink } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import { setUserType } from '../../features/user/userSlice';
import { toast } from 'react-toastify';

export function AdminLoginForm() {
const dispatch = useDispatch();
const navigate = useNavigate();
const theme = useMantineTheme();
const handleLoginAs = (userType: 'student' | 'sponsor' | 'alumni' | 'admin') => {
// Simulate successful login (to be replaced with the actual authentication logic)
const mockToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
localStorage.setItem('accessToken', mockToken);
// If authentication is successful: Update Redux store with userType
dispatch(setUserType(userType));
// Redirect to the appropriate profile page based on userType
const profilePath = {
student: '/profile/student',
sponsor: '/profile/sponsor',
alumni: '/profile/alumni',
admin: '/profile/admin',
}[userType];
toast.success('Logged in as ' + userType);
navigate(profilePath, { replace: true });
};

const handleLogin = () => {
console.log('Login button clicked');
};

return (
<Flex
gap="xl"
justify="center"
align="center"
direction="column"
className={styles.loginFormContainer}
>
<form className={styles.form}>
<Title order={3} ta="center" mt="md" mb={50}>
Login
</Title>

<TextInput placeholder="Enter email" size="lg" mb="lg" />
<PasswordInput placeholder="Enter password" mt="xl" size="lg" />
<Checkbox label="Remember Me" mt="xl" size="md" />
<Button
fullWidth
mt="xl"
mb="md"
size="lg"
color={theme.colors.customPapayaOrange[1]}
onClick={handleLogin}
>
Login
</Button>
<Flex justify="center" gap="md" mt="md" mr="md">
<Button variant="filled" color="red" onClick={() => handleLoginAs('admin')}>
Temp Admin Login
</Button>
</Flex>
</form>
</Flex>
);
}
5 changes: 2 additions & 3 deletions web/src/app/components/Tabs/EmailTab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stack, TextInput, PasswordInput, Flex } from '@mantine/core';
import { Stack, TextInput, Flex } from '@mantine/core';
import styles from '../Tabs/Settings.module.css';
import { useState } from 'react';
import { useState, FC } from 'react';

interface EmailTabProp {
email: string;
Expand All @@ -9,7 +9,6 @@ interface EmailTabProp {
const EmailTab: FC<EmailTabProp> = ({ email }) => {
const [isPortrait, setIsPortrait] = useState(window.innerHeight > window.innerWidth);


return (
<Flex direction="column" align="center" justify="center">
<Stack className={styles.container} w="100%" justify="center" align="center">
Expand Down
4 changes: 2 additions & 2 deletions web/src/app/components/Tabs/PasswordTab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stack, TextInput, PasswordInput, Flex } from '@mantine/core';
import { Stack, PasswordInput, Flex } from '@mantine/core';
import styles from '../Tabs/Settings.module.css';
import { useState } from 'react';
import { useState, FC } from 'react';

interface PasswordTabProp {
password: string;
Expand Down
27 changes: 27 additions & 0 deletions web/src/app/pages/Admin/AdminLogin.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { AdminLoginForm } from '@/app/components/AuthForms/AdminLoginForm';
import { LoginSideImage } from '../../components/LoginSideImage/LoginSideImage';
import { Grid } from '@mantine/core';
import { useMediaQuery } from '@mantine/hooks';

export function AdminLogin() {
const isSmallScreen = useMediaQuery('(max-width: 768px)');

return (
<Grid>
{isSmallScreen ? (
<Grid.Col span={12}>
<AdminLoginForm />
</Grid.Col>
) : (
<>
<Grid.Col span={6}>
<LoginSideImage />
</Grid.Col>
<Grid.Col span={6}>
<AdminLoginForm />
</Grid.Col>
</>
)}
</Grid>
);
}
Loading