Fix tampilan admin dan notifikasi to admin
# fix - Notifikasi report posting _ Realtime notifikasi ## Issuee: Cooming soon saat report komentar langsung menuju tablenya
This commit is contained in:
@@ -27,13 +27,11 @@ import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/component_global/notif_global/notifikasi_gagal";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import _ from "lodash";
|
||||
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_v2_getAllPosting from "../../fun/get/v2_get_all_posting";
|
||||
import { forum_new_getAllPosting } from "../../fun/get/new_get_all_posting";
|
||||
import _ from "lodash";
|
||||
import { MODEL_FORUM_POSTING } from "../../model/interface";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
|
||||
export default function ComponentForum_V2_CardMoreButton({
|
||||
authorId,
|
||||
|
||||
@@ -4,22 +4,20 @@ import prisma from "@/app/lib/prisma";
|
||||
import { user_getOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function forum_funCreateReportPosting(
|
||||
postingId: string,
|
||||
value: string,
|
||||
) {
|
||||
export async function forum_funCreateReportPosting({
|
||||
postingId,
|
||||
kategoriId,
|
||||
}: {
|
||||
postingId: string;
|
||||
kategoriId: number;
|
||||
}) {
|
||||
const authorId = await user_getOneUserId();
|
||||
const cekId = await prisma.forumMaster_KategoriReport.findFirst({
|
||||
where: {
|
||||
title: value,
|
||||
},
|
||||
});
|
||||
|
||||
const createReport = await prisma.forum_ReportPosting.create({
|
||||
data: {
|
||||
userId: authorId,
|
||||
forum_PostingId: postingId,
|
||||
forumMaster_KategoriReportId: cekId?.id,
|
||||
forumMaster_KategoriReportId: kategoriId,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
17
src/app_modules/forum/fun/get/get_one_kategori_by_id.ts
Normal file
17
src/app_modules/forum/fun/get/get_one_kategori_by_id.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function forum_getOneKategoriById({
|
||||
kategoriId,
|
||||
}: {
|
||||
kategoriId: number;
|
||||
}) {
|
||||
const cekData = await prisma.forumMaster_KategoriReport.findFirst({
|
||||
where: {
|
||||
id: kategoriId,
|
||||
},
|
||||
});
|
||||
|
||||
return cekData
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
"use server"
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
|
||||
export default async function forum_v2_getAllPosting({search}: {search?: string}) {
|
||||
const getData = await prisma.forum_Posting.findMany({
|
||||
// take: takeData,
|
||||
// skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
diskusi: {
|
||||
mode: "insensitive",
|
||||
contains: search,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
createdAt: true,
|
||||
isActive: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
imagesId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Forum_Komentar: {
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
ForumMaster_StatusPosting: true,
|
||||
},
|
||||
});
|
||||
|
||||
return getData
|
||||
}
|
||||
@@ -1,50 +1,30 @@
|
||||
"use client";
|
||||
|
||||
import { RouterForum } from "@/app/lib/router_hipmi/router_forum";
|
||||
import { RouterJob } from "@/app/lib/router_hipmi/router_job";
|
||||
import ComponentGlobal_AuthorNameOnHeader from "@/app_modules/component_global/author_name_on_header";
|
||||
import {
|
||||
Affix,
|
||||
rem,
|
||||
ActionIcon,
|
||||
Card,
|
||||
CardSection,
|
||||
Text,
|
||||
Stack,
|
||||
Divider,
|
||||
Group,
|
||||
Box,
|
||||
TextInput,
|
||||
Center,
|
||||
Button,
|
||||
Pagination,
|
||||
Loader,
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect, useTimeout, useWindowScroll } from "@mantine/hooks";
|
||||
import {
|
||||
IconCirclePlus,
|
||||
IconMessageCircle,
|
||||
IconPencilPlus,
|
||||
IconSearch,
|
||||
IconSearchOff,
|
||||
} from "@tabler/icons-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import ComponentForum_PostingAuthorNameOnHeader from "../component/header/posting_author_header_name";
|
||||
import { useState } from "react";
|
||||
import ComponentGlobal_V2_LoadingPage from "@/app_modules/component_global/loading_page_v2";
|
||||
import { useAtom } from "jotai";
|
||||
import { gs_forum_loading_edit_posting } from "../global_state";
|
||||
import { MODEL_FORUM_POSTING } from "../model/interface";
|
||||
import ComponentForum_MainCardView from "../component/main_card_view";
|
||||
import { forum_getListAllPosting } from "../fun/get/get_list_all_posting";
|
||||
import { forum_funSearchListPosting } from "../fun/search/fun_search_list_posting";
|
||||
import _ from "lodash";
|
||||
import ComponentForum_BerandaCardView from "../component/beranda/beranda_card";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import {
|
||||
ActionIcon,
|
||||
Affix,
|
||||
Button,
|
||||
Center,
|
||||
Loader,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
rem
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect, useWindowScroll } from "@mantine/hooks";
|
||||
import {
|
||||
IconPencilPlus,
|
||||
IconSearchOff
|
||||
} from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import ComponentForum_V2_MainCardView from "../component/main_component/card_view";
|
||||
import { forum_new_getAllPosting } from "../fun/get/new_get_all_posting";
|
||||
import forum_v2_getAllPosting from "../fun/get/v2_get_all_posting";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
import { MODEL_FORUM_POSTING } from "../model/interface";
|
||||
|
||||
export default function Forum_Beranda({
|
||||
listForum,
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface MODEL_FORUM_POSTING {
|
||||
Forum_Komentar: MODEL_FORUM_KOMENTAR[];
|
||||
Forum_ReportPosting: MODEL_FORUM_MASTER_REPORT[];
|
||||
ForumMaster_StatusPosting: MODEL_FORUM_MASTER_STATUS;
|
||||
forumMaster_StatusPostingId: number
|
||||
forumMaster_StatusPostingId: number;
|
||||
}
|
||||
|
||||
export interface MODEL_FORUM_KOMENTAR {
|
||||
@@ -53,5 +53,8 @@ export interface MODEL_FORUM_REPORT {
|
||||
deskripsi: string;
|
||||
ForumMaster_KategoriReport: MODEL_FORUM_MASTER_REPORT;
|
||||
forumMaster_KategoriReportId: string;
|
||||
forum_PostingId: string;
|
||||
Forum_Posting: MODEL_FORUM_POSTING;
|
||||
userId: string;
|
||||
User: MODEL_USER;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import { RouterForum } from "@/app/lib/router_hipmi/router_forum";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import adminNotifikasi_funCreateToUser from "@/app_modules/admin/notifikasi/fun/create/fun_create_notif_user";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import forum_getOneKategoriById from "../../fun/get/get_one_kategori_by_id";
|
||||
import { toNumber } from "lodash";
|
||||
|
||||
export default function Forum_ReportPosting({
|
||||
postingId,
|
||||
@@ -21,17 +23,22 @@ export default function Forum_ReportPosting({
|
||||
listReport: MODEL_FORUM_MASTER_REPORT[];
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const [reportValue, setReportValue] = useState("Kebencian");
|
||||
const [reportValue, setReportValue] = useState("1");
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack px={"sm"}>
|
||||
<Radio.Group value={reportValue as any} onChange={setReportValue}>
|
||||
<Radio.Group
|
||||
value={reportValue as any}
|
||||
onChange={(val: any) => {
|
||||
setReportValue(val);
|
||||
}}
|
||||
>
|
||||
<Stack spacing={"xl"}>
|
||||
{listReport.map((e) => (
|
||||
<Stack key={e.id}>
|
||||
<Stack key={e?.id.toString()}>
|
||||
<Radio
|
||||
value={e.title}
|
||||
value={e.id.toString()}
|
||||
label={<Title order={5}>{e.title}</Title>}
|
||||
/>
|
||||
<Text>{e.deskripsi}</Text>
|
||||
@@ -40,7 +47,7 @@ export default function Forum_ReportPosting({
|
||||
</Stack>
|
||||
</Radio.Group>
|
||||
<ButtonAction
|
||||
value={reportValue}
|
||||
kategoriId={toNumber(reportValue)}
|
||||
postingId={postingId}
|
||||
userLoginId={userLoginId}
|
||||
/>
|
||||
@@ -50,11 +57,11 @@ export default function Forum_ReportPosting({
|
||||
}
|
||||
|
||||
function ButtonAction({
|
||||
value,
|
||||
kategoriId,
|
||||
postingId,
|
||||
userLoginId,
|
||||
}: {
|
||||
value: string;
|
||||
kategoriId: number;
|
||||
postingId: string;
|
||||
userLoginId: string;
|
||||
}) {
|
||||
@@ -62,27 +69,36 @@ function ButtonAction({
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onReport() {
|
||||
const report = await forum_funCreateReportPosting(postingId, value);
|
||||
const report = await forum_funCreateReportPosting({
|
||||
postingId: postingId,
|
||||
kategoriId: kategoriId,
|
||||
});
|
||||
if (report.status === 201) {
|
||||
const getKategori = await forum_getOneKategoriById({
|
||||
kategoriId: toNumber(kategoriId),
|
||||
});
|
||||
console.log(getKategori);
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(report.message, 2000);
|
||||
setLoading(true);
|
||||
router.back();
|
||||
|
||||
// const dataNotif = {
|
||||
// appId: postingId,
|
||||
// pesan: value,
|
||||
// kategoriApp: "FORUM",
|
||||
// title: "Report Posting",
|
||||
// userId: userLoginId,
|
||||
// };
|
||||
const dataNotif = {
|
||||
appId: postingId,
|
||||
pesan: getKategori?.deskripsi,
|
||||
kategoriApp: "FORUM",
|
||||
title: getKategori?.title,
|
||||
userId: userLoginId,
|
||||
status: "Report Posting",
|
||||
};
|
||||
|
||||
// const notif = await notifikasiToAdmin_funCreate({
|
||||
// data: dataNotif as any,
|
||||
// });
|
||||
const createNotifikasi = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
// if (notif.status === 201) {
|
||||
// mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
// }
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 }));
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(report.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user