(1);
const [activePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
const [isLoadingReport, setLoadingReport] = useState(false);
const [idData, setIdData] = useState("");
+ useShallowEffect(() => {
+ handleLoadData();
+ }, []);
+
+ async function handleLoadData() {
+ try {
+ const response = await apiAdminGetKomentarForumById({
+ id: postingId,
+ page: `${activePage}`,
+ search: isSearch,
+ });
+
+ if (response && response.success) {
+ setData(response.data.data);
+ }
+ } catch (error) {
+ console.error("Invalid data format received:", error);
+ setData([]);
+ }
+ }
+
async function onSearch(s: string) {
setSearch(s);
setActivePage(1);
@@ -108,96 +117,112 @@ function TableKomentar({
setNPage(loadData.nPage);
}
- const rowTable = data?.map((e, i) => (
-
- |
-
- {e?.Author?.username}
-
- |
-
-
-
-
-
-
- |
-
-
-
- {new Intl.DateTimeFormat(["id-ID"], { dateStyle: "medium" }).format(
- e.createdAt
- )}
-
-
- |
-
-
- = 3 ? "red" : AdminColor.white}
- fw={"bold"}
- fz={"lg"}
- >
- {e?.Forum_ReportKomentar.length}
-
-
- |
-
-
- }
- onClick={() => {
- setIdData(e?.id);
- setLoadingReport(true);
- router.push(RouterAdminForum.report_komentar + e?.id);
- }}
- >
- Lihat Report
-
-
-
- |
-
- ));
+ const rowTable = () => {
+ if (!Array.isArray(data) || data.length === 0) {
+ return (
+
+ |
+
+ Tidak ada data
+
+ |
+
+ );
+ }
+
+ return data?.map((e, i) => (
+
+ |
+
+ {e?.Author?.username}
+
+ |
+
+
+
+
+
+
+ |
+
+
+ {moment(e?.createdAt).format("DD-MM-YYYY")}
+
+ |
+
+
+ = 3 ? "red" : AdminColor.white
+ }
+ fw={"bold"}
+ fz={"lg"}
+ >
+ {e?.Forum_ReportKomentar.length}
+
+
+ |
+
+
+ }
+ onClick={() => {
+ setIdData(e?.id);
+ setLoadingReport(true);
+ router.push(RouterAdminForum.report_komentar + e?.id);
+ }}
+ >
+ Lihat Report
+
+
+
+ |
+
+ ));
+ };
return (
<>
-
-
-
- Komentar
-
-
- {`(${countKomentar})`}
-
-
- }
- radius={"xl"}
- placeholder="Cari komentar"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
-
+
+
+ Komentar:
+
+
+ {data?.length}
+
+
+ }
+ component={
+ }
+ radius={"xl"}
+ placeholder="Cari komentar"
+ onChange={(val) => {
+ onSearch(val.currentTarget.value);
+ }}
+ />
+ }
+ />
- {_.isEmpty(data) ? (
-
+ {!data ? (
+
) : (
@@ -207,39 +232,36 @@ function TableKomentar({
p={"md"}
w={"100%"}
h={"100%"}
-
>
|
- Username
+ Username
|
- Komentar
+ Komentar
|
- Tgl Komentar
+ Tgl Komentar
|
- Total Report
+ Total Report
|
- Aksi
+ Aksi
|
- {rowTable}
+ {rowTable()}
-
- {
- onPageClick(val);
- }}
- />
-
+ {
+ onPageClick(val);
+ }}
+ />
)}
diff --git a/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts b/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts
index 3c6f5367..2a549e27 100644
--- a/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts
+++ b/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts
@@ -6,6 +6,7 @@ export {
apiGetAdminForumReportKomentar,
apiGetAdminForumPublish,
apiGetAdminHasilReportPosting,
+ apiAdminGetKomentarForumById,
};
const apiGetAdminForumPublishCountDasboard = async () => {
@@ -159,3 +160,55 @@ const apiGetAdminHasilReportPosting = async ({
return await response.json().catch(() => null);
};
+
+const apiAdminGetKomentarForumById = async ({
+ id,
+ page,
+ search,
+}: {
+ id: string;
+ page?: string;
+ search?: string;
+}) => {
+ try {
+ const { token } = await fetch("/api/get-cookie").then((res) => res.json());
+ if (!token) {
+ console.error("No token found");
+ return null;
+ }
+
+ const isPage = page ? `?page=${page}` : "";
+ const isSearch = search ? `&search=${search}` : "";
+ const response = await fetch(
+ `/api/admin/forum/${id}/komentar${isPage}${isSearch}`,
+ {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ }
+ );
+
+ // Check if the response is OK
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => null);
+ console.error(
+ "Failed to get admin komentar forum",
+ response.statusText,
+ errorData
+ );
+ throw new Error(
+ errorData?.message || "Failed to get admin komentar forum"
+ );
+ }
+
+ // Return the JSON response
+ const resulst = await response.json();
+ return resulst;
+ } catch (error) {
+ console.error("Error get admin komentar forum", error);
+ throw error; // Re-throw the error to handle it in the calling function
+ }
+};
diff --git a/src/app_modules/admin/forum/sub_menu/table_posting.tsx b/src/app_modules/admin/forum/sub_menu/table_posting.tsx
index dd66322f..0eeec292 100644
--- a/src/app_modules/admin/forum/sub_menu/table_posting.tsx
+++ b/src/app_modules/admin/forum/sub_menu/table_posting.tsx
@@ -96,20 +96,17 @@ function TablePublish() {
);
}
return data?.map((e, i) => (
-
- {/* Aksi */}
+
+ {/* Author */}
|
-
-
- {
- onDelete(val);
- }}
- />
-
+
+ {e?.Author?.username}
+
|
{/* Status */}
@@ -127,15 +124,6 @@ function TablePublish() {
- {/* Author */}
-
-
-
- {e?.Author?.username}
-
-
- |
-
{/* Deskripsi */}
@@ -176,6 +164,19 @@ function TablePublish() {
|
+ {/* Aksi */}
+
+
+
+ {
+ onDelete(val);
+ }}
+ />
+
+ |
+
{/*
@@ -222,15 +223,11 @@ function TablePublish() {
|
- Aksi
+ Username
|
-
Status
|
-
- Username
- |
Postingan
|
@@ -240,6 +237,10 @@ function TablePublish() {
Total Report Posting
|
+
+
+ Aksi
+ |
{renderTableBody()}
|