5656<script >
5757import { ref , reactive } from ' vue'
5858import { api } from ' @/api'
59+
5960export default {
6061 name: ' DeleteAccount' ,
6162 props: {
@@ -66,7 +67,8 @@ export default {
6667 },
6768 data () {
6869 return {
69- error: ' '
70+ error: ' ' ,
71+ isDeleting: false
7072 }
7173 },
7274 created () {
@@ -85,6 +87,7 @@ export default {
8587 },
8688 handleSubmit (e ) {
8789 e .preventDefault ()
90+ if (this .isDeleting ) return // Prevent double submission
8891 this .formRef .value .validate ().then (async () => {
8992 if (this .form .name !== this .resource .name ) {
9093 this .error = ` ${ this .$t (' message.error.account.delete.name.mismatch' )} `
@@ -93,22 +96,54 @@ export default {
9396 if (this .hasActiveResources ) {
9497 return
9598 }
96- api (' deleteAccount' , {
97- id: this .resource .id
98- }).then (response => {
99- this .$pollJob ({
100- jobId: response .deleteaccountresponse .jobid ,
101- title: this .$t (' label.action.delete.account' ),
102- description: this .resource .id ,
103- successMessage: ` ${ this .$t (' message.delete.account.success' )} - ${ this .resource .name } ` ,
104- errorMessage: ` ${ this .$t (' message.delete.account.failed' )} - ${ this .resource .name } ` ,
105- loadingMessage: ` ${ this .$t (' message.delete.account.processing' )} - ${ this .resource .name } ` ,
106- catchMessage: this .$t (' error.fetching.async.job.result' )
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+ })
107146 })
108- this .closeModal ()
109- }).catch (error => {
110- this .$notifyError (error)
111- })
112147 }).catch ((error ) => {
113148 this .formRef .value .scrollToField (error .errorFields [0 ].name )
114149 })
0 commit comments