add attendnace table

This commit is contained in:
tylen
2025-11-03 12:25:35 +02:00
parent 4ff56ec06c
commit f69fa8b563
4 changed files with 107 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ import { useCookies } from 'react-cookie';
import { API_URL } from '../constants/constants';
import { hashPassword } from './hashPassword';
import { useState } from 'react';
import type { User } from '../types';
const useFetchUser = () => {
const [isLoading, setIsLoading] = useState(false)
@@ -162,7 +163,30 @@ const useFetchUser = () => {
}
}
return { userSet, passwordCreate, signUser, validToken, updateAttendance, getAttendance, isLoading };
const getAttendanceAll = async (): Promise<User[]> => {
const token = apiCookie.apiToken
try {
const response = await fetch(`${API_URL}/users/attendance/all?token=${encodeURIComponent(token)}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
if (!data.success) throw new Error(data.message);
return data.attendance_list
} catch (error) {
console.error('Error retrieving attendance:', error);
return []
}
}
return { userSet, passwordCreate, signUser, validToken, updateAttendance, getAttendance, isLoading, getAttendanceAll };
};
export default useFetchUser;