diff options
Diffstat (limited to 'src/lib/ServiceFilters.tsx')
-rw-r--r-- | src/lib/ServiceFilters.tsx | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/lib/ServiceFilters.tsx b/src/lib/ServiceFilters.tsx index 8a1e160..b3cfae9 100644 --- a/src/lib/ServiceFilters.tsx +++ b/src/lib/ServiceFilters.tsx @@ -5,13 +5,13 @@ import hooks from '../hooks/useAPIClient'; import useQuery from '../hooks/useQuery'; import ServiceContext, { Filter } from './ServiceContext'; import { SelectBase } from '../components/Select'; +import { InputBase } from '../components/Input'; const getOptionLabel = (item: any, filter: Filter) => { const value = _.get(item, filter.as || filter.key); return filter.transform ? filter.transform(value) : value; }; - const ServiceFilters: React.FC = () => { const service = useContext(ServiceContext); const { query, setQuery } = useQuery(); @@ -32,12 +32,12 @@ const ServiceFilters: React.FC = () => { label: filter.label, }); - const value = _.get(query, filter.key) || '-'; + const value = _.get(query, filter.key, '-'); return { ...filter, options, value }; }); - const handleFilterChange = (key: string) => (event: React.ChangeEvent<HTMLSelectElement>) => { + const handleFilterChange = (key: string) => (event: React.ChangeEvent<HTMLSelectElement | HTMLInputElement>) => { const { value } = event.target; const updatedQuery = { ...query, [key]: value }; if (value === '-') delete updatedQuery[key]; @@ -57,14 +57,21 @@ const ServiceFilters: React.FC = () => { Сбросить фильтры </span> )} - {filters?.map(filter => ( + {filters?.map(filter => (filter.date ? ( + <InputBase + type="date" + key={filter.key} + onChange={handleFilterChange(filter.key)} + value={filter.value} + /> + ) : ( <SelectBase key={filter.key} options={filter.options || []} value={filter.value} onChange={handleFilterChange(filter.key)} /> - ))} + )))} </div> ); }; |