Skip to content

Commit 22e4e30

Browse files
committed
refactor: enhance undelete identity functionality with confirmation dialog
- Updated the undeleteIdentity method in both trash.vue and trash/[_id].vue to include a confirmation dialog before restoring identities. - Improved user feedback with notifications for successful restoration and error handling. - Streamlined the code for better readability and maintainability.
1 parent 7f35375 commit 22e4e30

File tree

2 files changed

+65
-43
lines changed

2 files changed

+65
-43
lines changed

apps/web/src/pages/identities/trash.vue

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,30 +130,41 @@ export default defineNuxtComponent({
130130
},
131131
},
132132
methods: {
133-
async undeleteIdentity(identity) {
134-
try {
135-
await this.$http.post('/core/backends/undelete', {
136-
body: {
137-
payload: [identity._id],
138-
},
133+
undeleteIdentity(identity) {
134+
const { confirmButton, cancelDeleteButton } = useModalButtons()
135+
this.$q
136+
.dialog({
137+
title: 'Confirmation',
138+
message: 'Voulez-vous vraiment restaurer cette identité ?',
139+
ok: confirmButton.value,
140+
cancel: cancelDeleteButton.value,
141+
persistent: true,
139142
})
143+
.onOk(async () => {
144+
try {
145+
await this.$http.post('/core/backends/undelete', {
146+
body: {
147+
payload: [identity._id],
148+
},
149+
})
140150
141-
this.$q.notify({
142-
message: "L'identité a été restaurée.",
143-
color: 'positive',
144-
position: 'top-right',
145-
icon: 'mdi-check-circle-outline',
146-
})
147-
await this.fetchAllStateCount()
148-
this.refresh()
149-
} catch (error: any) {
150-
this.$q.notify({
151-
message: "Impossible de restaurer l'identité : " + (error?.response?._data?.message || 'erreur inconnue'),
152-
color: 'negative',
153-
position: 'top-right',
154-
icon: 'mdi-alert-circle-outline',
151+
this.$q.notify({
152+
message: "L'identité a été restaurée.",
153+
color: 'positive',
154+
position: 'top-right',
155+
icon: 'mdi-check-circle-outline',
156+
})
157+
await this.fetchAllStateCount()
158+
this.refresh()
159+
} catch (error: any) {
160+
this.$q.notify({
161+
message: "Impossible de restaurer l'identité : " + (error?.response?._data?.message || 'erreur inconnue'),
162+
color: 'negative',
163+
position: 'top-right',
164+
icon: 'mdi-alert-circle-outline',
165+
})
166+
}
155167
})
156-
}
157168
},
158169
},
159170
})

apps/web/src/pages/identities/trash/[_id].vue

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,42 @@ export default defineNuxtComponent({
125125
},
126126
},
127127
methods: {
128-
async undeleteIdentity() {
129-
try {
130-
await this.$http.post('/core/backends/undelete', {
131-
body: {
132-
payload: [this.identity._id],
133-
},
128+
undeleteIdentity() {
129+
const { confirmButton, cancelDeleteButton } = useModalButtons()
130+
this.$q
131+
.dialog({
132+
title: 'Confirmation',
133+
message: 'Voulez-vous vraiment restaurer cette identité ?',
134+
ok: confirmButton.value,
135+
cancel: cancelDeleteButton.value,
136+
persistent: true,
134137
})
138+
.onOk(async () => {
139+
try {
140+
await this.$http.post('/core/backends/undelete', {
141+
body: {
142+
payload: [this.identity._id],
143+
},
144+
})
135145
136-
this.$q.notify({
137-
message: "L'identité a été restaurée.",
138-
color: 'positive',
139-
position: 'top-right',
140-
icon: 'mdi-check-circle-outline',
141-
})
142-
await this.fetchAllStateCount()
143-
this.$emit('refresh')
144-
this.navigateToTab('/identities/trash')
145-
} catch (error: any) {
146-
this.$q.notify({
147-
message: "Impossible de restaurer l'identité : " + (error?.response?._data?.message || 'erreur inconnue'),
148-
color: 'negative',
149-
position: 'top-right',
150-
icon: 'mdi-alert-circle-outline',
146+
this.$q.notify({
147+
message: "L'identité a été restaurée.",
148+
color: 'positive',
149+
position: 'top-right',
150+
icon: 'mdi-check-circle-outline',
151+
})
152+
await this.fetchAllStateCount()
153+
this.$emit('refresh')
154+
this.navigateToTab('/identities/trash')
155+
} catch (error: any) {
156+
this.$q.notify({
157+
message: "Impossible de restaurer l'identité : " + (error?.response?._data?.message || 'erreur inconnue'),
158+
color: 'negative',
159+
position: 'top-right',
160+
icon: 'mdi-alert-circle-outline',
161+
})
162+
}
151163
})
152-
}
153164
},
154165
async save() {
155166
try {

0 commit comments

Comments
 (0)