UNPKG

@replyke/core

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

30 lines 1.25 kB
import { useCallback } from "react"; import { useReplykeDispatch } from "../../../store/hooks"; import { setConversation } from "../../../store/slices/chatSlice"; import useAxiosPrivate from "../../../config/useAxiosPrivate"; import useProject from "../../projects/useProject"; import { handleError } from "../../../utils/handleError"; function useCreateDirectConversation() { const dispatch = useReplykeDispatch(); const { projectId } = useProject(); const axios = useAxiosPrivate(); const create = useCallback(async ({ userId }) => { if (!projectId) throw new Error("No projectId available."); if (!userId) throw new Error("Please pass a userId."); try { const response = await axios.post(`/${projectId}/chat/conversations/direct`, { userId }); const conversation = response.data; dispatch(setConversation(conversation)); return conversation; } catch (err) { handleError(err, "Failed to create direct conversation"); throw err; } }, [projectId, axios, dispatch]); return create; } export default useCreateDirectConversation; //# sourceMappingURL=useCreateDirectConversation.js.map