added prize draw name to tables
This commit is contained in:
@@ -10,10 +10,12 @@ import { useTranslation } from "react-i18next";
|
||||
interface SelectUserModalProps {
|
||||
showSelectUser: boolean;
|
||||
setShowSelectUser: (value: boolean) => void;
|
||||
usernameData: { users: string[] };
|
||||
usernameDataIsLoading: boolean;
|
||||
info: { users: string[]; prize_draws: string[] };
|
||||
infoIsLoading: boolean;
|
||||
selectedUser: string | null;
|
||||
selectedDraw: string | null;
|
||||
handleUserSelection: (value: string | null) => void;
|
||||
handleDrawSelection: (value: string | null) => void;
|
||||
}
|
||||
|
||||
export const SelectUserModal = (props: SelectUserModalProps) => {
|
||||
@@ -25,8 +27,8 @@ export const SelectUserModal = (props: SelectUserModalProps) => {
|
||||
<Typography>{t("user")}</Typography>
|
||||
{/* User selection */}
|
||||
<Autocomplete
|
||||
options={props.usernameData?.users ?? []}
|
||||
loading={props.usernameDataIsLoading}
|
||||
options={props.info?.users ?? []}
|
||||
loading={props.infoIsLoading}
|
||||
loadingText={t("loading")}
|
||||
value={props.selectedUser}
|
||||
onChange={(_, value) => props.handleUserSelection(value)}
|
||||
@@ -34,6 +36,17 @@ export const SelectUserModal = (props: SelectUserModalProps) => {
|
||||
variant="soft"
|
||||
sx={{ borderRadius: "10px" }}
|
||||
/>
|
||||
{/* Prize selection */}
|
||||
<Autocomplete
|
||||
options={props.info?.prize_draws ?? []}
|
||||
loading={props.infoIsLoading}
|
||||
loadingText={t("loading")}
|
||||
value={props.selectedDraw}
|
||||
onChange={(_, value) => props.handleDrawSelection(value)}
|
||||
placeholder={t("prize_draws")}
|
||||
variant="soft"
|
||||
sx={{ borderRadius: "10px" }}
|
||||
/>
|
||||
</ModalDialog>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
@@ -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} />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { API_BASE } from "../../config/api.config";
|
||||
import type { FormData } from "../../config/interfaces.config";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export const submitFormData = async (
|
||||
data: FormData,
|
||||
@@ -7,10 +8,16 @@ export const submitFormData = async (
|
||||
) => {
|
||||
console.warn("submitFormData is fetching!");
|
||||
|
||||
const draw = Cookies.get("selectedDraw");
|
||||
|
||||
if (!draw) {
|
||||
throw new Error("You need to set an prize draw!");
|
||||
}
|
||||
|
||||
// await new Promise((resolve) => setTimeout(resolve, 3000)); // Wait 3 seconds
|
||||
|
||||
const response = await fetch(
|
||||
`${API_BASE}/default/new-entry?username=${username}`,
|
||||
`${API_BASE}/default/new-entry?username=${username}&draw=${draw}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { API_BASE } from "../../config/api.config";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export const fetchUsers = async () => {
|
||||
console.warn("fetchUsers is fetching!");
|
||||
export const fetchInfo = async () => {
|
||||
console.warn("fetchInfo is fetching!");
|
||||
|
||||
const response = await fetch(`${API_BASE}/default/users`);
|
||||
const response = await fetch(`${API_BASE}/default/info`);
|
||||
const data = await response.json();
|
||||
|
||||
return data;
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
"user": "Benutzer",
|
||||
"next-id": "Nächste Eintragsnummer: ",
|
||||
"form-submitted-successfully": "Formular erfolgreich übermittelt!",
|
||||
"form-submission-failed": "Formularübermittlung fehlgeschlagen.",
|
||||
"form-submission-failed": "Formularübermittlung fehlgeschlagen. Haben Sie eine Verlosung ausgewählt?",
|
||||
"success": "Erfolg",
|
||||
"error": "Fehler",
|
||||
"cash": "Bar",
|
||||
"paypal": "PayPal",
|
||||
"prize_draws": "Verlosungen",
|
||||
"transfer": "Andere (notieren)",
|
||||
"ticket-payment_one": "Sie haben erfolgreich {{count}} Los gekauft.",
|
||||
"ticket-payment_other": "Sie haben erfolgreich {{count}} Lose gekauft.",
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
"user": "User",
|
||||
"next-id": "Next Entry Number: ",
|
||||
"form-submitted-successfully": "Form submitted successfully!",
|
||||
"orm-submission-failed": "Form submission failed.",
|
||||
"form-submission-failed": "Form submission failed. Have you set an prize draw?",
|
||||
"prize_draws": "Prize draws",
|
||||
"success": "Success",
|
||||
"error": "Error",
|
||||
"cash": "Cash",
|
||||
|
||||
Reference in New Issue
Block a user