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
This commit is contained in:
2025-11-25 11:04:12 +08:00
parent 41e648d8f3
commit 00eea71248
6 changed files with 98 additions and 8 deletions

View File

@@ -223,6 +223,7 @@ export default function ForumDetail() {
> >
<Forum_MenuDrawerBerandaSection <Forum_MenuDrawerBerandaSection
id={dataId} id={dataId}
authorUsername={data?.Author?.username as string}
status={status} status={status}
setIsDrawerOpen={() => { setIsDrawerOpen={() => {
setOpenDrawer(false); setOpenDrawer(false);

View File

@@ -18,6 +18,8 @@ export default function Application() {
const { token, user } = useAuth(); const { token, user } = useAuth();
const [data, setData] = useState<any>(); const [data, setData] = useState<any>();
console.log("[User] >>", JSON.stringify(user?.id, null, 2));
useEffect(() => { useEffect(() => {
onLoadData(); onLoadData();
checkVersion(); checkVersion();

View File

@@ -22,6 +22,7 @@ const drawerItemsForumBerandaForAuthor = ({
), ),
label: "Edit posting", label: "Edit posting",
path: `/forum/${id}/edit`, path: `/forum/${id}/edit`,
values: "edit"
}, },
{ {
icon: icon:
@@ -34,6 +35,7 @@ const drawerItemsForumBerandaForAuthor = ({
label: status === "Open" ? "Tutup forum" : "Buka forum", label: status === "Open" ? "Tutup forum" : "Buka forum",
path: "", path: "",
color: status === "Open" ? MainColor.orange : MainColor.green, color: status === "Open" ? MainColor.orange : MainColor.green,
value: "status"
}, },
{ {
icon: ( icon: (
@@ -42,10 +44,11 @@ const drawerItemsForumBerandaForAuthor = ({
label: "Hapus", label: "Hapus",
path: "", path: "",
color: MainColor.red, color: MainColor.red,
value: "delete"
}, },
]; ];
const drawerItemsForumBerandaForNonAuthor = ({ id }: { id: string }) => [ const drawerItemsForumBerandaForNonAuthor = ({ id, username }: { id: string; username: string }) => [
{ {
icon: ( icon: (
<Ionicons name="flag" size={ICON_SIZE_SMALL} color={MainColor.white} /> <Ionicons name="flag" size={ICON_SIZE_SMALL} color={MainColor.white} />
@@ -53,6 +56,16 @@ const drawerItemsForumBerandaForNonAuthor = ({ id }: { id: string }) => [
label: "Laporkan diskusi", label: "Laporkan diskusi",
// color: MainColor.white, // color: MainColor.white,
path: `/forum/${id}/report-posting`, path: `/forum/${id}/report-posting`,
value: "report"
},
{
icon: (
<Ionicons name="ban" size={ICON_SIZE_SMALL} color={MainColor.white} />
),
label: `Blockir @${username}`,
color: MainColor.red,
path: `/forum/${id}/report-posting`,
value: "block"
}, },
]; ];
@@ -64,6 +77,7 @@ const drawerItemsForumComentarForAuthor = ({ id }: { id: string }) => [
label: "Hapus", label: "Hapus",
color: MainColor.red, color: MainColor.red,
path: "", path: "",
value: "delete"
}, },
]; ];
@@ -75,5 +89,6 @@ const drawerItemsForumComentarForNonAuthor = ({ id }: { id: string }) => [
label: "Laporkan", label: "Laporkan",
// color: MainColor.white, // color: MainColor.white,
path: `/forum/${id}/report-commentar`, path: `/forum/${id}/report-commentar`,
value: "report"
}, },
]; ];

View File

@@ -9,15 +9,18 @@ import {
import { useAuth } from "@/hooks/use-auth"; import { useAuth } from "@/hooks/use-auth";
import { apiForumDelete } from "@/service/api-client/api-forum"; import { apiForumDelete } from "@/service/api-client/api-forum";
import Toast from "react-native-toast-message"; import Toast from "react-native-toast-message";
import { apiForumBlockUser } from "@/service/api-client/api-user";
export default function Forum_MenuDrawerBerandaSection({ export default function Forum_MenuDrawerBerandaSection({
id, id,
authorUsername,
status, status,
setIsDrawerOpen, setIsDrawerOpen,
authorId, authorId,
handlerUpdateStatus, handlerUpdateStatus,
}: { }: {
id: string; id: string;
authorUsername: string;
status: string; status: string;
setIsDrawerOpen: (value: boolean) => void; setIsDrawerOpen: (value: boolean) => void;
authorId: string; authorId: string;
@@ -25,7 +28,7 @@ export default function Forum_MenuDrawerBerandaSection({
}) { }) {
const { user } = useAuth(); const { user } = useAuth();
const handlePress = (item: IMenuDrawerItem) => { const handlePress = (item: IMenuDrawerItem) => {
if (item.label === "Hapus") { if (item.value === "delete") {
AlertDefaultSystem({ AlertDefaultSystem({
title: "Hapus diskusi", title: "Hapus diskusi",
message: "Apakah Anda yakin ingin menghapus diskusi ini?", message: "Apakah Anda yakin ingin menghapus diskusi ini?",
@@ -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({ AlertDefaultSystem({
title: "Ubah Status", title: "Ubah Status",
message: "Apakah Anda yakin ingin mengubah status forum ini?", message: "Apakah Anda yakin ingin mengubah status forum ini?",
textLeft: "Batal", textLeft: "Batal",
textRight: "Ubah", textRight: "Ubah",
onPressRight: () => { 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 { } else {
@@ -76,9 +111,12 @@ export default function Forum_MenuDrawerBerandaSection({
data={ data={
authorId === user?.id authorId === user?.id
? drawerItemsForumBerandaForAuthor({ id, status }) ? 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} onPressItem={handlePress as any}
/> />
</> </>

View File

@@ -1,5 +1,17 @@
import { apiConfig } from "../api-config"; 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 ================== // // ================== START MASTER PORTFOLIO ================== //
export async function apiMasterBidangBisnis() { export async function apiMasterBidangBisnis() {
try { try {

View File

@@ -14,3 +14,25 @@ export async function apiDeleteUser({id}:{id: string}) {
const response = await apiConfig.delete(`/mobile/user/${id}`); const response = await apiConfig.delete(`/mobile/user/${id}`);
return response.data; 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;
}
}