fix api forum
deskripsi: - delete button and function
This commit is contained in:
@@ -24,7 +24,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
Profile: true,
|
Profile: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
_count: {
|
_count: {
|
||||||
select: {
|
select: {
|
||||||
Forum_Komentar: true,
|
Forum_Komentar: true,
|
||||||
@@ -35,10 +34,15 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const fixData = {
|
||||||
|
...data,
|
||||||
|
count: data?._count.Forum_Komentar,
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success get data",
|
message: "Success get data",
|
||||||
data: data,
|
data: fixData,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
backendLogger.error("Error get data forum", error);
|
backendLogger.error("Error get data forum", error);
|
||||||
|
|||||||
@@ -1,31 +1,12 @@
|
|||||||
import { RouterForum } from "@/lib/router_hipmi/router_forum";
|
|
||||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||||
import Forum_MainDetail from "@/app_modules/forum/detail/main_detail";
|
import Forum_MainDetail from "@/app_modules/forum/detail/main_detail";
|
||||||
import { forum_countTotalKomenById } from "@/app_modules/forum/fun/count/count_total_komentar_by_id";
|
|
||||||
import { forum_funGetAllKomentarById } from "@/app_modules/forum/fun/get/get_all_komentar_by_id";
|
|
||||||
import { forum_getOnePostingById } from "@/app_modules/forum/fun/get/get_one_posting_by_id";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
|
|
||||||
export default async function Page({ params }: { params: { id: string } }) {
|
export default async function Page() {
|
||||||
let postingId = params.id;
|
|
||||||
const userLoginId = await funGetUserIdByToken();
|
const userLoginId = await funGetUserIdByToken();
|
||||||
|
|
||||||
// const dataPosting = await forum_getOnePostingById(postingId);
|
|
||||||
const listKomentar = await forum_funGetAllKomentarById({
|
|
||||||
postingId: postingId,
|
|
||||||
page: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
const countKomentar = await forum_countTotalKomenById(postingId);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Forum_MainDetail
|
<Forum_MainDetail userLoginId={userLoginId as string} />
|
||||||
// dataPosting={dataPosting as any}
|
|
||||||
// listKomentar={listKomentar as any}
|
|
||||||
userLoginId={userLoginId as string}
|
|
||||||
countKomentar={countKomentar}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,11 @@ import backendLogger from "@/util/backendLogger";
|
|||||||
import { clientLogger } from "@/util/clientLogger";
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
export default function ComponentForum_DetailCreateKomentar({
|
export default function ComponentForum_DetailCreateKomentar({
|
||||||
postingId,
|
postingId,
|
||||||
onSetKomentar,
|
|
||||||
data,
|
data,
|
||||||
userLoginId,
|
userLoginId,
|
||||||
onSetNewKomentar,
|
onSetNewKomentar,
|
||||||
}: {
|
}: {
|
||||||
postingId: string;
|
postingId: string;
|
||||||
onSetKomentar: (val: any) => void;
|
|
||||||
data: MODEL_FORUM_POSTING;
|
data: MODEL_FORUM_POSTING;
|
||||||
userLoginId: string;
|
userLoginId: string;
|
||||||
onSetNewKomentar: (val: boolean) => void;
|
onSetNewKomentar: (val: boolean) => void;
|
||||||
@@ -48,11 +46,6 @@ export default function ComponentForum_DetailCreateKomentar({
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const createComment = await forum_funCreateKomentar(postingId, value);
|
const createComment = await forum_funCreateKomentar(postingId, value);
|
||||||
if (createComment.status === 201) {
|
if (createComment.status === 201) {
|
||||||
// const loadData = await forum_funGetAllKomentarById({
|
|
||||||
// postingId: data.id,
|
|
||||||
// page: 1,
|
|
||||||
// });
|
|
||||||
// onSetKomentar(loadData);
|
|
||||||
|
|
||||||
onSetNewKomentar(true);
|
onSetNewKomentar(true);
|
||||||
setValue("");
|
setValue("");
|
||||||
@@ -88,7 +81,6 @@ export default function ComponentForum_DetailCreateKomentar({
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
clientLogger.error("Error create komentar forum", error);
|
clientLogger.error("Error create komentar forum", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ import {
|
|||||||
} from "@/app_modules/_global/color/color_pallet";
|
} from "@/app_modules/_global/color/color_pallet";
|
||||||
import { ComponentGlobal_LoaderAvatar } from "@/app_modules/_global/component";
|
import { ComponentGlobal_LoaderAvatar } from "@/app_modules/_global/component";
|
||||||
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
|
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
export default function ComponentForum_DetailHeader({
|
export default function ComponentForum_DetailHeader({
|
||||||
data,
|
data,
|
||||||
@@ -123,7 +125,8 @@ export default function ComponentForum_DetailHeader({
|
|||||||
postingId={data?.id}
|
postingId={data?.id}
|
||||||
authorId={data?.Author.id}
|
authorId={data?.Author.id}
|
||||||
userLoginId={userLoginId}
|
userLoginId={userLoginId}
|
||||||
statusId={data?.forumMaster_StatusPostingId}
|
statusId={data?.ForumMaster_StatusPosting.id}
|
||||||
|
dataPosting={data}
|
||||||
onLoadData={(val) => {
|
onLoadData={(val) => {
|
||||||
onLoadData(val);
|
onLoadData(val);
|
||||||
}}
|
}}
|
||||||
@@ -141,12 +144,14 @@ function ComponentForum_DetailButtonMore_V2({
|
|||||||
postingId,
|
postingId,
|
||||||
statusId,
|
statusId,
|
||||||
userLoginId,
|
userLoginId,
|
||||||
|
dataPosting,
|
||||||
onLoadData,
|
onLoadData,
|
||||||
}: {
|
}: {
|
||||||
authorId: any;
|
authorId: any;
|
||||||
postingId?: any;
|
postingId?: any;
|
||||||
statusId: any;
|
statusId: any;
|
||||||
userLoginId: any;
|
userLoginId: any;
|
||||||
|
dataPosting: any;
|
||||||
onLoadData: (val: any) => void;
|
onLoadData: (val: any) => void;
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -312,6 +317,7 @@ function ComponentForum_DetailButtonMore_V2({
|
|||||||
postingId={postingId}
|
postingId={postingId}
|
||||||
setOpenStatus={setOpenStatusClose}
|
setOpenStatus={setOpenStatusClose}
|
||||||
statusId={statusId}
|
statusId={statusId}
|
||||||
|
dataPosting={dataPosting}
|
||||||
onLoadData={(val) => {
|
onLoadData={(val) => {
|
||||||
onLoadData(val);
|
onLoadData(val);
|
||||||
}}
|
}}
|
||||||
@@ -338,13 +344,15 @@ function ButtonDelete({
|
|||||||
if (loading) return <ComponentGlobal_V2_LoadingPage />;
|
if (loading) return <ComponentGlobal_V2_LoadingPage />;
|
||||||
|
|
||||||
async function onDelete() {
|
async function onDelete() {
|
||||||
setOpenDel(false);
|
try {
|
||||||
await forum_funDeletePostingById(postingId as any).then((res) => {
|
|
||||||
if (res.status === 200) {
|
|
||||||
ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000);
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
const responseDelete = await forum_funDeletePostingById(postingId as any);
|
||||||
|
if (responseDelete.status === 200) {
|
||||||
|
setOpenDel(false);
|
||||||
router.back();
|
router.back();
|
||||||
|
|
||||||
|
ComponentGlobal_NotifikasiBerhasil(`Postingan Terhapus`, 2000);
|
||||||
|
|
||||||
// mqtt_client.publish(
|
// mqtt_client.publish(
|
||||||
// "Forum_detail_hapus_data",
|
// "Forum_detail_hapus_data",
|
||||||
// JSON.stringify({
|
// JSON.stringify({
|
||||||
@@ -352,9 +360,13 @@ function ButtonDelete({
|
|||||||
// })
|
// })
|
||||||
// );
|
// );
|
||||||
} else {
|
} else {
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
setLoading(false);
|
||||||
|
ComponentGlobal_NotifikasiGagal(responseDelete.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setLoading(false);
|
||||||
|
clientLogger.error("Error get data forum", error);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -387,38 +399,40 @@ function ButtonStatus({
|
|||||||
postingId,
|
postingId,
|
||||||
setOpenStatus,
|
setOpenStatus,
|
||||||
statusId,
|
statusId,
|
||||||
|
dataPosting,
|
||||||
onLoadData,
|
onLoadData,
|
||||||
}: {
|
}: {
|
||||||
postingId?: string;
|
postingId?: string;
|
||||||
setOpenStatus: any;
|
setOpenStatus: any;
|
||||||
statusId?: any;
|
statusId?: any;
|
||||||
|
dataPosting: any;
|
||||||
onLoadData: (val: any) => void;
|
onLoadData: (val: any) => void;
|
||||||
}) {
|
}) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
async function onTutupForum() {
|
async function onTutupForum() {
|
||||||
setOpenStatus(false);
|
try {
|
||||||
|
setLoading(true);
|
||||||
const closeForum = await forum_funEditStatusPostingById(
|
const closeForum = await forum_funEditStatusPostingById(
|
||||||
postingId as any,
|
postingId as any,
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
|
||||||
if (closeForum.status === 200) {
|
if (closeForum.status === 200) {
|
||||||
|
setOpenStatus(false);
|
||||||
ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000);
|
ComponentGlobal_NotifikasiBerhasil(`Forum Ditutup`, 2000);
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
const loadData = await forum_getOnePostingById(postingId as any);
|
const cloneData = _.clone(dataPosting);
|
||||||
onLoadData(loadData);
|
|
||||||
|
|
||||||
if (loadData) {
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
...loadData,
|
...cloneData,
|
||||||
ForumMaster_StatusPosting: {
|
ForumMaster_StatusPosting: {
|
||||||
id: 2,
|
id: 2,
|
||||||
status: "Close",
|
status: "Close",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onLoadData(updateData);
|
||||||
|
|
||||||
mqtt_client.publish(
|
mqtt_client.publish(
|
||||||
"Forum_detail_ganti_status",
|
"Forum_detail_ganti_status",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -426,32 +440,39 @@ function ButtonStatus({
|
|||||||
data: updateData.ForumMaster_StatusPosting,
|
data: updateData.ForumMaster_StatusPosting,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiGagal(closeForum.message);
|
ComponentGlobal_NotifikasiGagal(closeForum.message);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setLoading(false);
|
||||||
|
clientLogger.error("Error get data forum", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onBukaForum() {
|
async function onBukaForum() {
|
||||||
setOpenStatus(false);
|
|
||||||
|
|
||||||
const openForum = await forum_funEditStatusPostingById(postingId as any, 1);
|
|
||||||
if (openForum.status === 200) {
|
|
||||||
ComponentGlobal_NotifikasiBerhasil(`Forum Dibuka`, 2000);
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
const loadData = await forum_getOnePostingById(postingId as any);
|
try {
|
||||||
onLoadData(loadData);
|
const openForum = await forum_funEditStatusPostingById(
|
||||||
|
postingId as any,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
if (openForum.status === 200) {
|
||||||
|
setOpenStatus(false);
|
||||||
|
ComponentGlobal_NotifikasiBerhasil(`Forum Dibuka`, 2000);
|
||||||
|
|
||||||
if (loadData) {
|
const cloneData = _.clone(dataPosting);
|
||||||
const updateData = {
|
const updateData = {
|
||||||
...loadData,
|
...cloneData,
|
||||||
ForumMaster_StatusPosting: {
|
ForumMaster_StatusPosting: {
|
||||||
id: 1,
|
id: 1,
|
||||||
status: "Open",
|
status: "Open",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onLoadData(updateData);
|
||||||
|
|
||||||
mqtt_client.publish(
|
mqtt_client.publish(
|
||||||
"Forum_detail_ganti_status",
|
"Forum_detail_ganti_status",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -459,10 +480,14 @@ function ButtonStatus({
|
|||||||
data: updateData.ForumMaster_StatusPosting,
|
data: updateData.ForumMaster_StatusPosting,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiGagal(openForum.message);
|
ComponentGlobal_NotifikasiGagal(openForum.message);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setLoading(false);
|
||||||
|
clientLogger.error("Error get data forum", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Card, Stack, Group, Text, Box } from "@mantine/core";
|
import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
|
||||||
|
import { Box, Group, Stack, Text } from "@mantine/core";
|
||||||
import { IconMessageCircle, IconMessageCircleX } from "@tabler/icons-react";
|
import { IconMessageCircle, IconMessageCircleX } from "@tabler/icons-react";
|
||||||
import { MODEL_FORUM_POSTING } from "../../model/interface";
|
import { MODEL_FORUM_POSTING } from "../../model/interface";
|
||||||
import ComponentForum_DetailHeader from "./detail_header";
|
import ComponentForum_DetailHeader from "./detail_header";
|
||||||
import {
|
|
||||||
AccentColor,
|
|
||||||
MainColor,
|
|
||||||
} from "@/app_modules/_global/color/color_pallet";
|
|
||||||
import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
|
|
||||||
|
|
||||||
export default function ComponentForum_DetailForumView({
|
export default function ComponentForum_DetailForumView({
|
||||||
data,
|
data,
|
||||||
|
|||||||
@@ -27,16 +27,17 @@ import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empt
|
|||||||
|
|
||||||
export default function Forum_MainDetail({
|
export default function Forum_MainDetail({
|
||||||
userLoginId,
|
userLoginId,
|
||||||
countKomentar,
|
|
||||||
}: {
|
}: {
|
||||||
userLoginId: string;
|
userLoginId: string;
|
||||||
countKomentar: number;
|
|
||||||
}) {
|
}) {
|
||||||
const param = useParams<{ id: string }>();
|
const param = useParams<{ id: string }>();
|
||||||
const [data, setData] = useState<MODEL_FORUM_POSTING | null>(null);
|
const [dataPosting, setDataPosting] = useState<MODEL_FORUM_POSTING | null>(
|
||||||
const [lsKomentar, setLsKomentar] = useState<MODEL_FORUM_KOMENTAR[]>([]);
|
null
|
||||||
|
);
|
||||||
|
const [listKomentar, setListKomentar] = useState<MODEL_FORUM_KOMENTAR[]>([]);
|
||||||
const [activePage, setActivePage] = useState(1);
|
const [activePage, setActivePage] = useState(1);
|
||||||
const [newKomentar, setNewKomentar] = useState(false);
|
const [newKomentar, setNewKomentar] = useState(false);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
handleLoadData();
|
handleLoadData();
|
||||||
@@ -44,16 +45,21 @@ export default function Forum_MainDetail({
|
|||||||
|
|
||||||
const handleLoadData = async () => {
|
const handleLoadData = async () => {
|
||||||
try {
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
const response = await apiGetOneForumById({
|
const response = await apiGetOneForumById({
|
||||||
id: param.id,
|
id: param.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
setData(response.data);
|
setDataPosting(response.data);
|
||||||
|
} else {
|
||||||
|
setDataPosting(null);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clientLogger.error("Error get data forum", error);
|
clientLogger.error("Error get data forum", error);
|
||||||
setData(null);
|
setDataPosting(null);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -69,13 +75,13 @@ export default function Forum_MainDetail({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setLsKomentar(response.data);
|
setListKomentar(response.data);
|
||||||
} else {
|
} else {
|
||||||
setLsKomentar([]);
|
setListKomentar([]);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clientLogger.error("Error get data komentar forum", error);
|
clientLogger.error("Error get data komentar forum", error);
|
||||||
setLsKomentar([]);
|
setListKomentar([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,8 +110,8 @@ export default function Forum_MainDetail({
|
|||||||
|
|
||||||
mqtt_client.on("message", (topic: any, message: any) => {
|
mqtt_client.on("message", (topic: any, message: any) => {
|
||||||
const newData = JSON.parse(message.toString());
|
const newData = JSON.parse(message.toString());
|
||||||
if (newData.id === data?.id) {
|
if (newData.id === dataPosting?.id) {
|
||||||
const cloneData = _.clone(data);
|
const cloneData = _.clone(dataPosting);
|
||||||
|
|
||||||
// console.log(newData.data);
|
// console.log(newData.data);
|
||||||
const updateData = {
|
const updateData = {
|
||||||
@@ -116,37 +122,34 @@ export default function Forum_MainDetail({
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
setData(updateData as any);
|
setDataPosting(updateData as any);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [data]);
|
}, [dataPosting]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack>
|
<Stack>
|
||||||
{!data ? (
|
{!dataPosting || !listKomentar ? (
|
||||||
<CustomSkeleton height={200} width={"100%"} />
|
<CustomSkeleton height={200} width={"100%"} />
|
||||||
) : (
|
) : (
|
||||||
<ComponentForum_DetailForumView
|
<ComponentForum_DetailForumView
|
||||||
data={data}
|
data={dataPosting}
|
||||||
totalKomentar={countKomentar}
|
totalKomentar={dataPosting.count}
|
||||||
userLoginId={userLoginId}
|
userLoginId={userLoginId}
|
||||||
onLoadData={(val) => {
|
onLoadData={(val) => {
|
||||||
setData(val);
|
setDataPosting(val);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!data ? (
|
{!dataPosting ? (
|
||||||
<Forum_SkeletonKomentar />
|
<Forum_SkeletonKomentar />
|
||||||
) : (
|
) : (
|
||||||
(data?.ForumMaster_StatusPosting?.id as any) === 1 && (
|
(dataPosting?.ForumMaster_StatusPosting?.id as any) === 1 && (
|
||||||
<ComponentForum_DetailCreateKomentar
|
<ComponentForum_DetailCreateKomentar
|
||||||
postingId={data?.id}
|
postingId={dataPosting?.id}
|
||||||
onSetKomentar={(val) => {
|
data={dataPosting}
|
||||||
setLsKomentar(val);
|
|
||||||
}}
|
|
||||||
data={data}
|
|
||||||
userLoginId={userLoginId}
|
userLoginId={userLoginId}
|
||||||
onSetNewKomentar={(val) => {
|
onSetNewKomentar={(val) => {
|
||||||
setNewKomentar(val);
|
setNewKomentar(val);
|
||||||
@@ -155,12 +158,12 @@ export default function Forum_MainDetail({
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!lsKomentar.length ? (
|
{!listKomentar.length && isLoading ? (
|
||||||
<Forum_SkeletonListKomentar />
|
<Forum_SkeletonListKomentar />
|
||||||
) : _.isEmpty(lsKomentar) ? (
|
) : _.isEmpty(listKomentar) ? (
|
||||||
<ComponentGlobal_IsEmptyData />
|
<ComponentGlobal_IsEmptyData text="Tidak ada komentar" />
|
||||||
) : (
|
) : (
|
||||||
<Box >
|
<Box>
|
||||||
<ScrollOnly
|
<ScrollOnly
|
||||||
height={"60vh"}
|
height={"60vh"}
|
||||||
renderLoading={() => (
|
renderLoading={() => (
|
||||||
@@ -168,15 +171,15 @@ export default function Forum_MainDetail({
|
|||||||
<Loader color={"yellow"} />
|
<Loader color={"yellow"} />
|
||||||
</Center>
|
</Center>
|
||||||
)}
|
)}
|
||||||
data={lsKomentar}
|
data={listKomentar}
|
||||||
setData={setLsKomentar}
|
setData={setListKomentar}
|
||||||
moreData={handleMoreDataKomentar}
|
moreData={handleMoreDataKomentar}
|
||||||
>
|
>
|
||||||
{(item) => (
|
{(item) => (
|
||||||
<ComponentForum_KomentarView
|
<ComponentForum_KomentarView
|
||||||
data={item}
|
data={item}
|
||||||
setKomentar={setLsKomentar}
|
setKomentar={setListKomentar}
|
||||||
postingId={data?.id as any}
|
postingId={dataPosting?.id as any}
|
||||||
userLoginId={userLoginId}
|
userLoginId={userLoginId}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export async function forum_funCreateKomentar(
|
|||||||
postingId: string,
|
postingId: string,
|
||||||
komentar: string
|
komentar: string
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
const userLoginId = await funGetUserIdByToken();
|
const userLoginId = await funGetUserIdByToken();
|
||||||
|
|
||||||
const create = await prisma.forum_Komentar.create({
|
const create = await prisma.forum_Komentar.create({
|
||||||
@@ -19,6 +20,14 @@ export async function forum_funCreateKomentar(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!create) return { status: 400, message: "Gagal menambahkan komentar" };
|
if (!create) return { status: 400, message: "Gagal menambahkan komentar" };
|
||||||
revalidatePath("/dev/forum/detail");
|
|
||||||
return { status: 201, message: "Berhasil menambahkan komentar" };
|
return { status: 201, message: "Berhasil menambahkan komentar" };
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return {
|
||||||
|
status: 500,
|
||||||
|
message: "Error API",
|
||||||
|
error: (error as Error).message,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import prisma from "@/lib/prisma";
|
|||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
|
|
||||||
export async function forum_funDeletePostingById(forumId: string) {
|
export async function forum_funDeletePostingById(forumId: string) {
|
||||||
|
try {
|
||||||
const del = await prisma.forum_Posting.update({
|
const del = await prisma.forum_Posting.update({
|
||||||
where: {
|
where: {
|
||||||
id: forumId,
|
id: forumId,
|
||||||
@@ -16,4 +17,12 @@ export async function forum_funDeletePostingById(forumId: string) {
|
|||||||
if (!del) return { status: 400, message: "Gagal dihapus" };
|
if (!del) return { status: 400, message: "Gagal dihapus" };
|
||||||
revalidatePath("/dev/forum/main");
|
revalidatePath("/dev/forum/main");
|
||||||
return { status: 200, message: "Berhasil dihapus" };
|
return { status: 200, message: "Berhasil dihapus" };
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return {
|
||||||
|
status: 500,
|
||||||
|
message: "Error API",
|
||||||
|
error: (error as Error).message,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export interface MODEL_FORUM_POSTING {
|
|||||||
Forum_ReportPosting: MODEL_FORUM_MASTER_REPORT[];
|
Forum_ReportPosting: MODEL_FORUM_MASTER_REPORT[];
|
||||||
ForumMaster_StatusPosting: MODEL_FORUM_MASTER_STATUS;
|
ForumMaster_StatusPosting: MODEL_FORUM_MASTER_STATUS;
|
||||||
forumMaster_StatusPostingId: number;
|
forumMaster_StatusPostingId: number;
|
||||||
|
count: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MODEL_FORUM_KOMENTAR {
|
export interface MODEL_FORUM_KOMENTAR {
|
||||||
|
|||||||
Reference in New Issue
Block a user