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:
@@ -223,6 +223,7 @@ export default function ForumDetail() {
|
||||
>
|
||||
<Forum_MenuDrawerBerandaSection
|
||||
id={dataId}
|
||||
authorUsername={data?.Author?.username as string}
|
||||
status={status}
|
||||
setIsDrawerOpen={() => {
|
||||
setOpenDrawer(false);
|
||||
|
||||
@@ -17,6 +17,8 @@ import { useEffect, useState } from "react";
|
||||
export default function Application() {
|
||||
const { token, user } = useAuth();
|
||||
const [data, setData] = useState<any>();
|
||||
|
||||
console.log("[User] >>", JSON.stringify(user?.id, null, 2));
|
||||
|
||||
useEffect(() => {
|
||||
onLoadData();
|
||||
|
||||
@@ -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: (
|
||||
<Ionicons name="flag" size={ICON_SIZE_SMALL} color={MainColor.white} />
|
||||
@@ -53,6 +56,16 @@ const drawerItemsForumBerandaForNonAuthor = ({ id }: { id: string }) => [
|
||||
label: "Laporkan diskusi",
|
||||
// color: MainColor.white,
|
||||
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",
|
||||
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"
|
||||
},
|
||||
];
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user