// * Packages import { DeleteIcon } from "lucide-react"; import { FormEvent, ReactNode, useState } from "react"; import { route } from "ziggy-js"; // * Other import SimpleString from "@/back/Components/Inputs/SimpleString"; import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip"; import InputError from "@/back/Components/InputError"; import useTrans from "@/hooks/use-translations"; import addFilterToUrl from "@/lib/filters"; type DataTableSearchProps = { modelRoute: string; searchFields: string; children?: ReactNode; }; export default function DataTableSearch({ modelRoute, searchFields, children, }: DataTableSearchProps) { const [search, setSearch] = useState( route().params.search ?? null, ); const submit = (e: FormEvent) => { if (!search) return; e.preventDefault(); const params = { ...route().params, search, }; addFilterToUrl({ modelName: modelRoute, params }); }; const onDeleteSearch = () => { setSearch(null); const params = { ...route().params, search: undefined, }; addFilterToUrl({ modelName: modelRoute, params }); }; return ( <>
{ setSearch(value); }} className="w-[calc(100%-40px-0.5rem)]" /> {children} } tooltipContent={

{useTrans("back.table_search_reset")}

} type="button" variant="destructive" onClick={onDeleteSearch} /> ); }