fix attendnace
This commit is contained in:
@@ -88,7 +88,7 @@ const useFetchHosting = () => {
|
||||
}
|
||||
|
||||
// Optional: Fetch the updated data after reservation
|
||||
await fetchData();
|
||||
//await fetchData();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -114,6 +114,28 @@ const useFetchUser = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const getAttendance = async (): Promise<boolean | null> => {
|
||||
const token = apiCookie.apiToken
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/users/attendance?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
|
||||
} catch (error) {
|
||||
console.error('Error retrieving attendance:', error);
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const updateAttendance = async (attendanceStatus: boolean): Promise<boolean> => {
|
||||
const token = apiCookie.apiToken
|
||||
try {
|
||||
@@ -140,28 +162,6 @@ const useFetchUser = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const getAttendance = async (): Promise<boolean | null> => {
|
||||
const token = apiCookie.apiToken
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/users/attendance?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; // Returns attendance status (true/false)
|
||||
} catch (error) {
|
||||
console.error('Error retrieving attendance:', error);
|
||||
return null; // In case of error or if attendance status is not found
|
||||
}
|
||||
}
|
||||
|
||||
return { userSet, passwordCreate, signUser, validToken, updateAttendance, getAttendance, isLoading };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user