UNPKG

@replyke/core

Version:

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

47 lines 1.41 kB
import useAxiosPrivate from "../../config/useAxiosPrivate"; import useProject from "../projects/useProject"; import { useUser } from "../user"; function useCreateReport({ type }) { const axios = useAxiosPrivate(); const { projectId } = useProject(); const { user } = useUser(); const createReport = async ({ targetId, targetType, reason, details, }) => { if (!projectId) { throw new Error("Project ID is required"); } if (!user) { throw new Error("No user is logged in"); } await axios.post(`/${projectId}/reports`, { targetId, targetType, reason, details, }); }; const createCommentReport = async ({ targetId, reason, details, }) => { await createReport({ targetId, targetType: "comment", reason, details, }); }; const createEntityReport = async ({ targetId, reason, details, }) => { await createReport({ targetId, targetType: "entity", reason, details, }); }; if (type === "comment") { return createCommentReport; } else if (type === "entity") { return createEntityReport; } throw new Error("Invalid report type"); } export default useCreateReport; //# sourceMappingURL=useCreateReport.js.map