Compare commits
52 Commits
dev
..
c79f81ec7d
| Author | SHA1 | Date | |
|---|---|---|---|
| c79f81ec7d | |||
| 9af4ddaf18 | |||
| 9dd9ccebdd | |||
| 92605d85c2 | |||
| 59a1ae51fa | |||
| 80a3d4d464 | |||
| 9efb93c37c | |||
| cf638dc42d | |||
| 65092b57d9 | |||
| 7045317fc6 | |||
| 0f75f55ac4 | |||
| 2d2dc52012 | |||
| 566437bd71 | |||
| 266ee1af80 | |||
| 43f8e00968 | |||
| 5c43b817a7 | |||
| 0953847f24 | |||
| 9e7fc530b5 | |||
| 18777e5f7c | |||
| b55129dfff | |||
| 26856ee1df | |||
| dd1d8d8d6b | |||
| cf2df0aaac | |||
| 1199d6468f | |||
| 7cd958c31e | |||
| f89cf84a38 | |||
| e3fc1d8659 | |||
| 060f8d01c6 | |||
| 667609d70c | |||
| b05f19acd9 | |||
| 2aa9a968f5 | |||
| e42a2f510a | |||
| d2b22fc71f | |||
| 471c0c7a49 | |||
| 75ff65e76b | |||
| 7cf1245ef6 | |||
| 2adbfa75a5 | |||
| 216a1cb1d4 | |||
| 7fc98d6c9f | |||
| e346cf9445 | |||
| c030b6dbe6 | |||
| 6f26b9bbc3 | |||
| a34a70572f | |||
| 4b3c8a2424 | |||
| 568b3bf495 | |||
| 5653d32857 | |||
| 7cf5b8df48 | |||
| 65c5fc0f8f | |||
| b626a67907 | |||
| 6643a176a6 | |||
| 89803754a7 | |||
| 5052b3e83a |
@@ -158,7 +158,6 @@ keys/
|
||||
# Own files
|
||||
ToDo.txt
|
||||
PayPal-QR-Code.png
|
||||
.docker/volumes
|
||||
|
||||
# only in development branch
|
||||
next-env.d.ts
|
||||
@@ -20,7 +20,7 @@ Ticket intake and validation app with a React frontend and an Express + MySQL ba
|
||||
|
||||
### Production Tech Stack
|
||||
|
||||
> **Note** For production, check the [prod branch](https://git.the1s.de/theis.gaedigk/ca-lose/src/branch/prod/) which contains an VPN git submodule of wg-easy to run the app securely on a private network. It also contains a dnsmasq container to resolve the backend service name from the frontend container. The main branch is meant for local development and testing, so it doesn't include those components to keep things simple.
|
||||
> **Note** For production, check the [prod branch](prod) which contains an VPN git submodule of wg-easy to run the app securely on a private network. It also contains a dnsmasq container to resolve the backend service name from the frontend container. The main branch is meant for local development and testing, so it doesn't include those components to keep things simple.
|
||||
|
||||

|
||||

|
||||
|
||||
@@ -11,16 +11,14 @@ const pool = mysql
|
||||
})
|
||||
.promise();
|
||||
|
||||
export const getInfo = async () => {
|
||||
const [rows] = await pool.query("SELECT username FROM users;");
|
||||
const [rows2] = await pool.query("SELECT name FROM prize_draws;");
|
||||
export const getUser = async () => {
|
||||
const [rows] = await pool.query("SELECT username FROM users");
|
||||
|
||||
if (rows.length > 0 && rows2.length > 0) {
|
||||
if (rows.length > 0) {
|
||||
const users = rows.map((r) => r.username);
|
||||
const prize_draws = rows2.map((n) => n.name);
|
||||
return { users, prize_draws };
|
||||
return { users };
|
||||
} else {
|
||||
return { message: "No data found" };
|
||||
return { users: [], message: "No data found" };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,13 +43,11 @@ export const confirmUser = async (username) => {
|
||||
const [createTable] = await pool.query(
|
||||
`CREATE TABLE IF NOT EXISTS ?? (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
Verlosung VARCHAR(100) NOT NULL,
|
||||
Vorname VARCHAR(100) NOT NULL,
|
||||
Nachname Varchar(100) NOT NULL,
|
||||
EMail Varchar(100) NOT NULL,
|
||||
Telefonnummer Varchar(100) NOT NULL,
|
||||
Lose INT NOT NULL,
|
||||
Schokolade BOOLEAN NOT NULL,
|
||||
Firmenname Varchar(100),
|
||||
Vorname_Geschaeftlich Varchar(100),
|
||||
Nachname_Geschaeftlich Varchar(100),
|
||||
@@ -84,7 +80,7 @@ export const confirmUser = async (username) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const newEntry = async (formData, username, prizeDraw) => {
|
||||
export const newEntry = async (formData, username) => {
|
||||
const confirmation = await confirmUser(username);
|
||||
|
||||
if (!confirmation || !confirmation.success) {
|
||||
@@ -94,16 +90,14 @@ export const newEntry = async (formData, username, prizeDraw) => {
|
||||
const tableName = confirmation.tableName;
|
||||
|
||||
const [result] = await pool.query(
|
||||
`INSERT INTO ?? (Verlosung, Vorname, Nachname, EMail, Telefonnummer, Lose, Schokolade, Firmenname, Vorname_Geschaeftlich, Nachname_Geschaeftlich, EMail_Geschaeftlich, Telefonnummer_Geschaeftlich, Strasse_Hausnr, Plz_Ort, Zahlungsmethode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
`INSERT INTO ?? (Vorname, Nachname, EMail, Telefonnummer, Lose, Firmenname, Vorname_Geschaeftlich, Nachname_Geschaeftlich, EMail_Geschaeftlich, Telefonnummer_Geschaeftlich, Strasse_Hausnr, Plz_Ort, Zahlungsmethode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
tableName,
|
||||
prizeDraw,
|
||||
formData.firstName,
|
||||
formData.lastName,
|
||||
formData.email,
|
||||
formData.phoneNumber,
|
||||
formData.tickets,
|
||||
formData.chocolates,
|
||||
formData.companyName,
|
||||
formData.cmpFirstName,
|
||||
formData.cpmLastName,
|
||||
|
||||
@@ -3,33 +3,24 @@ import dotenv from "dotenv";
|
||||
const router = express.Router();
|
||||
dotenv.config();
|
||||
|
||||
import { getInfo, newEntry, confirmUser } from "./frontend.data.js";
|
||||
import { getUser, newEntry, confirmUser } from "./frontend.data.js";
|
||||
|
||||
router.post("/new-entry", async (req, res) => {
|
||||
const username = req.query.username;
|
||||
const draw = req.query.draw;
|
||||
|
||||
const result = await newEntry(req.body, username, draw);
|
||||
|
||||
const result = await newEntry(req.body, username);
|
||||
if (!result.success) {
|
||||
return res.status(500).json({ message: "Form Data Invalid" });
|
||||
}
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
||||
router.get("/info", async (req, res) => {
|
||||
const info = await getInfo();
|
||||
|
||||
if (!info) {
|
||||
return res.status(500).json({ message: "Server error" });
|
||||
}
|
||||
|
||||
res.json(info);
|
||||
router.get("/users", async (req, res) => {
|
||||
const users = await getUser();
|
||||
res.json(users);
|
||||
});
|
||||
|
||||
router.get("/confirm-user", async (req, res) => {
|
||||
const username = req.query.username;
|
||||
|
||||
if (!username) {
|
||||
return res.status(400).json({ message: "Username is required" });
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
USE ca_lose;
|
||||
|
||||
CREATE TABLE users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(100) NOT NULL UNIQUE,
|
||||
@@ -8,16 +6,9 @@ CREATE TABLE users (
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE prize_draws (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL UNIQUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
/* This scheme does not have to be implemented manually. It always will be generated by the backend */
|
||||
CREATE TABLE xx_DD_MM_YYYY (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
Verlosung VARCHAR(100) NOT NULL,
|
||||
Vorname VARCHAR(100) NOT NULL,
|
||||
Nachname Varchar(100) NOT NULL,
|
||||
EMail Varchar(100) NOT NULL,
|
||||
|
||||
+73
-13
@@ -1,16 +1,19 @@
|
||||
services:
|
||||
# frontend:
|
||||
# container_name: ca-lose-frontend
|
||||
# build: ./frontend
|
||||
# ports:
|
||||
# - "8002:80"
|
||||
# restart: unless-stopped
|
||||
frontend:
|
||||
container_name: ca-lose-frontend
|
||||
hostname: lose-verkaufen
|
||||
build: ./frontend
|
||||
depends_on:
|
||||
- backend
|
||||
networks:
|
||||
ca-lose-internal:
|
||||
ipv4_address: 172.25.0.2
|
||||
restart: unless-stopped
|
||||
|
||||
backend:
|
||||
container_name: ca-lose-backend
|
||||
hostname: backend
|
||||
build: ./backend
|
||||
ports:
|
||||
- "8004:8004"
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
DB_HOST: ca-lose-mysql
|
||||
@@ -19,21 +22,78 @@ services:
|
||||
DB_NAME: ca_lose
|
||||
depends_on:
|
||||
- database
|
||||
networks:
|
||||
ca-lose-internal:
|
||||
ipv4_address: 172.25.0.3
|
||||
restart: unless-stopped
|
||||
|
||||
database:
|
||||
container_name: ca-lose-mysql
|
||||
hostname: database
|
||||
image: mysql:8.0
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3311:3306"
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||
MYSQL_DATABASE: ca_lose
|
||||
TZ: Europe/Berlin
|
||||
volumes:
|
||||
- ./.docker/volumes/ca-lose_mysql:/var/lib/mysql
|
||||
- ../docker/volumes/ca-lose_mysql:/var/lib/mysql
|
||||
- ./mysql-timezone.cnf:/etc/mysql/conf.d/timezone.cnf:ro
|
||||
networks:
|
||||
ca-lose-internal:
|
||||
ipv4_address: 172.25.0.4
|
||||
|
||||
volumes:
|
||||
ca-lose_mysql:
|
||||
# DNS Server for hostname resolution within the Docker network
|
||||
dnsmasq:
|
||||
container_name: ca-lose-dns
|
||||
image: andyshinn/dnsmasq:latest
|
||||
restart: unless-stopped
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
command: >
|
||||
--no-daemon
|
||||
--log-queries
|
||||
--address=/lose-verkaufen/172.25.0.2
|
||||
--address=/frontend/172.25.0.2
|
||||
--address=/backend/172.25.0.3
|
||||
--address=/database/172.25.0.4
|
||||
--address=/wireguard/172.25.0.6
|
||||
networks:
|
||||
ca-lose-internal:
|
||||
ipv4_address: 172.25.0.5
|
||||
|
||||
# WireGuard VPN server for secure remote access to the Docker network
|
||||
wireguard:
|
||||
build: ./wg-easy-ca-lose
|
||||
container_name: ca-lose-wireguard
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
- SYS_MODULE
|
||||
environment:
|
||||
WG_HOST: dus3.the1s.de
|
||||
INSECURE: "true"
|
||||
HOST: "172.25.0.6"
|
||||
PORT: "80"
|
||||
volumes:
|
||||
- ../docker/volumes/ca-lose-wireguard-v15:/etc/wireguard
|
||||
- /lib/modules:/lib/modules:ro
|
||||
ports:
|
||||
- "51830:51830/udp"
|
||||
# - "51831:51821/tcp" Public Web-UI Port
|
||||
sysctls:
|
||||
- net.ipv4.ip_forward=1
|
||||
- net.ipv4.conf.all.src_valid_mark=1
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- dnsmasq
|
||||
networks:
|
||||
ca-lose-internal:
|
||||
ipv4_address: 172.25.0.6
|
||||
|
||||
networks:
|
||||
ca-lose-internal:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.25.0.0/24
|
||||
gateway: 172.25.0.1
|
||||
|
||||
@@ -10,12 +10,10 @@ import { useTranslation } from "react-i18next";
|
||||
interface SelectUserModalProps {
|
||||
showSelectUser: boolean;
|
||||
setShowSelectUser: (value: boolean) => void;
|
||||
info: { users: string[]; prize_draws: string[] };
|
||||
infoIsLoading: boolean;
|
||||
usernameData: { users: string[] };
|
||||
usernameDataIsLoading: boolean;
|
||||
selectedUser: string | null;
|
||||
selectedDraw: string | null;
|
||||
handleUserSelection: (value: string | null) => void;
|
||||
handleDrawSelection: (value: string | null) => void;
|
||||
}
|
||||
|
||||
export const SelectUserModal = (props: SelectUserModalProps) => {
|
||||
@@ -27,8 +25,8 @@ export const SelectUserModal = (props: SelectUserModalProps) => {
|
||||
<Typography>{t("user")}</Typography>
|
||||
{/* User selection */}
|
||||
<Autocomplete
|
||||
options={props.info?.users ?? []}
|
||||
loading={props.infoIsLoading}
|
||||
options={props.usernameData?.users ?? []}
|
||||
loading={props.usernameDataIsLoading}
|
||||
loadingText={t("loading")}
|
||||
value={props.selectedUser}
|
||||
onChange={(_, value) => props.handleUserSelection(value)}
|
||||
@@ -36,17 +34,6 @@ 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>
|
||||
);
|
||||
|
||||
@@ -46,7 +46,6 @@ export const createFormSchema = (
|
||||
email: z.email(t("email-error")),
|
||||
phoneNumber: z.string(t("phone-error")).refine(validator.isMobilePhone),
|
||||
tickets: z.number(t("ticket-error")).min(1),
|
||||
chocolates: z.boolean(t("chocolates-error")),
|
||||
companyName: invoice
|
||||
? z.string().min(1, t("name-error"))
|
||||
: z.string().optional(),
|
||||
|
||||
@@ -21,31 +21,51 @@ 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, fetchInfo } from "../utils/api/users";
|
||||
import { confirmUser, fetchUsers } from "../utils/api/users";
|
||||
import { QRcodeModal } from "../components/modals/QR-CodeModal";
|
||||
import { SelectUserModal } from "../components/modals/SelectUserModal";
|
||||
import { useForm } from "@tanstack/react-form";
|
||||
import { changeTranslation } from "../utils/uxFncs";
|
||||
import { createFormSchema } from "../config/interfaces.config";
|
||||
import { validateFieldWithZod } from "../utils/uxFncs";
|
||||
import type { ZodObject, ZodRawShape } from "zod";
|
||||
import { TextField } from "../components/TextField";
|
||||
import { PAYMENT_METHODS, PAYMENT_LABELS } from "../utils/uxFncs";
|
||||
|
||||
const PAYMENT_METHODS = ["bar", "paypal", "andere"] as const;
|
||||
const PAYMENT_LABELS: Record<string, string> = {
|
||||
bar: "Cash",
|
||||
paypal: "PayPal",
|
||||
andere: "Transfer",
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a single field against the full Zod schema.
|
||||
* Returns the first error message for that field, or undefined if valid.
|
||||
*/
|
||||
function validateFieldWithZod(
|
||||
schema: ZodObject<ZodRawShape>,
|
||||
fieldName: string,
|
||||
allValues: Record<string, unknown>,
|
||||
): string | undefined {
|
||||
const result = schema.safeParse(allValues);
|
||||
if (result.success) return undefined;
|
||||
const issue = result.error.issues.find(
|
||||
(i) => i.path.length === 1 && i.path[0] === fieldName,
|
||||
);
|
||||
return issue?.message;
|
||||
}
|
||||
|
||||
export const MainForm = () => {
|
||||
const { t } = useTranslation();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// States
|
||||
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);
|
||||
|
||||
const formSchema = createFormSchema(t, invoice);
|
||||
|
||||
// Validates the fields and makes sure that the form is maching the zod schema
|
||||
const makeFieldValidator = (fieldName: string) => ({
|
||||
onSubmit: ({
|
||||
fieldApi,
|
||||
@@ -65,15 +85,13 @@ export const MainForm = () => {
|
||||
},
|
||||
});
|
||||
|
||||
// Creates a form with tanstack form
|
||||
const { Field, Subscribe, handleSubmit, setFieldValue } = useForm({
|
||||
defaultValues: {
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
email: "",
|
||||
phoneNumber: "",
|
||||
tickets: 0,
|
||||
chocolates: false,
|
||||
tickets: 1,
|
||||
companyName: "",
|
||||
cmpFirstName: "",
|
||||
cpmLastName: "",
|
||||
@@ -90,7 +108,6 @@ export const MainForm = () => {
|
||||
},
|
||||
});
|
||||
|
||||
// This function returns the errors for one field
|
||||
const getErrors = (field: {
|
||||
state: { meta: { errorMap: Record<string, unknown> } };
|
||||
}) => {
|
||||
@@ -105,14 +122,8 @@ export const MainForm = () => {
|
||||
return [...blurErrors, ...submitErrors].filter(Boolean);
|
||||
};
|
||||
|
||||
// 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 {
|
||||
@@ -124,20 +135,17 @@ export const MainForm = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Fetch users tanstack query
|
||||
const { data: info, isLoading: infoIsLoading } = useQuery({
|
||||
queryKey: ["info"],
|
||||
queryFn: fetchInfo,
|
||||
const { data: usernameData, isLoading: usernameDataIsLoading } = useQuery({
|
||||
queryKey: ["users"],
|
||||
queryFn: fetchUsers,
|
||||
});
|
||||
|
||||
// Query for validating selcted user
|
||||
const { data: userData } = useQuery({
|
||||
queryKey: ["user", selectedUser],
|
||||
enabled: !!selectedUser,
|
||||
queryFn: () => confirmUser(selectedUser),
|
||||
});
|
||||
|
||||
// Tanstack query (mutate) for sending the form
|
||||
const { mutate: mutateForm, isPending: mutateFormIsPending } = useMutation({
|
||||
mutationFn: (values: FormData) => submitFormData(values, selectedUser),
|
||||
onSuccess: (_, values) => {
|
||||
@@ -156,7 +164,6 @@ export const MainForm = () => {
|
||||
|
||||
const nextID = userData?.nextID ?? "N/A";
|
||||
|
||||
// function for selecting user
|
||||
const handleUserSelection = (username: string | null) => {
|
||||
if (username == null || username == "") {
|
||||
return;
|
||||
@@ -164,26 +171,15 @@ 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}
|
||||
info={info}
|
||||
infoIsLoading={infoIsLoading}
|
||||
usernameData={usernameData}
|
||||
usernameDataIsLoading={usernameDataIsLoading}
|
||||
selectedUser={selectedUser}
|
||||
selectedDraw={selectedDraw}
|
||||
handleUserSelection={handleUserSelection}
|
||||
handleDrawSelection={handleDrawSelection}
|
||||
/>
|
||||
|
||||
<QRcodeModal setQRmodal={setQRmodal} QRmodal={QRmodal} />
|
||||
@@ -317,7 +313,7 @@ export const MainForm = () => {
|
||||
)}
|
||||
</Field>
|
||||
|
||||
{/* Tickets + Invoice + Chocolate toggle */}
|
||||
{/* Tickets + Invoice toggle */}
|
||||
<div className="grid grid-cols-2 gap-3 items-end">
|
||||
<FormControl required>
|
||||
<FormLabel>{t("tickets")}</FormLabel>
|
||||
@@ -331,14 +327,12 @@ export const MainForm = () => {
|
||||
<>
|
||||
<Input
|
||||
type="number"
|
||||
value={
|
||||
field.state.value === 0 ? "" : field.state.value
|
||||
}
|
||||
value={field.state.value ?? ""}
|
||||
onBlur={field.handleBlur}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value;
|
||||
field.handleChange(val === "" ? 0 : Number(val));
|
||||
}}
|
||||
onChange={(e) =>
|
||||
field.handleChange(Number(e.target.value))
|
||||
}
|
||||
slotProps={{ input: { min: 1 } }}
|
||||
variant="soft"
|
||||
sx={{ borderRadius: "10px" }}
|
||||
/>
|
||||
@@ -352,7 +346,7 @@ export const MainForm = () => {
|
||||
}}
|
||||
</Field>
|
||||
</FormControl>
|
||||
<div className="flex flex-col gap-2 pb-2">
|
||||
<div className="flex items-center pb-2">
|
||||
<Checkbox
|
||||
checked={invoice}
|
||||
onChange={(e) => {
|
||||
@@ -371,16 +365,6 @@ export const MainForm = () => {
|
||||
label={t("invoice")}
|
||||
variant="outlined"
|
||||
/>
|
||||
<Field name="chocolates">
|
||||
{(field) => (
|
||||
<Checkbox
|
||||
checked={!!field.state.value}
|
||||
onChange={(e) => field.handleChange(e.target.checked)}
|
||||
label={t("chocolates")}
|
||||
variant="outlined"
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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,
|
||||
@@ -8,16 +7,10 @@ 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}&draw=${draw}`,
|
||||
`${API_BASE}/default/new-entry?username=${username}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { API_BASE } from "../../config/api.config";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export const fetchInfo = async () => {
|
||||
console.warn("fetchInfo is fetching!");
|
||||
export const fetchUsers = async () => {
|
||||
console.warn("fetchUsers is fetching!");
|
||||
|
||||
const response = await fetch(`${API_BASE}/default/info`);
|
||||
const response = await fetch(`${API_BASE}/default/users`);
|
||||
const data = await response.json();
|
||||
|
||||
return data;
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
"user": "Benutzer",
|
||||
"next-id": "Nächste Eintragsnummer: ",
|
||||
"form-submitted-successfully": "Formular erfolgreich übermittelt!",
|
||||
"form-submission-failed": "Formularübermittlung fehlgeschlagen. Haben Sie eine Verlosung ausgewählt?",
|
||||
"form-submission-failed": "Formularübermittlung fehlgeschlagen.",
|
||||
"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.",
|
||||
@@ -35,7 +34,5 @@
|
||||
"name-error": "Sie müssen einen Namen eingeben!",
|
||||
"email-error": "Sie müssen eine gültige E-Mail Adresse eingeben!",
|
||||
"phone-error": "Sie müssen eine gültige Telefonnummer eingeben!",
|
||||
"footer-headline": "Dieses System wurde vollständig konzipiert und entwickelt von Theis Gaedigk. - Portfolio: ",
|
||||
"chocolates": "Schokoladen",
|
||||
"chocolates-error": "Dieses Feld kann nur wahr oder falsch sein."
|
||||
"footer-headline": "Dieses System wurde vollständig konzipiert und entwickelt von Theis Gaedigk. - Portfolio: "
|
||||
}
|
||||
@@ -13,8 +13,7 @@
|
||||
"user": "User",
|
||||
"next-id": "Next Entry Number: ",
|
||||
"form-submitted-successfully": "Form submitted successfully!",
|
||||
"form-submission-failed": "Form submission failed. Have you set an prize draw?",
|
||||
"prize_draws": "Prize draws",
|
||||
"orm-submission-failed": "Form submission failed.",
|
||||
"success": "Success",
|
||||
"error": "Error",
|
||||
"cash": "Cash",
|
||||
@@ -36,7 +35,5 @@
|
||||
"name-error": "You have to enter a name!",
|
||||
"email-error": "You have to enter a valid E-Mail adress!",
|
||||
"phone-error": "You have to enter a vaild phone number!",
|
||||
"footer-headline": "This system was fully designed and developed by Theis Gaedigk. - Portfolio: ",
|
||||
"chocolates": "Chocolates",
|
||||
"chocolates-error": "This field can only be true or false."
|
||||
"footer-headline": "This system was fully designed and developed by Theis Gaedigk. - Portfolio: "
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import i18n from "./i18n";
|
||||
import Cookies from "js-cookie";
|
||||
import { ZodObject } from "zod";
|
||||
import type { ZodRawShape } from "zod";
|
||||
|
||||
export const changeTranslation = () => {
|
||||
const clientLng = i18n.language;
|
||||
@@ -16,27 +14,3 @@ export const changeTranslation = () => {
|
||||
alert("Cannot change language.");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a single field against the full Zod schema.
|
||||
* Returns the first error message for that field, or undefined if valid.
|
||||
*/
|
||||
export function validateFieldWithZod(
|
||||
schema: ZodObject<ZodRawShape>,
|
||||
fieldName: string,
|
||||
allValues: Record<string, unknown>,
|
||||
): string | undefined {
|
||||
const result = schema.safeParse(allValues);
|
||||
if (result.success) return undefined;
|
||||
const issue = result.error.issues.find(
|
||||
(i) => i.path.length === 1 && i.path[0] === fieldName,
|
||||
);
|
||||
return issue?.message;
|
||||
}
|
||||
|
||||
export const PAYMENT_METHODS = ["bar", "paypal", "andere"] as const;
|
||||
export const PAYMENT_LABELS: Record<string, string> = {
|
||||
bar: "Cash",
|
||||
paypal: "PayPal",
|
||||
andere: "Transfer",
|
||||
};
|
||||
+1
-1
Submodule wg-easy-ca-lose updated: 8c70c24205...9581e6eacb
Reference in New Issue
Block a user