@@ -132,7 +132,7 @@ import TagIcon from 'vue-material-design-icons/TagOutline.vue'
132132import IconDelete from ' vue-material-design-icons/TrashCanOutline.vue'
133133import Action from ' ./Action.vue'
134134import logger from ' ../../logger.js'
135- import { createActionStep , deleteActionStep , findAllStepsForAction , updateActionStep } from ' ../../service/QuickActionsService.js'
135+ import { createActionStep , deleteActionStep , updateActionStep } from ' ../../service/QuickActionsService.js'
136136import useMainStore from ' ../../store/mainStore.js'
137137
138138export default {
@@ -228,8 +228,8 @@ export default {
228228 this .localAction = { id: null , name: ' ' }
229229 this .actions = []
230230 } else {
231- this .localAction = { ... action }
232- this .actions = await findAllStepsForAction ( action .id )
231+ this .localAction = { id : action . id , name : action . name , accountId : action . accountId }
232+ this .actions = action .actionSteps
233233 this .highestOrder = Math .max (... this .actions .map ((a ) => a .order ), 0 )
234234 this .editMode = true
235235 }
@@ -260,7 +260,7 @@ export default {
260260 for (const [index , action ] of this .actions .entries ()) {
261261 if (action? .id !== null && action? .id !== undefined ) {
262262 try {
263- await updateActionStep (action .id , action .name , action .order , action? .tagId , action? .mailboxId )
263+ this . actions [index] = await updateActionStep (action .id , action .name , action .order , action? .tagId , action? .mailboxId )
264264 } catch (error) {
265265 logger .error (' Could not update quick action step' , {
266266 error,
@@ -273,10 +273,12 @@ export default {
273273 this .actions [index] = createdStep
274274 }
275275 }
276+ this .localAction = quickAction
276277 }
277278 showSuccess (t (' mail' , ' Quick action updated' ))
278279 } else {
279280 let quickAction
281+ const createdSteps = []
280282 try {
281283 quickAction = await this .mainStore .createQuickAction (this .localAction .name , this .account .id )
282284 } catch (error) {
@@ -288,17 +290,23 @@ export default {
288290 }
289291 try {
290292 for (const action of this .actions ) {
291- await createActionStep (action .name , action .order , quickAction .id , action? .tagId , action? .mailboxId )
293+ const createdStep = await createActionStep (action .name , action .order , quickAction .id , action? .tagId , action? .mailboxId )
294+ if (createdStep) {
295+ createdSteps .push (createdStep)
296+ }
292297 }
298+ this .actions = createdSteps
293299 } catch (error) {
294300 logger .error (' Could not add step to quick action' , {
295301 error,
296302 })
297303 showError (t (' mail' , ' Failed to add steps to quick action' ))
298304 this .closeEditModal ()
299305 }
306+ this .localAction = quickAction
300307 showSuccess (t (' mail' , ' Quick action created' ))
301308 }
309+ this .mainStore .patchActionStepsLocally (this .localAction .id , this .actions )
302310 this .closeEditModal ()
303311 },
304312
@@ -338,9 +346,13 @@ export default {
338346 },
339347
340348 async deleteAction (item ) {
349+ this .actions = this .actions .filter ((action ) => action .order !== item .order ).map ((action , index ) => ({ ... action, order: index + 1 }))
350+ this .highestOrder = Math .max (... this .actions .map ((a ) => a .order ), 0 )
341351 if (item .id ) {
342352 try {
343353 await deleteActionStep (item .id )
354+ const actions = this .actions .filter ((action ) => action .id )
355+ this .mainStore .patchActionStepsLocally (this .localAction .id , actions)
344356 } catch (error) {
345357 logger .error (' Could not delete action step' , {
346358 error,
@@ -349,8 +361,6 @@ export default {
349361 return
350362 }
351363 }
352- this .actions = this .actions .filter ((action ) => action .order !== item .order ).map ((action , index ) => ({ ... action, order: index + 1 }))
353- this .highestOrder = Math .max (... this .actions .map ((a ) => a .order ), 0 )
354364 },
355365 },
356366}
0 commit comments