mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 11:42:15 +01:00
added success and error notifications
This commit is contained in:
@@ -3,29 +3,39 @@ import { api } from '../../../openapi.json.client';
|
||||
import { computed, ref } from 'vue';
|
||||
import type { CreateProjectBody, Project, ProjectResponse } from '@/utils/api';
|
||||
import { getCurrentOrganizationId } from '@/utils/useUser';
|
||||
import { useNotificationsStore } from '@/utils/notification';
|
||||
|
||||
export const useProjectsStore = defineStore('projects', () => {
|
||||
const projectResponse = ref<ProjectResponse | null>(null);
|
||||
|
||||
const { handleApiRequestNotifications } = useNotificationsStore();
|
||||
async function fetchProjects() {
|
||||
const organization = getCurrentOrganizationId();
|
||||
if (organization) {
|
||||
projectResponse.value = await api.getProjects({
|
||||
params: {
|
||||
organization: organization,
|
||||
},
|
||||
});
|
||||
projectResponse.value = await handleApiRequestNotifications(
|
||||
api.getProjects({
|
||||
params: {
|
||||
organization: organization,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
'Failed to fetch projects'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function createProject(projectBody: CreateProjectBody) {
|
||||
const organization = getCurrentOrganizationId();
|
||||
if (organization) {
|
||||
await api.createProject(projectBody, {
|
||||
params: {
|
||||
organization: organization,
|
||||
},
|
||||
});
|
||||
await handleApiRequestNotifications(
|
||||
api.createProject(projectBody, {
|
||||
params: {
|
||||
organization: organization,
|
||||
},
|
||||
}),
|
||||
'Project created successfully',
|
||||
'Failed to create project'
|
||||
);
|
||||
|
||||
await fetchProjects();
|
||||
}
|
||||
}
|
||||
@@ -33,14 +43,18 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
async function deleteProject(projectId: string) {
|
||||
const organizationId = getCurrentOrganizationId();
|
||||
if (organizationId) {
|
||||
await api.deleteProject(
|
||||
{},
|
||||
{
|
||||
params: {
|
||||
organization: organizationId,
|
||||
project: projectId,
|
||||
},
|
||||
}
|
||||
await handleApiRequestNotifications(
|
||||
api.deleteProject(
|
||||
{},
|
||||
{
|
||||
params: {
|
||||
organization: organizationId,
|
||||
project: projectId,
|
||||
},
|
||||
}
|
||||
),
|
||||
'Project deleted successfully',
|
||||
'Failed to delete project'
|
||||
);
|
||||
await fetchProjects();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user