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