From b28f2b0a1c8494acfa729b1ed88ccb798ab8c380 Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Mon, 22 Apr 2024 14:05:14 +0200 Subject: [PATCH] add error notifications to importer --- .../js/Pages/Teams/Partials/ImportData.vue | 28 +++++++++++-------- resources/js/utils/notification.ts | 5 ++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/resources/js/Pages/Teams/Partials/ImportData.vue b/resources/js/Pages/Teams/Partials/ImportData.vue index fd384537..e439ba7d 100644 --- a/resources/js/Pages/Teams/Partials/ImportData.vue +++ b/resources/js/Pages/Teams/Partials/ImportData.vue @@ -33,7 +33,7 @@ onMounted(async () => { } }); -const reportResult = ref(); +const reportResult = ref(); const files = ref(null); async function importData() { @@ -51,18 +51,24 @@ async function importData() { const base64String = await toBase64(files.value[0]); const organizationId = getCurrentOrganizationId(); if (organizationId !== null) { - reportResult.value = await api.importData( - { - type: importType.value.key, - data: base64String.replace('data:text/csv;base64,', ''), - }, - { - params: { - organization: organizationId, + const { handleApiRequestNotifications } = useNotificationsStore(); + + reportResult.value = await handleApiRequestNotifications( + api.importData( + { + type: importType.value.key, + data: base64String.replace('data:text/csv;base64,', ''), }, - } + { + params: { + organization: organizationId, + }, + } + ) ); - showResultModal.value = true; + if (reportResult.value) { + showResultModal.value = true; + } } } diff --git a/resources/js/utils/notification.ts b/resources/js/utils/notification.ts index 658cbd72..abd06000 100644 --- a/resources/js/utils/notification.ts +++ b/resources/js/utils/notification.ts @@ -1,6 +1,7 @@ import { defineStore } from 'pinia'; import { ref } from 'vue'; import axios from 'axios'; + export type NotificationType = 'success' | 'error'; export const useNotificationsStore = defineStore('notifications', () => { @@ -50,9 +51,7 @@ export const useNotificationsStore = defineStore('notifications', () => { if (axios.isAxiosError(error)) { if ( error?.response?.status === 403 || - (error?.response?.status === 400 && - error?.response?.data?.error === true && - error?.response?.data?.errorMessage !== undefined) + error?.response?.status === 400 ) { addNotification( 'error',