add error notifications to importer

This commit is contained in:
Gregor Vostrak
2024-04-22 14:05:14 +02:00
parent 7f6dbfdf60
commit b28f2b0a1c
2 changed files with 19 additions and 14 deletions

View File

@@ -33,7 +33,7 @@ onMounted(async () => {
}
});
const reportResult = ref<ImportReport>();
const reportResult = ref<ImportReport | null>();
const files = ref<FileList | null>(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;
}
}
}

View File

@@ -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',