Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Miningmark committed Dec 11, 2024
1 parent 7923486 commit 9524398
Show file tree
Hide file tree
Showing 10 changed files with 608 additions and 29 deletions.
8 changes: 8 additions & 0 deletions src/components/styled/RadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ const StyledWrapper = styled.div`
--_i: 4;
--_x: 0.1px;
}
.container:has(label:nth-child(6) input:checked):before {
--_i: 5;
--_x: 0.12px;
}
.container:has(label:nth-child(7) input:checked):before {
--_i: 6;
--_x: 0.14px;
}
@media print {
input[type="radio"] {
Expand Down
10 changes: 8 additions & 2 deletions src/pages/api/registrationAsArtist.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CREATE TABLE registration_artist (
stand_size VARCHAR(50) NOT NULL,
additional_exhibitor_ticket BOOLEAN DEFAULT FALSE,
wlan BOOLEAN DEFAULT FALSE,
programm_booklet VARCHAR(50) NOT NULL DEFAULT 'Nein',
website VARCHAR(100),
instagram VARCHAR(100),
message TEXT,
Expand Down Expand Up @@ -92,6 +93,7 @@ export default async function handler(req, res) {
fields.additionalExhibitorTicket[0].toLowerCase()
);
const wlan = ["true", "yes", "1"].includes(fields.wlan[0].toLowerCase());
const programmBooklet = fields.programmBooklet[0];
const website = fields.website[0];
const instagram = fields.instagram[0];
const message = fields.message[0];
Expand Down Expand Up @@ -137,6 +139,7 @@ export default async function handler(req, res) {
validateString(typeOfArt, "typeOfArt", 3, 2500);
validateString(descriptionOfStand, "descriptionOfStand", 3, 2500);
validateString(standSize, "standSize", 3, 50);
validateString(programmBooklet, "programmBooklet", 3, 50);

// Optional fields
if (vendorName) validateString(vendorName, "vendorName", 3, 50);
Expand Down Expand Up @@ -241,6 +244,7 @@ export default async function handler(req, res) {
stand_size,
additional_exhibitor_ticket,
wlan,
programm_booklet,
website,
instagram,
message,
Expand All @@ -250,7 +254,7 @@ export default async function handler(req, res) {
picture_rights,
artist_conditions,
image_url
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`;
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`;

const values = [
clientIp,
Expand All @@ -268,6 +272,7 @@ export default async function handler(req, res) {
standSize,
additionalExhibitorTicket || false,
wlan || false,
programmBooklet,
website || null,
instagram || null,
message || null,
Expand Down Expand Up @@ -298,14 +303,15 @@ export default async function handler(req, res) {
standSize,
additionalExhibitorTicket,
wlan,
programmBooklet,
website,
instagram,
message,
});

res.status(200).json({ message: "Daten erfolgreich eingefügt." });
} catch (error) {
console.error("Fehler beim Einfügen der Daten:", err);
console.error("Fehler beim Einfügen der Daten:", error);
res.status(500).json({ error: "Daten konnten nicht gespeichert werden." });
}
}
Expand Down
32 changes: 25 additions & 7 deletions src/pages/api/registrationAsVendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mysql from "mysql2/promise";
import path from "path";
import fs from "fs/promises";
import formidable from "formidable";
import emailRegistrationVendor from "@/util/email_registrationVendor";

export const config = {
api: {
Expand All @@ -28,6 +29,8 @@ CREATE TABLE registration_vendor (
additional_exhibitor_ticket int DEFAULT 0,
strom BOOLEAN DEFAULT FALSE,
wlan BOOLEAN DEFAULT FALSE,
programm_booklet VARCHAR(50) DEFAULT 'Nein',
table_required BOOLEAN DEFAULT FALSE,
website VARCHAR(100),
instagram VARCHAR(100),
message TEXT,
Expand Down Expand Up @@ -91,6 +94,8 @@ export default async function handler(req, res) {
);
const strom = ["true", "yes", "1"].includes(fields.strom[0].toLowerCase());
const wlan = ["true", "yes", "1"].includes(fields.wlan[0].toLowerCase());
const programmBooklet = fields.programmBooklet[0];
const table = ["true", "yes", "1"].includes(fields.table[0].toLowerCase());
const website = fields.website[0];
const instagram = fields.instagram[0];
const message = fields.message[0];
Expand Down Expand Up @@ -135,6 +140,7 @@ export default async function handler(req, res) {
validateString(typeOfAssortment, "typeOfAssortment", 3, 2500);
validateString(descriptionOfStand, "descriptionOfStand", 3, 2500);
validateString(standSize, "standSize", 3, 50);
validateString(programmBooklet, "programmBooklet", 3, 50);

// Optional fields
if (website) validateString(website, "website", 3, 100);
Expand All @@ -154,6 +160,12 @@ export default async function handler(req, res) {
message: "Wlan muss ein wahrheitswert sein",
});
}
if (typeof table !== "boolean") {
errors.push({
field: "table",
message: "Tisch muss ein wahrheitswert sein",
});
}
if (typeof privacyPolicy !== "boolean" || privacyPolicy === false) {
errors.push({
field: "privacyPolicy",
Expand Down Expand Up @@ -192,14 +204,14 @@ export default async function handler(req, res) {
}

try {
// Spam-Prüfung: Gibt es eine Anfrage von derselben E-Mail in den letzten 5 Minuten?
// Spam-Prüfung: Gibt es zu viele Anfrage von derselben E-Mail in den letzten 5 Minuten?
const spamCheckQuery = `
SELECT COUNT(*) AS count
FROM registration_vendor
WHERE (email = ? OR client_ip = ?) AND created_at > NOW() - INTERVAL 5 MINUTE
`;
const [spamCheckResult] = await connection.query(spamCheckQuery, [email, clientIp]);
if (spamCheckResult[0].count > 0) {
if (spamCheckResult[0].count > 2) {
// Ungewöhnliches Verhalten loggen
await logUnusualActivity(clientIp, email, "Spam-Versuch");
return res
Expand Down Expand Up @@ -238,6 +250,8 @@ export default async function handler(req, res) {
additional_exhibitor_ticket,
strom,
wlan,
programm_booklet,
table_required,
website,
instagram,
message,
Expand All @@ -247,7 +261,7 @@ export default async function handler(req, res) {
picture_rights,
vendor_conditions,
image_url
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`;
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`;

const values = [
clientIp,
Expand All @@ -265,6 +279,8 @@ export default async function handler(req, res) {
additionalExhibitorTicket || 0,
strom || false,
wlan || false,
programmBooklet || "Nein",
table || false,
website || null,
instagram || null,
message || null,
Expand All @@ -279,7 +295,7 @@ export default async function handler(req, res) {
const [result] = await connection.query(query, values);

// Erfolgsmeldung zurückgeben
emailRegistrationVendor(
emailRegistrationVendor({
name,
lastName,
email,
Expand All @@ -294,14 +310,16 @@ export default async function handler(req, res) {
additionalExhibitorTicket,
strom,
wlan,
programmBooklet,
table,
website,
instagram,
message
);
message,
});

res.status(200).json({ message: "Daten erfolgreich eingefügt." });
} catch (error) {
console.error("Fehler beim Einfügen der Daten:", err);
console.error("Fehler beim Einfügen der Daten:", error);
res.status(500).json({ error: "Daten konnten nicht gespeichert werden." });
}
}
Expand Down
35 changes: 32 additions & 3 deletions src/pages/registration/registrationAsArtist.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default function RegistrationAsArtist() {
const [standSize, setStandSize] = useState("");
const [additionalExhibitorTicket, setAdditionalExhibitorTicket] = useState("");
const [wlan, setWlan] = useState(false);
const [programmBooklet, setProgrammBooklet] = useState("Nein");
const [descriptionOfStand, setDescriptionOfStand] = useState("");
const [website, setWebsite] = useState("");
const [instagram, setInstagram] = useState("");
Expand Down Expand Up @@ -97,6 +98,7 @@ export default function RegistrationAsArtist() {
standSize: useRef(null),
additionalExhibitorTicket: useRef(null),
wlan: useRef(null),
programmBooklet: useRef(null),
descriptionOfStand: useRef(null),
website: useRef(null),
instagram: useRef(null),
Expand All @@ -115,14 +117,22 @@ export default function RegistrationAsArtist() {
"Halber Tisch": 50,
};

const programmBookletCost = {
Nein: 0,
"Ganze Seite": 85,
"Halbe Seite": 45,
"Viertel Seite": 30,
};

const ticketCost = 52;
const wlanCost = 10;

const selectedStandCost = standCosts[standSize] || 0;
const totalTicketCost = additionalExhibitorTicket ? ticketCost : 0;
const totalWlanCost = wlan ? wlanCost : 0;
const totalProgrammBookletCost = programmBookletCost[programmBooklet] || 0;

const totalCost = selectedStandCost + totalTicketCost + totalWlanCost;
const totalCost = selectedStandCost + totalProgrammBookletCost + totalTicketCost + totalWlanCost;

async function submit(event) {
event.preventDefault();
Expand Down Expand Up @@ -173,6 +183,8 @@ export default function RegistrationAsArtist() {
validateField(message, "message", "Nachricht", 0, 2500, false);
if (!standSize)
newErrors.push({ field: "standSize", message: "Standgröße ist ein Pflichtfeld" });
if (!programmBooklet)
newErrors.push({ field: "programmBooklet", message: "Programmheft ist ein Pflichtfeld" });

//Bild
if (!file) newErrors.push({ field: "image", message: "Bild ist ein Pflichtfeld" });
Expand Down Expand Up @@ -231,6 +243,7 @@ export default function RegistrationAsArtist() {
formData.append("standSize", standSize);
formData.append("additionalExhibitorTicket", additionalExhibitorTicket);
formData.append("wlan", wlan);
formData.append("programmBooklet", programmBooklet);
formData.append("website", website);
formData.append("instagram", instagram);
formData.append("message", message);
Expand Down Expand Up @@ -265,6 +278,7 @@ export default function RegistrationAsArtist() {
setStandSize("");
setAdditionalExhibitorTicket("");
setWlan(false);
setProgrammBooklet("Nein");
setDescriptionOfStand("");
setWebsite("");
setInstagram("");
Expand Down Expand Up @@ -468,7 +482,7 @@ export default function RegistrationAsArtist() {
require
/>
<CheckBox
title="Zusätzliches Ausstellerticket"
title="Zusätzliches Ausstellerticket (42,00€)"
inputText={additionalExhibitorTicket}
inputChange={(value) => setAdditionalExhibitorTicket(value)}
inputRef={refs.additionalExhibitorTicket}
Expand All @@ -483,6 +497,16 @@ export default function RegistrationAsArtist() {
isError={errors.some((error) => error.field === "wlan")}
/>
<p>Der Zugang wird von einem YumeKai-Helfer auf dem ausgewählten Gerät eingerichtet.</p>
<RadioButton
title="Programmheft"
names={["Nein", "Viertel Seite (30€)", "Halbe Seite (45€)", "Ganze Seite (85€)"]}
options={["Nein", "Viertel Seite", "Halbe Seite", "Ganze Seite"]}
selectedOption={programmBooklet}
inputChange={(value) => setProgrammBooklet(value)}
inputRef={refs.programmBooklet}
isError={errors.some((error) => error.field === "programmBooklet")}
require
/>

<h3>Gesamtkosten</h3>
<ul>
Expand All @@ -491,9 +515,14 @@ export default function RegistrationAsArtist() {
</li>
{additionalExhibitorTicket && <li>Zusätzliche Ausstellertickets: 52,00€</li>}
{wlan && <li>W-Lan: 10,00€</li>}
{programmBooklet !== "Nein" && (
<li>
Programmheft: {programmBooklet} ({totalProgrammBookletCost.toFixed(2)}€)
</li>
)}
</ul>

<h4>Gesamtbetrag: {totalCost.toFixed(2)}ink.MWST</h4>
<h4>Gesamtbetrag: {totalCost.toFixed(2)}zzgl.MWST</h4>

<Spacer />
<h2>Allgemeines</h2>
Expand Down
Loading

0 comments on commit 9524398

Please sign in to comment.