Merge pull request #364 from bipproduction/amalia/30-des-24
rev : diskusi umum
This commit is contained in:
@@ -60,6 +60,7 @@ model Village {
|
|||||||
Division Division[]
|
Division Division[]
|
||||||
ColorTheme ColorTheme[]
|
ColorTheme ColorTheme[]
|
||||||
BannerImage BannerImage[]
|
BannerImage BannerImage[]
|
||||||
|
Discussion Discussion[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model Group {
|
model Group {
|
||||||
@@ -75,6 +76,7 @@ model Group {
|
|||||||
Project Project[]
|
Project Project[]
|
||||||
Division Division[]
|
Division Division[]
|
||||||
AnnouncementMember AnnouncementMember[]
|
AnnouncementMember AnnouncementMember[]
|
||||||
|
Discussion Discussion[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model Position {
|
model Position {
|
||||||
@@ -125,6 +127,9 @@ model User {
|
|||||||
Notifications Notifications[] @relation("UserToUser")
|
Notifications Notifications[] @relation("UserToUser")
|
||||||
Notifications2 Notifications[] @relation("UserFromUser")
|
Notifications2 Notifications[] @relation("UserFromUser")
|
||||||
Subscribe Subscribe?
|
Subscribe Subscribe?
|
||||||
|
Discussion Discussion[]
|
||||||
|
DiscussionMember DiscussionMember[]
|
||||||
|
DiscussionComment DiscussionComment[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model UserLog {
|
model UserLog {
|
||||||
@@ -213,18 +218,18 @@ model ProjectFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model ProjectTask {
|
model ProjectTask {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
Project Project @relation(fields: [idProject], references: [id])
|
Project Project @relation(fields: [idProject], references: [id])
|
||||||
idProject String
|
idProject String
|
||||||
title String
|
title String
|
||||||
desc String?
|
desc String?
|
||||||
status Int @default(0) // 0 = todo, 1 = done
|
status Int @default(0) // 0 = todo, 1 = done
|
||||||
notifikasi Boolean @default(false)
|
notifikasi Boolean @default(false)
|
||||||
dateStart DateTime @db.Date
|
dateStart DateTime @db.Date
|
||||||
dateEnd DateTime @db.Date
|
dateEnd DateTime @db.Date
|
||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model ProjectComment {
|
model ProjectComment {
|
||||||
@@ -521,3 +526,44 @@ model Subscribe {
|
|||||||
createdAt DateTime? @default(now())
|
createdAt DateTime? @default(now())
|
||||||
updatedAt DateTime? @updatedAt
|
updatedAt DateTime? @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model Discussion {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
Village Village @relation(fields: [idVillage], references: [id])
|
||||||
|
idVillage String
|
||||||
|
Group Group @relation(fields: [idGroup], references: [id])
|
||||||
|
idGroup String
|
||||||
|
title String?
|
||||||
|
desc String @db.Text
|
||||||
|
status Int @default(1) // 1 = open, 2 = close
|
||||||
|
isActive Boolean @default(true)
|
||||||
|
User User @relation(fields: [createdBy], references: [id])
|
||||||
|
createdBy String
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
DiscussionMember DiscussionMember[]
|
||||||
|
DiscussionComment DiscussionComment[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model DiscussionMember {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
Discussion Discussion @relation(fields: [idDiscussion], references: [id])
|
||||||
|
idDiscussion String
|
||||||
|
User User @relation(fields: [idUser], references: [id])
|
||||||
|
idUser String
|
||||||
|
isActive Boolean @default(true)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
model DiscussionComment {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
Discussion Discussion @relation(fields: [idDiscussion], references: [id])
|
||||||
|
idDiscussion String
|
||||||
|
User User @relation(fields: [idUser], references: [id])
|
||||||
|
idUser String
|
||||||
|
comment String @db.Text
|
||||||
|
isActive Boolean @default(true)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
}
|
||||||
|
|||||||
7
src/app/(application)/discussion/[id]/page.tsx
Normal file
7
src/app/(application)/discussion/[id]/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default function Page() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
detail diskusi umum
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
11
src/app/(application)/discussion/create/page.tsx
Normal file
11
src/app/(application)/discussion/create/page.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { LayoutNavbarNew } from "@/module/_global";
|
||||||
|
import { FormCreateDiscussionGeneral } from "@/module/discussion_general";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<LayoutNavbarNew back="" title="Tambah Diskusi Umum" menu={<></>} />
|
||||||
|
<FormCreateDiscussionGeneral />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
13
src/app/(application)/discussion/page.tsx
Normal file
13
src/app/(application)/discussion/page.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { ListDiscussionGeneral, NavbarDiscussionGeneral } from '@/module/discussion_general';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
function Page() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<NavbarDiscussionGeneral />
|
||||||
|
<ListDiscussionGeneral />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Page;
|
||||||
213
src/app/api/discussion-general/route.ts
Normal file
213
src/app/api/discussion-general/route.ts
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
import { prisma } from "@/module/_global";
|
||||||
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
|
import { createLogUser } from "@/module/user";
|
||||||
|
import _ from "lodash";
|
||||||
|
import moment from "moment";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// GET ALL DISCUSSION GENERAL
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
try {
|
||||||
|
const user = await funGetUserByCookies()
|
||||||
|
if (user.id == undefined) {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
let grup
|
||||||
|
const roleUser = user.idUserRole
|
||||||
|
const villageId = user.idVillage
|
||||||
|
const userId = user.id
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const idGroup = searchParams.get("group");
|
||||||
|
const search = searchParams.get('search');
|
||||||
|
const page = searchParams.get('page');
|
||||||
|
const dataSkip = Number(page) * 10 - 10;
|
||||||
|
|
||||||
|
if (idGroup == "null" || idGroup == undefined || idGroup == "") {
|
||||||
|
grup = user.idGroup
|
||||||
|
} else {
|
||||||
|
grup = idGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
const cek = await prisma.group.count({
|
||||||
|
where: {
|
||||||
|
id: grup,
|
||||||
|
isActive: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cek == 0) {
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan data kegiatan, data tidak ditemukan", }, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let kondisi: any = {
|
||||||
|
isActive: true,
|
||||||
|
idVillage: String(villageId),
|
||||||
|
idGroup: grup,
|
||||||
|
title: {
|
||||||
|
contains: (search == undefined || search == "null") ? "" : search,
|
||||||
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roleUser != "supadmin" && roleUser != "cosupadmin" && roleUser != "admin") {
|
||||||
|
kondisi = {
|
||||||
|
isActive: true,
|
||||||
|
idVillage: String(villageId),
|
||||||
|
idGroup: grup,
|
||||||
|
title: {
|
||||||
|
contains: (search == undefined || search == "null") ? "" : search,
|
||||||
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
DiscussionMember: {
|
||||||
|
some: {
|
||||||
|
idUser: String(userId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.discussion.findMany()
|
||||||
|
|
||||||
|
// const data = await prisma.discussion.findMany({
|
||||||
|
// skip: dataSkip,
|
||||||
|
// take: 10,
|
||||||
|
// where: {
|
||||||
|
// isActive: true,
|
||||||
|
// idVillage: String(villageId),
|
||||||
|
// idGroup: grup,
|
||||||
|
// title: {
|
||||||
|
// contains: (search == undefined || search == "null") ? "" : search,
|
||||||
|
// mode: "insensitive"
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// orderBy: {
|
||||||
|
// status: 'desc'
|
||||||
|
// },
|
||||||
|
// select: {
|
||||||
|
// id: true,
|
||||||
|
// title: true,
|
||||||
|
// desc: true,
|
||||||
|
// status: true,
|
||||||
|
// createdAt: true,
|
||||||
|
// User: {
|
||||||
|
// select: {
|
||||||
|
// name: true,
|
||||||
|
// img: true
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// DiscussionComment: {
|
||||||
|
// select: {
|
||||||
|
// id: true,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
const fixData = data.map((v: any) => ({
|
||||||
|
..._.omit(v, ["User", "DiscussionComment", "createdAt"]),
|
||||||
|
user_name: v.User.name,
|
||||||
|
img: v.User.img,
|
||||||
|
total_komentar: v.DiscussionComment.length,
|
||||||
|
createdAt: moment(v.createdAt).format("ll")
|
||||||
|
}))
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan diskusi", data: fixData, }, { 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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// CREATE DISCUSSION GENERALE
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const user = await funGetUserByCookies()
|
||||||
|
if (user.id == undefined) {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const userId = user.id
|
||||||
|
const userRoleLogin = user.idUserRole
|
||||||
|
const { idGroup, title, desc, member } = (await request.json());
|
||||||
|
|
||||||
|
const data = await prisma.discussion.create({
|
||||||
|
data: {
|
||||||
|
idVillage: String(user.idVillage),
|
||||||
|
idGroup: idGroup,
|
||||||
|
title: title,
|
||||||
|
desc: desc,
|
||||||
|
createdBy: String(userId),
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const dataMember = member.map((v: any) => ({
|
||||||
|
..._.omit(v, ["idUser", "name", "img"]),
|
||||||
|
idDiscussion: data.id,
|
||||||
|
idUser: v.idUser,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const insertMember = await prisma.discussionMember.createMany({
|
||||||
|
data: dataMember
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataNotif = member.map((v: any) => ({
|
||||||
|
..._.omit(v, ["idUser", "name", "img"]),
|
||||||
|
idUserTo: v.idUser,
|
||||||
|
idUserFrom: userId,
|
||||||
|
category: 'discussion-general',
|
||||||
|
idContent: data.id,
|
||||||
|
title: 'Diskusi Umum Baru',
|
||||||
|
desc: 'Terdapat diskusi umum baru. Silahkan periksa detailnya.'
|
||||||
|
}))
|
||||||
|
|
||||||
|
if (userRoleLogin != "supadmin") {
|
||||||
|
const perbekel = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idUserRole: "supadmin",
|
||||||
|
idVillage: user.idVillage
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
dataNotif.push({
|
||||||
|
idUserTo: perbekel?.id,
|
||||||
|
idUserFrom: userId,
|
||||||
|
category: 'discussion-general',
|
||||||
|
idContent: data.id,
|
||||||
|
title: 'Diskusi Umum Baru',
|
||||||
|
desc: 'Terdapat diskusi umum baru. Silahkan periksa detailnya.'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
|
data: dataNotif
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data diskusi umum', table: 'discussion', data: data.id })
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil menambahkan diskusi umum", notif: dataNotif }, { status: 200 });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal menambahkan diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/module/discussion_general/index.ts
Normal file
7
src/module/discussion_general/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import FormCreateDiscussionGeneral from "./ui/create_discussion";
|
||||||
|
import ListDiscussionGeneral from "./ui/list_discussion";
|
||||||
|
import NavbarDiscussionGeneral from "./ui/navbar_discussion";
|
||||||
|
|
||||||
|
export { ListDiscussionGeneral }
|
||||||
|
export { NavbarDiscussionGeneral }
|
||||||
|
export { FormCreateDiscussionGeneral }
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export const funGetAllDiscussionGeneral = async (path?: string) => {
|
||||||
|
const response = await fetch(`/api/discussion-general${(path) ? path : ''}`, { next: { tags: ['discussion-general'] } });
|
||||||
|
return await response.json().catch(() => null);
|
||||||
|
}
|
||||||
140
src/module/discussion_general/ui/create_discussion.tsx
Normal file
140
src/module/discussion_general/ui/create_discussion.tsx
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
'use client'
|
||||||
|
import { keyWibu, TEMA } from "@/module/_global";
|
||||||
|
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||||
|
import { funGetProfileByCookies } from "@/module/user/profile/lib/api_profile";
|
||||||
|
import { useHookstate } from "@hookstate/core";
|
||||||
|
import { Avatar, Box, Button, Grid, rem, Textarea } from "@mantine/core";
|
||||||
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
|
import { useParams, useRouter } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import { useWibuRealtime } from "wibu-realtime";
|
||||||
|
|
||||||
|
export default function FormCreateDiscussionGeneral() {
|
||||||
|
const [isValModal, setValModal] = useState(false)
|
||||||
|
const [loadingModal, setLoadingModal] = useState(false)
|
||||||
|
const router = useRouter()
|
||||||
|
const param = useParams<{ id: string, detail: string }>()
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [img, setIMG] = useState<any | null>()
|
||||||
|
const tema = useHookstate(TEMA)
|
||||||
|
const [touched, setTouched] = useState({
|
||||||
|
desc: false,
|
||||||
|
});
|
||||||
|
const [isData, setData] = useState({
|
||||||
|
desc: "",
|
||||||
|
idDivision: param.id
|
||||||
|
})
|
||||||
|
const [data, setDataRealtime] = useWibuRealtime({
|
||||||
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
|
project: "sdm"
|
||||||
|
})
|
||||||
|
|
||||||
|
async function getData() {
|
||||||
|
try {
|
||||||
|
setLoading(true)
|
||||||
|
const res = await funGetProfileByCookies()
|
||||||
|
setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`)
|
||||||
|
setLoading(false)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
getData()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// async function createDiscussion(val: boolean) {
|
||||||
|
// try {
|
||||||
|
// if (val) {
|
||||||
|
// setLoadingModal(true)
|
||||||
|
// const response = await funCreateDiscussion({
|
||||||
|
// desc: isData.desc,
|
||||||
|
// idDivision: id
|
||||||
|
// })
|
||||||
|
|
||||||
|
// if (response.success) {
|
||||||
|
// setDataRealtime(response.notif)
|
||||||
|
// toast.success(response.message)
|
||||||
|
// router.push(`/division/${param.id}/discussion/`)
|
||||||
|
// } else {
|
||||||
|
// toast.error(response.message)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error(error);
|
||||||
|
// toast.error("Gagal menambahkan diskusi, coba lagi nanti");
|
||||||
|
// } finally {
|
||||||
|
// setLoadingModal(false)
|
||||||
|
// setValModal(false)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box >
|
||||||
|
<Box p={20} >
|
||||||
|
<Grid pt={10}>
|
||||||
|
<Grid.Col span={2}>
|
||||||
|
<Avatar src={img} alt="it's me" size="lg" />
|
||||||
|
</Grid.Col>
|
||||||
|
<Grid.Col span={10}>
|
||||||
|
<Box>
|
||||||
|
<Textarea
|
||||||
|
placeholder="Tuliskan apa yang ingin anda diskusikan"
|
||||||
|
styles={{
|
||||||
|
input: {
|
||||||
|
border: 'none',
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
height: "50vh"
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
value={isData.desc}
|
||||||
|
onChange={(e) => setData({ ...isData, desc: e.target.value })}
|
||||||
|
// onBlur={() => setTouched({ ...touched, desc: true })}
|
||||||
|
// error={
|
||||||
|
// touched.desc && (
|
||||||
|
// isData.desc == "" ? "Form Tidak Boleh Kosong" : null
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Grid.Col>
|
||||||
|
</Grid>
|
||||||
|
</Box>
|
||||||
|
<Box pos={'fixed'} bottom={0} p={rem(20)} w={"100%"} style={{
|
||||||
|
maxWidth: rem(550),
|
||||||
|
zIndex: 999,
|
||||||
|
backgroundColor: `${tema.get().bgUtama}`,
|
||||||
|
}}>
|
||||||
|
<Button
|
||||||
|
color="white"
|
||||||
|
bg={tema.get().utama}
|
||||||
|
size="lg"
|
||||||
|
radius={30}
|
||||||
|
fullWidth
|
||||||
|
onClick={() => {
|
||||||
|
if (
|
||||||
|
isData.desc !== ""
|
||||||
|
) {
|
||||||
|
setValModal(true)
|
||||||
|
} else {
|
||||||
|
toast.error("Form Tidak Boleh Kosong");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<LayoutModal loading={loadingModal} opened={isValModal} onClose={() => setValModal(false)}
|
||||||
|
description="Apakah Anda yakin ingin menambah data?"
|
||||||
|
onYes={(val) => {
|
||||||
|
// createDiscussion(val)
|
||||||
|
}} />
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
25
src/module/discussion_general/ui/drawer_discussion.tsx
Normal file
25
src/module/discussion_general/ui/drawer_discussion.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { TEMA } from "@/module/_global";
|
||||||
|
import { useHookstate } from "@hookstate/core";
|
||||||
|
import { Box, Flex, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||||
|
import { IoAddCircle } from "react-icons/io5";
|
||||||
|
|
||||||
|
export default function DrawerDiscussionGeneral() {
|
||||||
|
const tema = useHookstate(TEMA)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack pt={10}>
|
||||||
|
<SimpleGrid cols={{ base: 2, sm: 2, lg: 3 }} >
|
||||||
|
<Flex onClick={() => window.location.href = "/discussion/create"} justify={'center'} align={'center'} direction={'column'} >
|
||||||
|
<Box>
|
||||||
|
<IoAddCircle size={30} color={tema.get().utama} />
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text c={tema.get().utama}>Tambah Diskusi</Text>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
</SimpleGrid>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
251
src/module/discussion_general/ui/list_discussion.tsx
Normal file
251
src/module/discussion_general/ui/list_discussion.tsx
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
'use client'
|
||||||
|
import { currentScroll, globalNotifPage, keyWibu, ReloadButtonTop, TEMA } from "@/module/_global";
|
||||||
|
import { useHookstate } from "@hookstate/core";
|
||||||
|
import { Avatar, 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 { useEffect, useState } from "react";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import { GrChatOption } from "react-icons/gr";
|
||||||
|
import { HiMagnifyingGlass } from "react-icons/hi2";
|
||||||
|
import { useWibuRealtime } from "wibu-realtime";
|
||||||
|
import { funGetAllDiscussionGeneral } from "../lib/api_discussion_general";
|
||||||
|
|
||||||
|
|
||||||
|
export default function ListDiscussionGeneral() {
|
||||||
|
const [isData, setData] = useState<any[]>([])
|
||||||
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
|
const param = useParams<{ id: string }>()
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const tema = useHookstate(TEMA)
|
||||||
|
const router = useRouter()
|
||||||
|
const { value: containerRef } = useHookstate(currentScroll);
|
||||||
|
const [isPage, setPage] = useState(1)
|
||||||
|
const notifLoadPage = useHookstate(globalNotifPage)
|
||||||
|
const [isRefresh, setRefresh] = useState(false)
|
||||||
|
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||||
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
|
project: "sdm"
|
||||||
|
})
|
||||||
|
|
||||||
|
const getData = async (loading: boolean) => {
|
||||||
|
try {
|
||||||
|
setLoading(loading)
|
||||||
|
const response = await funGetAllDiscussionGeneral('?search=' + searchQuery + '&page=' + isPage)
|
||||||
|
if (response.success) {
|
||||||
|
if (isPage == 1) {
|
||||||
|
setData(response.data)
|
||||||
|
} else {
|
||||||
|
setData([...isData, ...response.data])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toast.error(response.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
getData(false)
|
||||||
|
}, [isPage])
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
setPage(1)
|
||||||
|
getData(true)
|
||||||
|
}, [searchQuery])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleScroll = async () => {
|
||||||
|
if (containerRef && containerRef.current) {
|
||||||
|
const scrollTop = containerRef.current.scrollTop;
|
||||||
|
const containerHeight = containerRef.current.clientHeight;
|
||||||
|
const scrollHeight = containerRef.current.scrollHeight;
|
||||||
|
|
||||||
|
if (scrollTop + containerHeight >= scrollHeight) {
|
||||||
|
setPage(isPage + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const container = containerRef?.current;
|
||||||
|
container?.addEventListener("scroll", handleScroll);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
container?.removeEventListener("scroll", handleScroll);
|
||||||
|
};
|
||||||
|
}, [containerRef, isPage]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
if (notifLoadPage.get().category == 'discussion-general' && notifLoadPage.get().load == true) {
|
||||||
|
setRefresh(true)
|
||||||
|
}
|
||||||
|
}, [notifLoadPage.get().load])
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'discussion-general')) {
|
||||||
|
setRefresh(true)
|
||||||
|
}
|
||||||
|
}, [dataRealTime])
|
||||||
|
|
||||||
|
function onRefresh() {
|
||||||
|
notifLoadPage.set({
|
||||||
|
category: '',
|
||||||
|
load: false
|
||||||
|
})
|
||||||
|
setRefresh(false)
|
||||||
|
setPage(1)
|
||||||
|
setTimeout(() => {
|
||||||
|
getData(false)
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box p={20}>
|
||||||
|
{
|
||||||
|
isRefresh &&
|
||||||
|
<ReloadButtonTop
|
||||||
|
onReload={() => { onRefresh() }}
|
||||||
|
title='UPDATE'
|
||||||
|
/>
|
||||||
|
|
||||||
|
}
|
||||||
|
<TextInput
|
||||||
|
styles={{
|
||||||
|
input: {
|
||||||
|
color: tema.get().utama,
|
||||||
|
borderRadius: tema.get().utama,
|
||||||
|
borderColor: tema.get().utama,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
size="md"
|
||||||
|
radius={30}
|
||||||
|
leftSection={<HiMagnifyingGlass size={20} />}
|
||||||
|
placeholder="Pencarian"
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
/>
|
||||||
|
{loading ?
|
||||||
|
Array(3)
|
||||||
|
.fill(null)
|
||||||
|
.map((_, i) => (
|
||||||
|
<Box key={i}>
|
||||||
|
<Box pl={5} pr={5}>
|
||||||
|
<Flex
|
||||||
|
justify={"space-between"}
|
||||||
|
align={"center"}
|
||||||
|
mt={20}
|
||||||
|
>
|
||||||
|
<Group>
|
||||||
|
<Skeleton width={60} height={60} radius={100} />
|
||||||
|
<Box>
|
||||||
|
<Skeleton width={100} height={20} radius={"md"} />
|
||||||
|
<Skeleton mt={8} width={60} height={20} radius={"md"} />
|
||||||
|
</Box>
|
||||||
|
</Group>
|
||||||
|
<Skeleton width={"40%"} height={20} radius={"md"} />
|
||||||
|
</Flex>
|
||||||
|
<Box mt={10}>
|
||||||
|
<Skeleton width={"100%"} height={100} radius={"md"} />
|
||||||
|
</Box>
|
||||||
|
<Group justify="space-between" mt={20} c={'#8C8C8C'}>
|
||||||
|
<Skeleton width={"20%"} height={20} radius={"md"} />
|
||||||
|
<Skeleton width={"20%"} height={20} radius={"md"} />
|
||||||
|
</Group>
|
||||||
|
<Box mt={20}>
|
||||||
|
<Skeleton width={"100%"} height={1} radius={"md"} />
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
))
|
||||||
|
:
|
||||||
|
_.isEmpty(isData)
|
||||||
|
?
|
||||||
|
<Box style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '50vh' }}>
|
||||||
|
<Text c="dimmed" ta={"center"} fs={"italic"}>Tidak ada Diskusi</Text>
|
||||||
|
</Box>
|
||||||
|
:
|
||||||
|
isData.map((v, i) => {
|
||||||
|
return (
|
||||||
|
<Box key={i} pl={5} pr={5}>
|
||||||
|
<Grid align="center" mt={20} onClick={() => {
|
||||||
|
router.push(`/division/${param.id}/discussion/${v.id}`)
|
||||||
|
}}>
|
||||||
|
<Grid.Col span={{
|
||||||
|
sm: 2,
|
||||||
|
lg: 2,
|
||||||
|
xl: 2,
|
||||||
|
md: 2,
|
||||||
|
xs: 1,
|
||||||
|
base: 2
|
||||||
|
}}>
|
||||||
|
<Avatar alt="it's me" src={`https://wibu-storage.wibudev.com/api/files/${v.img}`} size="lg" />
|
||||||
|
</Grid.Col>
|
||||||
|
<Grid.Col span={{
|
||||||
|
sm: 6,
|
||||||
|
lg: 6,
|
||||||
|
xl: 6,
|
||||||
|
md: 6,
|
||||||
|
xs: 7,
|
||||||
|
base: 6
|
||||||
|
}}>
|
||||||
|
<Box pl={{
|
||||||
|
sm: 0,
|
||||||
|
lg: 0,
|
||||||
|
xl: 0,
|
||||||
|
md: 0,
|
||||||
|
xs: 40,
|
||||||
|
base: 10
|
||||||
|
}}>
|
||||||
|
<Text c={tema.get().utama} fw={"bold"} lineClamp={1}>
|
||||||
|
{v.user_name}
|
||||||
|
</Text>
|
||||||
|
<Badge color={v.status === 1 ? "green" : "red"} size="sm">{v.status === 1 ? "BUKA" : "TUTUP"}</Badge>
|
||||||
|
</Box>
|
||||||
|
</Grid.Col>
|
||||||
|
<Grid.Col span={4}>
|
||||||
|
<Text c={"grey"} ta={"end"} fz={13}>{v.createdAt}</Text>
|
||||||
|
</Grid.Col>
|
||||||
|
</Grid>
|
||||||
|
<Box mt={10}>
|
||||||
|
<Spoiler maxHeight={50} showLabel="Lebih banyak" hideLabel="Lebih sedikit">
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
overflowWrap: "break-word"
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/division/${param.id}/discussion/${v.id}`)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{v.desc}
|
||||||
|
</Text>
|
||||||
|
</Spoiler>
|
||||||
|
</Box>
|
||||||
|
<Group justify="space-between" mt={40} c={'#8C8C8C'}>
|
||||||
|
<Group gap={5} align="center">
|
||||||
|
<GrChatOption size={18} />
|
||||||
|
<Text fz={13}>Diskusikan</Text>
|
||||||
|
</Group >
|
||||||
|
<Group gap={5} align="center">
|
||||||
|
<Text fz={13}>{v.total_komentar} Komentar</Text>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
<Box mt={20}>
|
||||||
|
{isData.length <= 1 ? "" :
|
||||||
|
<Divider size={"xs"} />
|
||||||
|
}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
26
src/module/discussion_general/ui/navbar_discussion.tsx
Normal file
26
src/module/discussion_general/ui/navbar_discussion.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
'use client'
|
||||||
|
import { LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||||
|
import { useHookstate } from "@hookstate/core";
|
||||||
|
import { ActionIcon } from "@mantine/core";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { HiMenu } from "react-icons/hi";
|
||||||
|
import DrawerDiscussionGeneral from "./drawer_discussion";
|
||||||
|
|
||||||
|
export default function NavbarDiscussionGeneral() {
|
||||||
|
const [openDrawer, setOpenDrawer] = useState(false)
|
||||||
|
const tema = useHookstate(TEMA)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<LayoutNavbarNew back={`/home`} title="Diskusi Umum"
|
||||||
|
menu={
|
||||||
|
<ActionIcon variant="light" onClick={() => setOpenDrawer(true)} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings">
|
||||||
|
<HiMenu size={20} color='white' />
|
||||||
|
</ActionIcon>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<LayoutDrawer opened={openDrawer} title={'Menu'} onClose={() => setOpenDrawer(false)}>
|
||||||
|
<DrawerDiscussionGeneral />
|
||||||
|
</LayoutDrawer>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user