efc72b720e
- scoreCalculator: apply dataQuality/confidence modifiers to finalScore (were computed but hardcoded to 0) - authService: call queryClient.clear() on logout to prevent cross-session data leakage - queryClient: extract to src/lib/queryClient.ts singleton so services can access it without circular imports - matchSyncService: new service layer owns match-generation logic; MockupNeedProvider no longer imports other providers directly - hooks (11 files): add onError + German toast feedback to every useMutation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { inquiryService } from '../services/inquiryService'
|
|
import type { InquiryFilters } from '../provider/IInquiryProvider'
|
|
import type { Attachment } from '../domain/inquiry'
|
|
import { useToastStore } from '../stores/toastStore'
|
|
|
|
export function useActiveInquiries(filters?: InquiryFilters) {
|
|
return useQuery({
|
|
queryKey: ['inquiries', 'active', filters ?? {}],
|
|
queryFn: () => inquiryService.getActiveInquiries(filters),
|
|
select: (res) => res.data ?? [],
|
|
})
|
|
}
|
|
|
|
export function useInquiryById(id: string) {
|
|
return useQuery({
|
|
queryKey: ['inquiry', id],
|
|
queryFn: () => inquiryService.getInquiryById(id),
|
|
enabled: !!id,
|
|
select: (res) => res.data ?? null,
|
|
})
|
|
}
|
|
|
|
export function useSendInquiryReply() {
|
|
const qc = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: ({
|
|
inquiryId,
|
|
payload,
|
|
}: {
|
|
inquiryId: string
|
|
payload: { subject?: string; body: string; attachments?: Attachment[] }
|
|
}) => inquiryService.sendInquiryReply(inquiryId, payload),
|
|
onSuccess: (_data, { inquiryId }) => {
|
|
qc.invalidateQueries({ queryKey: ['inquiry', inquiryId] })
|
|
qc.invalidateQueries({ queryKey: ['inquiries'] })
|
|
},
|
|
onError: () => {
|
|
useToastStore.getState().showToast('Antwort konnte nicht gesendet werden.', 'error')
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useMarkThreadAsRead() {
|
|
const qc = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: (id: string) => inquiryService.markThreadAsRead(id),
|
|
onSuccess: (_data, id) => {
|
|
qc.invalidateQueries({ queryKey: ['inquiry', id] })
|
|
qc.invalidateQueries({ queryKey: ['inquiries'] })
|
|
},
|
|
})
|
|
}
|