delete account and later on modal closing effect.
This commit is contained in:
@@ -35,7 +35,8 @@
|
|||||||
"DelteQuestion": "Are you sure to delete ?",
|
"DelteQuestion": "Are you sure to delete ?",
|
||||||
"DeleteFirstClause": "deletion is irreversible !",
|
"DeleteFirstClause": "deletion is irreversible !",
|
||||||
"DeleteSecondClause": "You will delete all data and content on this account.",
|
"DeleteSecondClause": "You will delete all data and content on this account.",
|
||||||
"MsgAccountAdded": "Account added."
|
"MsgAccountAdded": "Account added.",
|
||||||
|
"MsgAccountDeleteSuccess": "Account deleted."
|
||||||
},
|
},
|
||||||
"Compare": {
|
"Compare": {
|
||||||
"timeUsage": "Time Usage",
|
"timeUsage": "Time Usage",
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ export default defineStore('acctMgmtStore', {
|
|||||||
isAcctMenuOpen: false,
|
isAcctMenuOpen: false,
|
||||||
currentViewingUser: {
|
currentViewingUser: {
|
||||||
detail: null,
|
detail: null,
|
||||||
}
|
},
|
||||||
|
response: {
|
||||||
|
deleteAccount: null,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
},
|
},
|
||||||
@@ -92,6 +95,26 @@ export default defineStore('acctMgmtStore', {
|
|||||||
apiError(error, 'Failed to add a new account.');
|
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.
|
* Get user detail by unique username.
|
||||||
* @param {string} uniqueUsername
|
* @param {string} uniqueUsername
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { MODAL_ACCT_INFO, } from '@/constants/constants.js';
|
import { MODAL_ACCT_INFO, } from '@/constants/constants.js';
|
||||||
|
import { delaySecond } from "@/utils/timeUtil.js";
|
||||||
|
|
||||||
export const useModalStore = defineStore('modalStore', {
|
export const useModalStore = defineStore('modalStore', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
isModalOpen: false,
|
isModalOpen: false,
|
||||||
@@ -10,7 +12,8 @@ export const useModalStore = defineStore('modalStore', {
|
|||||||
this.isModalOpen = true;
|
this.isModalOpen = true;
|
||||||
this.whichModal = whichModal;
|
this.whichModal = whichModal;
|
||||||
},
|
},
|
||||||
closeModal() {
|
async closeModal(){
|
||||||
|
await delaySecond(2);
|
||||||
this.isModalOpen = false;
|
this.isModalOpen = false;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
4
src/utils/timeUtil.js
Normal file
4
src/utils/timeUtil.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export const delaySecond = (s = 2.5) => {
|
||||||
|
return new Promise((resolve) =>
|
||||||
|
setTimeout(resolve, s * 1000)
|
||||||
|
);}
|
||||||
@@ -219,6 +219,7 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onDeleteBtnClick = (usernameToDelete) => {
|
const onDeleteBtnClick = (usernameToDelete) => {
|
||||||
|
acctMgmtStore.setCurrentViewingUser(usernameToDelete);
|
||||||
modalStore.openModal(MODAL_DELETE);
|
modalStore.openModal(MODAL_DELETE);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -199,13 +199,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
//TODO: 這邊要記得回來加一個判斷帳號是否已經存在的邏輯
|
//TODO: 這邊要記得回來加一個判斷帳號是否已經存在的邏輯
|
||||||
checkAccountIsUnique();
|
checkAccountIsUnique();
|
||||||
console.log('input content to feed in',
|
|
||||||
inputUserAccount.value,
|
|
||||||
inputPwd.value,
|
|
||||||
inputName.value,
|
|
||||||
isSetAsAdminChecked.value,
|
|
||||||
isSetActivedChecked.value,
|
|
||||||
);
|
|
||||||
await acctMgmtStore.createNewAccount({
|
await acctMgmtStore.createNewAccount({
|
||||||
username: inputUserAccount.value,
|
username: inputUserAccount.value,
|
||||||
password: inputPwd.value,
|
password: inputPwd.value,
|
||||||
|
|||||||
@@ -18,7 +18,9 @@
|
|||||||
{{ i18next.t("No") }}
|
{{ i18next.t("No") }}
|
||||||
</button>
|
</button>
|
||||||
<button id="sure_to_delete_acct_btn" class="flex justify-center items-center rounded-full cursor-pointer w-[100px] h-[40px]
|
<button id="sure_to_delete_acct_btn" class="flex justify-center items-center rounded-full cursor-pointer w-[100px] h-[40px]
|
||||||
border-2 border-[#FF3366] text-[#FF3366]">
|
border-2 border-[#FF3366] text-[#FF3366]"
|
||||||
|
@click="onDeleteConfirmBtnClick"
|
||||||
|
>
|
||||||
{{ i18next.t("Yes") }}
|
{{ i18next.t("Yes") }}
|
||||||
</button>
|
</button>
|
||||||
</footer>
|
</footer>
|
||||||
@@ -28,13 +30,25 @@
|
|||||||
<script>
|
<script>
|
||||||
import { defineComponent, ref, computed, onBeforeMount, watch, } from 'vue';
|
import { defineComponent, ref, computed, onBeforeMount, watch, } from 'vue';
|
||||||
import { useModalStore } from '@/stores/modal.js';
|
import { useModalStore } from '@/stores/modal.js';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
import useAcctMgmtStore from '@/stores/acctMgmt.js';
|
import useAcctMgmtStore from '@/stores/acctMgmt.js';
|
||||||
import i18next from '@/i18n/i18n.js';
|
import i18next from '@/i18n/i18n.js';
|
||||||
|
import { useToast } from 'vue-toast-notification';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
setup() {
|
setup() {
|
||||||
const acctMgmtStore = useAcctMgmtStore();
|
const acctMgmtStore = useAcctMgmtStore();
|
||||||
const modalStore = useModalStore();
|
const modalStore = useModalStore();
|
||||||
|
const toast = useToast();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const onDeleteConfirmBtnClick = async() => {
|
||||||
|
if(acctMgmtStore.deleteAccount(acctMgmtStore.currentViewingUser.username)){
|
||||||
|
toast.success(i18next.t("AcctMgmt.MsgAccountDeleteSuccess"));
|
||||||
|
modalStore.closeModal();
|
||||||
|
router.push("/account/account-admin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onNoBtnClick = () => {
|
const onNoBtnClick = () => {
|
||||||
modalStore.closeModal();
|
modalStore.closeModal();
|
||||||
@@ -42,6 +56,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
i18next,
|
i18next,
|
||||||
|
onDeleteConfirmBtnClick,
|
||||||
onNoBtnClick,
|
onNoBtnClick,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user