feat : update search

Deskripsi:
- search group
- search position
- search member / user / anggota

No Issue
This commit is contained in:
lukman
2024-08-07 10:37:04 +08:00
parent b2ecfe4f4b
commit ad94d0aaa0
7 changed files with 67 additions and 45 deletions

View File

@@ -8,10 +8,15 @@ export async function listGroups(req: NextRequest): Promise<Response> {
const searchParams = req.nextUrl.searchParams
const villaId = user.idVillage
const active = searchParams.get('active');
const name = searchParams.get('name');
const groups = await prisma.group.findMany({
where: {
isActive: (active == "true" ? true : false),
idVillage: String(villaId),
name: {
contains: String(name),
mode: "insensitive"
}
},
select: {
id: true,

View File

@@ -26,6 +26,7 @@ export default function ListGroupActive({ status }: { status: boolean }) {
const [isData, setData] = useState<dataGroup[]>([]);
const [selectId, setSelectId] = useState<string | null>(null);
const [active, setActive] = useState<boolean | null>(null);
const [searchQuery, setSearchQuery] = useState('')
const [loading, setLoading] = useState(true);
const getData = async () => {
@@ -33,7 +34,7 @@ export default function ListGroupActive({ status }: { status: boolean }) {
setData([]);
setLoading(true);
const res = await fetch(
`${API_ADDRESS.apiGetAllGroup}&villageId=121212&active=` + status
`${API_ADDRESS.apiGetAllGroup}&villageId=121212&active=${status}&name=${searchQuery}`
);
const data = await res.json();
setData(data);
@@ -52,7 +53,7 @@ export default function ListGroupActive({ status }: { status: boolean }) {
useShallowEffect(() => {
getData();
}, [status]);
}, [status, searchQuery]);
return (
<Box pt={20}>
@@ -68,6 +69,7 @@ export default function ListGroupActive({ status }: { status: boolean }) {
radius={30}
leftSection={<HiMagnifyingGlass size={20} />}
placeholder="Pencarian"
onChange={(e) => setSearchQuery(e.target.value)}
/>
{loading
? Array(6)