useReports.ts 745 B

1234567891011121314151617181920212223242526272829
  1. import Toast from "toasters";
  2. import ws from "@/ws";
  3. export const useReports = () => {
  4. const resolveReport = ({ reportId, value }) =>
  5. new Promise((resolve, reject) => {
  6. ws.socket.dispatch("reports.resolve", reportId, value, res => {
  7. new Toast(res.message);
  8. if (res.status === "success")
  9. return resolve({ status: "success" });
  10. return reject(new Error(res.message));
  11. });
  12. });
  13. const removeReport = reportId =>
  14. new Promise((resolve, reject) => {
  15. ws.socket.dispatch("reports.remove", reportId, res => {
  16. new Toast(res.message);
  17. if (res.status === "success")
  18. return resolve({ status: "success" });
  19. return reject(new Error(res.message));
  20. });
  21. });
  22. return {
  23. resolveReport,
  24. removeReport
  25. };
  26. };