30 lines
770 B
TypeScript
30 lines
770 B
TypeScript
import { useMutation, useQuery } from '@tanstack/react-query'
|
|
import * as api from '../service/ChatService'
|
|
import type { AddChatMessageType } from '../type/Types'
|
|
|
|
export const useGetChatMessages = (refId: string) => {
|
|
return useQuery({
|
|
queryKey: ['chat', refId],
|
|
queryFn: () => api.getChatMessages(refId),
|
|
enabled: !!refId,
|
|
})
|
|
}
|
|
|
|
export const useAddChatMessage = () => {
|
|
return useMutation({
|
|
mutationFn: ({
|
|
refId,
|
|
params,
|
|
}: {
|
|
refId: string
|
|
params: AddChatMessageType
|
|
}) => api.addChatMessage(refId, params),
|
|
})
|
|
}
|
|
|
|
export const useDeleteChatMessage = () => {
|
|
return useMutation({
|
|
mutationFn: (id: string) => api.deleteChatMessage(id),
|
|
})
|
|
}
|