feat(app): organisation settings page with tags & registration field templates
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
91
apps/app/src/composables/api/usePersonTags.ts
Normal file
91
apps/app/src/composables/api/usePersonTags.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||
import type { Ref } from 'vue'
|
||||
import { apiClient } from '@/lib/axios'
|
||||
import type { PersonTag, PersonTagCreateDTO, PersonTagUpdateDTO } from '@/types/person-tag'
|
||||
|
||||
interface ApiResponse<T> {
|
||||
success: boolean
|
||||
data: T
|
||||
message?: string
|
||||
}
|
||||
|
||||
export function usePersonTags(orgId: Ref<string>) {
|
||||
return useQuery({
|
||||
queryKey: ['person-tags', orgId],
|
||||
queryFn: async () => {
|
||||
const { data } = await apiClient.get<{ data: PersonTag[] }>(
|
||||
`/organisations/${orgId.value}/person-tags`,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
enabled: () => !!orgId.value,
|
||||
staleTime: Infinity,
|
||||
})
|
||||
}
|
||||
|
||||
export function usePersonTagCategories(orgId: Ref<string>) {
|
||||
return useQuery({
|
||||
queryKey: ['person-tag-categories', orgId],
|
||||
queryFn: async () => {
|
||||
const { data } = await apiClient.get<{ data: string[] }>(
|
||||
`/organisations/${orgId.value}/person-tag-categories`,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
enabled: () => !!orgId.value,
|
||||
staleTime: Infinity,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreatePersonTag(orgId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (payload: PersonTagCreateDTO) => {
|
||||
const { data } = await apiClient.post<ApiResponse<PersonTag>>(
|
||||
`/organisations/${orgId.value}/person-tags`,
|
||||
payload,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['person-tags', orgId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['person-tag-categories', orgId] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdatePersonTag(orgId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, ...payload }: PersonTagUpdateDTO & { id: string }) => {
|
||||
const { data } = await apiClient.put<ApiResponse<PersonTag>>(
|
||||
`/organisations/${orgId.value}/person-tags/${id}`,
|
||||
payload,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['person-tags', orgId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['person-tag-categories', orgId] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeletePersonTag(orgId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
await apiClient.delete(`/organisations/${orgId.value}/person-tags/${id}`)
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['person-tags', orgId] })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||
import type { Ref } from 'vue'
|
||||
import { apiClient } from '@/lib/axios'
|
||||
import type { RegistrationFieldTemplate, RegistrationFieldTemplateCreateDTO, RegistrationFieldTemplateUpdateDTO } from '@/types/registration-field-template'
|
||||
|
||||
interface ApiResponse<T> {
|
||||
success: boolean
|
||||
data: T
|
||||
message?: string
|
||||
}
|
||||
|
||||
export function useRegistrationFieldTemplates(orgId: Ref<string>) {
|
||||
return useQuery({
|
||||
queryKey: ['registration-field-templates', orgId],
|
||||
queryFn: async () => {
|
||||
const { data } = await apiClient.get<{ data: RegistrationFieldTemplate[] }>(
|
||||
`/organisations/${orgId.value}/registration-field-templates`,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
enabled: () => !!orgId.value,
|
||||
staleTime: Infinity,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateRegistrationFieldTemplate(orgId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (payload: RegistrationFieldTemplateCreateDTO) => {
|
||||
const { data } = await apiClient.post<ApiResponse<RegistrationFieldTemplate>>(
|
||||
`/organisations/${orgId.value}/registration-field-templates`,
|
||||
payload,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['registration-field-templates', orgId] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateRegistrationFieldTemplate(orgId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, ...payload }: RegistrationFieldTemplateUpdateDTO & { id: string }) => {
|
||||
const { data } = await apiClient.put<ApiResponse<RegistrationFieldTemplate>>(
|
||||
`/organisations/${orgId.value}/registration-field-templates/${id}`,
|
||||
payload,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['registration-field-templates', orgId] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteRegistrationFieldTemplate(orgId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
await apiClient.delete(`/organisations/${orgId.value}/registration-field-templates/${id}`)
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['registration-field-templates', orgId] })
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user