mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-11 01:32:16 +01:00
add filters and sorting to projects table
This commit is contained in:
34
resources/js/utils/useProjectsQuery.ts
Normal file
34
resources/js/utils/useProjectsQuery.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useQuery, useQueryClient } from '@tanstack/vue-query';
|
||||
import { api } from '@/packages/api/src';
|
||||
import { getCurrentOrganizationId } from '@/utils/useUser';
|
||||
import type { Project } from '@/packages/api/src';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export function useProjectsQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ['projects'],
|
||||
queryFn: async () => {
|
||||
const organizationId = getCurrentOrganizationId();
|
||||
if (!organizationId) throw new Error('No organization');
|
||||
return api.getProjects({
|
||||
params: { organization: organizationId },
|
||||
queries: { archived: 'all' },
|
||||
});
|
||||
},
|
||||
enabled: () => !!getCurrentOrganizationId(),
|
||||
});
|
||||
|
||||
const projects = computed<Project[]>(() => query.data.value?.data ?? []);
|
||||
|
||||
const invalidateProjects = () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projects'] });
|
||||
};
|
||||
|
||||
return {
|
||||
...query,
|
||||
projects,
|
||||
invalidateProjects,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user