Don't use API to update amount after a refilling query

This commit is contained in:
Antoine Bartuccio 2024-12-17 00:45:51 +01:00
parent 379527cd58
commit 66e5ef64fd
2 changed files with 8 additions and 15 deletions

View File

@ -1,5 +1,4 @@
import { exportToHtml } from "#core:utils/globals";
import { customerGetCustomer } from "#openapi";
interface CounterConfig {
csrfToken: string;
@ -33,19 +32,13 @@ exportToHtml("loadCounter", (config: CounterConfig) => {
return total / 100;
},
async updateBalance() {
this.customerBalance = (
await customerGetCustomer({
path: {
// biome-ignore lint/style/useNamingConvention: api is in snake_case
customer_id: config.customerId,
},
})
).data.amount;
},
async onRefillingSuccess() {
await this.updateBalance();
onRefillingSuccess(event: CustomEvent) {
if (event.type !== "htmx:after-request" || event.detail.failed) {
return;
}
this.customerBalance += Number.parseFloat(
(event.detail.target.querySelector("#id_amount") as HTMLInputElement).value,
);
document.getElementById("selling-accordion").click();
},

View File

@ -103,7 +103,7 @@
{% if refilling_fragment %}
<h5>{% trans %}Refilling{% endtrans %}</h5>
<div
@htmx:after-request="onRefillingSuccess()"
@htmx:after-request="onRefillingSuccess"
>
{{ refilling_fragment }}
</div>