Skip to content

Development - #3

Merged
sheaf-hassan merged 7 commits into
mainfrom
development
Jun 17, 2026
Merged

sheaf-hassan merged 7 commits into
mainfrom
development

Conversation

@sheaf-hassan

@sheaf-hassan sheaf-hassan commented Jun 17, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • New dashboard with role-based views for admins and employees
    • Admin dashboard displays employee count, department count, daily attendance, and pending leaves
    • Employee dashboard shows personal attendance records, pending leaves, and latest payslip with quick navigation links
    • Added loading indicator while dashboard data initializes

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR replaces a static <div>Dashboard</div> placeholder with a functional Dashboard page that simulates a 1-second data load via useEffect/setTimeout using dummy data. It adds three new components: a full-screen Loading spinner, AdminDashboard with four stat cards, and EmployeeDashboard with three stat cards and navigation links.

Changes

Dashboard Role-Based Rendering

Layer / File(s) Summary
Loading spinner component
client/src/components/Loading.jsx
Adds a default-exported Loading component rendering a full-height centered Tailwind CSS spinner, consumed by Dashboard during the simulated load delay.
AdminDashboard component and stat cards
client/src/components/AdminDashboard.jsx
Adds AdminDashboard with lucide-react icons, a stats array built from the data prop (total employees, departments, attendance, pending leaves), and a responsive grid of stat cards with hover and animation classes.
EmployeeDashboard component and stat cards
client/src/components/EmployeeDashboard.jsx
Adds EmployeeDashboard with a welcome header from data.employee, three stat cards including a conditional payslip net salary fallback to "N/A", and react-router-dom Link navigation to /attendance and /leave.
Dashboard page orchestration and role routing
client/src/pages/Dashboard.jsx
Replaces the placeholder with a hook-based component using useState/useEffect and a 1-second setTimeout to set dummy data; conditionally renders Loading, an error message, AdminDashboard, or EmployeeDashboard based on data.role.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • sheaf-hassan/employee_management_system#1: Introduced the placeholder Dashboard component in client/src/pages/Dashboard.jsx that this PR directly replaces with the hook-based role-routing implementation.

Poem

🐇 Hop hop, the dashboard blooms today,
A spinner spins while data's on its way,
If you're an admin, your stats stand tall,
If you're an employee, links await your call,
The placeholder sleeps — real components play! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Development' is vague and does not specifically describe the changes in the pull request, which include adding multiple dashboard components and updating the Dashboard page. Use a descriptive title that captures the main change, such as 'Add Admin and Employee Dashboard components with loading state' or 'Implement dashboard UI with role-based rendering'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch development

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
client/src/components/EmployeeDashboard.jsx (1)

37-38: ⚡ Quick win

Use a stable key instead of array index in the card list.

Line 38 uses key={index}. Prefer a semantic stable key (for example card.title) to avoid identity issues if cards are reordered or changed later.

Suggested change
-            {cards.map((card, index)=>(
-                <div key={index} className="card card-hover p-5 sm:p-6 relative overflow-hidden group flex items-center justify-between">
+            {cards.map((card)=>(
+                <div key={card.title} className="card card-hover p-5 sm:p-6 relative overflow-hidden group flex items-center justify-between">
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/src/components/EmployeeDashboard.jsx` around lines 37 - 38, In the
EmployeeDashboard.jsx component, the cards.map() function currently uses
key={index} which creates identity tracking problems if cards are reordered or
filtered. Replace the index-based key with a stable, unique property from the
card object such as key={card.title} or key={card.id} to ensure React can
properly identify and update individual card elements across re-renders and data
changes.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@client/src/pages/Dashboard.jsx`:
- Line 13: The setData call in the Dashboard component always uses
dummyEmployeeDashboardData, making the admin role check unreachable. Modify the
setData call to conditionally pass the appropriate dummy dataset based on the
current user role or route. Instead of hard-coding dummyEmployeeDashboardData,
determine whether to use dummyEmployeeDashboardData or dummyAdminDashboardData
(or equivalent) before calling setData so that the role-based conditional logic
on the data.role === "ADMIN" branch can execute correctly.
- Around line 14-17: The setTimeout call in the useEffect hook that sets loading
to false after 1000ms does not have a cleanup function, which means if the
component unmounts before the timer fires, the setLoading state update will
still attempt to execute on an unmounted component. To fix this, capture the
timeout ID returned by setTimeout and return a cleanup function from the
useEffect that calls clearTimeout with that timeout ID to clear the pending
timer when the component unmounts or the effect is cleaned up.

---

Nitpick comments:
In `@client/src/components/EmployeeDashboard.jsx`:
- Around line 37-38: In the EmployeeDashboard.jsx component, the cards.map()
function currently uses key={index} which creates identity tracking problems if
cards are reordered or filtered. Replace the index-based key with a stable,
unique property from the card object such as key={card.title} or key={card.id}
to ensure React can properly identify and update individual card elements across
re-renders and data changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e26cbf64-b913-48d1-8a65-2cd0e680eda8

📥 Commits

Reviewing files that changed from the base of the PR and between f4e73e9 and 03a0daa.

📒 Files selected for processing (4)
  • client/src/components/AdminDashboard.jsx
  • client/src/components/EmployeeDashboard.jsx
  • client/src/components/Loading.jsx
  • client/src/pages/Dashboard.jsx

const [loading, setLoading] = useState(true);

useEffect(()=>{
setData(dummyEmployeeDashboardData)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Admin route branch is currently unreachable with the hard-coded dataset.

Line 13 always sets dummyEmployeeDashboardData, so the data.role === "ADMIN" branch (Line 22) never executes with current fixtures. This breaks the role-based behavior described by the PR objective.

Suggested change
   useEffect(()=>{
-    setData(dummyEmployeeDashboardData)
+    const role = "ADMIN"; // replace with authenticated user role source
+    setData(role === "ADMIN" ? dummyAdminDashboardData : dummyEmployeeDashboardData)
     setTimeout(()=>{
       setLoading(false)
     },1000)
   },[])

Also applies to: 22-26

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/src/pages/Dashboard.jsx` at line 13, The setData call in the Dashboard
component always uses dummyEmployeeDashboardData, making the admin role check
unreachable. Modify the setData call to conditionally pass the appropriate dummy
dataset based on the current user role or route. Instead of hard-coding
dummyEmployeeDashboardData, determine whether to use dummyEmployeeDashboardData
or dummyAdminDashboardData (or equivalent) before calling setData so that the
role-based conditional logic on the data.role === "ADMIN" branch can execute
correctly.

Comment on lines +14 to +17
setTimeout(()=>{
setLoading(false)
},1000)
},[])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

fd -t f Dashboard.jsx

Repository: sheaf-hassan/employee_management_system

Length of output: 199


🏁 Script executed:

cat -n client/src/pages/Dashboard.jsx | head -25

Repository: sheaf-hassan/employee_management_system

Length of output: 1059


Add timeout cleanup in useEffect to prevent state updates after unmount.

The timer is never cleared. If the component unmounts before 1s, the callback will still fire and attempt to update state on an unmounted component, causing a warning.

Suggested change
   useEffect(()=>{
     setData(dummyEmployeeDashboardData)
+    const timerId = setTimeout(()=>{
-    setTimeout(()=>{
       setLoading(false)
     },1000)
+    return () => clearTimeout(timerId)
   },[])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/src/pages/Dashboard.jsx` around lines 14 - 17, The setTimeout call in
the useEffect hook that sets loading to false after 1000ms does not have a
cleanup function, which means if the component unmounts before the timer fires,
the setLoading state update will still attempt to execute on an unmounted
component. To fix this, capture the timeout ID returned by setTimeout and return
a cleanup function from the useEffect that calls clearTimeout with that timeout
ID to clear the pending timer when the component unmounts or the effect is
cleaned up.

@sheaf-hassan
sheaf-hassan merged commit 217bd3b into main Jun 17, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant