"use client"; import { LayoutNavbarNew, TEMA, 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 { useMediaQuery, useShallowEffect } from "@mantine/hooks"; import { IDataDivisionSearch, IDataProjectSearch, IDataUserSearch, } from "../lib/type_search"; import { useRouter } from "next/navigation"; import _ from "lodash"; import { useHookstate } from "@hookstate/core"; export default function ViewSearch() { const [search, setSearch] = useState(""); const [dataUser, setDataUser] = useState([]); const [dataProject, setDataProject] = useState([]); const [dataDivision, setDataDivision] = useState([]); const router = useRouter(); const tema = useHookstate(TEMA); 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]); const isMobile2 = useMediaQuery("(max-width: 460px)"); return ( <> } /> } placeholder="Pencarian" onChange={(e) => setSearch(e.target.value)} /> {dataUser.length || dataProject.length || dataDivision.length > 0 ? ( {dataUser.length > 0 ? ( ANGGOTA {dataUser.length > 0 ? ( {dataUser.map((v, i) => { return ( { router.push(`/member/${v.id}`); }} > {_.startCase(v.name)} {v.group + " - " + v.position} ); })} ) : null} ) : null} {dataDivision.length > 0 ? ( DIVISI {dataDivision.length > 0 ? ( {dataDivision.map((v, i) => { return ( router.push(`/division/${v.id}`)} > {v.name.toUpperCase()} {v.group} {v.desc} ); })} ) : null} ) : null} {dataProject.length > 0 ? ( KEGIATAN {dataProject.length > 0 ? ( {dataProject.map((v, i) => { return ( router.push(`/project/${v.id}`)} > {v.title.toUpperCase()} {v.group} ); })} ) : null} ) : null} ) : null} ); }