91 lines
2.7 KiB
TypeScript
91 lines
2.7 KiB
TypeScript
/* eslint-disable react-hooks/exhaustive-deps */
|
|
'use client'
|
|
import colors from '@/con/colors';
|
|
import { Box, Button, Paper, Skeleton, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr } from '@mantine/core';
|
|
import { IconDeviceImacCog, IconSearch } from '@tabler/icons-react';
|
|
import { useRouter } from 'next/navigation';
|
|
import { useEffect, useState } from 'react';
|
|
import { useProxy } from 'valtio/utils';
|
|
import HeaderSearch from '../../../_com/header';
|
|
import JudulList from '../../../_com/judulList';
|
|
import infoSekolahPaud from '../../../_state/pendidikan/info-sekolah-paud';
|
|
|
|
function Siswa() {
|
|
const [search, setSearch] = useState('');
|
|
return (
|
|
<Box>
|
|
<HeaderSearch
|
|
title='Siswa'
|
|
placeholder='pencarian'
|
|
searchIcon={<IconSearch size={20} />}
|
|
value={search}
|
|
onChange={(e) => setSearch(e.currentTarget.value)}
|
|
/>
|
|
<ListSiswa search={search} />
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
function ListSiswa({ search }: { search: string }) {
|
|
const listState = useProxy(infoSekolahPaud.siswa)
|
|
const router = useRouter();
|
|
useEffect(() => {
|
|
listState.findMany.load()
|
|
}, [])
|
|
|
|
const filteredData = (listState.findMany.data || []).filter(item => {
|
|
const keyword = search.toLowerCase();
|
|
return (
|
|
item.nama.toLowerCase().includes(keyword) ||
|
|
item.lembaga.nama.toLowerCase().includes(keyword)
|
|
);
|
|
});
|
|
|
|
if (!listState.findMany.data) {
|
|
return (
|
|
<Stack py={10}>
|
|
<Skeleton h={500} />
|
|
</Stack>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Box py={10}>
|
|
<Paper bg={colors['white-1']} p={'md'}>
|
|
<Stack>
|
|
<JudulList
|
|
title='List Siswa'
|
|
href='/admin/pendidikan/info-sekolah/siswa/create'
|
|
/>
|
|
<Box style={{ overflowX: 'auto' }}>
|
|
<Table striped withRowBorders withTableBorder style={{ minWidth: '700px' }}>
|
|
<TableThead>
|
|
<TableTr>
|
|
<TableTh>Nama Siswa</TableTh>
|
|
<TableTh>Lembaga</TableTh>
|
|
<TableTh>Detail</TableTh>
|
|
</TableTr>
|
|
</TableThead>
|
|
<TableTbody>
|
|
{filteredData.map((item) => (
|
|
<TableTr key={item.id}>
|
|
<TableTd>{item.nama}</TableTd>
|
|
<TableTd>{item.lembaga.nama}</TableTd>
|
|
<TableTd>
|
|
<Button onClick={() => router.push(`/admin/pendidikan/info-sekolah/siswa/${item.id}`)}>
|
|
<IconDeviceImacCog size={25} />
|
|
</Button>
|
|
</TableTd>
|
|
</TableTr>
|
|
))}
|
|
</TableTbody>
|
|
</Table>
|
|
</Box>
|
|
</Stack>
|
|
</Paper>
|
|
</Box>
|
|
)
|
|
}
|
|
|
|
export default Siswa;
|