From 8c3f0092d2735b1c85976f4e6955780b1035f68a Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Mon, 19 May 2025 21:07:12 +0200 Subject: [PATCH] refactor(donation): Refactor donor selection and add new donor creation functionality --- src/components/tools/DonationCreate.svelte | 475 ++++++++++++--------- 1 file changed, 266 insertions(+), 209 deletions(-) diff --git a/src/components/tools/DonationCreate.svelte b/src/components/tools/DonationCreate.svelte index 3602200f..87672ad6 100644 --- a/src/components/tools/DonationCreate.svelte +++ b/src/components/tools/DonationCreate.svelte @@ -5,7 +5,6 @@ DonorService, RunnerService, } from "@odit/lfk-client-js"; - import Svelecte from "svelecte"; import Select from "svelte-select"; import toast from "svelte-french-toast"; @@ -21,8 +20,9 @@ country: "Germany", }; let amount = 0; - let lastname = ""; let address_checked = false; + let donor_create_new = false; + let last_created = null; RunnerService.runnerControllerGetAll() .then((val) => { @@ -38,7 +38,7 @@ DonorService.donorControllerGetAll() .then((val) => { donors = val.map((r) => { - return { label: getDonorlabel(r), value: r }; + return { label: getRunnerLabel(r), value: r }; }); console.log("refreshed donors"); setTimeout(() => { @@ -54,8 +54,6 @@ const getRunnerLabel = (option) => option.firstname + " " + (option.middlename || "") + " " + option.lastname; - const getDonorlabel = (option) => `${option.firstname} (${option.lastname})`; - const filterRunners = (label, filterText, option) => { if (filterText.startsWith("#")) { return option.value.id == parseInt(filterText.replace("#", "")); @@ -70,221 +68,280 @@ runnerinfo = { id: 0, firstname: "", lastname: "" }; donorinfo = { id: 0, firstname: "", lastname: "" }; amount = 0; + address_checked = false; + donor_create_new = false; }

{$_("fast_donation_create")}

-
-
-

- {$_("runner")} -

- { - donorinfo.lastname = e.target.value; - }} - type="text" - name="lastname" - class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" - /> -
-
-
- {#if donorinfo.id == 0} - - {:else} - - {/if} -
-
- -
-
- {#if address_checked} -
- - -
-
- - -
-
- - -
-
- - +
+
+ {#if last_created} +
+

+ {$_("last-created-donation")}: #{last_created.id}: {last_created.amountPerDistance / + 100} € für {getRunnerLabel(last_created.runner)} von {getRunnerLabel( + last_created.donor + )} +

{/if} -
-
-

- {$_("amount-per-kilometer")} -

-
- 0} - class:focus:border-red-500={!amount > 0} - class:focus:ring-red-500={!amount > 0} - bind:value={amount} - type="number" - step="0.01" - name="donation_amount_eur" - class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" - placeholder="2.00" + + +
+

{$_("runner")}

+ 0} + class:focus:border-red-500={!amount > 0} + class:focus:ring-red-500={!amount > 0} + bind:value={amount} + type="number" + step="0.01" + name="donation_amount_eur" + class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" + placeholder="2.00" + /> + +
+
+ + +
+

{$_("donor")}

+ + +
+
+ + +
+
+ + {#if !donor_create_new} + +
+ + +
+ + +
+ + +
+
+ +
+
+ +
+
+ + {#if address_checked} + +
+
+ + +
+ +
+ + +
+ +
+
+ + +
+ +
+ + +
+
+
+ {/if} +
+ {/if} +
+ +
+ + + DonationService.donationControllerPostDistance({ + donor: donorinfo.id, + runner: runnerinfo.id, + amountPerDistance: amount * 100, + }) + .then((data) => { + last_created = data; + toast.success($_("donation-created-successfully")); + resetAll(); + loadDonors(); + }) + .catch((err) => { + console.error("Error creating donation:", err); + toast.error($_("error-creating-donation")); + }); + }} + > + {$_("create")} + +