feat : filter api
This commit is contained in:
@@ -3,7 +3,7 @@ import { ViewListMember } from "@/module/user/member";
|
||||
|
||||
function Page({ searchParams }: { searchParams: { page: string } }) {
|
||||
if (searchParams.page == "filter")
|
||||
return <ViewFilter />
|
||||
return <ViewFilter linkFilter="member"/>
|
||||
|
||||
return (
|
||||
<ViewListMember />
|
||||
|
||||
@@ -4,7 +4,7 @@ import React from 'react';
|
||||
|
||||
function Page({ searchParams }: { searchParams: { page: string } }) {
|
||||
if (searchParams.page == "filter")
|
||||
return <ViewFilter />
|
||||
return <ViewFilter linkFilter='position'/>
|
||||
|
||||
return (
|
||||
<ViewListPosition />
|
||||
|
||||
@@ -1,43 +1,47 @@
|
||||
'use client'
|
||||
import { Box, Group, Divider, Button, Text } from "@mantine/core";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { FaCheck } from "react-icons/fa6";
|
||||
import { WARNA } from "../fun/WARNA";
|
||||
import LayoutNavbarNew from "../layout/layout_navbar_new";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { API_ADDRESS } from "../bin/api_address";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
|
||||
const dataFilter = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Dinas'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Adat'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'LPD'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Karang Taruna'
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: 'BPD'
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: 'LPM'
|
||||
},
|
||||
]
|
||||
export default function ViewFilter() {
|
||||
interface dataGroup {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export default function ViewFilter({linkFilter}: {linkFilter: string}) {
|
||||
const [selectedFilter, setSelectedFilter] = useState<string | null>(null);
|
||||
const [checked, setChecked] = useState<dataGroup[]>([]);
|
||||
const [searchParams, setSearchParams] = useState({ groupId: '' });
|
||||
|
||||
const handleFilterClick = (filterName: string) => {
|
||||
setSelectedFilter(filterName);
|
||||
const handleFilterClick = (id: string) => {
|
||||
setSelectedFilter(id);
|
||||
};
|
||||
|
||||
async function getAllGroupFilter() {
|
||||
try {
|
||||
const response = await fetch(`${API_ADDRESS.apiGetAllGroup}&active=true&groupId=${searchParams.groupId}`);
|
||||
const data = await response.json();
|
||||
console.log("mana data", response);
|
||||
setChecked(data);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedFilter) {
|
||||
setSearchParams({ groupId: selectedFilter });
|
||||
}
|
||||
}, [selectedFilter]);
|
||||
|
||||
useEffect(() => {
|
||||
getAllGroupFilter();
|
||||
}, [searchParams.groupId]);
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
@@ -45,18 +49,18 @@ export default function ViewFilter() {
|
||||
<Box>
|
||||
<LayoutNavbarNew back='' title='Filter' menu />
|
||||
<Box p={20}>
|
||||
{dataFilter.map((filter) => (
|
||||
{checked.map((filter) => (
|
||||
<Box key={filter.id}>
|
||||
<Group
|
||||
justify="space-between"
|
||||
align="center"
|
||||
mb={10}
|
||||
onClick={() => handleFilterClick(filter.name)}
|
||||
onClick={() => handleFilterClick(filter.id)}
|
||||
>
|
||||
<Text fw={selectedFilter === filter.name ? 'bold' : 'normal'}>
|
||||
<Text fw={selectedFilter === filter.id ? 'bold' : 'normal'}>
|
||||
{filter.name}
|
||||
</Text>
|
||||
{selectedFilter === filter.name && <FaCheck size={25} />}
|
||||
{selectedFilter === filter.id && <FaCheck size={25} />}
|
||||
</Group>
|
||||
<Divider my={"sm"} />
|
||||
</Box>
|
||||
@@ -66,7 +70,9 @@ export default function ViewFilter() {
|
||||
radius={100}
|
||||
size="lg"
|
||||
color={WARNA.biruTua}
|
||||
onClick={() => { router.back() }}
|
||||
onClick={() => {
|
||||
router.push(`/${linkFilter}?group=` + selectedFilter)
|
||||
}}
|
||||
>
|
||||
Terapkan
|
||||
</Button>
|
||||
|
||||
@@ -50,7 +50,7 @@ export default function ListGroupActive({ status }: { status: boolean }) {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
useShallowEffect(() => {
|
||||
getData();
|
||||
}, [status]);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
Text,
|
||||
TextInput,
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { FaPencil, FaToggleOff } from "react-icons/fa6";
|
||||
@@ -42,7 +43,7 @@ export default function EditDrawerGroup({
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
useShallowEffect(() => {
|
||||
getOneGroup();
|
||||
}, []);
|
||||
|
||||
@@ -109,7 +110,7 @@ export default function EditDrawerGroup({
|
||||
<FaToggleOff size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua}>Non Aktifkan</Text>
|
||||
<Text c={WARNA.biruTua}>{isActive == false ? "Aktifkan" : "Non Aktifkan"}</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
<Flex
|
||||
|
||||
@@ -13,13 +13,11 @@ export async function getAllPosition(req: NextRequest) {
|
||||
const user = await funGetUserByCookies()
|
||||
console.log(groupID)
|
||||
|
||||
if (groupID == null) {
|
||||
if (groupID == "null") {
|
||||
grupFix = user.idGroup
|
||||
} else {
|
||||
grupFix = groupID
|
||||
}
|
||||
|
||||
|
||||
|
||||
const positions = await prisma.position.findMany({
|
||||
where: {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function deletePosition(req: Request) {
|
||||
export async function deletePosition(req: NextRequest) {
|
||||
try {
|
||||
const data = await req.json();
|
||||
const active = data.isActive;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { API_ADDRESS, LayoutDrawer, WARNA } from "@/module/_global"
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal"
|
||||
import { Box, Stack, SimpleGrid, Flex, Text, Select, TextInput, Button } from "@mantine/core"
|
||||
import { useShallowEffect } from "@mantine/hooks"
|
||||
import { useEffect, useState } from "react"
|
||||
import toast from "react-hot-toast"
|
||||
import { FaPencil, FaToggleOff } from "react-icons/fa6"
|
||||
@@ -11,8 +12,8 @@ type dataGroup = {
|
||||
idGroup: string
|
||||
};
|
||||
|
||||
export default function DrawerDetailPosition({ onUpdated, id }: {
|
||||
onUpdated: (val: boolean) => void, id: string | null,
|
||||
export default function DrawerDetailPosition({ onUpdated, id, isActive }: {
|
||||
onUpdated: (val: boolean) => void, id: string | null, isActive: boolean | null;
|
||||
}) {
|
||||
const [openDrawerGroup, setOpenDrawerGroup] = useState(false)
|
||||
const [isModal, setModal] = useState(false)
|
||||
@@ -28,12 +29,6 @@ export default function DrawerDetailPosition({ onUpdated, id }: {
|
||||
setOpenDrawerGroup(false)
|
||||
}
|
||||
|
||||
function onTrue(val: boolean) {
|
||||
if (val) {
|
||||
onUpdated(true)
|
||||
}
|
||||
setModal(false)
|
||||
}
|
||||
async function getAllGroup() {
|
||||
try {
|
||||
const res = await fetch(`${API_ADDRESS.apiGetAllGroup}&villageId=121212&active=true`)
|
||||
@@ -65,7 +60,7 @@ export default function DrawerDetailPosition({ onUpdated, id }: {
|
||||
body: JSON.stringify({
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
idGroup: data.idGroup
|
||||
idGroup: data.idGroup,
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -84,7 +79,7 @@ export default function DrawerDetailPosition({ onUpdated, id }: {
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
useShallowEffect(() => {
|
||||
getAllGroup()
|
||||
getOneData()
|
||||
}, [])
|
||||
@@ -98,7 +93,8 @@ export default function DrawerDetailPosition({ onUpdated, id }: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
data
|
||||
id,
|
||||
isActive,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -132,7 +128,7 @@ export default function DrawerDetailPosition({ onUpdated, id }: {
|
||||
<FaToggleOff size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua}>Non Aktifkan</Text>
|
||||
<Text c={WARNA.biruTua}>{isActive == false ? "Aktifkan" : "Non Aktifkan"}</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { WARNA, LayoutDrawer, API_ADDRESS } from "@/module/_global";
|
||||
import { Box, Stack, SimpleGrid, Flex, TextInput, Button, Text, Select } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
@@ -31,7 +32,7 @@ export default function DrawerListPosition({ onCreated }: { onCreated: (val: boo
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
useShallowEffect(() => {
|
||||
getAllGroup()
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import DrawerDetailPosition from "./drawer_detail_position";
|
||||
import toast from "react-hot-toast";
|
||||
import _ from "lodash";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
type dataPosition = {
|
||||
name: string;
|
||||
@@ -23,12 +24,14 @@ export default function ListPositionActive({ status }: { status: boolean }) {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [selectId, setSelectId] = useState<string | null>(null);
|
||||
const [active, setActive] = useState<boolean | null>(null)
|
||||
const searchParams = useSearchParams()
|
||||
const group = searchParams.get('group')
|
||||
|
||||
async function getAllPosition() {
|
||||
try {
|
||||
setDataPosition([]);
|
||||
setLoading(true)
|
||||
const res = await fetch(`${API_ADDRESS.apiGetAllPosition}&active=` + status);
|
||||
const res = await fetch(`${API_ADDRESS.apiGetAllPosition}&active=${status}&groupId=${group}`);
|
||||
const data = await res.json();
|
||||
setDataPosition(data);
|
||||
setLoading(false);
|
||||
@@ -41,7 +44,7 @@ export default function ListPositionActive({ status }: { status: boolean }) {
|
||||
|
||||
useShallowEffect(() => {
|
||||
getAllPosition();
|
||||
}, [status])
|
||||
}, [status, group])
|
||||
|
||||
return (
|
||||
<Box pt={20}>
|
||||
@@ -111,6 +114,7 @@ export default function ListPositionActive({ status }: { status: boolean }) {
|
||||
>
|
||||
<DrawerDetailPosition
|
||||
id={selectId}
|
||||
isActive={active}
|
||||
onUpdated={() => {
|
||||
setOpenDrawer(false);
|
||||
}}
|
||||
|
||||
@@ -7,11 +7,11 @@ export async function getAllUser(req: NextRequest) {
|
||||
try {
|
||||
let fixGroup
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const idGroup = searchParams.get("groupID");
|
||||
const idGroup = searchParams.get("groupId");
|
||||
const active = searchParams.get("active");
|
||||
const user = await funGetUserByCookies();
|
||||
|
||||
if (idGroup == null || idGroup == undefined) {
|
||||
if (idGroup == "null" || idGroup == undefined) {
|
||||
fixGroup = user.idGroup
|
||||
} else {
|
||||
fixGroup = idGroup
|
||||
|
||||
@@ -19,6 +19,7 @@ export async function getOneUser(req: NextRequest) {
|
||||
email: true,
|
||||
gender: true,
|
||||
idGroup: true,
|
||||
isActive: true,
|
||||
idPosition: true,
|
||||
UserRole: {
|
||||
select: {
|
||||
|
||||
@@ -2,39 +2,42 @@
|
||||
import { API_ADDRESS, WARNA } from "@/module/_global";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
import { Box, Flex, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { FaPencil, FaToggleOff } from "react-icons/fa6";
|
||||
import { ImUserCheck } from "react-icons/im";
|
||||
|
||||
export default function DrawerDetailMember({ onDeleted, id }: { onDeleted: (val: boolean) => void, id: string | undefined }) {
|
||||
export default function DrawerDetailMember({ onDeleted, id, status }: { onDeleted: (val: boolean) => void, id: string | undefined, status: boolean |undefined }) {
|
||||
const router = useRouter()
|
||||
const [isModal, setModal] = useState(false)
|
||||
|
||||
|
||||
async function nonActive(val: boolean) {
|
||||
// try {
|
||||
// if (val) {
|
||||
// const res = await fetch(API_ADDRESS.apiDeleteUser, {
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
// },
|
||||
// body: JSON.stringify({ id: id}),
|
||||
// })
|
||||
// if (res.status == 200) {
|
||||
// onDeleted(true);
|
||||
// } else {
|
||||
// onDeleted(false);
|
||||
// }
|
||||
// }
|
||||
// router.push('/member')
|
||||
// setModal(false)
|
||||
// } catch (error) {
|
||||
// console.error(error)
|
||||
// setModal(false);
|
||||
// toast.error("Terjadi kesalahan");
|
||||
// }
|
||||
try {
|
||||
const res = await fetch(API_ADDRESS.apiDeleteUser, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id,
|
||||
isActive: status
|
||||
}),
|
||||
})
|
||||
if (res.status == 200) {
|
||||
onDeleted(true);
|
||||
} else {
|
||||
onDeleted(false);
|
||||
}
|
||||
router.push('/member')
|
||||
setModal(false)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
setModal(false);
|
||||
toast.error("Terjadi kesalahan");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -53,7 +56,7 @@ export default function DrawerDetailMember({ onDeleted, id }: { onDeleted: (val:
|
||||
<FaToggleOff size={30} color={WARNA.biruTua} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={WARNA.biruTua} ta='center'>Non Aktifkan</Text>
|
||||
<Text c={WARNA.biruTua} ta='center'> {status === false ? "Aktifkan" : "Non Aktifkan"}</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ interface DataMember {
|
||||
gender: string
|
||||
position: string
|
||||
group: string
|
||||
isActive: boolean | undefined
|
||||
}
|
||||
|
||||
export default function NavbarDetailMember({ id }: IdMember) {
|
||||
@@ -102,7 +103,7 @@ export default function NavbarDetailMember({ id }: IdMember) {
|
||||
</Group>
|
||||
</Box>
|
||||
<LayoutDrawer opened={isOpen} title={'Menu'} onClose={() => setOpen(false)}>
|
||||
<DrawerDetailMember id={dataOne?.id} onDeleted={() => setOpen(false)} />
|
||||
<DrawerDetailMember id={dataOne?.id} status={dataOne?.isActive} onDeleted={() => setOpen(false)} />
|
||||
</LayoutDrawer>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { API_ADDRESS, WARNA } from "@/module/_global"
|
||||
import { Box, Group, ActionIcon, Text } from "@mantine/core"
|
||||
import { useShallowEffect } from "@mantine/hooks"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useRouter, useSearchParams } from "next/navigation"
|
||||
import { useEffect, useState } from "react"
|
||||
import { HiMiniUser } from "react-icons/hi2"
|
||||
|
||||
@@ -22,12 +22,14 @@ export default function TabListMember({ status }: { status: boolean }) {
|
||||
const router = useRouter()
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [dataMember, setDataMember] = useState<dataMember[]>([])
|
||||
const searchParams = useSearchParams()
|
||||
const group = searchParams.get('group')
|
||||
|
||||
|
||||
async function getAllUser() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const res = await fetch(API_ADDRESS.apiGetAllUser + '&active=' + status )
|
||||
const res = await fetch(`${API_ADDRESS.apiGetAllUser}&active=${status}&groupId=${group}` )
|
||||
const data = await res.json()
|
||||
|
||||
setDataMember(data)
|
||||
|
||||
Reference in New Issue
Block a user