| import { useDeleteMessage, useFeedback } from '@/hooks/chat-hooks'; | |
| import { useSetModalState } from '@/hooks/common-hooks'; | |
| import { IRemoveMessageById } from '@/hooks/logic-hooks'; | |
| import { IFeedbackRequestBody } from '@/interfaces/request/chat'; | |
| import { getMessagePureId } from '@/utils/chat'; | |
| import { useCallback } from 'react'; | |
| export const useSendFeedback = (messageId: string) => { | |
| const { visible, hideModal, showModal } = useSetModalState(); | |
| const { feedback, loading } = useFeedback(); | |
| const onFeedbackOk = useCallback( | |
| async (params: IFeedbackRequestBody) => { | |
| const ret = await feedback({ | |
| ...params, | |
| messageId: getMessagePureId(messageId), | |
| }); | |
| if (ret === 0) { | |
| hideModal(); | |
| } | |
| }, | |
| [feedback, hideModal, messageId], | |
| ); | |
| return { | |
| loading, | |
| onFeedbackOk, | |
| visible, | |
| hideModal, | |
| showModal, | |
| }; | |
| }; | |
| export const useRemoveMessage = ( | |
| messageId: string, | |
| removeMessageById?: IRemoveMessageById['removeMessageById'], | |
| ) => { | |
| const { deleteMessage, loading } = useDeleteMessage(); | |
| const onRemoveMessage = useCallback(async () => { | |
| const pureId = getMessagePureId(messageId); | |
| if (pureId) { | |
| const retcode = await deleteMessage(pureId); | |
| if (retcode === 0) { | |
| removeMessageById?.(messageId); | |
| } | |
| } | |
| }, [deleteMessage, messageId, removeMessageById]); | |
| return { onRemoveMessage, loading }; | |
| }; | |