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

show leave entitlement for current user #17

Merged
merged 7 commits into from
Dec 25, 2023
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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LAPS React</title>
<title>Leave Application Processing System</title>
</head>

<body>
Expand Down
12,574 changes: 9,722 additions & 2,852 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions src/components/Authentification/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,16 @@ export default function Login() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const validateEmail = () => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
};

const validateForm = () => {
if (!validateEmail(email)) {
setError('Please enter a valid email address');
if (!email) {
setError('Please enter a email address');
return false;
}
// Password check (basic example: check for non-empty and minimum length)
if (!password) {
setError('Please enter a password');
return false;
}
if (password.length < 8) {
setError('Password must be at least 8 characters long.');
}
if (password.length > 20) {
setError('Password must be at most 20 characters long.');
}
setError('');
return true;
};

Expand Down
15 changes: 3 additions & 12 deletions src/components/Authentification/SignUp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,15 @@ export default function SignUp() {
const [password2, setPassword2] = useState('');
const [error, setError] = useState('');
const navigate = useNavigate();
const validateEmail = () => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
};

const validateForm = () => {
if (!validateEmail(email)) {
setError('Please enter a valid email address');
if (!email) {
setError('Please enter a email address');
return false;
}
// Password check (basic example: check for non-empty and minimum length)
if (!password) {
if (password.length < 8) {
setError('Password must be at least 8 characters long.');
}
if (password.length > 20) {
setError('Password must be at most 20 characters long.');
}
setError('Please enter a password');
return false;
}

Expand Down
14 changes: 11 additions & 3 deletions src/components/Dashboard/SideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Link } from 'react-router-dom';
import { AuthContext } from '../../context/AuthContext';

export default function SideBar({ isOpen }) {
// eslint-disable-next-line no-unused-vars
const { userData } = useContext(AuthContext);
const sideBarClass = isOpen ? 'block' : 'hidden';
const role = userData.role;
Expand Down Expand Up @@ -49,7 +48,7 @@ function NavigationEmployee({ employeeId }) {
);
}

function NavigationAdmin({ managerId }) {
function NavigationAdmin() {
return (
<div className={'divide-y-2 w-full'}>
<NavLink>
Expand All @@ -58,6 +57,15 @@ function NavigationAdmin({ managerId }) {
<NavLink>
<Link to={'/Dashboard'}>Dashboard</Link>
</NavLink>
<NavLink>
<a href={`/leavetype/list`}>Edit Leave Types</a>
</NavLink>
<NavLink>
<a href={`/publicholidays/list`}>Public Holidays</a>
</NavLink>
<NavLink>
<a href={`/admin/role/list`}>Role List</a>
</NavLink>
</div>
);
}
Expand All @@ -69,7 +77,7 @@ function NavigationManager({ managerId }) {
<a href={`/leave/${managerId}`}>New Leave Application</a>
</NavLink>
<NavLink>
<Link to={'/Approval'}>Subordinate Applications</Link>
<Link to={'/Approval'}>View Leave Application for Approval</Link>
</NavLink>
<NavLink>
<Link to={'/LeaveHistory'}>My Leave History</Link>
Expand Down
10 changes: 1 addition & 9 deletions src/components/LeaveHistory/LeaveHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import * as React from 'react';
import LeaveTitle from './Leave-Title';
import LeaveButtonCategories from './Leave-Button-Categories.jsx';
import LeaveRow, { HeaderRow } from './LeaveRow.jsx';
// eslint-disable-next-line no-unused-vars
import LeavePerPage from './LeavePerPage.jsx';
// eslint-disable-next-line no-unused-vars
import LeaveTotalPage from './LeaveTotalPage.jsx';

import Layout from '../Dashboard/Layout.jsx';
import { AuthContext } from '../../context/AuthContext.jsx';
import { useContext, useEffect, useState } from 'react';
Expand Down Expand Up @@ -90,11 +87,6 @@ export default function LeaveHistory() {
status={la.status}
/>
))}

{/*<div className="self-center flex w-[812px] max-w-full items-stretch justify-between gap-5 mt-80 px-0.5 max-md:flex-wrap max-md:mt-10">*/}
{/* <LeavePerPage />*/}
{/* <LeaveTotalPage />*/}
{/*</div>*/}
</div>
</div>
</Layout>
Expand Down
17 changes: 0 additions & 17 deletions src/components/LeaveHistory/LeavePerPage.jsx

This file was deleted.

22 changes: 0 additions & 22 deletions src/components/LeaveHistory/LeaveTotalPage.jsx

This file was deleted.

33 changes: 31 additions & 2 deletions src/components/Profile/Profile.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
import React, { useContext } from 'react';
import React, { useContext, useEffect } from 'react';
import { AuthContext } from '../../context/AuthContext.jsx';
import { useNavigate } from 'react-router-dom';

export default function Profile() {
const navigate = useNavigate();
const { isAuthenticated, logout, userData } = useContext(AuthContext);
const { logout, userData } = useContext(AuthContext);
const [leaveEntitlement, setLeaveEntitlement] = React.useState({});
const fetchLeaveEntitlement = async () => {
try {
const response = await fetch(`/api/leave-entitlement/get/${userData.id}`);
if (response.ok) {
const data = await response.json();
return data;
} else {
console.log('Bad request', response.statusText);
}
} catch (error) {
console.error('Caught error:', error);
}
};
useEffect(() => {
if (userData && userData.id) {
fetchLeaveEntitlement().then((data) => {
setLeaveEntitlement(data);
console.log('Leave Entitlement:', data);
});
}
}, [userData]);
return (
<div className={'prose flex flex-col mx-auto container'}>
<h1 className={'mt-5 mx-auto'}>Profile Page</h1>
<h2>Id: {userData.id}</h2>
<h2>Role: {userData.role}</h2>
<h2>User: {userData.name}</h2>
<h2>Email: {userData.email}</h2>
<h2>Leave Entitlement: </h2>
<ul>
<li>Annual Leave: {leaveEntitlement.annualLeaveDays}</li>
<li>Medical Leave: {leaveEntitlement.medicalLeaveDays}</li>
<li>Compensation Leave: {leaveEntitlement.compensationLeaveDays}</li>
</ul>
<button
className="btn btn-xs sm:btn-sm md:btn-md lg:btn-lg w-full my-2"
onClick={logout}
Expand Down