19 e.preventDefault();
20 try {
21 const response = await fetch("/register", {
22 method: "POST",
23 headers: { "Content-Type": "application/json" },
48 setCurrentUser({ username: "admin", fullName: "Admin" });
49 setView("admin-dashboard");
50 await fetchUserRegistrationList();
51 await fetchDateWiseAttendance(selectedDate);
52 return;
53 }
54
55 try {
56 const response = await fetch("/login", {
57 method: "POST",
58 headers: { "Content-Type": "application/json" },
63 setCurrentUser(result.user);
64 setView("attendance");
65 await fetchAttendanceList();
66 await fetchMonthlyStats();
67 } else {
68 alert(result.message);
75 const markAttendance = async (status) => {
76 try {
77 const response = await fetch("/mark-attendance", {
78 method: "POST",
79 headers: { "Content-Type": "application/json" },
87 const result = await response.json();
88 if (result.success) {
89 await fetchAttendanceList();
90 await fetchMonthlyStats();
91 alert(`Attendance marked as ${status}`);
92 } else {
98 };
99
100 const fetchAttendanceList = async () => {
101 try {
102 const response = await fetch("/attendance-list");
103 const list = await response.json();
104 setAttendanceList(list);
105 } catch (error) {
106 console.error("Failed to fetch attendance list");
107 }
108 };
109
110 const fetchMonthlyStats = async () => {
111 try {
112 const response = await fetch("/monthly-stats");
113 const stats = await response.json();
114 setMonthlyStats(stats);
115 } catch (error) {
116 console.error("Failed to fetch monthly stats");
117 }
118 };
119
120 const fetchUserRegistrationList = async () => {
121 try {
122 const response = await fetch("/user-registration-list");
123 const list = await response.json();
124 setUserRegistrationList(list);
125 } catch (error) {
126 console.error("Failed to fetch user registration list");
127 }
128 };
129
130 const fetchDateWiseAttendance = async (date) => {
131 try {
132 const response = await fetch(`/date-wise-attendance?date=${date}`);
133 const list = await response.json();
134 setDateWiseAttendance(list);
135 } catch (error) {
136 console.error("Failed to fetch date-wise attendance");
137 }
138 };
140 const deleteUser = async (username) => {
141 try {
142 const response = await fetch("/delete-user", {
143 method: "POST",
144 headers: { "Content-Type": "application/json" },
147 const result = await response.json();
148 if (result.success) {
149 await fetchUserRegistrationList();
150 alert("User deleted successfully");
151 } else {
232 onChange={(e) => {
233 setSelectedDate(e.target.value);
234 fetchDateWiseAttendance(e.target.value);
235 }}
236 style={{ marginBottom: "15px" }}
540 }
541
542 // Fetch User Registration List
543 if (request.url.includes("/user-registration-list")) {
544 const result = await sqlite.execute(
554 }
555
556 // Fetch Date-wise Attendance
557 if (request.url.includes("/date-wise-attendance")) {
558 const url = new URL(request.url);
572 }
573
574 // Fetch Monthly Stats
575 if (request.url.includes("/monthly-stats")) {
576 const currentDate = new Date();
609 }
610
611 // Fetch Attendance List
612 if (request.url.includes("/attendance-list")) {
613 const result = await sqlite.execute(