diff --git a/prisma/schema.prisma b/prisma/schema.prisma index fdd7eddc..940bc0e7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -865,8 +865,8 @@ model Notifikasi { Role MasterUserRole? @relation(fields: [userRoleId], references: [id]) userRoleId String - User User @relation("UserNotifikasi", fields: [userId], references: [id], map: "NotifikasiUser") + User User @relation("UserNotifikasi", fields: [userId], references: [id], map: "NotifikasiUser") userId String - Admin User @relation("AdminNotifikasi", fields: [adminId], references: [id], map: "NotifikasiAdmin") - adminId String + Admin User? @relation("AdminNotifikasi", fields: [adminId], references: [id], map: "NotifikasiAdmin") + adminId String? } diff --git a/src/app/dev/forum/main/page.tsx b/src/app/dev/forum/main/page.tsx index c0b887a9..c712b95d 100644 --- a/src/app/dev/forum/main/page.tsx +++ b/src/app/dev/forum/main/page.tsx @@ -1,11 +1,14 @@ import { Forum_Beranda } from "@/app_modules/forum"; import { forum_getListAllPosting } from "@/app_modules/forum/fun/get/get_list_all_posting"; +import { forum_new_getAllPosting } from "@/app_modules/forum/fun/get/new_get_all_posting"; +import forum_v2_getAllPosting from "@/app_modules/forum/fun/get/v2_get_all_posting"; import { user_getOneUserId } from "@/app_modules/fun_global/get_user_token"; export default async function Page() { - const listForum = await forum_getListAllPosting(); + const listForum = await forum_v2_getAllPosting({}); const userLoginId = await user_getOneUserId(); + return ( <> { if (res.status === 200) { - ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000); + // ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000); setLoading(true); const listForum = await forum_getListAllPosting(); setData(listForum); + return null; } else { - ComponentGlobal_NotifikasiGagal(res.message); + // ComponentGlobal_NotifikasiGagal(res.message); + return null; } }); } @@ -273,19 +275,34 @@ function ButtonStatus({ async function onTutupForum() { setOpenStatus(false); - await forum_funEditStatusPostingById(postingId as any, 2).then( - async (res) => { - if (res.status === 200) { - await forum_getListAllPosting().then((val) => { - setData(val as any); - ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000); - setLoading(true); - }); - } else { - ComponentGlobal_NotifikasiGagal(res.message); - } - } + const upateStatusClose = await forum_funEditStatusPostingById( + postingId as any, + 2 ); + if (upateStatusClose.status === 200) { + const loadData = await forum_getListAllPosting(); + // ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000); + setData(loadData); + setLoading(true); + return null; + } else { + // ComponentGlobal_NotifikasiGagal(upateStatusClose.message); + return null; + } + + // await forum_funEditStatusPostingById(postingId as any, 2).then( + // async (res) => { + // if (res.status === 200) { + // await forum_getListAllPosting().then((val) => { + // setData(val as any); + // ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000); + // setLoading(true); + // }); + // } else { + // ComponentGlobal_NotifikasiGagal(res.message); + // } + // } + // ); } async function onBukaForum() { diff --git a/src/app_modules/forum/component/beranda/beranda_card.tsx b/src/app_modules/forum/component/beranda/beranda_card.tsx index 5f732089..d0c4d57d 100644 --- a/src/app_modules/forum/component/beranda/beranda_card.tsx +++ b/src/app_modules/forum/component/beranda/beranda_card.tsx @@ -37,9 +37,6 @@ export default function ComponentForum_BerandaCardView({ {data.map((e, i) => ( - {/*
{JSON.stringify(e.Author.id, null, 2)}
-
{JSON.stringify(userLoginId, null, 2)}
*/} -
+ { - // console.log("halaman forum"); setLoadingDetail(true); router.push(RouterForum.main_detail + e.id); }} @@ -65,6 +62,7 @@ export default function ComponentForum_BerandaCardView({
+ diff --git a/src/app_modules/forum/component/card_loader.tsx b/src/app_modules/forum/component/card_loader.tsx new file mode 100644 index 00000000..e3660996 --- /dev/null +++ b/src/app_modules/forum/component/card_loader.tsx @@ -0,0 +1,25 @@ +"use client"; + +import { Overlay, Center, Loader } from "@mantine/core"; + +export default function ComponentForum_CardLoadingOverlay({ + size, + variant, +}: { + size?: number; + variant?: any; +}) { + return ( + <> + +
+ +
+
+ + ); +} diff --git a/src/app_modules/forum/component/main_component/card_header.tsx b/src/app_modules/forum/component/main_component/card_header.tsx new file mode 100644 index 00000000..92487d9c --- /dev/null +++ b/src/app_modules/forum/component/main_component/card_header.tsx @@ -0,0 +1,146 @@ +"use client"; + +import loading from "@/app/dev/home/loading"; +import { RouterForum } from "@/app/lib/router_hipmi/router_forum"; +import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog"; +import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/component_global/notif_global/notifikasi_peringatan"; +import { + Stack, + Loader, + Avatar, + Badge, + Group, + Divider, + Grid, + Text, +} from "@mantine/core"; +import { IconCircle } from "@tabler/icons-react"; +import ComponentForum_BerandaButtonMore from "../beranda/beranda_button_more"; +import { MODEL_USER } from "@/app_modules/home/model/interface"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { MODEL_FORUM_POSTING } from "../../model/interface"; +import ComponentForum_V2_CardMoreButton from "./card_more_button"; + +export default function ComponentForum_V2_HeaderCard({ + data, + isMoreButton, + userLoginId, + onLoadData, +}: { + data: MODEL_FORUM_POSTING; + isMoreButton: boolean; + userLoginId: string; + onLoadData: (val: any) => void +}) { + const router = useRouter(); + const [isLoading, setIsLoading] = useState(false); + + return ( + <> + + + { + if (data.Author.id) { + setIsLoading(true); + router.push(RouterForum.forumku + data.Author.id); + } else { + ComponentGlobal_NotifikasiPeringatan("Id tidak ditemukan"); + } + }} + > + {isLoading ? ( + + ) : ( + + )} + + + + + + + + {data.Author.username + ? data.Author.username + : "Nama author "} + + + + + + + + {(data.ForumMaster_StatusPosting.id as any) === 1 + ? "Open" + : "Close"} + + + + + + + + + + {data.createdAt + ? data.createdAt.toLocaleDateString(["id-ID"], { + day: "numeric", + month: "short", + }) + : new Date().toLocaleDateString(["id-ID"], { + day: "numeric", + month: "short", + })} + + + + + + {isMoreButton ? ( + + + + + ) : ( + "" + )} + + + + {/* {isPembatas ? : ""} */} + + + ); +} diff --git a/src/app_modules/forum/component/main_component/card_more_button.tsx b/src/app_modules/forum/component/main_component/card_more_button.tsx new file mode 100644 index 00000000..c082b7c6 --- /dev/null +++ b/src/app_modules/forum/component/main_component/card_more_button.tsx @@ -0,0 +1,350 @@ +"use client"; + +import { RouterForum } from "@/app/lib/router_hipmi/router_forum"; +import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil"; +import { + ActionIcon, + Button, + Drawer, + Grid, + Group, + Loader, + Modal, + Stack, + Text, + Title, +} from "@mantine/core"; +import { useDisclosure } from "@mantine/hooks"; +import { + IconDots, + IconEdit, + IconFlag3, + IconSquareCheck, + IconSquareRoundedX, + IconTrash, +} from "@tabler/icons-react"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; + +import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/component_global/notif_global/notifikasi_gagal"; +import { forum_funDeletePostingById } from "../../fun/delete/fun_delete_posting_by_id"; +import { forum_funEditStatusPostingById } from "../../fun/edit/fun_edit_status_posting_by_id"; +import { forum_getListAllPosting } from "../../fun/get/get_list_all_posting"; +import { forum_new_getAllPosting } from "../../fun/get/new_get_all_posting"; +import forum_v2_getAllPosting from "../../fun/get/v2_get_all_posting"; + +export default function ComponentForum_V2_CardMoreButton({ + authorId, + postingId, + statusId, + userLoginId, + onLoadData, +}: { + authorId: any; + postingId?: any; + statusId?: any; + userLoginId: any; + onLoadData: (val: any) => void; +}) { + const router = useRouter(); + + // modal & drawer + const [opened, { open, close }] = useDisclosure(false); + const [openDel, setOpenDel] = useState(false); + const [openStatusClose, setOpenStatusClose] = useState(false); + + // loading + const [loadingEdit, setLoadingEdit] = useState(false); + const [loadingReport, setLoadingReport] = useState(false); + + // if (loadingEdit) return ; + + return ( + <> + + + {userLoginId != authorId ? ( + "" + ) : ( + + { + close(); + setOpenStatusClose(true); + }} + > + + {statusId === 1 ? ( + + ) : ( + + )} + + + {statusId === 1 ? ( + Tutup forum + ) : ( + Buka forum + )} + + + + { + close(); + setOpenDel(true); + }} + > + + + + + Hapus + + + + { + setLoadingEdit(true); + router.push(RouterForum.edit_posting + postingId); + }} + > + + + + + + Edit posting{" "} + {loadingEdit ? : ""} + + + + + )} + + {userLoginId == authorId ? ( + "" + ) : ( + { + setLoadingReport(true); + router.push(RouterForum.report_posting + postingId); + }} + > + + + + + + + Laporkan posting + {" "} + {loadingReport ? : ""} + + + + )} + + + + + + { + setOpenDel(false); + }} + centered + withCloseButton={false} + > + + + + setOpenStatusClose(false)} + centered + withCloseButton={false} + > + + + + open()}> + + + + ); +} + +function ButtonDelete({ + postingId, + setOpenDel, + onLoadData, +}: { + postingId?: string; + setOpenDel: any; + onLoadData: (val: any) => void; +}) { + const [loading, setLoading] = useState(false); + + async function onDelete() { + setOpenDel(false); + await forum_funDeletePostingById(postingId as any).then(async (res) => { + if (res.status === 200) { + // ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000); + setLoading(true); + const loadData = await forum_new_getAllPosting({ page: 1 }); + onLoadData(loadData); + return null; + } else { + // ComponentGlobal_NotifikasiGagal(res.message); + return null; + } + }); + } + return ( + <> + + Yakin menghapus posting ini ? + + + + + + + ); +} + +function ButtonStatus({ + postingId, + setOpenStatus, + statusId, + onLoadData, + userLoginId, + authorId, +}: { + postingId?: string; + setOpenStatus: any; + statusId?: any; + onLoadData: (val: any) => void; + userLoginId: string; + authorId: string; +}) { + const [loading, setLoading] = useState(false); + + async function onTutupForum() { + setOpenStatus(false); + + const upateStatusClose = await forum_funEditStatusPostingById( + postingId as any, + 2 + ); + if (upateStatusClose.status === 200) { + ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000); + + const loadData = await forum_v2_getAllPosting({}) + onLoadData(loadData); + setLoading(true); + + } else { + ComponentGlobal_NotifikasiGagal(upateStatusClose.message); + + } + + } + + async function onBukaForum() { + setOpenStatus(false); + + await forum_funEditStatusPostingById(postingId as any, 1).then( + async (res) => { + if (res.status === 200) { + const loadData = await forum_v2_getAllPosting({}); + onLoadData(loadData); + + ComponentGlobal_NotifikasiBerhasil(`Forum Dibuka`, 2000); + setLoading(true); + + } else { + ComponentGlobal_NotifikasiGagal(res.message); + } + } + ); + } + + return ( + <> + + {statusId === 1 ? ( + Yakin menutup forum ini ? + ) : ( + Yakin membuka forum ini ? + )} + + + + {statusId === 1 ? ( + + ) : ( + + )} + + + + ); +} diff --git a/src/app_modules/forum/component/main_component/card_view.tsx b/src/app_modules/forum/component/main_component/card_view.tsx new file mode 100644 index 00000000..334efac6 --- /dev/null +++ b/src/app_modules/forum/component/main_component/card_view.tsx @@ -0,0 +1,97 @@ +"use client"; + +import { RouterForum } from "@/app/lib/router_hipmi/router_forum"; +import { Stack, Card, Group, ActionIcon, Divider, Text } from "@mantine/core"; +import { IconMessageCircle, IconMessageCircleX } from "@tabler/icons-react"; +import { useRouter } from "next/navigation"; +import ComponentForum_BerandaAuthorNameOnHeader from "../beranda/beranda_author_header"; +import ComponentForum_V2_HeaderCard from "./card_header"; +import { MODEL_FORUM_POSTING } from "../../model/interface"; +import { useState } from "react"; +import ComponentGlobal_CardLoadingOverlay from "@/app_modules/component_global/loading_card"; +import ComponentForum_CardLoadingOverlay from "../card_loader"; + +export default function ComponentForum_V2_MainCardView({ + data, + userLoginId, + onLoadData, +}: { + data: MODEL_FORUM_POSTING[]; + userLoginId: string; + onLoadData: (val: any) => void; +}) { + const router = useRouter(); + const [loadingKomen, setLoadingKomen] = useState(false); + const [loadingDetail, setLoadingDetail] = useState(false); + + const [postingId, setPostingId] = useState(""); + + return ( + <> + + {data.map((e, i) => ( + + + + {/* */} + + + { + router.push(RouterForum.main_detail + e.id) + }} + > + +
+ + + + + + + { + setPostingId(e?.id), + (e?.ForumMaster_StatusPosting.id as any) === 1 + ? (router.push(RouterForum.komentar + e?.id), + setLoadingKomen(true)) + : router.push(RouterForum.main_detail + e?.id); + }} + > + {(e?.ForumMaster_StatusPosting?.id as any) === 1 ? ( + + ) : ( + + )} + + + {/* */} + + {e?.Forum_Komentar.length} + + + + + + ))} + + + ); +} diff --git a/src/app_modules/forum/create/index.tsx b/src/app_modules/forum/create/index.tsx index 4906734d..71f3a3d3 100644 --- a/src/app_modules/forum/create/index.tsx +++ b/src/app_modules/forum/create/index.tsx @@ -35,6 +35,8 @@ const ReactQuill = dynamic( { ssr: false } ); +import mqtt_client from "@/util/mqtt_client"; + export default function Forum_Create() { const [value, setValue] = useState(""); const [totalLength, setTotalLength] = useState(0); @@ -74,7 +76,6 @@ export default function Forum_Create() { - {/*
 {JSON.stringify(value, null, 2)}
*/} ); } @@ -88,15 +89,17 @@ function ButtonAction({ value }: { value: string }) { return null; } - await forum_funCreate(value).then((res) => { - if (res.status === 201) { - setLoading(true); - ComponentGlobal_NotifikasiBerhasil(res.message); - setTimeout(() => router.back(), 1000); - } else { - ComponentGlobal_NotifikasiGagal(res.message); - } - }); + const create = await forum_funCreate(value); + if (create.status === 201) { + setLoading(true); + ComponentGlobal_NotifikasiBerhasil(create.message); + setTimeout(() => router.back(), 1000); + + mqtt_client.publish("Forum_user_to_user", JSON.stringify({isNewPost: true, count: 1 })); + + } else { + ComponentGlobal_NotifikasiGagal(create.message); + } } return ( <> diff --git a/src/app_modules/forum/forumku/index.tsx b/src/app_modules/forum/forumku/index.tsx index 35af2a7a..e246717e 100644 --- a/src/app_modules/forum/forumku/index.tsx +++ b/src/app_modules/forum/forumku/index.tsx @@ -1,36 +1,28 @@ "use client"; +import { RouterForum } from "@/app/lib/router_hipmi/router_forum"; import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog"; -import ComponentGlobal_AuthorNameOnHeader from "@/app_modules/component_global/author_name_on_header"; +import ComponentGlobal_V2_LoadingPage from "@/app_modules/component_global/loading_page_v2"; import { MODEL_USER } from "@/app_modules/home/model/interface"; import { ActionIcon, Affix, Avatar, Button, - Card, Center, Divider, Grid, - Group, Stack, Text, rem, } from "@mantine/core"; -import { - IconCircleFilled, - IconMessageCircle, - IconPencilPlus, -} from "@tabler/icons-react"; -import { useRouter } from "next/navigation"; -import ComponentForum_PostingAuthorNameOnHeader from "../component/header/posting_author_header_name"; -import { RouterForum } from "@/app/lib/router_hipmi/router_forum"; -import { useState } from "react"; -import ComponentGlobal_V2_LoadingPage from "@/app_modules/component_global/loading_page_v2"; -import { MODEL_FORUM_POSTING } from "../model/interface"; -import ComponentForum_MainCardView from "../component/main_card_view"; import { useWindowScroll } from "@mantine/hooks"; +import { IconCircleFilled, IconPencilPlus } from "@tabler/icons-react"; import _ from "lodash"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import ComponentForum_MainCardView from "../component/main_card_view"; +import { MODEL_FORUM_POSTING } from "../model/interface"; export default function Forum_Forumku({ auhtorSelectedData, @@ -185,9 +177,6 @@ function ForumPosting({ if (loadingKomen) return ; return ( <> - - - (listForum); + // const [nPage, setNPage] = useState(listForum.nPage); + // const [activePage, setActivePage] = useState(1); + const [isSearch, setIsSearch] = useState(""); - if (loadingDetail) return ; - if (loadingKomen) return ; + const [loadingCreate, setLoadingCreate] = useState(false); + + // + const [isNewPost, setIsNewPost] = useState(false); + const [countNewPost, setCountNewPost] = useState(0); + + // useShallowEffect(() => { + // onLoadAllData({ + // onLoad(val) { + // setData(val.data); + // setNPage(val.nPage); + // }, + // }); + // }, [setData, setNPage]); + + // async function onLoadAllData({ onLoad }: { onLoad: (val: any) => void }) { + // const loadData = await forum_new_getAllPosting({ page: 1 }); + // onLoad(loadData); + // } + + useShallowEffect(() => { + mqtt_client.subscribe("Forum_user_to_user"); + + mqtt_client.on("message", (topic: any, message: any) => { + const data = JSON.parse(message.toString()); + // console.log(data); + setIsNewPost(data.isNewPost); + const tambah = countNewPost + data.count; + setCountNewPost(tambah); + }); + }, [countNewPost]); async function onSearch(text: string) { - await forum_funSearchListPosting(text).then((res: any) => { - setData(res); - }); + setIsSearch(text); + const search = await forum_v2_getAllPosting({search: text}); + setData(search as any); + // setNPage(search.nPage); + // setActivePage(1); } + // async function onClickPage(nextpage: number) { + // setActivePage(nextpage); + // const next = await forum_new_getAllPosting({ + // page: nextpage, + // search: isSearch, + // }); + // scrollTo({ y: 0 }); + // setData(next.data as any); + // setNPage(next.nPage); + // } + + return ( <> + {isNewPost && ( + + setData(val)} + onSetNewPost={(val) => { + setIsNewPost(val); + }} + onSetCountNewPosting={(val) => { + setCountNewPost(val); + }} + /> + + )} + {/*
{JSON.stringify(listForum, null, 2)}
*/} - Forum tidak ditemukan - - - Coba masukan kata yang bebeda + Tidak ada data ) : ( - { + setData(val); + // setNPage(val.nPage); + }} /> )} + + {/*
+ { + onClickPage(val); + }} + styles={(theme) => ({ + control: { + borderRadius: "100%", + + }, + })} + /> +
*/} + + ); +} + +function ButtonUpdateBeranda({ + countNewPost, + onSetData, + onSetNewPost, + onSetCountNewPosting, +}: { + countNewPost: number; + onSetData: (val: any) => void; + onSetNewPost: (val: any) => void; + onSetCountNewPosting: (val: any) => void; +}) { + const [scroll, scrollTo] = useWindowScroll(); + const [isLoading, setIsLoading] = useState(false); + + async function onLoadData() { + setIsLoading(true); + const loadData = await forum_getListAllPosting(); + if (loadData) { + onSetData(loadData); + onSetNewPost(false); + setIsLoading(false); + onSetCountNewPosting(0); + } + } + + return ( + <> +
+ +
); } diff --git a/src/app_modules/forum/model/interface.tsx b/src/app_modules/forum/model/interface.tsx index 530d7d67..fc543f10 100644 --- a/src/app_modules/forum/model/interface.tsx +++ b/src/app_modules/forum/model/interface.tsx @@ -9,7 +9,7 @@ export interface MODEL_FORUM_POSTING { diskusi: string; authorId: string; Author: MODEL_USER; - _count: number; + _count: number Forum_Komentar: MODEL_FORUM_KOMENTAR[]; Forum_ReportPosting: MODEL_FORUM_MASTER_REPORT[]; ForumMaster_StatusPosting: MODEL_FORUM_MASTER_STATUS;