refactor: update MainForm layout and payment method selection; localize submit button text

This commit is contained in:
2026-01-21 16:15:52 +01:00
parent 308b21ae6c
commit 9445f5d417
4 changed files with 156 additions and 77 deletions

View File

@@ -9,8 +9,7 @@ import {
Chip, Chip,
Box, Box,
Paper, Paper,
Menu, Typography,
MenuItem,
} from "@mui/material"; } from "@mui/material";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
@@ -48,16 +47,6 @@ export const MainForm = () => {
const [users, setUsers] = useState<string[]>([]); const [users, setUsers] = useState<string[]>([]);
const [selectedUser, setSelectedUser] = useState<string | null>(null); const [selectedUser, setSelectedUser] = useState<string | null>(null);
// Payment Methods Menu States
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
useEffect(() => { useEffect(() => {
// Fetch user data or any other data needed for the form // Fetch user data or any other data needed for the form
try { try {
@@ -126,11 +115,33 @@ export const MainForm = () => {
}; };
return ( return (
<Box className="min-h-screen bg-gray-800 flex items-center justify-center p-4"> <Box
className="bg-gray-100 py-10 px-4"
sx={{
minHeight: "100vh",
width: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
<Paper <Paper
elevation={3} elevation={6}
className="w-full max-w-md p-6 rounded-lg" className="w-full rounded-2xl"
sx={{ backgroundColor: "#fff" }} sx={{
backgroundColor: "#fff",
boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
width: "100%",
maxWidth: {
xs: 360, // kompakte Handy-Ansicht
sm: 420, // kleine Tablets / große Phones
md: 480, // Desktop, bleibt angenehm schmal
},
padding: {
xs: "1.5rem",
sm: "2rem",
},
}}
> >
<form <form
onSubmit={(e) => { onSubmit={(e) => {
@@ -162,10 +173,14 @@ export const MainForm = () => {
color="primary" color="primary"
sx={{ sx={{
alignSelf: "flex-start", alignSelf: "flex-start",
fontWeight: "bold", fontWeight: 500,
fontSize: "1rem", fontSize: "0.9rem",
py: 2, mt: 0.5,
px: 1, mb: 0.5,
py: 0.5,
px: 1.25,
borderRadius: "999px",
background: "linear-gradient(135deg, #1976d2 0%, #1565c0 100%)",
}} }}
/> />
@@ -247,7 +262,14 @@ export const MainForm = () => {
{/* Invoice Fields */} {/* Invoice Fields */}
{invoice && ( {invoice && (
<Box className="flex flex-col gap-3 pt-2 border-t border-gray-200"> <Box
className="flex flex-col gap-2 pt-3 mt-2"
sx={{
borderTop: "2px solid",
borderColor: "primary.light",
borderRadius: "0",
}}
>
<TextField <TextField
required required
id="company-name" id="company-name"
@@ -331,64 +353,117 @@ export const MainForm = () => {
</Box> </Box>
)} )}
{/* Payment Methods */} {/* Payment Methods */}
<Button <Box className="flex flex-col gap-2 mt-2">
id="basic-button" <Typography
aria-controls={open ? "basic-menu" : undefined} component="label"
aria-haspopup="true" sx={{
aria-expanded={open ? "true" : undefined} fontSize: "0.875rem",
onClick={handleClick} fontWeight: 500,
> color: "text.secondary",
{formData.paymentMethod || t("select-payment-method")} display: "flex",
</Button> alignItems: "center",
<Menu gap: 0.5,
id="basic-menu"
anchorEl={anchorEl}
open={open}
onClose={handleClose}
slotProps={{
list: {
"aria-labelledby": "basic-button",
},
}} }}
> >
<MenuItem {t("select-payment-method")} *
onClick={() => { </Typography>
setFormData({ ...formData, paymentMethod: "bar" }); <Box className="flex gap-2 flex-wrap">
handleClose(); <Button
variant={
formData.paymentMethod === "bar" ? "contained" : "outlined"
}
onClick={() =>
setFormData({ ...formData, paymentMethod: "bar" })
}
sx={{
flex: 1,
minWidth: "100px",
py: 1.5,
borderRadius: "12px",
textTransform: "none",
fontWeight: formData.paymentMethod === "bar" ? 600 : 400,
}} }}
> >
{t("cash")} {t("cash")}
</MenuItem> </Button>
<MenuItem <Button
onClick={() => { variant={
setFormData({ ...formData, paymentMethod: "paypal" }); formData.paymentMethod === "paypal" ? "contained" : "outlined"
handleClose(); }
onClick={() =>
setFormData({ ...formData, paymentMethod: "paypal" })
}
sx={{
flex: 1,
minWidth: "100px",
py: 1.5,
borderRadius: "12px",
textTransform: "none",
fontWeight: formData.paymentMethod === "paypal" ? 600 : 400,
}} }}
> >
{t("paypal")} {t("paypal")}
</MenuItem> </Button>
<MenuItem <Button
onClick={() => { variant={
setFormData({ ...formData, paymentMethod: "andere" }); formData.paymentMethod === "andere" ? "contained" : "outlined"
handleClose(); }
onClick={() =>
setFormData({ ...formData, paymentMethod: "andere" })
}
sx={{
flex: 1,
minWidth: "100px",
py: 1.5,
borderRadius: "12px",
textTransform: "none",
fontWeight: formData.paymentMethod === "andere" ? 600 : 400,
}} }}
> >
{t("transfer")} {t("transfer")}
</MenuItem> </Button>
</Menu> </Box>
{!formData.paymentMethod && (
<input
tabIndex={-1}
autoComplete="off"
style={{
opacity: 0,
width: 0,
height: 0,
position: "absolute",
}}
required
value={formData.paymentMethod}
onChange={() => {}}
/>
)}
</Box>
{/* Submit Button */} {/* Submit Button */}
<Button <Button
type="submit" type="submit"
variant="contained" variant="contained"
disabled={isLoading} disabled={isLoading || !formData.paymentMethod}
fullWidth fullWidth
size="large" size="large"
sx={{ sx={{
mt: 2, mt: 3,
py: 1.5, py: 2,
textTransform: "uppercase", textTransform: "uppercase",
fontWeight: "bold", fontWeight: "bold",
borderRadius: "12px",
fontSize: "1rem",
background: "linear-gradient(135deg, #1976d2 0%, #1565c0 100%)",
boxShadow: "0 4px 14px 0 rgba(25, 118, 210, 0.39)",
"&:hover": {
background: "linear-gradient(135deg, #1565c0 0%, #0d47a1 100%)",
boxShadow: "0 6px 20px 0 rgba(25, 118, 210, 0.5)",
},
"&:disabled": {
background: "#e0e0e0",
boxShadow: "none",
},
}} }}
> >
{isLoading ? ( {isLoading ? (

View File

@@ -8,7 +8,7 @@
"street": "Straße + Haus Nr.", "street": "Straße + Haus Nr.",
"postal-code": "Plz + Stadt", "postal-code": "Plz + Stadt",
"email": "E-Mail", "email": "E-Mail",
"submit": "Kaufen", "submit": "Abschicken",
"failed-to-load-users": "Das Laden der Benutzer ist fehlgeschlagen.", "failed-to-load-users": "Das Laden der Benutzer ist fehlgeschlagen.",
"user": "Benutzer", "user": "Benutzer",
"next-id": "Nächste Eintragsnummer: ", "next-id": "Nächste Eintragsnummer: ",

View File

@@ -7,7 +7,7 @@
"street": "Street + House No.", "street": "Street + House No.",
"postal-code": "Postal Code + City", "postal-code": "Postal Code + City",
"email": "Email", "email": "Email",
"submit": "Buy", "submit": "Submit Form",
"failed-to-load-users": "Failed to load users.", "failed-to-load-users": "Failed to load users.",
"user": "User", "user": "User",
"next-id": "Next Entry Number: ", "next-id": "Next Entry Number: ",
@@ -20,8 +20,8 @@
"transfer": "Other (note down)", "transfer": "Other (note down)",
"ticket-payment_one": "You have successfully purchased {{count}} ticket.", "ticket-payment_one": "You have successfully purchased {{count}} ticket.",
"ticket-payment_other": "You have successfully purchased {{count}} tickets.", "ticket-payment_other": "You have successfully purchased {{count}} tickets.",
"ticket": "ticket", "ticket": "Ticket",
"tickets": "tickets", "tickets": "Tickets",
"entry-id": "Entry ID", "entry-id": "Entry ID",
"thank-you": "Thank you for supporting the Claudius Akademie! We wish you the best of luck with your ticket.", "thank-you": "Thank you for supporting the Claudius Akademie! We wish you the best of luck with your ticket.",
"select-payment-method": "Select Payment Method" "select-payment-method": "Select Payment Method"

View File

@@ -15,14 +15,18 @@ interface FormData {
} }
export const submitFormData = async (data: FormData, username: string) => { export const submitFormData = async (data: FormData, username: string) => {
console.log(data);
try { try {
const response = await fetch(`http://localhost:8004/default/new-entry?username=${username}`, { const response = await fetch(
`http://localhost:8004/default/new-entry?username=${username}`,
{
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify(data), body: JSON.stringify(data),
}); },
);
if (!response.ok) { if (!response.ok) {
const errorText = await response.text(); const errorText = await response.text();