Forum
Fix: - Tampilan beranda forum & bisa melakukan search dan sudah terintegrasi API - Fitur hapus edit dan ubah status sudah terintegrasi API - List komentar sudah bisa muncul dan bisa mengahpus ### No Issue
This commit is contained in:
@@ -1,30 +1,56 @@
|
||||
import { IMenuDrawerItem } from "@/components/_Interface/types";
|
||||
import MenuDrawerDynamicGrid from "@/components/Drawer/MenuDrawerDynamicGird";
|
||||
import { router } from "expo-router";
|
||||
import { drawerItemsForumBeranda } from "../ListPage";
|
||||
import { AlertDefaultSystem } from "@/components";
|
||||
import {
|
||||
drawerItemsForumBerandaForAuthor,
|
||||
drawerItemsForumBerandaForNonAuthor,
|
||||
} from "../ListPage";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { apiForumDelete } from "@/service/api-client/api-forum";
|
||||
import Toast from "react-native-toast-message";
|
||||
|
||||
export default function Forum_MenuDrawerBerandaSection({
|
||||
id,
|
||||
status,
|
||||
setIsDrawerOpen,
|
||||
setShowDeleteAlert,
|
||||
setShowAlertStatus,
|
||||
authorId,
|
||||
handlerUpdateStatus,
|
||||
}: {
|
||||
id: string;
|
||||
status: string;
|
||||
setIsDrawerOpen: (value: boolean) => void;
|
||||
setShowDeleteAlert?: (value: boolean) => void;
|
||||
setShowAlertStatus?: (value: boolean) => void;
|
||||
authorId: string;
|
||||
handlerUpdateStatus?: (value: string) => void;
|
||||
}) {
|
||||
const { user } = useAuth();
|
||||
const handlePress = (item: IMenuDrawerItem) => {
|
||||
if (item.label === "Hapus") {
|
||||
AlertDefaultSystem({
|
||||
title: "Hapus",
|
||||
message: "Apakah Anda yakin ingin menghapus forum ini?",
|
||||
title: "Hapus diskusi",
|
||||
message: "Apakah Anda yakin ingin menghapus diskusi ini?",
|
||||
textLeft: "Batal",
|
||||
textRight: "Hapus",
|
||||
onPressRight: () => {},
|
||||
onPressRight: async () => {
|
||||
try {
|
||||
const response = await apiForumDelete({ id });
|
||||
|
||||
if (response.success) {
|
||||
Toast.show({
|
||||
type: "success",
|
||||
text1: "Berhasil dihapus",
|
||||
});
|
||||
router.back();
|
||||
} else {
|
||||
Toast.show({
|
||||
type: "error",
|
||||
text1: response.message,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("[ERROR]", error);
|
||||
}
|
||||
},
|
||||
});
|
||||
} else if (item.label === "Buka forum" || item.label === "Tutup forum") {
|
||||
AlertDefaultSystem({
|
||||
@@ -32,7 +58,9 @@ export default function Forum_MenuDrawerBerandaSection({
|
||||
message: "Apakah Anda yakin ingin mengubah status forum ini?",
|
||||
textLeft: "Batal",
|
||||
textRight: "Ubah",
|
||||
onPressRight: () => {},
|
||||
onPressRight: () => {
|
||||
handlerUpdateStatus?.(item.label === "Buka forum" ? "Open" : "Closed");
|
||||
},
|
||||
});
|
||||
} else {
|
||||
router.push(item.path as any);
|
||||
@@ -45,7 +73,11 @@ export default function Forum_MenuDrawerBerandaSection({
|
||||
<>
|
||||
{/* Menu Items */}
|
||||
<MenuDrawerDynamicGrid
|
||||
data={drawerItemsForumBeranda({ id, status })}
|
||||
data={
|
||||
authorId === user?.id
|
||||
? drawerItemsForumBerandaForAuthor({ id, status })
|
||||
: drawerItemsForumBerandaForNonAuthor({ id })
|
||||
}
|
||||
columns={4} // Ubah ke 2 jika ingin 2 kolom per baris
|
||||
onPressItem={handlePress as any}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user