fix attendnace

This commit is contained in:
tylen
2025-11-02 21:31:01 +02:00
parent c2e6f81775
commit c39384badf
4 changed files with 66 additions and 47 deletions

View File

@@ -88,7 +88,7 @@ const useFetchHosting = () => {
}
// Optional: Fetch the updated data after reservation
await fetchData();
//await fetchData();
} finally {
setLoading(false);
}

View File

@@ -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 };
};