From 8713105b62d13370c642a326dfa1ba3603533642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Mon, 25 Jan 2021 12:55:29 +0100 Subject: [PATCH] changes notification handling from catch-all to specific messages per action --- packages/client/src/api/api.js | 3 --- packages/client/src/api/automations.js | 7 ++++++- packages/client/src/api/rows.js | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/client/src/api/api.js b/packages/client/src/api/api.js index 2a78cdb049..1e73baf602 100644 --- a/packages/client/src/api/api.js +++ b/packages/client/src/api/api.js @@ -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 } } diff --git a/packages/client/src/api/automations.js b/packages/client/src/api/automations.js index c163ffee82..8076728b6f 100644 --- a/packages/client/src/api/automations.js +++ b/packages/client/src/api/automations.js @@ -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 } diff --git a/packages/client/src/api/rows.js b/packages/client/src/api/rows.js index dfbe9a55f5..775173eb12 100644 --- a/packages/client/src/api/rows.js +++ b/packages/client/src/api/rows.js @@ -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 }