@@ -130,7 +130,7 @@ import IconDelete from 'vue-material-design-icons/TrashCanOutline.vue'
130130
131131import Action from ' ./Action.vue'
132132import logger from ' ../../logger.js'
133- import { createActionStep , deleteActionStep , findAllStepsForAction , updateActionStep } from ' ../../service/QuickActionsService.js'
133+ import { createActionStep , deleteActionStep , updateActionStep } from ' ../../service/QuickActionsService.js'
134134import useMainStore from ' ../../store/mainStore.js'
135135
136136export default {
@@ -217,8 +217,8 @@ export default {
217217 this .localAction = { id: null , name: ' ' }
218218 this .actions = []
219219 } else {
220- this .localAction = { ... action }
221- this .actions = await findAllStepsForAction ( action .id )
220+ this .localAction = { id : action . id , name : action . name , accountId : action . accountId }
221+ this .actions = action .actionSteps
222222 this .highestOrder = Math .max (... this .actions .map (a => a .order ), 0 )
223223 this .editMode = true
224224 }
@@ -247,7 +247,7 @@ export default {
247247 for (const [index , action ] of this .actions .entries ()) {
248248 if (action? .id !== null && action? .id !== undefined ) {
249249 try {
250- await updateActionStep (action .id , action .name , action .order , action? .tagId , action? .mailboxId )
250+ this . actions [index] = await updateActionStep (action .id , action .name , action .order , action? .tagId , action? .mailboxId )
251251 } catch (error) {
252252 logger .error (' Could not update quick action step' , {
253253 error,
@@ -260,10 +260,12 @@ export default {
260260 this .actions [index] = createdStep
261261 }
262262 }
263+ this .localAction = quickAction
263264 }
264265 showSuccess (t (' mail' , ' Quick action updated' ))
265266 } else {
266267 let quickAction
268+ let createdSteps = []
267269 try {
268270 quickAction = await this .mainStore .createQuickAction (this .localAction .name , this .account .id )
269271 } catch (error) {
@@ -275,17 +277,23 @@ export default {
275277 }
276278 try {
277279 for (const action of this .actions ) {
278- await createActionStep (action .name , action .order , quickAction .id , action? .tagId , action? .mailboxId )
280+ const createdStep = await createActionStep (action .name , action .order , quickAction .id , action? .tagId , action? .mailboxId )
281+ if (createdStep) {
282+ createdSteps .push (createdStep)
283+ }
279284 }
285+ this .actions = createdSteps
280286 } catch (error) {
281287 logger .error (' Could not add step to quick action' , {
282288 error,
283289 })
284290 showError (t (' mail' , ' Failed to add steps to quick action' ))
285291 this .closeEditModal ()
286292 }
293+ this .localAction = quickAction
287294 showSuccess (t (' mail' , ' Quick action created' ))
288295 }
296+ this .mainStore .patchActionStepsLocally (this .localAction .id , this .actions )
289297 this .closeEditModal ()
290298 },
291299 addQuickAction (name ) {
@@ -321,9 +329,13 @@ export default {
321329 this .actions = this .actions .map ((action , index ) => ({ ... action, order: index + 1 }))
322330 },
323331 async deleteAction (item ) {
332+ this .actions = this .actions .filter (action => action .order !== item .order ).map ((action , index ) => ({ ... action, order: index + 1 }))
333+ this .highestOrder = Math .max (... this .actions .map (a => a .order ), 0 )
324334 if (item .id ) {
325335 try {
326336 await deleteActionStep (item .id )
337+ const actions = this .actions .filter (action => action .id )
338+ this .mainStore .patchActionStepsLocally (this .localAction .id , actions)
327339 } catch (error) {
328340 logger .error (' Could not delete action step' , {
329341 error,
@@ -332,8 +344,6 @@ export default {
332344 return
333345 }
334346 }
335- this .actions = this .actions .filter (action => action .order !== item .order ).map ((action , index ) => ({ ... action, order: index + 1 }))
336- this .highestOrder = Math .max (... this .actions .map (a => a .order ), 0 )
337347 },
338348 },
339349}
0 commit comments