changes notification handling from catch-all to specific messages per action

This commit is contained in:
Keviin Åberg Kultalahti 2021-01-25 12:55:29 +01:00
parent 1f13fb3bd2
commit 0832fc5e86
3 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,3 @@
import { notificationStore } from "../store/notification"
/**
* API cache for cached request responses.
*/
@ -9,7 +7,6 @@ let cache = {}
* Handler for API errors.
*/
const handleError = error => {
notificationStore.danger('An error has occured.')
return { error }
}

View File

@ -1,10 +1,15 @@
import { notificationStore } from "../store/notification"
import API from "./api"
/**
* Executes an automation. Must have "App Action" trigger.
*/
export const triggerAutomation = async (automationId, fields) => {
return await API.post({
const res = await API.post({
url: `/api/automations/${automationId}/trigger`,
body: { fields },
})
res.error
? notificationStore.danger("En error has occured")
: notificationStore.success("Automation triggered.")
return res
}

View File

@ -20,7 +20,9 @@ export const saveRow = async row => {
url: `/api/${row.tableId}/rows`,
body: row,
})
notificationStore.success("Row saved")
res.error
? notificationStore.danger("En error has occured")
: notificationStore.success("Row saved")
return res
}
@ -32,7 +34,9 @@ export const updateRow = async row => {
url: `/api/${row.tableId}/rows/${row._id}`,
body: row,
})
notificationStore.success("Row updated")
res.error
? notificationStore.danger("En error has occured")
: notificationStore.success("Row updated")
return res
}
@ -43,7 +47,9 @@ export const deleteRow = async ({ tableId, rowId, revId }) => {
const res = await API.del({
url: `/api/${tableId}/rows/${rowId}/${revId}`,
})
notificationStore.success("Row deleted")
res.error
? notificationStore.danger("En error has occured")
: notificationStore.success("Row deleted")
return res
}
@ -58,7 +64,9 @@ export const deleteRows = async ({ tableId, rows }) => {
type: "delete",
},
})
notificationStore.success(`${rows.length} rows deleted.`)
res.error
? notificationStore.danger("En error has occured")
: notificationStore.success(`${rows.length} rows deleted.`)
return res
}