add attendance

This commit is contained in:
tylen
2025-11-02 01:15:02 +02:00
parent 9a192c9b61
commit 327ab8592a
4 changed files with 168 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ import { useCookies } from 'react-cookie';
import { GUESTS } from '../constants/constants';
import useFetchUser from '../utils/fetchUser'; // Import your custom hook
import { useNotification } from '../NotificationContext';
import ApologyMessage from './Attendance';
const InitialSetup = () => {
const [cookie, setCookie] = useCookies();
@@ -11,8 +12,9 @@ const InitialSetup = () => {
const [isSubmitted, setIsSubmitted] = useState(false);
const [password, setPassword] = useState('');
const [isPasswordSet, setIsPasswordSet] = useState(false); // To track if password is set
const [userAttendance, setUserAttendance] = useState<boolean | null>(null);
const { userSet, passwordCreate, signUser, validToken } = useFetchUser(); // Destructure functions from the hook
const { userSet, passwordCreate, signUser, validToken, getAttendance } = useFetchUser(); // Destructure functions from the hook
const notify = useNotification();
const checkUserPassword = async (name: string) => {
@@ -32,8 +34,16 @@ const InitialSetup = () => {
setIsSubmitted(isTokenValid);
};
const getUserAttendance = async () => {
const attendance = await getAttendance()
setUserAttendance(attendance)
}
useEffect(() => {
if (cookie.apiToken !== undefined) validateToken();
if (cookie.apiToken !== undefined) {
getUserAttendance()
validateToken();
}
}, [cookie.apiToken]);
@@ -54,13 +64,18 @@ const InitialSetup = () => {
}
validateToken()
};
if (isSubmitted) {
if (isSubmitted && userAttendance !== false) {
console.log('Selected', selectedName);
return null; // or you can redirect to another component or page
}
if (userAttendance == false) {
return (
<ApologyMessage/>
)
}
return (
<div style={styles.container}>
<h2 style={styles.title}>Выбери себя</h2>