Add Fitur Search Di setiap menu

This commit is contained in:
2025-07-08 00:30:55 +08:00
parent 2725c2c064
commit 7e95d5fbb4
38 changed files with 792 additions and 182 deletions

View File

@@ -8,21 +8,25 @@ import { useRouter } from 'next/navigation';
import { useProxy } from 'valtio/utils';
import posyandustate from '../../_state/kesehatan/posyandu/posyandu';
import { useShallowEffect } from '@mantine/hooks';
import { useState } from 'react';
function Posyandu() {
const [search, setSearch] = useState("");
return (
<Box>
<HeaderSearch
title='Posyandu'
placeholder='pencarian'
searchIcon={<IconSearch size={20} />}
value={search}
onChange={(e) => setSearch(e.currentTarget.value)}
/>
<ListPosyandu />
<ListPosyandu search={search} />
</Box>
);
}
function ListPosyandu() {
function ListPosyandu({ search }: { search: string }) {
const statePosyandu = useProxy(posyandustate)
const router = useRouter();
@@ -30,6 +34,14 @@ function ListPosyandu() {
statePosyandu.findMany.load()
}, [])
const filteredData = (statePosyandu.findMany.data || []).filter(item => {
const keyword = search.toLowerCase();
return (
item.name.toLowerCase().includes(keyword) ||
item.nomor.toString().toLowerCase().includes(keyword)
);
});
if (!statePosyandu.findMany.data) {
return (
<Box py={10}>
@@ -56,7 +68,7 @@ function ListPosyandu() {
</TableTr>
</TableThead>
<TableTbody>
{statePosyandu.findMany.data?.map((item) => (
{filteredData.map((item) => (
<TableTr key={item.id}>
<TableTd>{item.name}</TableTd>
<TableTd>{item.nomor}</TableTd>