feat : filter api
This commit is contained in:
@@ -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