@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
52 lines • 1.72 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const useAxiosPrivate_1 = __importDefault(require("../../config/useAxiosPrivate"));
const useProject_1 = __importDefault(require("../projects/useProject"));
const user_1 = require("../user");
function useCreateReport({ type }) {
const axios = (0, useAxiosPrivate_1.default)();
const { projectId } = (0, useProject_1.default)();
const { user } = (0, user_1.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");
}
exports.default = useCreateReport;
//# sourceMappingURL=useCreateReport.js.map