diff --git a/src/app/api/home/route.ts b/src/app/api/home/route.ts index 7d8ea13..6d197f7 100644 --- a/src/app/api/home/route.ts +++ b/src/app/api/home/route.ts @@ -4,6 +4,7 @@ import _, { ceil } from "lodash"; import moment from "moment"; import { NextResponse } from "next/server"; + // HOME export async function GET(request: Request) { try { @@ -71,24 +72,167 @@ export async function GET(request: Request) { createdAt: moment(v.dateStart).format("LL") })) - } - // else if (kategori == "division") { + } else if (kategori == "division") { + let kondisi - // } else if (kategori == "progress") { + // klo perbekel == semua grup + if (roleUser == "supadmin") { + kondisi = { + isActive: true, + idVillage: idVillage, + Group: { + isActive: true, + } + } + } else { + kondisi = { + isActive: true, + idGroup: idGroup + } + } - // } else if (kategori == "dokumen") { + const data = await prisma.division.findMany({ + where: kondisi, + select: { + id: true, + name: true, + DivisionProject: { + where: { + isActive: true, + NOT: { + status: 3 + } + } + } + }, + }) - // } else if (kategori == "event") { + const format = data.map((v: any) => ({ + ..._.omit(v, ["DivisionProject"]), + jumlah: v.DivisionProject.length, + })) - // } else if (kategori == "discussion") { + allData = _.orderBy(format, 'jumlah', 'desc').slice(0, 5) - // } + } else if (kategori == "progress") { + + } else if (kategori == "dokumen") { + + } else if (kategori == "event") { + let kondisi + + // klo perbekel == semua grup + if (roleUser == "supadmin") { + kondisi = { + isActive: true, + dateStart: new Date(), + Division: { + idVillage: idVillage, + Group: { + isActive: true, + } + } + } + } else { + kondisi = { + isActive: true, + dateStart: new Date(), + Division: { + idGroup: idGroup + } + } + } + + + const data = await prisma.divisionCalendar.findMany({ + skip: 0, + take: 5, + where: kondisi, + select: { + id: true, + idDivision: true, + title: true, + desc: true, + status: true, + timeStart: true, + dateStart: true, + timeEnd: true, + dateEnd: true, + createdAt: true, + User: { + select: { + name: true + } + } + }, + orderBy: { + createdAt: 'desc' + } + }) + + allData = data.map((v: any) => ({ + ..._.omit(v, ["User"]), + user_name: v.User.name, + timeStart: moment.utc(v.timeStart).format('HH:mm'), + timeEnd: moment.utc(v.timeEnd).format('HH:mm') + })) + + } else if (kategori == "discussion") { + let kondisi + + // klo perbekel == semua grup + if (roleUser == "supadmin") { + kondisi = { + isActive: true, + status: 1, + Division: { + idVillage: idVillage, + Group: { + isActive: true, + } + } + } + } else { + kondisi = { + isActive: true, + status: 1, + Division: { + idGroup: idGroup + } + } + } + + const data = await prisma.divisionDisscussion.findMany({ + skip: 0, + take: 5, + where: kondisi, + select: { + id: true, + idDivision: true, + title: true, + desc: true, + createdAt: true, + User: { + select: { + name: true + } + } + }, + orderBy: { + createdAt: "desc" + } + }) + + allData = data.map((v: any) => ({ + ..._.omit(v, ["createdAt", "User"]), + date: moment(v.dateStart).format("LL"), + user: v.User.name + })) + } return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", data: allData }, { status: 200 }); + } - - - catch (error) { console.log(error); return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); diff --git a/src/module/home/components/list_discussion.tsx b/src/module/home/components/list_discussion.tsx deleted file mode 100644 index a665cb9..0000000 --- a/src/module/home/components/list_discussion.tsx +++ /dev/null @@ -1,77 +0,0 @@ -'use client' -import { WARNA } from "@/module/_global"; -import { Box, Group, Text } from "@mantine/core"; -import { GoDiscussionClosed } from "react-icons/go"; -import { CiClock2, CiUser } from "react-icons/ci"; -import { useRouter } from "next/navigation"; - -const dataDiskusi = [ - { - id: 1, - judul: 'Mengatasi Limbah Makanan ', - user: 'Fibra Marcell', - date: '21 Juni 2024' - }, - { - id: 2, - judul: 'Pentingnya Menjaga Kelestarian Hutan ', - user: 'Bayu Tegar', - date: '15 Juni 2024' - }, - { - id: 3, - judul: 'Mengatasi Limbah Industri ', - user: 'Nian Putri', - date: '11 Mei 2024' - }, - { - id: 4, - judul: 'Manfaat Sampah Plastik', - user: 'Budi Prasetyo', - date: '10 Mei 2024' - }, -] - -export default function ListDiscussion() { - const router = useRouter() - - return ( - - Diskusi - - { - dataDiskusi.map((v, i) => { - return ( - router.push(`/discussion/1`)}> - - - - {v.judul} - - - - - - {v.user} - - - - {v.date} - - - - ) - }) - } - - - ) -} \ No newline at end of file diff --git a/src/module/home/components/list_divisi.tsx b/src/module/home/components/list_divisi.tsx deleted file mode 100644 index e4f0e85..0000000 --- a/src/module/home/components/list_divisi.tsx +++ /dev/null @@ -1,75 +0,0 @@ -'use client' -import { WARNA } from "@/module/_global"; -import { Carousel } from "@mantine/carousel"; -import { Box, Card, Flex, Title, Text } from "@mantine/core"; -import _ from "lodash"; -import { useRouter } from "next/navigation"; - -const dataProject = [ - { - id: 4, - title: 'Divisi Keuangan', - total: 24 - }, - { - id: 5, - title: 'Divisi Kesekretariatan', - total: 18 - }, - { - id: 6, - title: 'Divisi Kemasyarakatan', - total: 12 - }, -] -export default function ListDivisi() { - const router = useRouter() - - return ( - <> - - Divisi Teraktif - - {dataProject.map((v) => - - - router.push(`/division/${v.id}`)}> - - - - {_.toUpper(v.title)} - - - - - KEGIATAN - {v.total} - - - - - )} - - {/* {dataProject.map((v, i) => { - return ( - - - - - - {_.toUpper(v.title)} - - - - - PROYEK - {v.total} - - - - ); - })} */} - - - ) -} \ No newline at end of file diff --git a/src/module/home/components/list_event.tsx b/src/module/home/components/list_event.tsx deleted file mode 100644 index 08dbff4..0000000 --- a/src/module/home/components/list_event.tsx +++ /dev/null @@ -1,70 +0,0 @@ -'use client' -import { WARNA } from "@/module/_global" -import { Box, Divider, Group, Text } from "@mantine/core" -import { useRouter } from "next/navigation" - -const dataEvent = [ - { - id: 1, - title: 'Pembahasan Mengenai Darmasaba', - jamAwal: "10.00", - jamAkhir: "11.00", - dibuat: "Jhon" - }, - { - id: 2, - title: 'Pembahasan Mengenai Darmasaba', - jamAwal: "11.00", - jamAkhir: "12.00", - dibuat: "Jhon" - }, - { - id: 3, - title: 'Pembahasan Mengenai Darmasaba', - jamAwal: "13.00", - jamAkhir: "14.00", - dibuat: "Jhon" - }, - { - id: 4, - title: 'Pembahasan Mengenai Darmasaba', - jamAwal: "15.00", - jamAkhir: "16.00", - dibuat: "Jhon" - }, -] - -export default function ListEventHome() { - const router = useRouter() - return ( - - Event Hari Ini - - {dataEvent.map((event, index) => { - const bgColor = ['#D8D8F1', '#FED6C5'][index % 2] - const colorDivider = ['#535FCA', '#A7A7A7'][index % 2] - return ( - router.push(`/calender?page=detail-event`)}> - - - - - {event.jamAwal} - {event.jamAkhir} - {event.title} - Dibuat oleh : {event.dibuat} - - - - - ) - })} - - - ) -} \ No newline at end of file diff --git a/src/module/home/components/list_project.tsx b/src/module/home/components/list_project.tsx deleted file mode 100644 index c713508..0000000 --- a/src/module/home/components/list_project.tsx +++ /dev/null @@ -1,68 +0,0 @@ -'use client' -import { WARNA } from "@/module/_global"; -import { Carousel } from "@mantine/carousel"; -import { Box, Card, Flex, Title, Text, Progress, Stack } from "@mantine/core"; -import { useRouter } from "next/navigation"; - -const dataProject = [ - { - id: 4, - title: 'Project 4', - description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba', - status: 'PROSES', - progress: 60, - date: '05 Mei 2024' - }, - { - id: 5, - title: 'Project5', - description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba', - status: 'PROSES', - progress: 80, - date: '08 Juni 2024' - }, - { - id: 6, - title: 'Project 6', - description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba', - status: 'PROSES', - progress: 47, - date: '10 Mei 2024' - }, -] -export default function ListProjects() { - const router = useRouter() - - return ( - <> - - Kegiatan Terbaru - - {dataProject.map((v) => - - - router.push(`/project/${v.id}`)}> - - - - {v.title} - - - - - - - {v.progress}% - - - Progres {v.date} - - - - - )} - - - - ) -} \ No newline at end of file diff --git a/src/module/home/index.ts b/src/module/home/index.ts index 7b242dd..1ff8487 100644 --- a/src/module/home/index.ts +++ b/src/module/home/index.ts @@ -1,7 +1,7 @@ -import ViewDetailFeature from "./view/view_detail_feature"; -import ViewHome from "./view/view_home"; -import ViewNotification from "./view/view_notification"; -import ViewSearch from "./view/view_search"; +import ViewDetailFeature from "./ui/view_detail_feature"; +import ViewHome from "./ui/view_home"; +import ViewNotification from "./ui/view_notification"; +import ViewSearch from "./ui/view_search"; export { ViewHome } export { ViewDetailFeature } diff --git a/src/module/home/lib/api_home.ts b/src/module/home/lib/api_home.ts new file mode 100644 index 0000000..3ae6eae --- /dev/null +++ b/src/module/home/lib/api_home.ts @@ -0,0 +1,4 @@ +export const funGetHome = async (path?: string) => { + const response = await fetch(`/api/home${(path) ? path : ''}`, { next: { tags: ['discussion'] } }); + return await response.json().catch(() => null); +} \ No newline at end of file diff --git a/src/module/home/lib/type_home.ts b/src/module/home/lib/type_home.ts new file mode 100644 index 0000000..6b3d455 --- /dev/null +++ b/src/module/home/lib/type_home.ts @@ -0,0 +1,37 @@ +export interface IDataHomeKegiatan { + id: string + title: string + desc: string + status: string + progress: number + createdAt: string +} + +export interface IDataHomeDivision { + id: string + name: string + jumlah: number +} + +export interface IDataHomeEvent { + id: string + idDivision: string + title: string + desc: string + status: number + timeStart: string + timeEnd: string + dateStart: string + dateEnd: string + createdAt: string + user_name: string +} + +export interface IDataHomeDiskusi { + id: string + idDivision: string + desc: string + title: string + date: string + user: string +} \ No newline at end of file diff --git a/src/module/home/components/carosole.tsx b/src/module/home/ui/carosole.tsx similarity index 100% rename from src/module/home/components/carosole.tsx rename to src/module/home/ui/carosole.tsx diff --git a/src/module/home/components/chart_document.tsx b/src/module/home/ui/chart_document.tsx similarity index 95% rename from src/module/home/components/chart_document.tsx rename to src/module/home/ui/chart_document.tsx index 19c169c..c511b71 100644 --- a/src/module/home/components/chart_document.tsx +++ b/src/module/home/ui/chart_document.tsx @@ -70,21 +70,21 @@ export default function ChartDocumentHome() { data: [ { value: 78, - name: 'Confidence', + name: 'File', itemStyle: { color: "#F3C96B" } }, { value: 35, - name: 'Supportive', + name: 'Folder', itemStyle: { color: "#9EC97F" } }, { value: 58, - name: 'Positive', + name: 'Documen', itemStyle: { color: "#5971C0" } diff --git a/src/module/home/components/chart_progress_tugas.tsx b/src/module/home/ui/chart_progress_tugas.tsx similarity index 100% rename from src/module/home/components/chart_progress_tugas.tsx rename to src/module/home/ui/chart_progress_tugas.tsx diff --git a/src/module/home/components/features.tsx b/src/module/home/ui/features.tsx similarity index 100% rename from src/module/home/components/features.tsx rename to src/module/home/ui/features.tsx diff --git a/src/module/home/components/ui/icon_navbar.tsx b/src/module/home/ui/icon_navbar.tsx similarity index 100% rename from src/module/home/components/ui/icon_navbar.tsx rename to src/module/home/ui/icon_navbar.tsx diff --git a/src/module/home/ui/list_discussion.tsx b/src/module/home/ui/list_discussion.tsx new file mode 100644 index 0000000..6c3697f --- /dev/null +++ b/src/module/home/ui/list_discussion.tsx @@ -0,0 +1,107 @@ +'use client' +import { WARNA } from "@/module/_global"; +import { Box, Group, Skeleton, Text } from "@mantine/core"; +import { GoDiscussionClosed } from "react-icons/go"; +import { CiClock2, CiUser } from "react-icons/ci"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { IDataHomeDiskusi } from "../lib/type_home"; +import { funGetHome } from "../lib/api_home"; +import toast from "react-hot-toast"; +import { useShallowEffect } from "@mantine/hooks"; +import _ from "lodash"; + + +export default function ListDiscussion() { + const router = useRouter() + const [isData, setData] = useState([]) + const [loading, setLoading] = useState(true); + + const fetchData = async () => { + try { + setData([]); + setLoading(true); + const response = await funGetHome('?cat=discussion') + + if (response.success) { + setData(response.data) + } else { + toast.error(response.message); + } + setLoading(false); + } catch (error) { + toast.error("Gagal mendapatkan data, coba lagi nanti"); + console.error(error); + } finally { + setLoading(false); + } + }; + + + useShallowEffect(() => { + fetchData(); + }, []); + + return ( + + Diskusi + + + { + loading ? + Array(3) + .fill(null) + .map((_, i) => ( + + + + )) + : + _.isEmpty(isData) + ? + + Tidak ada diskusi + + : + <> + { + isData.map((v, i) => { + return ( + router.push(`/division/${v.idDivision}/discussion/${v.id}`)}> + + + + + {v.desc} + + + + + + + {v.user} + + + + {v.date} + + + + ) + }) + } + + + } + + + ) +} \ No newline at end of file diff --git a/src/module/home/ui/list_divisi.tsx b/src/module/home/ui/list_divisi.tsx new file mode 100644 index 0000000..4788aa5 --- /dev/null +++ b/src/module/home/ui/list_divisi.tsx @@ -0,0 +1,84 @@ +'use client' +import { WARNA } from "@/module/_global"; +import { Carousel } from "@mantine/carousel"; +import { Box, Card, Flex, Title, Text, Skeleton } from "@mantine/core"; +import _ from "lodash"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { IDataHomeDivision } from "../lib/type_home"; +import { funGetHome } from "../lib/api_home"; +import toast from "react-hot-toast"; +import { useShallowEffect } from "@mantine/hooks"; + +export default function ListDivisi() { + const router = useRouter() + const [isData, setData] = useState([]) + const [loading, setLoading] = useState(true); + + const fetchData = async () => { + try { + setData([]); + setLoading(true); + const response = await funGetHome('?cat=division') + + if (response.success) { + setData(response.data) + } else { + toast.error(response.message); + } + setLoading(false); + } catch (error) { + toast.error("Gagal mendapatkan data, coba lagi nanti"); + console.error(error); + } finally { + setLoading(false); + } + }; + + + useShallowEffect(() => { + fetchData(); + }, []); + + + return ( + <> + + Divisi Teraktif + {loading ? + + + + : + _.isEmpty(isData) + ? + + Tidak ada divisi + + : + + {isData.map((v) => + + + router.push(`/division/${v.id}`)}> + + + + {v.name} + + + + + KEGIATAN + {v.jumlah} + + + + + )} + + } + + + ) +} \ No newline at end of file diff --git a/src/module/home/ui/list_event.tsx b/src/module/home/ui/list_event.tsx new file mode 100644 index 0000000..486df6f --- /dev/null +++ b/src/module/home/ui/list_event.tsx @@ -0,0 +1,90 @@ +'use client' +import { WARNA } from "@/module/_global" +import { Box, Divider, Group, Skeleton, Text } from "@mantine/core" +import { useRouter } from "next/navigation" +import { useState } from "react" +import { IDataHomeEvent } from "../lib/type_home" +import { funGetHome } from "../lib/api_home" +import toast from "react-hot-toast" +import { useShallowEffect } from "@mantine/hooks" +import _ from "lodash" + + +export default function ListEventHome() { + const router = useRouter() + const [isData, setData] = useState([]) + const [loading, setLoading] = useState(true); + + const fetchData = async () => { + try { + setData([]); + setLoading(true); + const response = await funGetHome('?cat=event') + + if (response.success) { + setData(response.data) + } else { + toast.error(response.message); + } + setLoading(false); + } catch (error) { + toast.error("Gagal mendapatkan data, coba lagi nanti"); + console.error(error); + } finally { + setLoading(false); + } + }; + + + useShallowEffect(() => { + fetchData(); + }, []); + + return ( + + Event Hari Ini + + {loading ? + Array(3) + .fill(null) + .map((_, i) => ( + + + + )) + : + _.isEmpty(isData) + ? + + Tidak ada event + + : + isData.map((event, index) => { + const bgColor = ['#D8D8F1', '#FED6C5'][index % 2] + const colorDivider = ['#535FCA', '#A7A7A7'][index % 2] + return ( + + router.push(`/division/${event.idDivision}/calender/${event.id}`)} bg={bgColor} pl={15} p={10} style={{ + borderRadius: 10 + }} h={113}> + + + + {event.timeStart} - {event.timeEnd} + {event.title} + Dibuat oleh : {event.user_name} + + + + + ) + }) + } + + + ) +} \ No newline at end of file diff --git a/src/module/home/components/list_notification.tsx b/src/module/home/ui/list_notification.tsx similarity index 100% rename from src/module/home/components/list_notification.tsx rename to src/module/home/ui/list_notification.tsx diff --git a/src/module/home/ui/list_project.tsx b/src/module/home/ui/list_project.tsx new file mode 100644 index 0000000..c705869 --- /dev/null +++ b/src/module/home/ui/list_project.tsx @@ -0,0 +1,87 @@ +'use client' +import { WARNA } from "@/module/_global"; +import { Carousel } from "@mantine/carousel"; +import { Box, Card, Flex, Title, Text, Progress, Stack, Skeleton } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import toast from "react-hot-toast"; +import { funGetHome } from "../lib/api_home"; +import { IDataHomeKegiatan } from "../lib/type_home"; +import _ from "lodash"; + +export default function ListProjects() { + const router = useRouter() + const [isData, setData] = useState([]) + const [loading, setLoading] = useState(true); + + const fetchData = async () => { + try { + setData([]); + setLoading(true); + const response = await funGetHome('?cat=kegiatan') + + if (response.success) { + setData(response.data) + } else { + toast.error(response.message); + } + setLoading(false); + } catch (error) { + toast.error("Gagal mendapatkan data, coba lagi nanti"); + console.error(error); + } finally { + setLoading(false); + } + }; + + + useShallowEffect(() => { + fetchData(); + }, []); + + return ( + <> + + Kegiatan Terbaru + {loading ? + + + + : + _.isEmpty(isData) + ? + + Tidak ada kegiatan terbaru + + : + + {isData.map((v) => + + + router.push(`/project/${v.id}`)}> + + + + {v.title} + + + + + + + {v.progress}% + + + {v.createdAt} + + + + + )} + + } + + + ) +} \ No newline at end of file diff --git a/src/module/home/view/view_detail_feature.tsx b/src/module/home/ui/view_detail_feature.tsx similarity index 100% rename from src/module/home/view/view_detail_feature.tsx rename to src/module/home/ui/view_detail_feature.tsx diff --git a/src/module/home/view/view_home.tsx b/src/module/home/ui/view_home.tsx similarity index 52% rename from src/module/home/view/view_home.tsx rename to src/module/home/ui/view_home.tsx index 165a8d3..7fb4c93 100644 --- a/src/module/home/view/view_home.tsx +++ b/src/module/home/ui/view_home.tsx @@ -1,15 +1,15 @@ import { LayoutNavbarHome } from '@/module/_global'; import { Box, Group, Stack, Text } from '@mantine/core'; import React from 'react'; -import Carosole from '../components/carosole'; -import Features from '../components/features'; -import IconNavbar from '../components/ui/icon_navbar'; -import ListProjects from '../components/list_project'; -import ListDivisi from '../components/list_divisi'; -import ListDiscussion from '../components/list_discussion'; -import ListEventHome from '../components/list_event'; -import ChartProgressHome from '../components/chart_progress_tugas'; -import ChartDocumentHome from '../components/chart_document'; +import Carosole from './carosole'; +import Features from './features'; +import IconNavbar from './icon_navbar'; +import ListProjects from './list_project'; +import ListDivisi from './list_divisi'; +import ListDiscussion from './list_discussion'; +import ListEventHome from './list_event'; +import ChartProgressHome from './chart_progress_tugas'; +import ChartDocumentHome from './chart_document'; export default function ViewHome() { @@ -17,7 +17,7 @@ export default function ViewHome() { <> - Perbekel Darmasaba + Perbekel Darmasaba diff --git a/src/module/home/view/view_notification.tsx b/src/module/home/ui/view_notification.tsx similarity index 85% rename from src/module/home/view/view_notification.tsx rename to src/module/home/ui/view_notification.tsx index 441dddf..7417f83 100644 --- a/src/module/home/view/view_notification.tsx +++ b/src/module/home/ui/view_notification.tsx @@ -1,7 +1,7 @@ import { LayoutNavbarNew } from '@/module/_global' import { Box, } from '@mantine/core' import React from 'react' -import ListNotification from '../components/list_notification' +import ListNotification from './list_notification' export default function ViewNotification() { return ( diff --git a/src/module/home/view/view_search.tsx b/src/module/home/ui/view_search.tsx similarity index 100% rename from src/module/home/view/view_search.tsx rename to src/module/home/ui/view_search.tsx