"use client" import { LayoutNavbarNew, WARNA } from '@/module/_global'; import { ActionIcon, Avatar, Box, Divider, Grid, Group, Text, TextInput } from '@mantine/core'; import React, { useState } from 'react'; import { HiMagnifyingGlass, HiMiniPresentationChartBar, HiMiniUserGroup } from 'react-icons/hi2'; import { funGetSearchAll } from '../lib/api_search'; import { useShallowEffect } from '@mantine/hooks'; import { IDataDivisionSearch, IDataProjectSearch, IDataUserSearch } from '../lib/type_search'; import { useRouter } from 'next/navigation'; import _ from 'lodash'; export default function ViewSearch() { const [search, setSearch] = useState(''); const [dataUser, setDataUser] = useState([]); const [dataProject, setDataProject] = useState([]); const [dataDivision, setDataDivision] = useState([]); const router = useRouter() async function featchSearch() { try { const res = await funGetSearchAll('?search=' + search); setDataUser(res.data.user); setDataProject(res.data.project); setDataDivision(res.data.division); } catch (error) { console.error(error) throw new Error("Error") } } useShallowEffect(() => { if (search != '') { featchSearch() } else { setDataUser([]); setDataProject([]); setDataDivision([]); } }, [search]) return ( <> } /> } placeholder="Pencarian" onChange={(e) => setSearch(e.target.value)} /> {dataUser.length || dataProject.length || dataDivision.length > 0 ? ( ANGGOTA {dataUser.length > 0 ? ( {dataUser.map((v, i) => { return ( { router.push(`/member/${v.id}`) }}> {_.startCase(v.name)} {v.group + ' - ' + v.position} ) })} ) : Tidak Ada Anggota } DIVISI {dataDivision.length > 0 ? ( {dataDivision.map((v, i) => { return ( router.push(`/division/${v.id}`)}> {v.name.toUpperCase()} {v.group} {v.desc} ) })} ) : Tidak Ada Divisi } KEGIATAN {dataProject.length > 0 ? ( {dataProject.map((v, i) => { return ( router.push(`/project/${v.id}`)}> {v.title.toUpperCase()} {v.group} ) })} ) : Tidak Ada Kegiatan } ) : null } ); }