import { useMemo, useState } from "react"; import { Button, Select, Spin } from "antd"; import type { SelectProps } from "antd"; import { api } from "@nice/client"; interface StaffSelectProps { value?: string | string[]; onChange?: (value: string | string[]) => void; style?: React.CSSProperties; multiple?: boolean; domainId?: string; placeholder?: string; } export default function StaffSelect({ value, onChange, placeholder, style, multiple, domainId, }: StaffSelectProps) { const [keyword, setQuery] = useState(""); // Determine ids based on whether value is an array or not const ids = useMemo(() => { return Array.isArray(value) ? value : []; }, [value]); // Adjust the query to include ids when they are present const { data, isLoading } = api.staff.findMany.useQuery({ where: { OR: [ { username: { contains: keyword, }, }, { showname: { contains: keyword, }, }, { id: { in: ids } } ], domainId, }, select: { id: true, showname: true, username: true }, take: 30, orderBy: { order: "asc" } }); const handleSearch = (value: string) => { setQuery(value); }; const options: SelectProps["options"] = data?.map((staff: any) => ({ value: staff.id, label: staff?.showname || staff?.username, })) || []; return ( <>