|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +<template> |
| 19 | + <a-form |
| 20 | + class="form" |
| 21 | + :ref="formRef" |
| 22 | + :model="form" |
| 23 | + :rules="rules" |
| 24 | + layout="vertical" |
| 25 | + @finish="handleSubmit" |
| 26 | + v-ctrl-enter="handleSubmit" |
| 27 | + > |
| 28 | + <div style="margin-bottom: 10px"> |
| 29 | + <a-alert type="warning"> |
| 30 | + <template #message> |
| 31 | + <div v-html="$t('message.delete.account.warning')"></div> |
| 32 | + </template> |
| 33 | + </a-alert> |
| 34 | + </div> |
| 35 | + <div style="margin-bottom: 10px"> |
| 36 | + <a-alert> |
| 37 | + <template #message> |
| 38 | + <div v-html="$t('message.delete.account.confirm')"></div> |
| 39 | + </template> |
| 40 | + </a-alert> |
| 41 | + </div> |
| 42 | + <a-form-item name="name" ref="name"> |
| 43 | + <a-input |
| 44 | + v-model:value="form.name" |
| 45 | + :placeholder="$t('label.enter.account.name')" |
| 46 | + style="width: 100%"/> |
| 47 | + </a-form-item> |
| 48 | + <p v-if="error" class="error">{{ error }}</p> |
| 49 | + <div :span="24" class="actions"> |
| 50 | + <a-button @click="closeModal">{{ $t('label.cancel') }}</a-button> |
| 51 | + <a-button type="primary" ref="submit" @click="handleSubmit">{{ $t('label.ok') }}</a-button> |
| 52 | + </div> |
| 53 | + </a-form> |
| 54 | +</template> |
| 55 | + |
| 56 | +<script> |
| 57 | +import { ref, reactive } from 'vue' |
| 58 | +import { api } from '@/api' |
| 59 | +
|
| 60 | +export default { |
| 61 | + name: 'DeleteAccount', |
| 62 | + props: { |
| 63 | + resource: { |
| 64 | + type: Object, |
| 65 | + required: true |
| 66 | + } |
| 67 | + }, |
| 68 | + data () { |
| 69 | + return { |
| 70 | + error: '', |
| 71 | + isDeleting: false |
| 72 | + } |
| 73 | + }, |
| 74 | + created () { |
| 75 | + this.initForm() |
| 76 | + }, |
| 77 | + methods: { |
| 78 | + initForm () { |
| 79 | + this.formRef = ref() |
| 80 | + this.form = reactive({}) |
| 81 | + this.rules = reactive({ |
| 82 | + name: [{ required: true, message: this.$t('label.required') }] |
| 83 | + }) |
| 84 | + }, |
| 85 | + closeModal () { |
| 86 | + this.$emit('close-action') |
| 87 | + }, |
| 88 | + handleSubmit (e) { |
| 89 | + e.preventDefault() |
| 90 | + if (this.isDeleting) return // Prevent double submission |
| 91 | + this.formRef.value.validate().then(async () => { |
| 92 | + if (this.form.name !== this.resource.name) { |
| 93 | + this.error = `${this.$t('message.error.account.delete.name.mismatch')}` |
| 94 | + return |
| 95 | + } |
| 96 | + if (this.hasActiveResources) { |
| 97 | + return |
| 98 | + } |
| 99 | + this.isDeleting = true |
| 100 | + // Store the account ID and name before we close the modal |
| 101 | + const accountId = this.resource.id |
| 102 | + const accountName = this.resource.name |
| 103 | + // Close the modal first |
| 104 | + this.closeModal() |
| 105 | + // Immediately navigate to the accounts page to avoid "unable to find account" errors |
| 106 | + this.$router.push({ path: '/account' }) |
| 107 | + .then(() => { |
| 108 | + // After successful navigation, start the deletion job |
| 109 | + api('deleteAccount', { |
| 110 | + id: accountId |
| 111 | + }).then(response => { |
| 112 | + this.$pollJob({ |
| 113 | + jobId: response.deleteaccountresponse.jobid, |
| 114 | + title: this.$t('label.action.delete.account'), |
| 115 | + description: accountId, |
| 116 | + successMessage: `${this.$t('message.delete.account.success')} - ${accountName}`, |
| 117 | + errorMessage: `${this.$t('message.delete.account.failed')} - ${accountName}`, |
| 118 | + loadingMessage: `${this.$t('message.delete.account.processing')} - ${accountName}`, |
| 119 | + catchMessage: this.$t('error.fetching.async.job.result') |
| 120 | + }) |
| 121 | + }).catch(error => { |
| 122 | + this.$notifyError(error) |
| 123 | + this.isDeleting = false |
| 124 | + }) |
| 125 | + }) |
| 126 | + .catch(err => { |
| 127 | + console.error('Navigation failed:', err) |
| 128 | + this.isDeleting = false |
| 129 | + // If navigation fails, still try to delete the account |
| 130 | + // but don't navigate afterwards |
| 131 | + api('deleteAccount', { |
| 132 | + id: accountId |
| 133 | + }).then(response => { |
| 134 | + this.$pollJob({ |
| 135 | + jobId: response.deleteaccountresponse.jobid, |
| 136 | + title: this.$t('label.action.delete.account'), |
| 137 | + description: accountId, |
| 138 | + successMessage: `${this.$t('message.delete.account.success')} - ${accountName}`, |
| 139 | + errorMessage: `${this.$t('message.delete.account.failed')} - ${accountName}`, |
| 140 | + loadingMessage: `${this.$t('message.delete.account.processing')} - ${accountName}`, |
| 141 | + catchMessage: this.$t('error.fetching.async.job.result') |
| 142 | + }) |
| 143 | + }).catch(error => { |
| 144 | + this.$notifyError(error) |
| 145 | + }) |
| 146 | + }) |
| 147 | + }).catch((error) => { |
| 148 | + this.formRef.value.scrollToField(error.errorFields[0].name) |
| 149 | + }) |
| 150 | + } |
| 151 | + } |
| 152 | +} |
| 153 | +</script> |
| 154 | + |
| 155 | +<style lang="scss" scoped> |
| 156 | +.form { |
| 157 | + width: 80vw; |
| 158 | + @media (min-width: 500px) { |
| 159 | + width: 400px; |
| 160 | + } |
| 161 | +} |
| 162 | +.actions { |
| 163 | + display: flex; |
| 164 | + justify-content: flex-end; |
| 165 | + margin-top: 20px; |
| 166 | + button { |
| 167 | + &:not(:last-child) { |
| 168 | + margin-right: 10px; |
| 169 | + } |
| 170 | + } |
| 171 | +} |
| 172 | +.error { |
| 173 | + color: red; |
| 174 | + margin-top: 10px; |
| 175 | +} |
| 176 | +</style> |
0 commit comments