"use client"; import { Input, Select, SelectItem } from "@nextui-org/react" import { Company } from "prisma/generated/client" import { useEffect } from "react" import { SelectOption } from "@/common/types/select" import { useResultStore } from "@/common/stores/useResultStore"; import getClientCredential from "@/common/libs/getClientCredential"; import { SHOWING_SELECTIONS } from "@/common/constants/result"; const Filter = () => { const { filter, updateFilter, companies, setCompanies } = useResultStore() const credential = getClientCredential() useEffect(() => { if (credential && !filter.company) updateFilter("company", credential.companyId.toString()) }, [credential, updateFilter, filter]) useEffect(() => { loadCompany().then((data: SelectOption[]) => { setCompanies(data) }) }, [setCompanies]) const handleInputChange = (e: React.ChangeEvent) => { const { name, value } = e.target updateFilter(name, value) } const handleSelectChange = (e: React.ChangeEvent) => { const { name, value } = e.target updateFilter(name, value) } return (
) } const loadCompany = async () => { const response = await fetch(`/api/company`) const data: Company[] = await response.json() || [] return data.map((company) => ({ value: company.id, label: company.name })) } export default Filter