add attendnace table
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user