diff --git a/src/app/(application)/discussion/[id]/member/page.tsx b/src/app/(application)/discussion/[id]/member/page.tsx
new file mode 100644
index 0000000..bf272ef
--- /dev/null
+++ b/src/app/(application)/discussion/[id]/member/page.tsx
@@ -0,0 +1,9 @@
+import { MemberDiscussionGeneral } from "@/module/discussion_general";
+
+export default function Page() {
+ return (
+ <>
+
+ >
+ )
+}
\ No newline at end of file
diff --git a/src/app/(application)/discussion/[id]/page.tsx b/src/app/(application)/discussion/[id]/page.tsx
index c306dfe..d179343 100644
--- a/src/app/(application)/discussion/[id]/page.tsx
+++ b/src/app/(application)/discussion/[id]/page.tsx
@@ -1,7 +1,9 @@
+import { DetailDiscussionGeneral } from "@/module/discussion_general";
+
export default function Page() {
return (
<>
- detail diskusi umum
+
>
)
}
\ No newline at end of file
diff --git a/src/app/api/discussion-general/[id]/member/route.ts b/src/app/api/discussion-general/[id]/member/route.ts
new file mode 100644
index 0000000..806923d
--- /dev/null
+++ b/src/app/api/discussion-general/[id]/member/route.ts
@@ -0,0 +1,92 @@
+import { prisma } from "@/module/_global";
+import { funGetUserByCookies } from "@/module/auth";
+import { createLogUser } from "@/module/user";
+import _ from "lodash";
+import { NextResponse } from "next/server";
+
+
+// ADD MEMBER DISCUSSION GENERAL
+export async function POST(request: Request, context: { params: { id: string } }) {
+ try {
+ const user = await funGetUserByCookies()
+ if (user.id == undefined) {
+ return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
+ }
+
+ const { id } = context.params
+ const { member } = (await request.json())
+
+ const cek = await prisma.discussion.count({
+ where: {
+ id,
+ isActive: true
+ }
+ })
+
+ if (cek == 0) {
+ return NextResponse.json({ success: false, message: "Gagal menambahkan anggota, data tidak ditemukan" }, { status: 404 });
+ }
+
+ if (member.length > 0) {
+ const dataMember = member.map((v: any) => ({
+ ..._.omit(v, ["idUser", "name", "img"]),
+ idDiscussion: id,
+ idUser: v.idUser
+ }))
+
+ const insertMember = await prisma.discussionMember.createMany({
+ data: dataMember
+ })
+ }
+
+ // create log user
+ const log = await createLogUser({ act: 'CREATE', desc: 'User menambah anggota diskusi umum', table: 'discussion', data: String(id) })
+ return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota diskusi umum" }, { status: 200 });
+
+ } catch (error) {
+ console.error(error);
+ return NextResponse.json({ success: false, message: "Gagal menambahkan anggota, coba lagi nanti (error : 500)" }, { status: 500 });
+ }
+}
+
+
+// MENGELUARKAN ANGGOTA
+export async function DELETE(request: Request, context: { params: { id: string } }) {
+ try {
+ const user = await funGetUserByCookies()
+ if (user.id == undefined) {
+ return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
+ }
+
+ const { id } = context.params
+ const { idUser } = (await request.json());
+
+
+ const cek = await prisma.discussion.count({
+ where: {
+ id,
+ isActive: true
+ }
+ })
+
+ if (cek == 0) {
+ return NextResponse.json({ success: false, message: "Gagal, data tidak ditemukan" }, { status: 404 });
+ }
+
+ const deleteMember = await prisma.discussionMember.deleteMany({
+ where: {
+ idDiscussion: id,
+ idUser
+ }
+ })
+
+ // create log user
+ const log = await createLogUser({ act: 'DELETE', desc: 'User mengeluarkan anggota diskusi umum', table: 'discussion', data: String(id) })
+
+ return NextResponse.json({ success: true, message: "Berhasil mengeluarkan anggota diskusi umum" }, { status: 200 });
+
+ } catch (error) {
+ console.error(error);
+ return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota, coba lagi nanti (error : 500)" }, { status: 500 });
+ }
+}
\ No newline at end of file
diff --git a/src/app/api/discussion-general/[id]/route.ts b/src/app/api/discussion-general/[id]/route.ts
new file mode 100644
index 0000000..9aacc5e
--- /dev/null
+++ b/src/app/api/discussion-general/[id]/route.ts
@@ -0,0 +1,112 @@
+import { prisma } from "@/module/_global";
+import { funGetUserByCookies } from "@/module/auth";
+import _ from "lodash";
+import moment from "moment";
+import { NextResponse } from "next/server";
+
+export async function GET(request: Request, context: { params: { id: string } }) {
+ try {
+ let dataFix
+ const { id } = context.params
+ const { searchParams } = new URL(request.url);
+ const kategori = searchParams.get("cat");
+
+ const user = await funGetUserByCookies()
+ if (user.id == undefined) {
+ return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
+ }
+
+ const cek = await prisma.discussion.count({
+ where: {
+ id,
+ isActive: true
+ }
+ })
+
+ if (cek == 0) {
+ return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, data tidak ditemukan" }, { status: 404 });
+ }
+
+ if (kategori == "detail") {
+ const data = await prisma.discussion.findUnique({
+ where: {
+ id,
+ isActive: true
+ },
+ select: {
+ id: true,
+ title: true,
+ desc: true,
+ status: true,
+ createdAt: true,
+ }
+ })
+
+ dataFix = {
+ id: data?.id,
+ title: data?.title,
+ desc: data?.desc,
+ status: data?.status,
+ createdAt: moment(data?.createdAt).format("ll"),
+ }
+
+ } else if (kategori == "komentar") {
+ const data = await prisma.discussionComment.findMany({
+ where: {
+ idDiscussion: id,
+ isActive: true
+ },
+ select: {
+ id: true,
+ comment: true,
+ createdAt: true,
+ idUser: true,
+ User: {
+ select: {
+ name: true,
+ img: true
+ }
+ }
+ }
+ })
+
+ dataFix = data.map((v: any) => ({
+ ..._.omit(v, ["createdAt", "User",]),
+ createdAt: moment(v.createdAt).format("ll"),
+ username: v.User.name,
+ img: v.User.img
+ }))
+
+ } else if (kategori == "anggota") {
+ const data = await prisma.discussionMember.findMany({
+ where: {
+ idDiscussion: id,
+ isActive: true
+ },
+ select: {
+ idUser: true,
+ User: {
+ select: {
+ name: true,
+ img: true
+ }
+ }
+ }
+ })
+
+ dataFix = data.map((v: any) => ({
+ ..._.omit(v, ["User",]),
+ name: v.User.name,
+ img: v.User.img
+ }))
+ }
+
+
+ return NextResponse.json({ success: true, message: "Berhasil mendapatkan diskusi", data: dataFix }, { status: 200 });
+
+
+ } catch (error) {
+ console.error(error);
+ return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
+ }
+}
\ No newline at end of file
diff --git a/src/module/discussion_general/index.ts b/src/module/discussion_general/index.ts
index e9e427b..e612e04 100644
--- a/src/module/discussion_general/index.ts
+++ b/src/module/discussion_general/index.ts
@@ -1,7 +1,11 @@
import FormCreateDiscussionGeneral from "./ui/create_discussion";
+import DetailDiscussionGeneral from "./ui/detail_discussion_general";
import ListDiscussionGeneral from "./ui/list_discussion";
+import MemberDiscussionGeneral from "./ui/member_discussion_general";
import NavbarDiscussionGeneral from "./ui/navbar_discussion";
export { ListDiscussionGeneral }
export { NavbarDiscussionGeneral }
-export { FormCreateDiscussionGeneral }
\ No newline at end of file
+export { FormCreateDiscussionGeneral }
+export { DetailDiscussionGeneral }
+export { MemberDiscussionGeneral }
\ No newline at end of file
diff --git a/src/module/discussion_general/lib/api_discussion_general.ts b/src/module/discussion_general/lib/api_discussion_general.ts
index d1fb6f3..d9cf15b 100644
--- a/src/module/discussion_general/lib/api_discussion_general.ts
+++ b/src/module/discussion_general/lib/api_discussion_general.ts
@@ -14,4 +14,9 @@ export const funCreateDiscussionGeneral = async (data: { idGroup: string, title:
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
-}
\ No newline at end of file
+}
+
+export const funGetOneDiscussionGeneral = async (id: string, path: string) => {
+ const response = await fetch(`/api/discussion-general/${id}${(path) ? path : ''}`, { next: { tags: ['discussion-general'] } });
+ return await response.json().catch(() => null);
+}
diff --git a/src/module/discussion_general/lib/type_discussion_general.ts b/src/module/discussion_general/lib/type_discussion_general.ts
index a27cefe..94b130d 100644
--- a/src/module/discussion_general/lib/type_discussion_general.ts
+++ b/src/module/discussion_general/lib/type_discussion_general.ts
@@ -2,4 +2,21 @@ export interface IFormMemberDisscussionGeneral {
idUser: string,
name: string,
img: string
- }
\ No newline at end of file
+ }
+
+ export interface IDetailDiscussionGeneral{
+ id: string
+ title: string
+ desc: string
+ status: number
+ createdAt: string
+ }
+
+ export interface IComentsDisscussionGeneral{
+ id: string
+ comment: string
+ createdAt: string
+ idUser: string
+ img: string
+ username: string
+}
\ No newline at end of file
diff --git a/src/module/discussion_general/lib/val_discussion_general.ts b/src/module/discussion_general/lib/val_discussion_general.ts
index 3c3fb26..321771d 100644
--- a/src/module/discussion_general/lib/val_discussion_general.ts
+++ b/src/module/discussion_general/lib/val_discussion_general.ts
@@ -1,4 +1,5 @@
import { hookstate } from "@hookstate/core";
import { IFormMemberDisscussionGeneral } from "./type_discussion_general";
-export const globalMemberDiscussionGeneral = hookstate([]);
\ No newline at end of file
+export const globalMemberDiscussionGeneral = hookstate([]);
+export const globalRefreshDiscussionGeneral = hookstate(false);
\ No newline at end of file
diff --git a/src/module/discussion_general/ui/detail_discussion_general.tsx b/src/module/discussion_general/ui/detail_discussion_general.tsx
new file mode 100644
index 0000000..651b540
--- /dev/null
+++ b/src/module/discussion_general/ui/detail_discussion_general.tsx
@@ -0,0 +1,380 @@
+"use client"
+import { globalRole, keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global";
+import { globalIsAdminDivision, globalIsMemberDivision } from "@/module/division_new";
+import { useHookstate } from "@hookstate/core";
+import { ActionIcon, Avatar, Badge, Box, Center, Divider, Flex, Grid, Group, rem, Skeleton, Spoiler, Text, TextInput } from "@mantine/core";
+import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
+import moment from "moment";
+import "moment/locale/id";
+import { useParams, useRouter } from "next/navigation";
+import { useState } from "react";
+import toast from "react-hot-toast";
+import { GrChatOption } from "react-icons/gr";
+import { HiMenu } from "react-icons/hi";
+import { VscSend } from "react-icons/vsc";
+import { useWibuRealtime } from "wibu-realtime";
+import { funGetOneDiscussionGeneral } from "../lib/api_discussion_general";
+import { IComentsDisscussionGeneral, IDetailDiscussionGeneral } from "../lib/type_discussion_general";
+import { globalRefreshDiscussionGeneral } from "../lib/val_discussion_general";
+import DrawerDetailDiscussionGeneral from "./drawer_detail_discussion_general";
+import { BiSolidCommentDetail } from "react-icons/bi";
+
+export default function DetailDiscussionGeneral() {
+ const [isData, setData] = useState()
+ const [isDataKomentar, setDataKomentar] = useState([])
+ const [isComent, setIsComent] = useState("")
+ const param = useParams<{ id: string }>()
+ const [isLoad, setIsLoad] = useState(true)
+ const [loadingKomentar, setLoadingKomentar] = useState(false)
+ const refresh = useHookstate(globalRefreshDiscussionGeneral)
+ const roleLogin = useHookstate(globalRole)
+ const [isCreator, setCreator] = useState(false)
+ const [isUser, setUser] = useState('')
+ const adminLogin = useHookstate(globalIsAdminDivision)
+ const memberDivision = useHookstate(globalIsMemberDivision)
+ const tema = useHookstate(TEMA)
+ const router = useRouter()
+ const [openDrawer, setOpenDrawer] = useState(false)
+ const isMobile = useMediaQuery('(max-width: 369px)')
+ const isMobile2 = useMediaQuery("(max-width: 438px)")
+ const [dataRealTime, setDataRealtime] = useWibuRealtime({
+ WIBU_REALTIME_TOKEN: keyWibu,
+ project: "sdm"
+ })
+
+ const getData = async (loading: boolean) => {
+ try {
+ setIsLoad(loading)
+ const response = await funGetOneDiscussionGeneral(param.id, "?cat=detail")
+ if (response.success) {
+ setData(response.data)
+ } else {
+ toast.error(response.message)
+ }
+ } catch (error) {
+ console.error(error)
+ toast.error("Gagal mendapatkan data, coba lagi nanti")
+ } finally {
+ setIsLoad(false)
+ }
+ }
+
+ useShallowEffect(() => {
+ getData(true)
+ }, [refresh.get()])
+
+ // useShallowEffect(() => {
+ // if (dataRealTime && dataRealTime.some((i: any) => i.category == 'discussion-detail' && i.id == param.id)) {
+ // getData(false)
+ // }
+
+ // if (dataRealTime && dataRealTime.some((i: any) => i.category == 'discussion-delete' && i.id == param.id && i.user != isUser)) {
+ // toast.error("Data telah di hapus, anda akan beralih ke halaman list diskusi")
+ // setTimeout(() => {
+ // router.push(`/division/${param.id}/discussion`)
+ // }, 1000)
+ // }
+ // }, [dataRealTime])
+
+ async function getKomentar(loading: boolean) {
+ try {
+ setLoadingKomentar(loading)
+ const response = await funGetOneDiscussionGeneral(param.id, "?cat=komentar")
+ if (response.success) {
+ setData(response.data)
+ } else {
+ toast.error(response.message)
+ }
+ } catch (error) {
+ console.error(error)
+ } finally {
+ setLoadingKomentar(false)
+ }
+ }
+
+ // const sendComent = async () => {
+ // try {
+ // if (isComent.trim() == "") {
+ // return toast.error("Masukkan Komentar Anda")
+ // }
+ // const response = await funCreateComent(id, { comment: isComent, idDiscussion: param.detail })
+
+ // if (response.success) {
+ // setIsComent("")
+ // setDataRealtime([{
+ // category: "discussion-detail",
+ // id: id,
+ // }])
+ // reloadData()
+ // } else {
+ // toast.error(response.message)
+ // }
+ // } catch (error) {
+ // console.error(error)
+ // }
+ // }
+
+
+
+
+
+ return (
+
+ setOpenDrawer(true)} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings">
+
+
+ : <>>
+ }
+ />
+ setOpenDrawer(false)}>
+ setOpenDrawer(false)} id={param.id} status={Number(isData?.status)} />
+
+
+
+
+ {isLoad ?
+ Array(1)
+ .fill(null)
+ .map((_, i) => (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ )) :
+ <>
+ {isDataKomentar?.length == 0 ?
+
+
+
+
+
+
+
+
+
+ {isData?.title}
+ {isData?.status === 1 ? "BUKA" : "TUTUP"}
+
+
+
+
+ {isData?.createdAt}
+
+
+
+
+
+
+ {isData?.desc}
+
+
+
+
+ {isDataKomentar?.length ?
+
+ {isDataKomentar?.length} Komentar
+ : ""}
+
+
+
+ :
+
+
+
+
+
+
+
+
+
+ {isData?.title}
+ {isData?.status === 1 ? "BUKA" : "TUTUP"}
+
+
+
+
+ {isData?.createdAt}
+
+
+
+
+
+
+ {isData?.desc}
+
+
+
+
+ {isDataKomentar?.length ?
+
+ {isDataKomentar.length} Komentar
+ : ""}
+
+
+
+ }
+ >
+ }
+
+ {isLoad ?
+ Array(2)
+ .fill(0)
+ .map((_, i) => (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ )) :
+ isDataKomentar.map((v, i) => {
+ return (
+
+
+
+
+
+
+
+
+ {v.username}
+
+
+
+
+ {moment(v.createdAt).format("ll")}
+
+
+
+
+
+ {v.comment}
+
+
+
+
+
+
+
+ );
+ })
+ }
+
+
+ {isLoad ?
+
+ :
+
+
+
+ {300 - isComent.length} karakter tersisa
+
+
+
+
+ setIsComent(e.target.value)}
+ value={isComent}
+ maxLength={300}
+ />
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+
+ )
+}
+
diff --git a/src/module/discussion_general/ui/drawer_detail_discussion_general.tsx b/src/module/discussion_general/ui/drawer_detail_discussion_general.tsx
new file mode 100644
index 0000000..d6eada3
--- /dev/null
+++ b/src/module/discussion_general/ui/drawer_detail_discussion_general.tsx
@@ -0,0 +1,163 @@
+import { keyWibu, TEMA } from "@/module/_global";
+import LayoutModal from "@/module/_global/layout/layout_modal";
+import { useHookstate } from "@hookstate/core";
+import { Box, Flex, SimpleGrid, Stack, Text } from "@mantine/core";
+import { useParams, useRouter } from "next/navigation";
+import { useState } from "react";
+import { BsTrash3 } from "react-icons/bs";
+import { FaCheck, FaPencil, FaUsers } from "react-icons/fa6";
+import { MdClose } from "react-icons/md";
+import { useWibuRealtime } from "wibu-realtime";
+import { globalRefreshDiscussionGeneral } from "../lib/val_discussion_general";
+
+export default function DrawerDetailDiscussionGeneral({ onSuccess, id, status }: { onSuccess: (val: boolean) => void, id: string, status: number }) {
+ const [isValModal, setValModal] = useState(false)
+ const [isValModalStatus, setValModalStatus] = useState(false)
+ const router = useRouter()
+ const param = useParams<{ id: string, detail: string }>()
+ const refresh = useHookstate(globalRefreshDiscussionGeneral)
+ const tema = useHookstate(TEMA)
+ const [dataRealTime, setDataRealtime] = useWibuRealtime({
+ WIBU_REALTIME_TOKEN: keyWibu,
+ project: "sdm"
+ })
+ const [loadingUpdate, setLoadingUpdate] = useState(false)
+ const [loadingDelete, setLoadingDelete] = useState(false)
+
+
+ // async function fetchStatusDiscussion(val: boolean) {
+ // try {
+ // setLoadingUpdate(true)
+ // if (val) {
+ // const response = await funEditStatusDiscussion(id, { status: status })
+ // if (response.success) {
+ // toast.success(response.message)
+ // refresh.set(!refresh.get())
+ // setDataRealtime([{
+ // category: "discussion-detail",
+ // id: id,
+ // }])
+ // onSuccess(false)
+ // } else {
+ // toast.error(response.message)
+ // }
+ // }
+ // } catch (error) {
+ // console.error(error);
+ // toast.error("Gagal menambahkan diskusi, coba lagi nanti");
+ // } finally {
+ // setLoadingUpdate(false)
+ // setValModalStatus(false)
+ // }
+ // }
+
+ // async function fetchDeleteDiscussion(val: boolean) {
+ // try {
+ // if (val) {
+ // setLoadingDelete(true)
+ // const response = await funDeleteDiscussion(id)
+ // if (response.success) {
+ // setDataRealtime([
+ // {
+ // category: "discussion-delete",
+ // id: id,
+ // user: response.user
+ // },
+ // {
+ // category: "division/" + param.id + "/discussion",
+ // }
+ // ])
+ // toast.success(response.message)
+ // onSuccess(false)
+ // router.push(`/division/${param.id}/discussion`)
+ // } else {
+ // toast.error(response.message)
+ // }
+ // }
+ // } catch (error) {
+ // console.error(error);
+ // toast.error("Gagal hapus diskusi, coba lagi nanti");
+ // } finally {
+ // setLoadingDelete(false)
+ // setValModal(false)
+ // }
+ // }
+
+
+ return (
+
+
+
+
+ window.location.href = `/discussion/${param.id}/member/`} justify={'center'} align={'center'} direction={'column'} >
+
+
+
+
+ Anggota
+
+
+
+ window.location.href = `/discussion/${param.id}/update/`} justify={'center'} align={'center'} direction={'column'} >
+
+
+
+
+ Edit
+
+
+
+ setValModalStatus(true)} >
+ {status === 1 ? (
+ <>
+
+
+
+
+ Tutup Diskusi
+
+ >
+ ) : (
+ <>
+
+
+
+
+
+ Buka Diskusi
+
+ >
+ )}
+
+
+ setValModal(true)} justify={'center'} align={'center'} direction={'column'} >
+
+
+
+
+ Hapus
+
+
+
+
+
+
+ setValModal(false)}
+ description="Apakah Anda yakin ingin menghapus diskusi ini?"
+ onYes={(val) => {
+ // fetchDeleteDiscussion(val)
+ }} />
+
+
+ setValModalStatus(false)}
+ description="Apakah Anda yakin ingin mengubah status diskusi ini?"
+ onYes={(val) => {
+ // fetchStatusDiscussion(val)
+ }} />
+
+ )
+}
\ No newline at end of file
diff --git a/src/module/discussion_general/ui/list_discussion.tsx b/src/module/discussion_general/ui/list_discussion.tsx
index 99d96b9..a5d8b7a 100644
--- a/src/module/discussion_general/ui/list_discussion.tsx
+++ b/src/module/discussion_general/ui/list_discussion.tsx
@@ -1,23 +1,22 @@
'use client'
import { currentScroll, globalNotifPage, keyWibu, ReloadButtonTop, TEMA } from "@/module/_global";
import { useHookstate } from "@hookstate/core";
-import { ActionIcon, Avatar, Badge, Box, Divider, Flex, Grid, Group, Skeleton, Spoiler, Text, TextInput } from "@mantine/core";
+import { ActionIcon, Badge, Box, Divider, Flex, Grid, Group, Skeleton, Spoiler, Text, TextInput } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import _ from "lodash";
-import { useParams, useRouter } from "next/navigation";
+import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
+import { BiSolidCommentDetail } from "react-icons/bi";
import { GrChatOption } from "react-icons/gr";
import { HiMagnifyingGlass } from "react-icons/hi2";
import { useWibuRealtime } from "wibu-realtime";
import { funGetAllDiscussionGeneral } from "../lib/api_discussion_general";
-import { BiSolidCommentDetail } from "react-icons/bi";
export default function ListDiscussionGeneral() {
const [isData, setData] = useState([])
const [searchQuery, setSearchQuery] = useState('')
- const param = useParams<{ id: string }>()
const [loading, setLoading] = useState(true)
const tema = useHookstate(TEMA)
const router = useRouter()
@@ -229,7 +228,7 @@ export default function ListDiscussionGeneral() {
overflowWrap: "break-word"
}}
onClick={() => {
- router.push(`/division/${param.id}/discussion/${v.id}`)
+ router.push(`/discussion/${v.id}`)
}}
>
{v.desc}
diff --git a/src/module/discussion_general/ui/member_discussion_general.tsx b/src/module/discussion_general/ui/member_discussion_general.tsx
new file mode 100644
index 0000000..ddda736
--- /dev/null
+++ b/src/module/discussion_general/ui/member_discussion_general.tsx
@@ -0,0 +1,278 @@
+"use client"
+import { globalRole, LayoutDrawer, LayoutNavbarNew, SkeletonList, TEMA } from '@/module/_global';
+import LayoutModal from '@/module/_global/layout/layout_modal';
+import { useHookstate } from '@hookstate/core';
+import { ActionIcon, Avatar, Box, Divider, Flex, Grid, Group, SimpleGrid, Stack, Text } from '@mantine/core';
+import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
+import { useParams, useRouter } from 'next/navigation';
+import { useState } from 'react';
+import toast from 'react-hot-toast';
+import { AiOutlineUserAdd } from 'react-icons/ai';
+import { FaPencil, FaToggleOff, FaUserTie } from 'react-icons/fa6';
+import { IoIosCloseCircle } from 'react-icons/io';
+import { funGetOneDiscussionGeneral } from '../lib/api_discussion_general';
+import { IFormMemberDisscussionGeneral } from '../lib/type_discussion_general';
+
+
+export default function MemberDiscussionGeneral() {
+ const router = useRouter()
+ const [openDrawer, setDrawer] = useState(false)
+ const [openDrawerInfo, setDrawerInfo] = useState(false)
+ const [valActive, setValActive] = useState(true)
+ const param = useParams<{ id: string }>()
+ const [member, setMember] = useState([])
+ const [loading, setLoading] = useState(true)
+ const [valChooseMember, setChooseMember] = useState("")
+ const [valChooseMemberStatus, setChooseMemberStatus] = useState(false)
+ const [valChooseMemberName, setChooseMemberName] = useState("")
+ const [isOpenModal, setOpenModal] = useState(false)
+ const [isOpenModalStatus, setOpenModalStatus] = useState(false)
+ const roleLogin = useHookstate(globalRole)
+ const [isAdmin, setAdmin] = useState(false)
+ const isMobile = useMediaQuery('(max-width: 455px)')
+ const isMobile2 = useMediaQuery("(max-width: 438px)")
+ const tema = useHookstate(TEMA)
+ const [loadingStatus, setLoadingStatus] = useState(false)
+ const [loadingDelete, setLoadingDelete] = useState(false)
+
+ async function getOneData(loading: boolean) {
+ try {
+ setLoading(loading)
+ const res = await funGetOneDiscussionGeneral(param.id, "?cat=anggota");
+ if (res.success) {
+ setMember(res.data)
+ } else {
+ toast.error(res.message);
+ }
+ } catch (error) {
+ console.error(error);
+ toast.error("Gagal mendapatkan data, coba lagi nanti");
+ } finally {
+ setLoading(false)
+ }
+ }
+
+ useShallowEffect(() => {
+ getOneData(true);
+ }, [param.id])
+
+
+ async function onClickMember(id: string, status: boolean) {
+ setChooseMember(id)
+ setChooseMemberStatus(status)
+ setDrawer(true)
+ }
+
+
+ // async function deleteMember() {
+ // try {
+ // setLoadingDelete(true)
+ // const res = await funDeleteMemberDivision(param.id, { id: valChooseMember })
+ // if (res.success) {
+ // toast.success(res.message)
+ // setDrawer(false)
+ // getOneData(false)
+ // } else {
+ // toast.error(res.message)
+ // }
+ // } catch (error) {
+ // console.error(error);
+ // toast.error("Gagal mendapatkan divisi, coba lagi nanti");
+ // } finally {
+ // setLoadingDelete(false)
+ // setOpenModal(false)
+ // }
+ // }
+
+
+ // async function editStatusAdmin() {
+ // try {
+ // const res = await funEditStatusAdminDivision(param.id, { id: valChooseMember, isAdmin: valChooseMemberStatus })
+ // if (res.success) {
+ // toast.success(res.message)
+ // getOneData(false)
+ // } else {
+ // toast.error(res.message)
+ // }
+ // setDrawer(false)
+ // } catch (error) {
+ // console.error(error);
+ // toast.error("Gagal mendapatkan divisi, coba lagi nanti");
+ // }
+ // }
+
+ // async function editStatusDivisi() {
+ // try {
+ // setLoadingStatus(true)
+ // const res = await funUpdateStatusDivision(param.id, { isActive: valActive })
+ // if (res.success) {
+ // toast.success(res.message)
+ // getOneData(false)
+ // } else {
+ // toast.error(res.message)
+ // }
+ // } catch (error) {
+ // console.error(error);
+ // toast.error("Gagal mendapatkan divisi, coba lagi nanti");
+ // } finally {
+ // setDrawerInfo(false)
+ // setLoadingStatus(false)
+ // setOpenModalStatus(false)
+ // }
+ // }
+
+ return (
+
+ >} />
+
+ {/*
+ Deskripsi Divisi
+
+ {
+ loading ?
+ Array(3)
+ .fill(null)
+ .map((_, i) => (
+
+
+
+ ))
+ :
+ (deskripsi != null && deskripsi != undefined && deskripsi != "") ?
+ {deskripsi}
+ : Tidak ada deskripsi
+ }
+
+ */}
+
+
+ {member.length} Anggota
+
+
+
+ {loading ?
+ <>>
+ :
+ router.push('/division/add-member/' + param.id)}>
+
+
+
+ Tambah Anggota
+
+ }
+
+
+
+ {loading
+ ? Array(6)
+ .fill(null)
+ .map((_, i) => (
+
+
+
+ ))
+ : member.map((v, i) => {
+ return (
+
+ {
+ if ((roleLogin.get() != 'user' && roleLogin.get() != 'coadmin') || isAdmin) {
+ // onClickMember(v.id, (v.isAdmin) ? true : false)
+ setChooseMemberName(v.name)
+ }
+ }}
+ >
+
+
+
+
+
+ {v.name}
+
+
+
+
+
+
+
+ );
+ })
+ }
+
+
+
+
+
+
+ setDrawer(false)} title={valChooseMemberName}>
+
+ valActive ? editStatusAdmin() : undefined}
+ >
+
+
+
+ {(valChooseMemberStatus == false) ? "Jadikan admin" : "Memberhentikan sebagai admin"}
+
+ valActive ? setOpenModal(true) : undefined}>
+
+
+
+ Keluarkan dari divisi
+
+
+
+
+ setOpenModal(false)}
+ description="Apakah Anda yakin ingin mengeluarkan anggota?"
+ onYes={(val) => {
+ // if (!val) {
+ // setOpenModal(false)
+ // } else {
+ // deleteMember()
+ // }
+ }} />
+
+ setDrawerInfo(false)} title={"Menu"}>
+
+
+
+ router.push('/division/edit/' + param.id)} justify={'center'} align={'center'} direction={'column'} >
+
+
+
+
+ Edit Divisi
+
+
+ { setOpenModalStatus(true) }} justify={'center'} align={'center'} direction={'column'} >
+
+
+
+
+ {valActive ? "Non Aktifkan Divisi" : "Aktifkan Divisi"}
+
+
+
+
+
+
+
+ setOpenModalStatus(false)}
+ description="Apakah Anda yakin ingin mangubah status aktifasi divisi?"
+ onYes={(val) => {
+ // if (!val) {
+ // setOpenModalStatus(false)
+ // } else {
+ // editStatusDivisi()
+ // }
+ }} />
+
+ );
+}