delete account and later on modal closing effect.

This commit is contained in:
Cindy Chang
2024-06-24 10:09:39 +08:00
parent b55cc0a6d6
commit 00d086ff1d
7 changed files with 51 additions and 11 deletions

View File

@@ -7,7 +7,10 @@ export default defineStore('acctMgmtStore', {
isAcctMenuOpen: false,
currentViewingUser: {
detail: null,
}
},
response: {
deleteAccount: null,
},
}),
getters: {
},
@@ -92,6 +95,26 @@ export default defineStore('acctMgmtStore', {
apiError(error, 'Failed to add a new account.');
};
},
/**
* Delete an account from database.
* @param {string} userToDelete this value is unique in database.
* @returns the result of whether the deletion is success or not.
*/
async deleteAccount(userToDelete) {
const apiDelete = `/api/users/${userToDelete}`;
try{
const response = await this.$axios.delete(apiDelete);
if(response.status === 200) {
return true;
}
}
catch(error) {
console.log('error', error, error.status, error.code);
apiError(error, 'Failed to delete the account.');
return false;
};
},
/**
* Get user detail by unique username.
* @param {string} uniqueUsername

View File

@@ -1,5 +1,7 @@
import { defineStore } from 'pinia';
import { MODAL_ACCT_INFO, } from '@/constants/constants.js';
import { delaySecond } from "@/utils/timeUtil.js";
export const useModalStore = defineStore('modalStore', {
state: () => ({
isModalOpen: false,
@@ -10,7 +12,8 @@ export const useModalStore = defineStore('modalStore', {
this.isModalOpen = true;
this.whichModal = whichModal;
},
closeModal() {
async closeModal(){
await delaySecond(2);
this.isModalOpen = false;
},
},