feat : filter api
This commit is contained in:
@@ -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);
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user