|
| 1 | +<template> |
| 2 | + <v-tooltip location="bottom" class="text-center" :disabled="!hasNamespace"> |
| 3 | + <template v-slot:activator="{ props }"> |
| 4 | + <div v-bind="props"> |
| 5 | + <v-btn |
| 6 | + :disabled="hasNamespace" |
| 7 | + color="red darken-1" |
| 8 | + variant="outlined" |
| 9 | + data-test="delete-dialog-btn" |
| 10 | + @click="open()" |
| 11 | + > |
| 12 | + Delete Account |
| 13 | + </v-btn> |
| 14 | + </div> |
| 15 | + </template> |
| 16 | + <span> All namespaces must be deleted before you can delete your account. </span> |
| 17 | + </v-tooltip> |
| 18 | + |
| 19 | + <v-dialog v-model="dialog" max-width="540"> |
| 20 | + <v-card data-test="user-delete-dialog" class="bg-v-theme-surface"> |
| 21 | + <v-card-title class="text-h5 pa-4 bg-primary" data-test=title> |
| 22 | + Confirm Account Deletion |
| 23 | + </v-card-title> |
| 24 | + |
| 25 | + <v-card-text class="mt-4 mb-3 pb-1" data-test="subtitle"> |
| 26 | + <div> |
| 27 | + <p class="mb-2"> |
| 28 | + Are you sure you want to delete your account? This action cannot be undone. |
| 29 | + </p> |
| 30 | + </div> |
| 31 | + </v-card-text> |
| 32 | + |
| 33 | + <v-card-actions> |
| 34 | + <v-spacer /> |
| 35 | + |
| 36 | + <v-btn variant="text" data-test="close-btn" @click="dialog = !dialog"> |
| 37 | + Cancel |
| 38 | + </v-btn> |
| 39 | + |
| 40 | + <v-btn |
| 41 | + color="red darken-1" |
| 42 | + variant="text" |
| 43 | + data-test="delete-user-btn" |
| 44 | + @click="deleteAccount()" |
| 45 | + > |
| 46 | + Delete Account |
| 47 | + </v-btn> |
| 48 | + </v-card-actions> |
| 49 | + </v-card> |
| 50 | + </v-dialog> |
| 51 | +</template> |
| 52 | + |
| 53 | +<script setup lang="ts"> |
| 54 | +import { ref, computed } from "vue"; |
| 55 | +import { useRouter } from "vue-router"; |
| 56 | +import { useStore } from "../../store"; |
| 57 | +import { |
| 58 | + INotificationsError, |
| 59 | + INotificationsSuccess, |
| 60 | +} from "@/interfaces/INotifications"; |
| 61 | +import handleError from "@/utils/handleError"; |
| 62 | +
|
| 63 | +const store = useStore(); |
| 64 | +const router = useRouter(); |
| 65 | +const dialog = ref(false); |
| 66 | +
|
| 67 | +const hasNamespace = computed(() => store.getters["namespaces/getNumberNamespaces"] > 0); |
| 68 | +
|
| 69 | +const open = () => { |
| 70 | + dialog.value = true; |
| 71 | +}; |
| 72 | +
|
| 73 | +const deleteAccount = async () => { |
| 74 | + try { |
| 75 | + dialog.value = !dialog.value; |
| 76 | +
|
| 77 | + await store.dispatch("auth/deleteUser"); |
| 78 | +
|
| 79 | + store.dispatch( |
| 80 | + "snackbar/showSnackbarSuccessAction", |
| 81 | + INotificationsSuccess.deleteAccount, |
| 82 | + ); |
| 83 | +
|
| 84 | + router.push({ name: "Login" }); |
| 85 | + } catch (error: unknown) { |
| 86 | + store.dispatch( |
| 87 | + "snackbar/showSnackbarErrorAction", |
| 88 | + INotificationsError.deleteAccount, |
| 89 | + ); |
| 90 | + handleError(error); |
| 91 | + } |
| 92 | +}; |
| 93 | +</script> |
0 commit comments