diff --git a/src/components/Dashboard/Attendance.jsx b/src/components/Dashboard/Attendance.jsx index b7e5a3b2..168fb065 100644 --- a/src/components/Dashboard/Attendance.jsx +++ b/src/components/Dashboard/Attendance.jsx @@ -7,182 +7,212 @@ import ApexChart from "../Charts/Circle"; const LOCAL_STORAGE_PROJECT_KEY = "selectedAttendanceProjectId"; const Attendance = () => { - const { projects } = useProjects(); - const today = new Date().toISOString().split("T")[0]; // Format: YYYY-MM-DD - const [selectedDate, setSelectedDate] = useState(today); - const storedProjectId = localStorage.getItem(LOCAL_STORAGE_PROJECT_KEY); - const initialProjectId = storedProjectId || "all"; - const [selectedProjectId, setSelectedProjectId] = useState(initialProjectId); - const [displayedProjectName, setDisplayedProjectName] = useState("Select Project"); - const [activeTab, setActiveTab] = useState("all"); + const { projects } = useProjects(); + const today = new Date().toISOString().split("T")[0]; // Format: YYYY-MM-DD + const [selectedDate, setSelectedDate] = useState(today); + const storedProjectId = localStorage.getItem(LOCAL_STORAGE_PROJECT_KEY); + const initialProjectId = storedProjectId || "all"; + const [selectedProjectId, setSelectedProjectId] = useState(initialProjectId); + const [displayedProjectName, setDisplayedProjectName] = + useState("Select Project"); + const [activeTab, setActiveTab] = useState("Summary"); - const { dashboard_Attendancedata: AttendanceData, isLoading, error: isError } = - useDashboard_AttendanceData(selectedDate, selectedProjectId); + const { + dashboard_Attendancedata: AttendanceData, + isLoading, + error: isError, + } = useDashboard_AttendanceData(selectedDate, selectedProjectId); - useEffect(() => { - if (selectedProjectId === "all") { - setDisplayedProjectName("All Projects"); - } else if (projects) { - const foundProject = projects.find((p) => p.id === selectedProjectId); - setDisplayedProjectName(foundProject ? foundProject.name : "Select Project"); - } else { - setDisplayedProjectName("Select Project"); - } + useEffect(() => { + if (selectedProjectId === "all") { + setDisplayedProjectName("All Projects"); + } else if (projects) { + const foundProject = projects.find((p) => p.id === selectedProjectId); + setDisplayedProjectName( + foundProject ? foundProject.name : "Select Project" + ); + } else { + setDisplayedProjectName("Select Project"); + } - localStorage.setItem(LOCAL_STORAGE_PROJECT_KEY, selectedProjectId); - }, [selectedProjectId, projects]); + localStorage.setItem(LOCAL_STORAGE_PROJECT_KEY, selectedProjectId); + }, [selectedProjectId, projects]); - const handleProjectSelect = (projectId) => { - setSelectedProjectId(projectId); - }; + const handleProjectSelect = (projectId) => { + setSelectedProjectId(projectId); + }; - const handleDateChange = (e) => { - setSelectedDate(e.target.value); - }; + const handleDateChange = (e) => { + setSelectedDate(e.target.value); + }; - return ( -
-
-
-
-
Attendance
-

Attendance Progress Chart

-
+ return ( +
+
+
+
+
Attendance
+

Daily Attendance Data

+
-
- -
    -
  • - -
  • - {projects?.map((project) => ( -
  • - -
  • - ))} -
-
-
-
- - {/* ✅ Date Picker Aligned Left with Padding */} -
-
- -
-
- - - {/* Tabs */} -
    -
  • - -
  • -
  • - +
    + +
      +
    • + +
    • + {projects?.map((project) => ( +
    • +
    • + ))}
    - -
    - {activeTab === "Summary" && ( -
    -
    - {isLoading ? ( -

    Loading Attendance data...

    - ) : isError ? ( -

    No data available.

    - ) : ( - AttendanceData && ( - <> -
    - Attendance -
    -

    - {AttendanceData.checkedInEmployee?.toLocaleString()}/ - {AttendanceData.assignedEmployee?.toLocaleString()} -

    - Checked-In / Assigned -
    - -
    - - ) - )} -
    -
    - - )} - - {activeTab === "Details" && ( -
    - - - - - - - - - - {AttendanceData?.attendanceTable && AttendanceData.attendanceTable.length > 0 ? ( - AttendanceData.attendanceTable.map((record, index) => ( - - - - - - - )) - ) : ( - - - - )} - -
    NameCheckinCheckout
    {record.firstName} {record.lastName}{new Date(record.inTime).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}{new Date(record.outTime).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
    No attendance data available
    -
    - )} - -
    +
- ); +
+ +
+ {/* Tabs */} +
+
    +
  • + +
  • +
  • + +
  • +
+
+ {/* ✅ Date Picker Aligned Left with Padding */} +
+
+ +
+
+
+ +
+ {activeTab === "Summary" && ( +
+
+ {isLoading ? ( +

Loading Attendance data...

+ ) : isError ? ( +

No data available.

+ ) : ( + AttendanceData && ( + <> +
+ Attendance +
+

+ {AttendanceData.checkedInEmployee?.toLocaleString()}/ + {AttendanceData.assignedEmployee?.toLocaleString()} +

+ Checked-In / Assigned +
+ +
+ + ) + )} +
+
+ )} + + {activeTab === "Details" && ( +
+ + + + + + + + + + {AttendanceData?.attendanceTable && + AttendanceData.attendanceTable.length > 0 ? ( + AttendanceData.attendanceTable.map((record, index) => ( + + + + + + )) + ) : ( + + + + )} + +
NameCheckinCheckout
+ {record.firstName} {record.lastName} + + {new Date(record.inTime).toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit", + })} + + {new Date(record.outTime).toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit", + })} +
+ No attendance data available +
+
+ )} +
+
+ ); }; export default Attendance;