feature: just create badge. Important thing is the await keyword
This commit is contained in:
@@ -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;
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user