mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 04:32:15 +01:00
remove redundant projects pinia store after tanstack query migration
This commit is contained in:
@@ -1,43 +1,14 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { api } from '@/packages/api/src';
|
import { api } from '@/packages/api/src';
|
||||||
import { computed, ref } from 'vue';
|
import type { CreateProjectBody, UpdateProjectBody } from '@/packages/api/src';
|
||||||
import type {
|
|
||||||
CreateProjectBody,
|
|
||||||
Project,
|
|
||||||
ProjectResponse,
|
|
||||||
UpdateProjectBody,
|
|
||||||
} from '@/packages/api/src';
|
|
||||||
import { getCurrentOrganizationId } from '@/utils/useUser';
|
import { getCurrentOrganizationId } from '@/utils/useUser';
|
||||||
import { useNotificationsStore } from '@/utils/notification';
|
import { useNotificationsStore } from '@/utils/notification';
|
||||||
import { useQueryClient } from '@tanstack/vue-query';
|
import { useQueryClient } from '@tanstack/vue-query';
|
||||||
|
|
||||||
export const useProjectsStore = defineStore('projects', () => {
|
export const useProjectsStore = defineStore('projects', () => {
|
||||||
const projectResponse = ref<ProjectResponse | null>(null);
|
|
||||||
const { handleApiRequestNotifications } = useNotificationsStore();
|
const { handleApiRequestNotifications } = useNotificationsStore();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
function invalidateProjectsQuery() {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['projects'] });
|
|
||||||
}
|
|
||||||
async function fetchProjects() {
|
|
||||||
const organization = getCurrentOrganizationId();
|
|
||||||
if (organization) {
|
|
||||||
projectResponse.value = await handleApiRequestNotifications(
|
|
||||||
() =>
|
|
||||||
api.getProjects({
|
|
||||||
params: {
|
|
||||||
organization: organization,
|
|
||||||
},
|
|
||||||
queries: {
|
|
||||||
archived: 'all',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
undefined,
|
|
||||||
'Failed to fetch projects'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createProject(projectBody: CreateProjectBody) {
|
async function createProject(projectBody: CreateProjectBody) {
|
||||||
const organization = getCurrentOrganizationId();
|
const organization = getCurrentOrganizationId();
|
||||||
|
|
||||||
@@ -53,8 +24,7 @@ export const useProjectsStore = defineStore('projects', () => {
|
|||||||
'Failed to create project'
|
'Failed to create project'
|
||||||
);
|
);
|
||||||
|
|
||||||
await fetchProjects();
|
queryClient.invalidateQueries({ queryKey: ['projects'] });
|
||||||
invalidateProjectsQuery();
|
|
||||||
return response['data'];
|
return response['data'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,8 +43,7 @@ export const useProjectsStore = defineStore('projects', () => {
|
|||||||
'Project deleted successfully',
|
'Project deleted successfully',
|
||||||
'Failed to delete project'
|
'Failed to delete project'
|
||||||
);
|
);
|
||||||
await fetchProjects();
|
queryClient.invalidateQueries({ queryKey: ['projects'] });
|
||||||
invalidateProjectsQuery();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,16 +61,11 @@ export const useProjectsStore = defineStore('projects', () => {
|
|||||||
'Project updated successfully',
|
'Project updated successfully',
|
||||||
'Failed to update project'
|
'Failed to update project'
|
||||||
);
|
);
|
||||||
await fetchProjects();
|
queryClient.invalidateQueries({ queryKey: ['projects'] });
|
||||||
invalidateProjectsQuery();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const projects = computed<Project[]>(() => projectResponse.value?.data || []);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
projects,
|
|
||||||
fetchProjects,
|
|
||||||
createProject,
|
createProject,
|
||||||
deleteProject,
|
deleteProject,
|
||||||
updateProject,
|
updateProject,
|
||||||
|
|||||||
Reference in New Issue
Block a user