From 3fe427fcc3d5c37ea06826f271e8c19f580ed791 Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Thu, 27 Jun 2024 11:39:44 +0800 Subject: [PATCH] update single account pinia state --- src/stores/acctMgmt.js | 11 +++++++++++ .../AccountManagement/AccountAdmin/AccountAdmin.vue | 9 +++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/stores/acctMgmt.js b/src/stores/acctMgmt.js index 1845a99..fc64828 100644 --- a/src/stores/acctMgmt.js +++ b/src/stores/acctMgmt.js @@ -225,5 +225,16 @@ export default defineStore('acctMgmtStore', { setShouldUpdateList(shouldUpdateBoolean) { this.shouldUpdateList = shouldUpdateBoolean; }, + /** Only update one single account in the pinia state. + * @param {object} userDataToReplace + */ + updateSingleAccountPiniaState(userDataToReplace){ + const userIndex = this.allUserAccoutList.findIndex(user => user.username === userDataToReplace.username); + if (userIndex !== -1) { + this.allUserAccoutList[userIndex] = { ...this.allUserAccoutList[userIndex], ...userDataToReplace }; + } else { + // Error handling here. + } + } }, }) \ No newline at end of file diff --git a/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue b/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue index 50b0475..8b7b5cf 100644 --- a/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue +++ b/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue @@ -274,13 +274,14 @@ export default { }; const setIsActiveInput = async(userData, inputIsActiveToSet) => { - await acctMgmtStore.editAccount(userData.username, { + const userDataToReplace = { username: userData.username, name: userData.name, is_active: inputIsActiveToSet, - }); - acctMgmtStore.setShouldUpdateList(true); - await toast.success(i18next.t("AcctMgmt.MsgAccountEdited")); + }; + await acctMgmtStore.editAccount(userData.username, userDataToReplace); + acctMgmtStore.updateSingleAccountPiniaState(userDataToReplace); + toast.success(i18next.t("AcctMgmt.MsgAccountEdited")); } onMounted(async () => {