Compare commits
No commits in common. "5051abc440607d132c64f7c309c5c27890113e1b" and "4ff56ec06cabd0bca7f697d01784a72dc767cc0d" have entirely different histories.
5051abc440
...
4ff56ec06c
@ -138,34 +138,6 @@ def registerUserEndpoints(app, database):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify(success=False, message=str(e)), 500
|
return jsonify(success=False, message=str(e)), 500
|
||||||
|
|
||||||
@app.route('/users/attendance/all', methods=['GET'])
|
|
||||||
def get_attendance_all():
|
|
||||||
token = request.args.get('token')
|
|
||||||
|
|
||||||
if not token:
|
|
||||||
return jsonify(success=False, message="Token is required"), 400
|
|
||||||
|
|
||||||
query_session = "SELECT * FROM sessions WHERE Token=%s"
|
|
||||||
|
|
||||||
try:
|
|
||||||
result = database.query(query_session, params=(token,))
|
|
||||||
if not result:
|
|
||||||
return jsonify(success=False, message="Token is invalid or expired"), 401
|
|
||||||
|
|
||||||
attendance_query = "SELECT Name, Attendance FROM users"
|
|
||||||
attendance_result = database.query(attendance_query)
|
|
||||||
|
|
||||||
if not attendance_result:
|
|
||||||
return jsonify(success=False, message="No users found"), 404
|
|
||||||
|
|
||||||
attendance_list = [{"name": row[0], "attendance": row[1]} for row in attendance_result]
|
|
||||||
|
|
||||||
return jsonify(success=True, attendance_list=attendance_list), 200
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
return jsonify(success=False, message=str(e)), 500
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,60 +1,16 @@
|
|||||||
import { useEffect, useState } from "react";
|
|
||||||
import useFetchUser from "../utils/fetchUser";
|
|
||||||
import CenteredContainer from "./ChildrenContainer";
|
import CenteredContainer from "./ChildrenContainer";
|
||||||
import type { User } from "../types";
|
|
||||||
|
|
||||||
const processAttendance = (attendance: boolean | null): string => {
|
|
||||||
if (attendance == null) {
|
|
||||||
return "Пока не ответил"
|
|
||||||
}
|
|
||||||
return (attendance == true) ? "Да!" : "Не в этот раз"
|
|
||||||
}
|
|
||||||
|
|
||||||
function AttendanceTable() {
|
function AttendanceTable() {
|
||||||
|
|
||||||
const {getAttendanceAll} = useFetchUser()
|
|
||||||
const [userAttendanceData, setUserAttendnaceData] = useState<User[]>([])
|
|
||||||
|
|
||||||
const fetchUserData = async () => {
|
|
||||||
const userData = await getAttendanceAll()
|
|
||||||
setUserAttendnaceData(userData)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleRefresh = () => {
|
|
||||||
fetchUserData()
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchUserData()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CenteredContainer>
|
<CenteredContainer>
|
||||||
<h2>Кто празднует?</h2>
|
<h2>Кто празднует?</h2>
|
||||||
{userAttendanceData && (
|
<p className="mainText">
|
||||||
<div className="table-wrapper">
|
Вскоре, вы сможете видеть всех, кто приедет и будет праздновать с нами. Данная фича по полной в разработке!
|
||||||
<table>
|
<br/><br/>
|
||||||
<thead>
|
Таблица в производстве... Ожидайте к <b>началу-середние ноября</b>
|
||||||
<tr>
|
</p>
|
||||||
<th>Пятка</th>
|
|
||||||
<th>Празднует с нами?</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{userAttendanceData && userAttendanceData.map((item) => (
|
|
||||||
<tr>
|
|
||||||
<td>{item.name}</td>
|
|
||||||
<td>{processAttendance(item.attendance)}</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<p className="scroll-instruction">Таблицу можно скроллить</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<br/>
|
|
||||||
<button onClick={handleRefresh}>Обновить</button>
|
|
||||||
</CenteredContainer>
|
</CenteredContainer>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
top: -10%; /* Start above the top of the screen */
|
top: -10%; /* Start above the top of the screen */
|
||||||
color: white; /* Snowflake color */
|
color: white; /* Snowflake color */
|
||||||
font-size: 1em; /* Size of the snowflake; adjust as needed */
|
font-size: 1em; /* Size of the snowflake; adjust as needed */
|
||||||
opacity: 0.5; /* Transparency */
|
opacity: 0.8; /* Transparency */
|
||||||
animation: fall linear infinite; /* Apply the fall animation */
|
animation: fall linear infinite; /* Apply the fall animation */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ const Snowflakes: React.FC = () => {
|
|||||||
className="snowflake"
|
className="snowflake"
|
||||||
style={{
|
style={{
|
||||||
left: `${Math.random() * 100}vw`, // Random position across the full width
|
left: `${Math.random() * 100}vw`, // Random position across the full width
|
||||||
animationDuration: `${Math.random() * 20 + 10}s`, // Random fall duration between 2s and 5s
|
animationDuration: `${Math.random() * 3 + 2}s`, // Random fall duration between 2s and 5s
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
❄️
|
❄️
|
||||||
|
|||||||
5
frontend/src/types/index.d.ts
vendored
5
frontend/src/types/index.d.ts
vendored
@ -10,8 +10,3 @@ export interface Furniture {
|
|||||||
export interface Hosting {
|
export interface Hosting {
|
||||||
furniture: Furniture[]; // Array of furniture items
|
furniture: Furniture[]; // Array of furniture items
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
|
||||||
attendance: boolean | null
|
|
||||||
name: string
|
|
||||||
}
|
|
||||||
@ -2,7 +2,6 @@ import { useCookies } from 'react-cookie';
|
|||||||
import { API_URL } from '../constants/constants';
|
import { API_URL } from '../constants/constants';
|
||||||
import { hashPassword } from './hashPassword';
|
import { hashPassword } from './hashPassword';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import type { User } from '../types';
|
|
||||||
|
|
||||||
const useFetchUser = () => {
|
const useFetchUser = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
@ -163,30 +162,7 @@ const useFetchUser = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAttendanceAll = async (): Promise<User[]> => {
|
return { userSet, passwordCreate, signUser, validToken, updateAttendance, getAttendance, isLoading };
|
||||||
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;
|
export default useFetchUser;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user