Skip to content

Commit

Permalink
Update bulk order form layout and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tobifra committed Aug 18, 2024
1 parent 238eb96 commit bf53d2c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 41 deletions.
94 changes: 56 additions & 38 deletions .vitepress/components/BulkOrderForm.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
<template>
<form class="flex flex-col space-y-2" @submit.prevent="submitForm">
<form class="flex flex-col space-y-2" @submit.prevent="submitForm" id="formular">
<div class="hidden rounded-md p-3 bg-green-300" id="successmessage">
Vielen Dank für deine Bestellung. Du erhältst eine Bestätigung per E-Mail zusammen mit der Rechnung.
Vielen Dank für deine Bestellung. Du erhältst eine Bestätigung per E-Mail
zusammen mit der Rechnung.
</div>
<h4 class="pt-2">Deine Daten</h4>
<TextInput v-model="form.pfadiname" label="Pfadiname (falls vorhanden)" :required="false" />
<TextInput
v-model="form.pfadiname"
label="Pfadiname"
:required="false"
/>
<BreakpointSpaceManager>
<TextInput v-model="form.first_name" label="Vorname" />
<TextInput v-model="form.last_name" label="Nachname" />
</BreakpointSpaceManager>

<TextInput v-model="form.email" label="E-Mail" />
<h4 class="pt-2">Bestellung</h4>
<SelectInput v-model="form.quantity" label="Ich hätte gerne ..." :options="options" />
<SelectInput
v-model="form.quantity"
label="Ich hätte gerne ..."
:options="options"
:required="true"
/>

<h4 class="pt-2">Lieferadresse</h4>
<BreakpointSpaceManager>
Expand All @@ -31,13 +41,12 @@
<TextInput v-model="form.delivery_town" label="Ort (Lieferung)" />
</BreakpointSpaceManager>
<button
type="submit"
type="submit"
class="bg-book-red hover:bg-chapter-red text-white py-2 px-4 rounded focus:outline-none focus:shadow-outline"
>
Bestellen
Bestellen
</button>

</form>
</form>
</template>

<script>
Expand All @@ -52,58 +61,67 @@ export default {
},
data() {
return {
success: false,
success: false,
form: {
first_name: undefined,
last_name: undefined,
pfadiname: undefined,
email: undefined,
delivery_first_name: undefined,
delivery_last_name: undefined,
delivery_street: undefined,
delivery_zip: undefined,
delivery_town: undefined,
pfadiname: undefined,
email: undefined,
delivery_first_name: undefined,
delivery_last_name: undefined,
delivery_street: undefined,
delivery_zip: undefined,
delivery_town: undefined,
quantity: 20,
},
options: [
{ label: "Sammelbestellung von 20 Stück à CHF 22: Total CHF 440", value: 20 },
{ label: "Sammelbestellung von 50 Stück à CHF 20: Total CHF 1000", value: 50 },
{ label: "Sammelbestellung von 100 Stück à CHF 18: Total CHF 1800", value: 100 },
{
label: "Sammelbestellung von 20 Stück à CHF 22: Total CHF 440",
value: 20,
},
{
label: "Sammelbestellung von 50 Stück à CHF 20: Total CHF 1000",
value: 50,
},
{
label: "Sammelbestellung von 100 Stück à CHF 18: Total CHF 1800",
value: 100,
},
],
};
},
methods: {
async submitForm() {
const backendURL = import.meta.env.VITE_BACKEND_URL
try {
const backendURL = import.meta.env.VITE_BACKEND_URL;
try {
const response = await fetch(`${backendURL}/order`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(this.form),
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(this.form),
});
if (!response.ok) {
throw new Error('Ein Fehler ist aufgetreten');
throw new Error("Ein Fehler ist aufgetreten");
}
const responseData = await response.json();
console.log('Success:', responseData);
this.form = {}
console.log("Success:", responseData);
this.form = {};
this.form.quantity = 20;
this.success = true;
const successElement = document.getElementById('successmessage')
successElement.classList.remove('hidden')
successElement.scrollIntoView({behavior: "smooth"});
const successElement = document.getElementById("successmessage");
successElement.classList.remove("hidden");
successElement.scrollIntoView({ behavior: "smooth" });
return responseData;
} catch (error) {
} catch (error) {
// Handle any errors that occurred during the request
console.error('Error:', error);
console.error("Error:", error);
throw error; // Rethrow the error if needed
}
}
},
},
};
Expand Down
5 changes: 4 additions & 1 deletion .vitepress/components/SelectInput.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<template>
<label class="block text-book-red text-sm font-bold mb-2 upper">
{{ label }} {{ required ? "*" : "" }}
</label>
<select
v-model="payload"
class="appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-book-red focus:border-chapter-red"
Expand All @@ -16,7 +19,7 @@
</template>
<script>
export default {
props: ["modelValue", "label", "placeholder", "options"],
props: ["modelValue", "label", "placeholder", "options", "required"],
computed: {
payload: {
get() {
Expand Down
2 changes: 1 addition & 1 deletion .vitepress/components/TextInput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="w-full">
<label class="block text-book-red text-sm font-bold mb-2 upper">
{{ label }}
{{ label }} {{ required ? "*" : "" }}
</label>
<input
v-model="payload"
Expand Down
1 change: 1 addition & 0 deletions api/app/Http/Controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function order(Request $request)
{

$validated = $request->validate([
'pfadiname' => 'nullable',
'first_name' => 'required',
'last_name' => 'required',
'email' => 'required|email',
Expand Down
3 changes: 2 additions & 1 deletion bestellen.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Sei bei den ersten, die bestellen und sichere dir für Sammelbestellungen den Ei

*keine Versandkosten*

Hinterlege deine E-Mailadresse und wir informieren dich, sobald du die Bestellung aufgeben kannst.

### Jetzt bestellen
Bitte fülle das Formular aus, um eine Sammelbestellung aufzugeben. Nach der Bestellung erhältst du per E-Mail eine Bestellbestätigung und die dazugehörige Rechnung, die wir dich bitten, zu begleichen. Sobald die Zahlung eingegangen ist, verschicken wir die Bücher.
<BulkOrderForm />

## Einzeln Bestellen
Expand Down

0 comments on commit bf53d2c

Please sign in to comment.