added prize draw name to tables

This commit is contained in:
2026-06-03 16:29:45 +02:00
parent f7a0a3753c
commit a66b150d97
11 changed files with 91 additions and 29 deletions
+23 -6
View File
@@ -21,7 +21,7 @@ import PersonIcon from "@mui/icons-material/Person";
import QrCodeIcon from "@mui/icons-material/QrCode";
import TranslateIcon from "@mui/icons-material/Translate";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { confirmUser, fetchUsers } from "../utils/api/users";
import { confirmUser, fetchInfo } from "../utils/api/users";
import { QRcodeModal } from "../components/modals/QR-CodeModal";
import { SelectUserModal } from "../components/modals/SelectUserModal";
import { useForm } from "@tanstack/react-form";
@@ -39,6 +39,7 @@ export const MainForm = () => {
const [invoice, setInvoice] = useState(false);
const [msg, setMsg] = useState<Message | null>(null);
const [selectedUser, setSelectedUser] = useState<string | null>(null);
const [selectedDraw, setSelectedDraw] = useState<string | null>(null);
const [showSelectUser, setShowSelectUser] = useState(false);
const [QRmodal, setQRmodal] = useState(false);
@@ -106,6 +107,11 @@ export const MainForm = () => {
// useEffect that only executes on mount and is checking if there is a user selcted in the cookies
useEffect(() => {
const savedUser = Cookies.get("selectedUser");
const savedDraw = Cookies.get("selectedDraw");
if (savedDraw) {
setSelectedDraw(savedDraw);
}
if (savedUser) {
setSelectedUser(savedUser);
} else {
@@ -118,9 +124,9 @@ export const MainForm = () => {
}, []);
// Fetch users tanstack query
const { data: usernameData, isLoading: usernameDataIsLoading } = useQuery({
queryKey: ["users"],
queryFn: fetchUsers,
const { data: info, isLoading: infoIsLoading } = useQuery({
queryKey: ["info"],
queryFn: fetchInfo,
});
// Query for validating selcted user
@@ -157,15 +163,26 @@ export const MainForm = () => {
setSelectedUser(username);
};
// function for selecting draw
const handleDrawSelection = (draw: string | null) => {
if (draw == null || draw == "") {
return;
}
setSelectedDraw(draw);
Cookies.set("selectedDraw", draw);
};
return (
<>
<SelectUserModal
showSelectUser={showSelectUser}
setShowSelectUser={setShowSelectUser}
usernameData={usernameData}
usernameDataIsLoading={usernameDataIsLoading}
info={info}
infoIsLoading={infoIsLoading}
selectedUser={selectedUser}
selectedDraw={selectedDraw}
handleUserSelection={handleUserSelection}
handleDrawSelection={handleDrawSelection}
/>
<QRcodeModal setQRmodal={setQRmodal} QRmodal={QRmodal} />