From 6174d895c9272ad196c582d96f260b6f8e343158 Mon Sep 17 00:00:00 2001 From: tree Date: Thu, 7 Apr 2022 19:38:45 +0200 Subject: [PATCH] Update --- src/lib/bundle.json | 2 +- src/lib/stores.js | 2 ++ src/routes/vstupenky.svelte | 54 +++++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/lib/bundle.json b/src/lib/bundle.json index 7364b68..9d29b61 120000 --- a/src/lib/bundle.json +++ b/src/lib/bundle.json @@ -1 +1 @@ -../utxo/dist/22/bundle.json \ No newline at end of file +../../../utxo/dist/22/bundle.json \ No newline at end of file diff --git a/src/lib/stores.js b/src/lib/stores.js index 054ac78..94bc3e8 100644 --- a/src/lib/stores.js +++ b/src/lib/stores.js @@ -7,6 +7,8 @@ export const orderTicketForm = writable({ email: '', tickets: [], paymentMethod: 'card', + tipPercent: 10, + tipCustom: '', }); export const userData = writable({ diff --git a/src/routes/vstupenky.svelte b/src/routes/vstupenky.svelte index 6e5751b..10bd62d 100644 --- a/src/routes/vstupenky.svelte +++ b/src/routes/vstupenky.svelte @@ -20,10 +20,18 @@ ] const maxTickets = 10 - const ticketPrice = 400 + const defaultTicketPrice = 400 const count = [...Array(maxTickets).keys()].map(i => i+1); + const tipPercentages = [ + [ 0, 'Bez dýška' ], + [ 5 ], + [ 10 ], + [ 20 ], + ] + + function selectPaymentMethod (el) { orderTicketForm.update(f => { f.paymentMethod = el.target.value @@ -42,6 +50,7 @@ } let tickets = 0 + orderTicketForm.subscribe(f => { if (f.count !== tickets) { tickets = f.count @@ -59,6 +68,31 @@ localStorage.setItem('orderTicketForm', JSON.stringify(f)) }) + function changeTip (perc) { + return () => { + orderTicketForm.update(of => { + of.tipPercent = perc + of.tipCustom = '' + return of + }) + } + } + + orderTicketForm.subscribe(of => { + const val = Number(of.tipCustom) + if (val === NaN || !val || val < 1 || !String(val).match(/^\d+$/)) { + of.tipCustom = '' + } + else if (val && val > 0 && of.tipPercent > 0) { + of.tipPercent = 0 + } + return of + }) + + $: ticketPrice = ($orderTicketForm.count * defaultTicketPrice) + $: tip = $orderTicketForm.tipPercent > 0 ? $orderTicketForm.tipPercent * (ticketPrice/100) : Number($orderTicketForm.tipCustom) + $: totalPrice = ticketPrice + tip + @@ -74,7 +108,7 @@

Nákup vstupenek

- Aktuální cena vstupenky: {ticketPrice} Kč / osobu + Aktuální cena vstupenky: {defaultTicketPrice} Kč / osobu
@@ -106,12 +140,12 @@
-
+
Email
Kontaktní email, na který budou zaslány vstupenky.
-
+
Údaje na jmenovku
Informace, které budou vytištěné na Vaší konferenční jmenovku. Tyto údaje jsou nepovinné a je možné je změnit později.
@@ -148,13 +182,23 @@ {/each}
+
+
Dýško pro organizátory
+
+ {#each tipPercentages as tp} + + {/each} +
Jiná částka:
+
+
- Celkem: {$orderTicketForm.count * ticketPrice} Kč + Celkem: {totalPrice} Kč
+
{JSON.stringify($orderTicketForm, null, 2)}