fix forum
deksripsi: - fix report komentar
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Forum_ReportKomentarLainnya } from "@/app_modules/forum";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
let komentarId = params.id;
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Forum_ReportKomentarLainnya
|
||||
komentarId={komentarId}
|
||||
userLoginId={userLoginId as string}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Forum_ReportKomentar } from "@/app_modules/forum";
|
||||
import { forum_getMasterKategoriReport } from "@/app_modules/forum/fun/master/get_master_kategori_report";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
let komentarId = params.id;
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const listReport = await forum_getMasterKategoriReport();
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Forum_ReportKomentar
|
||||
komentarId={komentarId}
|
||||
listReport={listReport as any}
|
||||
userLoginId={userLoginId as any}
|
||||
/>
|
||||
<Forum_ReportKomentar userLoginId={userLoginId as any} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ export async function forum_funCreateReportKomentar({
|
||||
}) {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
if (!userLoginId)
|
||||
return { status: 400, message: "Gagal menambahkan report komentar !" };
|
||||
|
||||
try {
|
||||
const createReport = await prisma.forum_ReportKomentar.create({
|
||||
data: {
|
||||
@@ -23,9 +26,15 @@ export async function forum_funCreateReportKomentar({
|
||||
|
||||
if (!createReport)
|
||||
return { status: 400, message: "Gagal menambahkan report komentar !" };
|
||||
|
||||
return { status: 201, message: "Berhasil me-report komentar !" };
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
status: 500,
|
||||
message: "Error API",
|
||||
error: (error as Error).message,
|
||||
};
|
||||
}
|
||||
|
||||
return { status: 201, message: "Berhasil me-report komentar !" };
|
||||
}
|
||||
|
||||
@@ -2,21 +2,33 @@
|
||||
|
||||
import prisma from "@/lib/prisma";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
|
||||
export async function forum_funCreateReportKomentarLainnya(
|
||||
komentarId: string,
|
||||
deskripsi: string
|
||||
) {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
try {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
if (!userLoginId)
|
||||
return { status: 400, message: "Gagal menambah report !" };
|
||||
|
||||
const create = await prisma.forum_ReportKomentar.create({
|
||||
data: {
|
||||
forum_KomentarId: komentarId,
|
||||
deskripsi: deskripsi,
|
||||
userId: userLoginId,
|
||||
},
|
||||
});
|
||||
const create = await prisma.forum_ReportKomentar.create({
|
||||
data: {
|
||||
forum_KomentarId: komentarId,
|
||||
deskripsi: deskripsi,
|
||||
userId: userLoginId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal menambah report !" };
|
||||
return { status: 201, message: "Berhasil menambah report !" };
|
||||
if (!create) return { status: 400, message: "Gagal menambah report !" };
|
||||
return { status: 201, message: "Berhasil menambah report !" };
|
||||
} catch (error) {
|
||||
backendLogger.error("Error create report komentar lainnya", error);
|
||||
return {
|
||||
status: 500,
|
||||
message: "Error API",
|
||||
error: (error as Error).message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { Button, Radio, Stack, Text, Title } from "@mantine/core";
|
||||
import { toNumber } from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { forum_funCreateReportKomentar } from "../../fun/create/fun_create_report_komentar";
|
||||
|
||||
@@ -14,21 +14,43 @@ import {
|
||||
AccentColor,
|
||||
MainColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { apiGetMasterReportForum } from "../../component/api_fetch_forum";
|
||||
import forum_getOneKategoriById from "../../fun/get/get_one_kategori_by_id";
|
||||
import { MODEL_FORUM_MASTER_REPORT } from "../../model/interface";
|
||||
|
||||
export default function Forum_ReportKomentar({
|
||||
komentarId,
|
||||
listReport,
|
||||
userLoginId,
|
||||
}: {
|
||||
komentarId: string;
|
||||
listReport: MODEL_FORUM_MASTER_REPORT[];
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const param = useParams<{ id: string }>();
|
||||
const komentarId = param.id;
|
||||
const [listReport, setListReport] = useState<
|
||||
MODEL_FORUM_MASTER_REPORT[] | null
|
||||
>(null);
|
||||
const [reportValue, setReportValue] = useState("1");
|
||||
|
||||
useShallowEffect(() => {
|
||||
handleLoadMasterReport();
|
||||
}, []);
|
||||
|
||||
const handleLoadMasterReport = async () => {
|
||||
try {
|
||||
const response = await apiGetMasterReportForum();
|
||||
if (response.success) {
|
||||
setListReport(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get master report", error);
|
||||
}
|
||||
};
|
||||
|
||||
if (!listReport) return <CustomSkeleton height={50} width={"100%"} />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack
|
||||
@@ -87,37 +109,43 @@ function ButtonAction({
|
||||
const [isLoadingLain, setIsLoadingLain] = useState(false);
|
||||
|
||||
async function onReport() {
|
||||
const report = await forum_funCreateReportKomentar({
|
||||
komentarId: komentarId,
|
||||
kategoriId: kategoriId,
|
||||
});
|
||||
|
||||
if (report.status === 201) {
|
||||
const getKategori = await forum_getOneKategoriById({
|
||||
try {
|
||||
setLoading(true);
|
||||
const report = await forum_funCreateReportKomentar({
|
||||
komentarId: komentarId,
|
||||
kategoriId: kategoriId,
|
||||
});
|
||||
// console.log(getKategori);
|
||||
const dataNotif = {
|
||||
appId: komentarId,
|
||||
pesan: getKategori?.deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: getKategori?.title,
|
||||
userId: userLoginId,
|
||||
status: "Report Komentar",
|
||||
};
|
||||
const createNotif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (createNotif.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
if (report.status === 201) {
|
||||
const getKategori = await forum_getOneKategoriById({
|
||||
kategoriId: kategoriId,
|
||||
});
|
||||
// console.log(getKategori);
|
||||
const dataNotif = {
|
||||
appId: komentarId,
|
||||
pesan: getKategori?.deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: getKategori?.title,
|
||||
userId: userLoginId,
|
||||
status: "Report Komentar",
|
||||
};
|
||||
const createNotif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (createNotif.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
}
|
||||
|
||||
router.back();
|
||||
return ComponentGlobal_NotifikasiBerhasil(report.message, 2000);
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
router.back();
|
||||
return ComponentGlobal_NotifikasiBerhasil(report.message, 2000);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
} catch (error) {
|
||||
clientLogger.error("Error report komentar", error);
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
@@ -125,7 +153,7 @@ function ButtonAction({
|
||||
<Stack mt={"md"}>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={isLoadingLain ? true : false}
|
||||
loading={isLoadingLain}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
setIsLoadingLain(true);
|
||||
@@ -138,7 +166,7 @@ function ButtonAction({
|
||||
radius={"xl"}
|
||||
color="orange"
|
||||
loaderPosition="center"
|
||||
loading={loading ? true : false}
|
||||
loading={loading}
|
||||
onClick={() => onReport()}
|
||||
>
|
||||
Report
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
||||
import { Button, Group, Stack, Textarea } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { forum_funCreateReportPosting } from "../../fun/create/fun_create_report_posting";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
@@ -11,15 +11,17 @@ import { forum_funCreateReportPostingLainnya } from "../../fun/create/fun_create
|
||||
import { forum_funCreateReportKomentarLainnya } from "../../fun/create/fun_create_report_komentar_lainnya";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function Forum_ReportKomentarLainnya({
|
||||
komentarId,
|
||||
userLoginId,
|
||||
}: {
|
||||
komentarId: string;
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const param = useParams<{ id: string }>();
|
||||
const komentarId = param.id;
|
||||
const [deskripsi, setDeskripsi] = useState("");
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
@@ -51,41 +53,53 @@ function ButtonAction({
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
async function onReport() {
|
||||
const report = await forum_funCreateReportKomentarLainnya(
|
||||
komentarId,
|
||||
deskripsi
|
||||
);
|
||||
try {
|
||||
setLoading(true);
|
||||
const report = await forum_funCreateReportKomentarLainnya(
|
||||
komentarId,
|
||||
deskripsi
|
||||
);
|
||||
|
||||
if (report.status === 201) {
|
||||
const dataNotif = {
|
||||
appId: komentarId,
|
||||
pesan: deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: "Lainnya",
|
||||
userId: userLoginId,
|
||||
status: "Report Komentar",
|
||||
};
|
||||
if (report.status === 201) {
|
||||
const dataNotif = {
|
||||
appId: komentarId,
|
||||
pesan: deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: "Lainnya",
|
||||
userId: userLoginId,
|
||||
status: "Report Komentar",
|
||||
};
|
||||
|
||||
const createNotifikasi = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
const createNotifikasi = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
}
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(report.message);
|
||||
router.back();
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
}
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(report.message);
|
||||
router.back();
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error report komentar lainnya", error);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Group position="apart" grow>
|
||||
<Button
|
||||
disabled={isLoading}
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
}}
|
||||
radius={"xl"}
|
||||
onClick={() =>
|
||||
router.replace(RouterForum.report_komentar + komentarId)
|
||||
@@ -94,6 +108,8 @@ function ButtonAction({
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
loading={isLoading}
|
||||
loaderPosition="center"
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
}}
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function Forum_ReportPosting({
|
||||
}) {
|
||||
const param = useParams<{ id: string }>();
|
||||
const postingId = param.id;
|
||||
const [listReport, setListReport] = useState<MODEL_FORUM_MASTER_REPORT[]>();
|
||||
const [listReport, setListReport] = useState<MODEL_FORUM_MASTER_REPORT[] | null>(null);
|
||||
const [reportValue, setReportValue] = useState("1");
|
||||
|
||||
useShallowEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user