From 00eea712482fe731ba202b353ecc348e53a0025f Mon Sep 17 00:00:00 2001 From: bagasbanuna Date: Tue, 25 Nov 2025 11:04:12 +0800 Subject: [PATCH] Penambahan fitur block user: 50% Fix: - app/(application)/(user)/forum/[id]/index.tsx - app/(application)/(user)/home.tsx - screens/Forum/ListPage.tsx - screens/Forum/MenuDrawerSection.tsx/MenuBeranda.tsx - service/api-client/api-master.ts - service/api-client/api-user.ts ### No Issue --- app/(application)/(user)/forum/[id]/index.tsx | 1 + app/(application)/(user)/home.tsx | 2 + screens/Forum/ListPage.tsx | 17 ++++++- .../MenuDrawerSection.tsx/MenuBeranda.tsx | 50 ++++++++++++++++--- service/api-client/api-master.ts | 14 +++++- service/api-client/api-user.ts | 22 ++++++++ 6 files changed, 98 insertions(+), 8 deletions(-) diff --git a/app/(application)/(user)/forum/[id]/index.tsx b/app/(application)/(user)/forum/[id]/index.tsx index 5882cfa..1759e6d 100644 --- a/app/(application)/(user)/forum/[id]/index.tsx +++ b/app/(application)/(user)/forum/[id]/index.tsx @@ -223,6 +223,7 @@ export default function ForumDetail() { > { setOpenDrawer(false); diff --git a/app/(application)/(user)/home.tsx b/app/(application)/(user)/home.tsx index f79038d..28c45f7 100644 --- a/app/(application)/(user)/home.tsx +++ b/app/(application)/(user)/home.tsx @@ -17,6 +17,8 @@ import { useEffect, useState } from "react"; export default function Application() { const { token, user } = useAuth(); const [data, setData] = useState(); + + console.log("[User] >>", JSON.stringify(user?.id, null, 2)); useEffect(() => { onLoadData(); diff --git a/screens/Forum/ListPage.tsx b/screens/Forum/ListPage.tsx index 004da43..5b03e2d 100644 --- a/screens/Forum/ListPage.tsx +++ b/screens/Forum/ListPage.tsx @@ -22,6 +22,7 @@ const drawerItemsForumBerandaForAuthor = ({ ), label: "Edit posting", path: `/forum/${id}/edit`, + values: "edit" }, { icon: @@ -34,6 +35,7 @@ const drawerItemsForumBerandaForAuthor = ({ label: status === "Open" ? "Tutup forum" : "Buka forum", path: "", color: status === "Open" ? MainColor.orange : MainColor.green, + value: "status" }, { icon: ( @@ -42,10 +44,11 @@ const drawerItemsForumBerandaForAuthor = ({ label: "Hapus", path: "", color: MainColor.red, + value: "delete" }, ]; -const drawerItemsForumBerandaForNonAuthor = ({ id }: { id: string }) => [ +const drawerItemsForumBerandaForNonAuthor = ({ id, username }: { id: string; username: string }) => [ { icon: ( @@ -53,6 +56,16 @@ const drawerItemsForumBerandaForNonAuthor = ({ id }: { id: string }) => [ label: "Laporkan diskusi", // color: MainColor.white, path: `/forum/${id}/report-posting`, + value: "report" + }, + { + icon: ( + + ), + label: `Blockir @${username}`, + color: MainColor.red, + path: `/forum/${id}/report-posting`, + value: "block" }, ]; @@ -64,6 +77,7 @@ const drawerItemsForumComentarForAuthor = ({ id }: { id: string }) => [ label: "Hapus", color: MainColor.red, path: "", + value: "delete" }, ]; @@ -75,5 +89,6 @@ const drawerItemsForumComentarForNonAuthor = ({ id }: { id: string }) => [ label: "Laporkan", // color: MainColor.white, path: `/forum/${id}/report-commentar`, + value: "report" }, ]; diff --git a/screens/Forum/MenuDrawerSection.tsx/MenuBeranda.tsx b/screens/Forum/MenuDrawerSection.tsx/MenuBeranda.tsx index 3b59b58..64cb3b1 100644 --- a/screens/Forum/MenuDrawerSection.tsx/MenuBeranda.tsx +++ b/screens/Forum/MenuDrawerSection.tsx/MenuBeranda.tsx @@ -9,15 +9,18 @@ import { import { useAuth } from "@/hooks/use-auth"; import { apiForumDelete } from "@/service/api-client/api-forum"; import Toast from "react-native-toast-message"; +import { apiForumBlockUser } from "@/service/api-client/api-user"; export default function Forum_MenuDrawerBerandaSection({ id, + authorUsername, status, setIsDrawerOpen, authorId, handlerUpdateStatus, }: { id: string; + authorUsername: string; status: string; setIsDrawerOpen: (value: boolean) => void; authorId: string; @@ -25,7 +28,7 @@ export default function Forum_MenuDrawerBerandaSection({ }) { const { user } = useAuth(); const handlePress = (item: IMenuDrawerItem) => { - if (item.label === "Hapus") { + if (item.value === "delete") { AlertDefaultSystem({ title: "Hapus diskusi", message: "Apakah Anda yakin ingin menghapus diskusi ini?", @@ -34,7 +37,7 @@ export default function Forum_MenuDrawerBerandaSection({ onPressRight: async () => { try { const response = await apiForumDelete({ id }); - + if (response.success) { Toast.show({ type: "success", @@ -52,14 +55,46 @@ export default function Forum_MenuDrawerBerandaSection({ } }, }); - } else if (item.label === "Buka forum" || item.label === "Tutup forum") { + } else if (item.value === "status") { AlertDefaultSystem({ title: "Ubah Status", message: "Apakah Anda yakin ingin mengubah status forum ini?", textLeft: "Batal", textRight: "Ubah", onPressRight: () => { - handlerUpdateStatus?.(item.label === "Buka forum" ? "Open" : "Closed"); + handlerUpdateStatus?.( + item.label === "Buka forum" ? "Open" : "Closed" + ); + }, + }); + } else if (item.value === "block") { + AlertDefaultSystem({ + title: "Blockir user", + message: `Apakah anda yakin ingin blockir user @${authorUsername}?`, + textLeft: "Batal", + textRight: "Blockir", + onPressRight: async () => { + console.log("Blockir"); + const response = await apiForumBlockUser({ + data: { + menuFeature: "Forum", + blockedId: authorId, + blockerId: user?.id || "", + }, + }); + + if (response.success) { + Toast.show({ + type: "success", + text1: "Berhasil blokir", + }); + router.back(); + } else { + Toast.show({ + type: "error", + text1: response.message, + }); + } }, }); } else { @@ -76,9 +111,12 @@ export default function Forum_MenuDrawerBerandaSection({ data={ authorId === user?.id ? drawerItemsForumBerandaForAuthor({ id, status }) - : drawerItemsForumBerandaForNonAuthor({ id }) + : drawerItemsForumBerandaForNonAuthor({ + id, + username: authorUsername, + }) } - columns={4} // Ubah ke 2 jika ingin 2 kolom per baris + columns={authorId === user?.id ? 4 : 2} // Ubah ke 2 jika ingin 2 kolom per baris onPressItem={handlePress as any} /> diff --git a/service/api-client/api-master.ts b/service/api-client/api-master.ts index 69210d7..c3b8689 100644 --- a/service/api-client/api-master.ts +++ b/service/api-client/api-master.ts @@ -1,5 +1,17 @@ import { apiConfig } from "../api-config"; +// ================== START MASTER ================== // +export async function apiMasterAppCategory() { + try { + const response = await apiConfig.get(`/mobile/master/app-category`); + return response.data; + } catch (error) { + throw error; + } +} + +// ================== END MASTER ================== // + // ================== START MASTER PORTFOLIO ================== // export async function apiMasterBidangBisnis() { try { @@ -167,4 +179,4 @@ export async function apiMasterTransaction() { } catch (error) { throw error; } -} \ No newline at end of file +} diff --git a/service/api-client/api-user.ts b/service/api-client/api-user.ts index 0e4d854..8c2a4b9 100644 --- a/service/api-client/api-user.ts +++ b/service/api-client/api-user.ts @@ -14,3 +14,25 @@ export async function apiDeleteUser({id}:{id: string}) { const response = await apiConfig.delete(`/mobile/user/${id}`); return response.data; } + +export async function apiForumBlockUser({ + data, +}: { + data: { + // Id yang di blokir + blockedId: string; + // Id yang melakukan blokir + blockerId: string; + menuFeature: "Event" | "Forum"; + }; +}) { + console.log("[FETCH API]", data); + try { + const response = await apiConfig.post(`/mobile/block-user`, { + data: data, + }); + return response.data; + } catch (error) { + throw error; + } +}