Merge pull request #201 from bipproduction/amalia/05-september-24
upd: project
This commit is contained in:
@@ -5,6 +5,7 @@ import moment from "moment";
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { createLogUser } from "@/module/user";
|
||||||
|
|
||||||
|
|
||||||
// GET ALL DATA PROJECT
|
// GET ALL DATA PROJECT
|
||||||
@@ -14,7 +15,7 @@ export async function GET(request: Request) {
|
|||||||
if (user.id == undefined) {
|
if (user.id == undefined) {
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
const roleUser = user.idUserRole
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
|
|
||||||
let grup
|
let grup
|
||||||
@@ -30,19 +31,49 @@ export async function GET(request: Request) {
|
|||||||
grup = idGroup
|
grup = idGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cek = await prisma.group.count({
|
||||||
const data = await prisma.project.findMany({
|
|
||||||
where: {
|
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: (name == undefined || name == "null") ? "" : name,
|
||||||
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
status: (status == "0" || status == "1" || status == "2" || status == "3") ? Number(status) : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roleUser != "supadmin" && roleUser != "cosupadmin" && roleUser != "admin") {
|
||||||
|
kondisi = {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
idVillage: String(villageId),
|
idVillage: String(villageId),
|
||||||
idGroup: grup,
|
idGroup: grup,
|
||||||
createdBy: String(userId),
|
|
||||||
title: {
|
title: {
|
||||||
contains: (name == undefined || name == "null") ? "" : name,
|
contains: (name == undefined || name == "null") ? "" : name,
|
||||||
mode: "insensitive"
|
mode: "insensitive"
|
||||||
},
|
},
|
||||||
status: (status == "0" || status == "1" || status == "2" || status == "3") ? Number(status) : 0
|
status: (status == "0" || status == "1" || status == "2" || status == "3") ? Number(status) : 0,
|
||||||
},
|
ProjectMember: {
|
||||||
|
some: {
|
||||||
|
idUser: String(userId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const data = await prisma.project.findMany({
|
||||||
|
where: kondisi,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
@@ -64,12 +95,22 @@ export async function GET(request: Request) {
|
|||||||
member: v.ProjectMember.length
|
member: v.ProjectMember.length
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const filter = await prisma.group.findUnique({
|
||||||
|
where: {
|
||||||
|
id: grup
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan project", data: omitData, }, { status: 200 });
|
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan kegiatan", data: omitData, filter }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan project, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +199,8 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data kegiatan', table: 'project', data: data.id })
|
||||||
return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan" }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { WARNA } from '@/module/_global';
|
import { globalRole, WARNA } from '@/module/_global';
|
||||||
import { ActionIcon, Avatar, Badge, Box, Card, Center, Divider, Flex, Grid, Group, Text, TextInput, Title } from '@mantine/core';
|
import { ActionIcon, Avatar, Badge, Box, Card, Center, Divider, Flex, Grid, Group, Text, TextInput, Title } from '@mantine/core';
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
@@ -11,6 +11,7 @@ import toast from 'react-hot-toast';
|
|||||||
import { useShallowEffect } from '@mantine/hooks';
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
import { IDataProject } from '../lib/type_project';
|
import { IDataProject } from '../lib/type_project';
|
||||||
import { funGetAllGroup, IDataGroup } from '@/module/group';
|
import { funGetAllGroup, IDataGroup } from '@/module/group';
|
||||||
|
import { useHookstate } from '@hookstate/core';
|
||||||
|
|
||||||
export default function ListProject() {
|
export default function ListProject() {
|
||||||
const [isList, setIsList] = useState(false)
|
const [isList, setIsList] = useState(false)
|
||||||
@@ -21,23 +22,22 @@ export default function ListProject() {
|
|||||||
const status = searchParams.get('status')
|
const status = searchParams.get('status')
|
||||||
const group = searchParams.get('group')
|
const group = searchParams.get('group')
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
|
const [nameGroup, setNameGroup] = useState('')
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
setData([]);
|
setLoading(true)
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
const response = await funGetAllProject('?status=' + status + '&search=' + searchQuery + '&group=' + group)
|
const response = await funGetAllProject('?status=' + status + '&search=' + searchQuery + '&group=' + group)
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setData(response?.data)
|
setData(response?.data)
|
||||||
|
setNameGroup(response.filter.name)
|
||||||
} else {
|
} else {
|
||||||
toast.error(response.message);
|
toast.error(response.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error("Gagal mendapatkan Kegiatan, coba lagi nanti");
|
toast.error("Gagal mendapatkan kegiatan, coba lagi nanti");
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -53,31 +53,6 @@ export default function ListProject() {
|
|||||||
setIsList(!isList)
|
setIsList(!isList)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
<Box mt={20}>
|
<Box mt={20}>
|
||||||
<Grid justify='center' align='center'>
|
<Grid justify='center' align='center'>
|
||||||
@@ -109,7 +84,7 @@ export default function ListProject() {
|
|||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Box pt={20}>
|
<Box pt={20}>
|
||||||
{group && <Text>Filter by: {groupNameMap(group)}</Text>}
|
{roleLogin.get() == 'supadmin' && <Text>Filter by: {nameGroup}</Text>}
|
||||||
<Box bg={"#DCEED8"} p={10} style={{ borderRadius: 10 }}>
|
<Box bg={"#DCEED8"} p={10} style={{ borderRadius: 10 }}>
|
||||||
<Text fw={'bold'} c={WARNA.biruTua}>Total Kegiatan</Text>
|
<Text fw={'bold'} c={WARNA.biruTua}>Total Kegiatan</Text>
|
||||||
<Flex justify={'center'} align={'center'} h={'100%'}>
|
<Flex justify={'center'} align={'center'} h={'100%'}>
|
||||||
@@ -121,7 +96,7 @@ export default function ListProject() {
|
|||||||
{isData.map((v, i) => {
|
{isData.map((v, i) => {
|
||||||
return (
|
return (
|
||||||
<Box key={i}>
|
<Box key={i}>
|
||||||
<Grid align='center'>
|
<Grid align='center'>
|
||||||
<Grid.Col span={{
|
<Grid.Col span={{
|
||||||
base: 2,
|
base: 2,
|
||||||
xl: 1
|
xl: 1
|
||||||
@@ -160,13 +135,13 @@ export default function ListProject() {
|
|||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
<RiCircleFill size={12} color={
|
<RiCircleFill size={12} color={
|
||||||
v.status === 0 ? '#1372C4' :
|
v.status === 0 ? '#1372C4' :
|
||||||
v.status === 1 ? '#C5771A' :
|
v.status === 1 ? '#C5771A' :
|
||||||
v.status === 2 ? '#0B6025' :
|
v.status === 2 ? '#0B6025' :
|
||||||
v.status === 3 ? '#BB1F1F' :
|
v.status === 3 ? '#BB1F1F' :
|
||||||
""
|
""
|
||||||
} />
|
} />
|
||||||
</Group>
|
</Group>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
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 { Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { HiOutlineFilter } from 'react-icons/hi';
|
import { HiOutlineFilter } from 'react-icons/hi';
|
||||||
import { IoAddCircle } from 'react-icons/io5';
|
import { IoAddCircle } from 'react-icons/io5';
|
||||||
|
|
||||||
export default function MenuDrawerProject() {
|
export default function MenuDrawerProject() {
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Stack pt={10}>
|
<Stack pt={10}>
|
||||||
@@ -19,14 +21,17 @@ export default function MenuDrawerProject() {
|
|||||||
<Text c={WARNA.biruTua}>Tambah Kegiatan</Text>
|
<Text c={WARNA.biruTua}>Tambah Kegiatan</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex onClick={() => window.location.href = "/project?cat=filter"} justify={'center'} align={'center'} direction={'column'} >
|
{
|
||||||
<Box>
|
roleLogin.get() == "supadmin" &&
|
||||||
<HiOutlineFilter size={30} color={WARNA.biruTua} />
|
<Flex onClick={() => window.location.href = "/project?cat=filter"} justify={'center'} align={'center'} direction={'column'} >
|
||||||
</Box>
|
<Box>
|
||||||
<Box>
|
<HiOutlineFilter size={30} color={WARNA.biruTua} />
|
||||||
<Text c={WARNA.biruTua}>Filter</Text>
|
</Box>
|
||||||
</Box>
|
<Box>
|
||||||
</Flex>
|
<Text c={WARNA.biruTua}>Filter</Text>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
}
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { LayoutDrawer, LayoutNavbarNew, WARNA } from '@/module/_global';
|
import { globalRole, LayoutDrawer, LayoutNavbarNew, WARNA } from '@/module/_global';
|
||||||
import { ActionIcon, Avatar, Badge, Box, Card, Center, Divider, Flex, Grid, Group, rem, Tabs, Text, TextInput, Title } from '@mantine/core';
|
import { ActionIcon, Box, rem, Tabs } from '@mantine/core';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { HiMenu } from 'react-icons/hi';
|
import { HiMenu } from 'react-icons/hi';
|
||||||
import { HiMagnifyingGlass, HiMiniPresentationChartBar, HiOutlineListBullet, HiSquares2X2 } from 'react-icons/hi2';
|
import { RiProgress3Line } from "react-icons/ri";
|
||||||
import { MdAccountCircle } from 'react-icons/md';
|
|
||||||
import { RiCircleFill, RiProgress3Line } from "react-icons/ri";
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
import { TbClockPause } from 'react-icons/tb';
|
import { TbClockPause } from 'react-icons/tb';
|
||||||
import { IoIosCheckmarkCircleOutline } from 'react-icons/io';
|
import { IoIosCheckmarkCircleOutline } from 'react-icons/io';
|
||||||
import { IoCloseCircleOutline } from 'react-icons/io5';
|
import { IoCloseCircleOutline } from 'react-icons/io5';
|
||||||
import ListProject from './list_project';
|
import ListProject from './list_project';
|
||||||
import MenuDrawerProject from './menu_drawer_project';
|
import MenuDrawerProject from './menu_drawer_project';
|
||||||
|
import { useHookstate } from '@hookstate/core';
|
||||||
|
|
||||||
export default function TabProject() {
|
export default function TabProject() {
|
||||||
const [openDrawer, setOpenDrawer] = useState(false)
|
const [openDrawer, setOpenDrawer] = useState(false)
|
||||||
@@ -20,13 +19,17 @@ export default function TabProject() {
|
|||||||
const status = searchParams.get('status')
|
const status = searchParams.get('status')
|
||||||
const group = searchParams.get("group");
|
const group = searchParams.get("group");
|
||||||
const iconStyle = { width: rem(20), height: rem(20) };
|
const iconStyle = { width: rem(20), height: rem(20) };
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<LayoutNavbarNew back='/home' title='Kegiatan'
|
<LayoutNavbarNew back='/home' title='Kegiatan'
|
||||||
menu={<ActionIcon variant="light" onClick={() => setOpenDrawer(true)} bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Settings">
|
menu={(roleLogin.get() != "user" && roleLogin.get() != "coadmin") ?
|
||||||
<HiMenu size={20} color='white' />
|
<ActionIcon variant="light" onClick={() => setOpenDrawer(true)} bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Settings">
|
||||||
</ActionIcon>} />
|
<HiMenu size={20} color='white' />
|
||||||
|
</ActionIcon>
|
||||||
|
: <></>
|
||||||
|
} />
|
||||||
|
|
||||||
<Box p={20}>
|
<Box p={20}>
|
||||||
<Tabs variant="pills" radius="xl" defaultValue={(status == "1" || status == "2" || status == "3") ? status : "0"}>
|
<Tabs variant="pills" radius="xl" defaultValue={(status == "1" || status == "2" || status == "3") ? status : "0"}>
|
||||||
|
|||||||
Reference in New Issue
Block a user