summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-04-18 20:36:19 +0300
committereug-vs <eug-vs@keemail.me>2021-04-18 20:36:19 +0300
commit6627ec88b2a02b522511b85eb38d21225098cfad (patch)
tree25a92e3c92a6a08bf513af29a236e4cbecbe1e4b
parentc222bc06f9c123d3e2fa4a428d74032f54887485 (diff)
downloadcommercel-ui-6627ec88b2a02b522511b85eb38d21225098cfad.tar.gz
feat: support date filters
-rw-r--r--src/lib/ServiceContext.tsx1
-rw-r--r--src/lib/ServiceFilters.tsx17
-rw-r--r--src/services/transfers/index.ts1
-rw-r--r--src/services/waybills/index.ts2
4 files changed, 16 insertions, 5 deletions
diff --git a/src/lib/ServiceContext.tsx b/src/lib/ServiceContext.tsx
index 2573134..b52c3d5 100644
--- a/src/lib/ServiceContext.tsx
+++ b/src/lib/ServiceContext.tsx
@@ -10,6 +10,7 @@ export interface Action extends ButtonProps {
export interface Filter extends Field {
as?: string;
+ date?: boolean;
options?: Option[];
value?: string;
}
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>
);
};
diff --git a/src/services/transfers/index.ts b/src/services/transfers/index.ts
index b0f71e6..84858ce 100644
--- a/src/services/transfers/index.ts
+++ b/src/services/transfers/index.ts
@@ -16,6 +16,7 @@ const service: ServiceParams<Transfer> = {
{ key: 'amount', label: 'Сумма' },
],
filters: [
+ { key: 'date', label: 'Дата', date: true },
{ key: 'operation', label: 'Операция', transform: transformOperation },
{ key: 'contractorId', label: 'Контрагент', as: 'contractor.name' },
],
diff --git a/src/services/waybills/index.ts b/src/services/waybills/index.ts
index 0b24876..b623da6 100644
--- a/src/services/waybills/index.ts
+++ b/src/services/waybills/index.ts
@@ -10,11 +10,13 @@ const service: ServiceParams<Waybill> = {
nameSingular: 'Накладная',
tableFields: [
{ key: 'status', label: 'Статус', transform: transformStatus },
+ { key: 'date', label: 'Дата' },
{ key: 'operation', label: 'Операция', transform: transformOperation },
{ key: 'total', label: 'Сумма' },
{ key: 'contractor.name', label: 'Контрагент' },
],
filters: [
+ { key: 'date', label: 'Дата', date: true },
{ key: 'status', label: 'Статус', transform: transformStatus },
{ key: 'operation', label: 'Операция', transform: transformOperation },
{ key: 'contractorId', label: 'Контрагент', as: 'contractor.name' },