From 57e468f1f4a4725eb43ea05a1adbde4097132fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 18 Apr 2021 00:42:21 +0200 Subject: [PATCH] [balance] modify limit of one user in admin page --- src/plugins/balance/pages/Admin.vue | 33 ++++++++++++++++++++++++++++- src/plugins/balance/store.ts | 10 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/plugins/balance/pages/Admin.vue b/src/plugins/balance/pages/Admin.vue index cd41368..ad2d5aa 100644 --- a/src/plugins/balance/pages/Admin.vue +++ b/src/plugins/balance/pages/Admin.vue @@ -21,7 +21,28 @@ {{ getName(props.row.userid) }} - {{ getLimit(props.row.userid) }}€ + + {{ getLimit(props.row.userid) }}€ + + + + {{ getBalance(props.row.debit, props.row.credit) }}€ @@ -148,6 +169,15 @@ export default defineComponent({ updateBalance(receiver); } + function setLimit(userid: string) { + setTimeout(() => { + void store.setLimit(limit.value, userid); + }, 50); + setTimeout(() => { + limit.value = undefined; + }, 100); + } + const tab = ref('add'); return { @@ -157,6 +187,7 @@ export default defineComponent({ setLimits: store.setLimits, getName, getLimit, + setLimit, getBalance, updateBalance, updateBalances, diff --git a/src/plugins/balance/store.ts b/src/plugins/balance/store.ts index 4a11fbc..9ad6cc5 100644 --- a/src/plugins/balance/store.ts +++ b/src/plugins/balance/store.ts @@ -187,5 +187,15 @@ export const useBalanceStore = defineStore({ } }); }, + + async setLimit(limit: number, userid: string) { + await api.put(`users/${userid}/balance/limit`, { limit }); + const user_limit = this.user_limits.find((a) => a.userid === userid); + if (user_limit) { + user_limit.limit = limit; + } else { + this.user_limits.push({ userid, limit }); + } + }, }, });