From 965aaeb097dc644a35dcfbfdfc1b323519d60969 Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Wed, 26 Jun 2024 11:46:53 +0800 Subject: [PATCH] feature: just create badge. Important thing is the await keyword --- src/assets/icon-new.svg | 4 ++ src/constants/constants.js | 2 + src/router/index.js | 2 +- src/stores/acctMgmt.js | 23 +++++++- .../{index.vue => AccountAdmin.vue} | 55 +++++++++++++++---- ...untEdit.vue => ModalAccountEditCreate.vue} | 7 +-- .../AccountManagement/ModalContainer.vue | 12 ++-- .../AccountManagement/ModalDeleteAlert.vue | 2 +- 8 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 src/assets/icon-new.svg rename src/views/AccountManagement/AccountAdmin/{index.vue => AccountAdmin.vue} (86%) rename src/views/AccountManagement/{ModalAccountEdit.vue => ModalAccountEditCreate.vue} (99%) diff --git a/src/assets/icon-new.svg b/src/assets/icon-new.svg new file mode 100644 index 0000000..dd90892 --- /dev/null +++ b/src/assets/icon-new.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/constants/constants.js b/src/constants/constants.js index 8cc2122..98c7b40 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -8,6 +8,8 @@ export const MODAL_ACCT_EDIT = 'MODAL_ACCT_EDIT'; export const MODAL_ACCT_INFO = 'MODAL_ACCT_INFO'; export const MODAL_DELETE = 'MODAL_DELETE'; +export const JUST_CREATE_ACCOUNT_HOT_DURATION_MINS = 2; + export const knownLayoutChartOption = { padding: { top: 16, diff --git a/src/router/index.js b/src/router/index.js index d6785d0..6d40897 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -8,7 +8,7 @@ import Map from '@/views/Discover/Map/index.vue'; import Conformance from '@/views/Discover/Conformance/index.vue'; import Performance from '@/views/Discover/Performance/index.vue'; import CompareDashboard from '@/views/Compare/Dashboard/index.vue'; -import AccountAdmin from '@/views/AccountManagement/AccountAdmin/index.vue'; +import AccountAdmin from '@/views/AccountManagement/AccountAdmin/AccountAdmin.vue'; import MemberArea from '@/views/MemberArea/index.vue'; import NotFound404 from '@/views/NotFound404.vue'; diff --git a/src/stores/acctMgmt.js b/src/stores/acctMgmt.js index c82ae20..43a43c4 100644 --- a/src/stores/acctMgmt.js +++ b/src/stores/acctMgmt.js @@ -1,5 +1,6 @@ import { defineStore } from "pinia"; import apiError from '@/module/apiError.js'; +import { JUST_CREATE_ACCOUNT_HOT_DURATION_MINS } from '@/constants/constants.js'; export default defineStore('acctMgmtStore', { state: () => ({ @@ -12,6 +13,9 @@ export default defineStore('acctMgmtStore', { response: { deleteAccount: null, }, + isOneAccountJustCreate: false, //如果有一個帳號剛剛建立,則會在列表上的第一列顯示這個帳號,並且右置一個徽章 + justCreateUsername: "", // unique username + shouldUpdateList: false, // 控制是否該刷新列表 }), getters: { }, @@ -90,6 +94,11 @@ export default defineStore('acctMgmtStore', { try{ const response = await this.$axios.post(apiCreateAccount, userToCreate); + if(response.status === 200) { + this.isOneAccountJustCreate = true; + this.justCreateUsername = userToCreate.username; + setTimeout(this.resetJustCreateFlag, JUST_CREATE_ACCOUNT_HOT_DURATION_MINS * 1000 * 60); + } } catch(error) { apiError(error, 'Failed to add a new account.'); @@ -132,7 +141,7 @@ export default defineStore('acctMgmtStore', { } } catch(error) { - apiError(error, 'Failed to get user detail.'); + //不需要跳出錯誤,因為如果是錯誤反而是好事,表示帳號是獨一的 return false; }; }, @@ -180,5 +189,17 @@ export default defineStore('acctMgmtStore', { userToChange.isDetailHovered = isDetailHovered; } }, + /** + * Reset isOneAccountJustCreate to false, causing the badge to disappear. + */ + resetJustCreateFlag(){ + this.isOneAccountJustCreate = false; + }, + /** Set the value of shouldUpdateList variable. + * @param {boolean} shouldUpdateBoolean + */ + setShouldUpdateList(shouldUpdateBoolean) { + this.shouldUpdateList = shouldUpdateBoolean; + }, }, }) \ No newline at end of file diff --git a/src/views/AccountManagement/AccountAdmin/index.vue b/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue similarity index 86% rename from src/views/AccountManagement/AccountAdmin/index.vue rename to src/views/AccountManagement/AccountAdmin/AccountAdmin.vue index 0082a75..043c476 100644 --- a/src/views/AccountManagement/AccountAdmin/index.vue +++ b/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue @@ -14,11 +14,15 @@ > @@ -100,7 +104,7 @@