added success and error notifications

This commit is contained in:
Gregor Vostrak
2024-04-12 03:19:58 +02:00
parent 0e96ad992f
commit 64023f3930
14 changed files with 508 additions and 208 deletions

View File

@@ -7,18 +7,24 @@ import type {
Client,
} from '@/utils/api';
import { getCurrentOrganizationId } from '@/utils/useUser';
import { useNotificationsStore } from '@/utils/notification';
export const useClientsStore = defineStore('clients', () => {
const clientResponse = ref<ClientIndexResponse | null>(null);
const { handleApiRequestNotifications } = useNotificationsStore();
async function fetchClients() {
const organization = getCurrentOrganizationId();
if (organization) {
clientResponse.value = await api.getClients({
params: {
organization: organization,
},
});
clientResponse.value = await handleApiRequestNotifications(
api.getClients({
params: {
organization: organization,
},
}),
undefined,
'Failed to fetch clients'
);
}
}
@@ -27,27 +33,35 @@ export const useClientsStore = defineStore('clients', () => {
): Promise<Client | undefined> {
const organization = getCurrentOrganizationId();
if (organization) {
const response = await api.createClient(clientBody, {
params: {
organization: organization,
},
});
const response = await handleApiRequestNotifications(
api.createClient(clientBody, {
params: {
organization: organization,
},
}),
'Client created successfully',
'Failed to create client'
);
await fetchClients();
return response.data;
return response?.data;
}
}
async function deleteClient(clientId: string) {
const organization = getCurrentOrganizationId();
if (organization) {
await api.deleteClient(
{},
{
params: {
organization: organization,
client: clientId,
},
}
await handleApiRequestNotifications(
api.deleteClient(
{},
{
params: {
organization: organization,
client: clientId,
},
}
),
'Client deleted successfully',
'Failed to delete client'
);
await fetchClients();
}