implement wihslist and secret santa

This commit is contained in:
tylen
2025-11-24 17:24:41 +02:00
parent 5051abc440
commit 06e146f1c4
5 changed files with 226 additions and 7 deletions

View File

@@ -2,7 +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';
import type { User, SantaInfo } from '../types';
const useFetchUser = () => {
const [isLoading, setIsLoading] = useState(false)
@@ -137,6 +137,54 @@ const useFetchUser = () => {
}
}
const updateWishlist = async (wishlistUrl: string): Promise<boolean> => {
const token = apiCookie.apiToken
try {
const response = await fetch(`${API_URL}/users/wishlist`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
token,
wishlist: wishlistUrl,
}),
});
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 true; // Attendance updated successfully
} catch (error) {
console.error('Error updating wishlist:', error);
return false; // Attendance update failed
}
}
const getSantaInfo = async (): Promise<SantaInfo | null> => {
const token = apiCookie.apiToken
try {
const response = await fetch(`${API_URL}/users/santa?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.santa_info
} catch (error) {
console.error('Error retrieving attendance:', error);
return null
}
}
const updateAttendance = async (attendanceStatus: boolean): Promise<boolean> => {
const token = apiCookie.apiToken
try {
@@ -186,7 +234,7 @@ const useFetchUser = () => {
}
return { userSet, passwordCreate, signUser, validToken, updateAttendance, getAttendance, isLoading, getAttendanceAll };
return { userSet, passwordCreate, signUser, validToken, updateAttendance, updateWishlist, getAttendance, isLoading, getAttendanceAll, getSantaInfo };
};
export default useFetchUser;