diff --git a/web/src/components/Modal.vue b/web/src/components/Modal.vue index faea3ca..5f0c076 100644 --- a/web/src/components/Modal.vue +++ b/web/src/components/Modal.vue @@ -7,7 +7,7 @@ const props = defineProps<{ }>(); const emit = defineEmits<{ - (e: 'submit'): void, + (e: 'submit', event : {cancel:boolean}): boolean, (e: 'open'): void, }>(); @@ -20,8 +20,12 @@ function openDialog() { visible.value = true; }; function submitDialog() { + const e = {cancel: false}; + emit("submit", e); + if(e.cancel) + return; + visible.value = false; - emit("submit"); } diff --git a/web/src/dialogs/EditAccount.vue b/web/src/dialogs/EditAccount.vue index 43b0456..d8e3515 100644 --- a/web/src/dialogs/EditAccount.vue +++ b/web/src/dialogs/EditAccount.vue @@ -14,8 +14,16 @@ const CurrentAccount = computed(() => accountStore.CurrentAccount); const accountName = ref(""); const accountOnBudget = ref(true); const accountOpen = ref(true); +const error = ref(""); -function editAccount(e : any) { +function editAccount(e : {cancel:boolean}) : boolean { + if(CurrentAccount.value?.ClearedBalance != 0 && !accountOpen.value){ + e.cancel = true; + error.value = "Cannot close account with balance"; + return false; + } + + error.value = ""; accountStore.EditAccount(CurrentAccount.value?.ID ?? "", accountName.value, accountOnBudget.value, accountOpen.value); // account closed, move to Budget @@ -23,6 +31,7 @@ function editAccount(e : any) { const currentBudgetID = useBudgetsStore().CurrentBudgetID; router.replace('/budget/'+currentBudgetID+'/budgeting'); } + return true; } function openEditAccount(e : any) { @@ -37,7 +46,7 @@ function openEditAccount(e : any) { ✎