diff --git a/backend/routes/default/frontend.data.js b/backend/routes/default/frontend.data.js index 9cd200c..1523e41 100644 --- a/backend/routes/default/frontend.data.js +++ b/backend/routes/default/frontend.data.js @@ -12,14 +12,14 @@ const pool = mysql .promise(); export const getUser = async () => { - const [rows] = await pool.query("SELECT unique_key FROM users"); + const [rows] = await pool.query("SELECT username FROM usersNEW"); + if (rows.length > 0) { - return {rows}; + const users = rows.map((r) => r.username); + return { users }; } else { - return { message: "No data found" }; + return { users: [], message: "No data found" }; } }; -export const confirmData = async (data) => { - -} +export const confirmData = async (data) => {}; diff --git a/backend/routes/default/frontend.route.js b/backend/routes/default/frontend.route.js index e79f26a..0ebd590 100644 --- a/backend/routes/default/frontend.route.js +++ b/backend/routes/default/frontend.route.js @@ -16,4 +16,9 @@ router.post("/frontend", async (req, res) => { res.sendStatus(204); }); +router.get("/users", async (req, res) => { + const users = await getUser(); + res.json(users); +}); + export default router; diff --git a/backend/scheme.sql b/backend/scheme.sql index 2c69777..000cb05 100644 --- a/backend/scheme.sql +++ b/backend/scheme.sql @@ -8,6 +8,14 @@ CREATE TABLE users ( created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); +CREATE TABLE usersNEW ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(100) NOT NULL UNIQUE, + first_name VARCHAR(100) NOT NULL, + last_name VARCHAR(100) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + -- Trigger zur automatischen Generierung eines 25‑stelligen Keys DELIMITER $ diff --git a/frontend/src/pages/MainForm.tsx b/frontend/src/pages/MainForm.tsx index 4c85da9..3b293c8 100644 --- a/frontend/src/pages/MainForm.tsx +++ b/frontend/src/pages/MainForm.tsx @@ -5,9 +5,10 @@ import { Button, Alert, CircularProgress, + Autocomplete, } from "@mui/material"; import { useTranslation } from "react-i18next"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { submitFormData } from "../utils/sender"; interface Message { @@ -35,8 +36,28 @@ export const MainForm = () => { street: "", postalCode: "", paymentMethod: "", - code: "", }); + const [users, setUsers] = useState([]); + + useEffect(() => { + // Fetch user data or any other data needed for the form + try { + const fetchUsers = async () => { + const response = await fetch("http://localhost:8004/default/users"); + const data = await response.json(); + setUsers(data.users); + }; + fetchUsers(); + console.log(users); + } catch (error) { + setMsg({ + type: "error", + headline: t("error"), + text: t("failed-to-load-users"), + }); + console.error("Error fetching users:", error); + } + }, []); const handleChange = (e: React.ChangeEvent) => { setFormData({ ...formData, [e.target.name]: e.target.value }); @@ -72,6 +93,12 @@ export const MainForm = () => { handleSubmit(); }} > + } + /> { } label={t("cash")} /> } label={t("paypal")} /> } label={t("transfer")} /> - {isLoading && }