diff --git a/src/components/donations/AddDonationPaymentModal.svelte b/src/components/donations/AddDonationPaymentModal.svelte index 77307752..dd018fd4 100644 --- a/src/components/donations/AddDonationPaymentModal.svelte +++ b/src/components/donations/AddDonationPaymentModal.svelte @@ -2,38 +2,24 @@ import { _ } from "svelte-i18n"; import { clickOutside } from "../base/outsideclick"; import { focusTrap } from "svelte-focus-trap"; - import { RunnerCardService, RunnerService } from "@odit/lfk-client-js"; + import { DonationService, RunnerCardService, RunnerService } from "@odit/lfk-client-js"; import Select from "svelte-select"; import Toastify from "toastify-js"; - export let edit_modal_open; - export let current_cards; - export let runner = {}; + export let payment_modal_open = false; + export let current_donations = []; export let editable = {}; export let original_data = {}; - const getRunnerLabel = (option) => - option.firstname + " " + (option.middlename || "") + " " + option.lastname; - const filterRunners = (label, filterText, option) => - label.toLowerCase().includes(filterText.toLowerCase()) || - option.value.toString().startsWith(filterText.toLowerCase()); + export let amount_input = 0; function focus(el) { el.focus(); } - $: runners = []; - $: enabled = true; - $: processed_last_submit = true; - RunnerService.runnerControllerGetAll().then((val) => { - runners = val.map((r) => { - return { label: getRunnerLabel(r), value: r }; - }); - }); - $: createbtnenabled = !( - JSON.stringify(editable) === JSON.stringify(original_data) - ); + $: createbtnenabled = is_amount_valid && !(amount_input*100 == original_data.paidAmount) + $: is_amount_valid = amount_input > 0; (() => { document.onkeydown = (e) => { e = e || window.event; if (e.key === "Escape") { - edit_modal_open = false; + payment_modal_open = false; } if (e.keyCode === 13) { if (createbtnenabled === true) { @@ -47,24 +33,24 @@ if (processed_last_submit === true) { processed_last_submit = false; const toast = Toastify({ - text: $_("updating-card"), + text: "Updating Donation", duration: -1, }).showToast(); - RunnerCardService.runnerCardControllerPut(original_data.id, editable) + if(editable.responseType == "DISTANCEDONATION" ){ + DonationService.donationControllerPutDistance(original_data.id, editable) .then((result) => { let id = original_data.id; - runner = {}; editable = {}; original_data = {}; - edit_modal_open = false; + payment_modal_open = false; // Toastify({ - text: $_("card-updated"), + text: "Donation updated", duration: 500, backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", }).showToast(); - current_cards[current_cards.findIndex((c) => c.id === id)] = result; - current_cards = current_cards; + current_donations[current_donations.findIndex((c) => c.id === id)] = result; + current_donations = current_donations; }) .catch((err) => { // @@ -75,16 +61,42 @@ toast.hideToast(); }); } + } + else{ + DonationService.donationControllerPutFixed(original_data.id, editable) + .then((result) => { + let id = original_data.id; + editable = {}; + original_data = {}; + payment_modal_open = false; + // + Toastify({ + text: "Donation updated", + duration: 500, + backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", + }).showToast(); + current_donations[current_donations.findIndex((c) => c.id === id)] = result; + current_donations = current_donations; + }) + .catch((err) => { + // + }) + .finally(() => { + processed_last_submit = true; + // + toast.hideToast(); + }); + } } -{#if edit_modal_open} +{#if payment_modal_open}
- {$_('you-can-provide-a-runner-but-you-dont-have-to')} + You can update the donation's paid amount manually or use the TODO button to use the donation's exact amount.
- { - editable.enabled = !editable.enabled; - }} - name="enabled" - type="checkbox" - checked={editable.enabled} - class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" /> - {$_('this-card-is')} - {#if editable.enabled} - {$_('enabled')} - {:else}{$_('disabled')}{/if} -