Merge pull request #206 from bipproduction/amalia/06-september-24
upd: division
This commit is contained in:
@@ -2,8 +2,8 @@ import { ViewFilter } from '@/module/_global';
|
||||
import { TabProject, ViewProject } from '@/module/project';
|
||||
import React from 'react';
|
||||
|
||||
function Page({ searchParams }: { searchParams: { cat: string } }) {
|
||||
if (searchParams.cat == 'filter')
|
||||
function Page({ searchParams }: { searchParams: { page: string } }) {
|
||||
if (searchParams.page == 'filter')
|
||||
return <ViewFilter linkFilter='project' />
|
||||
return (
|
||||
<TabProject />
|
||||
|
||||
@@ -15,6 +15,7 @@ export async function GET(request: Request) {
|
||||
|
||||
let grup
|
||||
const villaId = user.idVillage
|
||||
const roleUser = user.idUserRole
|
||||
const { searchParams } = new URL(request.url);
|
||||
const idGroup = searchParams.get("group");
|
||||
const name = searchParams.get('search');
|
||||
@@ -25,16 +26,37 @@ export async function GET(request: Request) {
|
||||
grup = idGroup
|
||||
}
|
||||
|
||||
const data = await prisma.division.findMany({
|
||||
where: {
|
||||
|
||||
let kondisi: any = {
|
||||
isActive: true,
|
||||
idVillage: String(villaId),
|
||||
idGroup: grup,
|
||||
name: {
|
||||
contains: (name == undefined || name == "null") ? "" : name,
|
||||
mode: "insensitive"
|
||||
}
|
||||
}
|
||||
|
||||
if (roleUser != "supadmin" && roleUser != "cosupadmin" && roleUser != "admin") {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
idVillage: String(villaId),
|
||||
idGroup: grup,
|
||||
name: {
|
||||
contains: (name == undefined || name == "null") ? "" : name,
|
||||
mode: "insensitive"
|
||||
},
|
||||
DivisionMember: {
|
||||
some: {
|
||||
isActive: true,
|
||||
idUser: String(user.id)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const data = await prisma.division.findMany({
|
||||
where: kondisi,
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
@@ -56,7 +78,18 @@ export async function GET(request: Request) {
|
||||
}))
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data: allData, }, { status: 200 });
|
||||
const filter = await prisma.group.findUnique({
|
||||
where: {
|
||||
id: grup
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data: allData, filter }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -93,7 +126,7 @@ export async function POST(request: Request) {
|
||||
|
||||
|
||||
const dataMember = sent.member.map((v: any) => ({
|
||||
..._.omit(v, ["idUser","name"]),
|
||||
..._.omit(v, ["idUser", "name"]),
|
||||
idUser: v.idUser,
|
||||
idDivision: data.id,
|
||||
isAdmin: sent.admin.some((i: any) => i == v.idUser)
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
"use client"
|
||||
import { WARNA } from '@/module/_global';
|
||||
import { globalRole, WARNA } from '@/module/_global';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import React, { useState } from 'react';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import React from 'react';
|
||||
import { HiOutlineFilter } from 'react-icons/hi';
|
||||
import { IoAddCircle } from 'react-icons/io5';
|
||||
import { TbReportAnalytics } from "react-icons/tb";
|
||||
|
||||
export default function DrawerDivision() {
|
||||
const router = useRouter()
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
const searchParams = useSearchParams()
|
||||
const group = searchParams.get('group')
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Stack pt={10}>
|
||||
@@ -23,26 +28,33 @@ export default function DrawerDivision() {
|
||||
<Text c={WARNA.biruTua}>Tambah Divisi</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
<Flex onClick={() => {
|
||||
router.push('/division?page=filter')
|
||||
}} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<HiOutlineFilter size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua}>Filter</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
<Flex onClick={() => {
|
||||
router.push('/division?page=report')
|
||||
}} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<TbReportAnalytics size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua}>Report</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
{
|
||||
roleLogin.get() == "supadmin" &&
|
||||
<Flex onClick={() => {
|
||||
router.push('/division?page=filter&group=' + group)
|
||||
}} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<HiOutlineFilter size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua}>Filter</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
|
||||
{
|
||||
(roleLogin.get() == "supadmin" || roleLogin.get() == "cosupadmin") &&
|
||||
<Flex onClick={() => {
|
||||
router.push('/division?page=report')
|
||||
}} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<TbReportAnalytics size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua}>Report</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
</SimpleGrid>
|
||||
</Stack>
|
||||
</Box>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use client"
|
||||
import { LayoutDrawer, LayoutNavbarNew, SkeletonSingle, WARNA } from '@/module/_global';
|
||||
import { globalRole, LayoutDrawer, LayoutNavbarNew, SkeletonSingle, WARNA } from '@/module/_global';
|
||||
import { ActionIcon, Avatar, Box, Button, Divider, Flex, Grid, Group, Skeleton, Stack, Text } from '@mantine/core';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
@@ -12,6 +12,8 @@ import { LuClipboardEdit } from 'react-icons/lu';
|
||||
import { funDeleteMemberDivision, funEditStatusAdminDivision, funGetDivisionById } from '../lib/api_division';
|
||||
import { IDataMemberDivision } from '../lib/type_division';
|
||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { funGetUserByCookies } from '@/module/auth';
|
||||
|
||||
|
||||
export default function InformationDivision() {
|
||||
@@ -26,15 +28,20 @@ export default function InformationDivision() {
|
||||
const [valChooseMemberStatus, setChooseMemberStatus] = useState<boolean>(false)
|
||||
const [valChooseMemberName, setChooseMemberName] = useState("")
|
||||
const [isOpenModal, setOpenModal] = useState(false)
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
const [isAdmin, setAdmin] = useState(false)
|
||||
|
||||
async function getOneData() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const res = await funGetDivisionById(param.id);
|
||||
const login = await funGetUserByCookies()
|
||||
if (res.success) {
|
||||
setName(res.data.division.name);
|
||||
setDeskripsi(res.data.division.desc);
|
||||
setMember(res.data.member)
|
||||
const cek = res.data.member.some((i: any) => i.id == login.id && i.isAdmin == true)
|
||||
setAdmin(cek)
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
@@ -163,12 +170,15 @@ export default function InformationDivision() {
|
||||
</Box>
|
||||
</Group>
|
||||
:
|
||||
<Group align='center' onClick={() => router.push('/division/add-member/' + param.id)}>
|
||||
<Avatar size="lg">
|
||||
<AiOutlineUserAdd size={30} color={WARNA.biruTua} />
|
||||
</Avatar>
|
||||
<Text>Tambah Anggota</Text>
|
||||
</Group>
|
||||
|
||||
((roleLogin.get() != 'user' && roleLogin.get() != 'coadmin') || isAdmin) ?
|
||||
<Group align='center' onClick={() => router.push('/division/add-member/' + param.id)}>
|
||||
<Avatar size="lg">
|
||||
<AiOutlineUserAdd size={30} color={WARNA.biruTua} />
|
||||
</Avatar>
|
||||
<Text>Tambah Anggota</Text>
|
||||
</Group>
|
||||
: <></>
|
||||
}
|
||||
</Box>
|
||||
<Box pt={10}>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
'use client'
|
||||
import { LayoutDrawer, LayoutNavbarNew, SkeletonSingle, WARNA } from '@/module/_global';
|
||||
import { globalRole, LayoutDrawer, LayoutNavbarNew, SkeletonSingle, WARNA } from '@/module/_global';
|
||||
import { ActionIcon, Avatar, Box, Card, Center, Divider, Flex, Grid, Group, Skeleton, Text, TextInput, Title } from '@mantine/core';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import React, { useState } from 'react';
|
||||
import { HiMenu } from 'react-icons/hi';
|
||||
import { HiMagnifyingGlass, HiMiniPresentationChartBar, HiMiniUserGroup, HiOutlineListBullet, HiSquares2X2 } from 'react-icons/hi2';
|
||||
import { HiMagnifyingGlass, HiMiniUserGroup, HiOutlineListBullet, HiSquares2X2 } from 'react-icons/hi2';
|
||||
import { MdAccountCircle } from 'react-icons/md';
|
||||
import DrawerDivision from './drawer_division';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { IDataDivison } from '../lib/type_division';
|
||||
import { funGetAllDivision } from '../lib/api_division';
|
||||
import toast from 'react-hot-toast';
|
||||
import { funGetAllGroup, IDataGroup } from '@/module/group';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
|
||||
export default function ListDivision() {
|
||||
const [isList, setIsList] = useState(false)
|
||||
@@ -23,6 +23,8 @@ export default function ListDivision() {
|
||||
const searchParams = useSearchParams()
|
||||
const group = searchParams.get('group')
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [nameGroup, setNameGroup] = useState('')
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
|
||||
|
||||
const handleList = () => {
|
||||
@@ -34,10 +36,10 @@ export default function ListDivision() {
|
||||
setData([]);
|
||||
setLoading(true);
|
||||
const response = await funGetAllDivision('?search=' + search + '&group=' + group)
|
||||
|
||||
if (response.success) {
|
||||
setData(response.data)
|
||||
setJumlah(response.data.length)
|
||||
setNameGroup(response.filter.name)
|
||||
} else {
|
||||
toast.error(response.message);
|
||||
}
|
||||
@@ -59,38 +61,17 @@ export default function ListDivision() {
|
||||
fetchData(searchQuery)
|
||||
}, [searchQuery])
|
||||
|
||||
const [checked, setChecked] = useState<IDataGroup[]>([]);
|
||||
|
||||
const groupNameMap = (groupId: string) => {
|
||||
const groupName = checked.find((group) => group.id === groupId)?.name;
|
||||
return groupName || '-';
|
||||
};
|
||||
|
||||
async function getAllGroupFilter() {
|
||||
try {
|
||||
const response = await funGetAllGroup('?active=true')
|
||||
if (response.success) {
|
||||
setChecked(response.data);
|
||||
} else {
|
||||
toast.error(response.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan grup, coba lagi nanti");
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getAllGroupFilter();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<LayoutNavbarNew back='/home' title='Divisi'
|
||||
menu={<ActionIcon variant="light" onClick={() => (setOpenDrawer(true))} bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Settings">
|
||||
<HiMenu size={20} color='white' />
|
||||
</ActionIcon>} />
|
||||
|
||||
menu={
|
||||
(roleLogin.get() != "user" && roleLogin.get() != "coadmin") &&
|
||||
<ActionIcon variant="light" onClick={() => (setOpenDrawer(true))} bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Settings">
|
||||
<HiMenu size={20} color='white' />
|
||||
</ActionIcon>
|
||||
} />
|
||||
|
||||
<Box p={20}>
|
||||
<Grid justify='center' align='center'>
|
||||
<Grid.Col span={10}>
|
||||
@@ -121,8 +102,7 @@ export default function ListDivision() {
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
<Box pt={20}>
|
||||
{/* {group && <Text>Filter by: {group}</Text>} */}
|
||||
{group && <Text>Filter by: {groupNameMap(group)}</Text>}
|
||||
{roleLogin.get() == 'supadmin' && <Text>Filter by: {nameGroup}</Text>}
|
||||
{loading ?
|
||||
<>
|
||||
<Skeleton width={"100%"} height={100} radius={"md"} />
|
||||
@@ -177,13 +157,13 @@ export default function ListDivision() {
|
||||
base: 10,
|
||||
xl: 11
|
||||
}}>
|
||||
<Box>
|
||||
<Box>
|
||||
<Box w={{
|
||||
base: 280,
|
||||
xl: 430
|
||||
}}>
|
||||
<Text truncate="end" pl={20}>
|
||||
{v.name}
|
||||
{v.name}
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -224,7 +204,11 @@ export default function ListDivision() {
|
||||
<Avatar>
|
||||
<MdAccountCircle size={32} color={WARNA.biruTua} />
|
||||
</Avatar>
|
||||
<Avatar>+{v.jumlah_member - 1}</Avatar>
|
||||
<Avatar>
|
||||
{
|
||||
(v.jumlah_member == 0) ? "0" : "+" + (v.jumlah_member - 1)
|
||||
}
|
||||
</Avatar>
|
||||
</Avatar.Group>
|
||||
</Group>
|
||||
</Box>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { WARNA } from '@/module/_global';
|
||||
import { Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import React, { useState } from 'react';
|
||||
import { HiOutlineFilter } from 'react-icons/hi';
|
||||
import { IoAddCircle } from 'react-icons/io5';
|
||||
|
||||
export default function DrawerProject() {
|
||||
const searchParams = useSearchParams()
|
||||
const group = searchParams.get('group')
|
||||
return (
|
||||
<Box>
|
||||
<Stack pt={10}>
|
||||
@@ -19,7 +22,7 @@ export default function DrawerProject() {
|
||||
<Text c={WARNA.biruTua}>Tambah Kegiatan</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
<Flex onClick={() => window.location.href = "/project?cat=filter"} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Flex onClick={() => window.location.href = "/project?page=filter&group=" + group} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<HiOutlineFilter size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
|
||||
@@ -10,7 +10,6 @@ import { funGetAllProject } from '../lib/api_project';
|
||||
import toast from 'react-hot-toast';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { IDataProject } from '../lib/type_project';
|
||||
import { funGetAllGroup, IDataGroup } from '@/module/group';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import _ from 'lodash';
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { globalRole, WARNA } from '@/module/_global';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import React, { useState } from 'react';
|
||||
import { HiOutlineFilter } from 'react-icons/hi';
|
||||
import { IoAddCircle } from 'react-icons/io5';
|
||||
|
||||
export default function MenuDrawerProject() {
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
const searchParams = useSearchParams()
|
||||
const group = searchParams.get('group')
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Stack pt={10}>
|
||||
@@ -23,7 +27,7 @@ export default function MenuDrawerProject() {
|
||||
</Flex>
|
||||
{
|
||||
roleLogin.get() == "supadmin" &&
|
||||
<Flex onClick={() => window.location.href = "/project?cat=filter"} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Flex onClick={() => window.location.href = "/project?page=filter&group=" + group} justify={'center'} align={'center'} direction={'column'} >
|
||||
<Box>
|
||||
<HiOutlineFilter size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user