summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-26 00:44:51 +0300
committereug-vs <eug-vs@keemail.me>2021-03-26 00:44:51 +0300
commitf1cdf02e9c0dca3354f4eebd38edd2ba12075893 (patch)
treec164c722d879869024a1dcd07fec225eb5f5bf47 /src/services
parent062f10a25d43b875d187cf582b2ecf96d075ec26 (diff)
downloadcommercel-ui-f1cdf02e9c0dca3354f4eebd38edd2ba12075893.tar.gz
fix: improve typings
Diffstat (limited to 'src/services')
-rw-r--r--src/services/account/index.ts8
-rw-r--r--src/services/constants.ts11
-rw-r--r--src/services/contractors/ContractorPanel.tsx6
-rw-r--r--src/services/contractors/index.ts3
-rw-r--r--src/services/index.ts4
-rw-r--r--src/services/products/index.ts3
-rw-r--r--src/services/transfers/TransfersUpload.tsx3
-rw-r--r--src/services/transfers/index.ts9
-rw-r--r--src/services/transforms.ts21
-rw-r--r--src/services/waybills/index.ts13
10 files changed, 45 insertions, 36 deletions
diff --git a/src/services/account/index.ts b/src/services/account/index.ts
index 5b5eb10..7cc28b4 100644
--- a/src/services/account/index.ts
+++ b/src/services/account/index.ts
@@ -1,8 +1,10 @@
-const service = {
+import { ServiceParams } from '../../containers/Service/ServiceContext';
+
+const service: ServiceParams = {
route: 'account',
name: 'Рассчётный счёт',
tableFields: [
- { key: 'date', label: 'Дата', transform: (date: string) => new Date(date).toLocaleDateString() },
+ { key: 'date', label: 'Дата', transform: date => new Date(date).toLocaleDateString() },
{ key: 'amount', label: 'Сумма' },
],
actions: [
@@ -11,7 +13,7 @@ const service = {
route: '/transfers/upload',
},
],
- rowLink: (item: any) => `/transfers?date=${item.date}`,
+ rowLink: item => `/transfers?date=${item.date}`,
};
export default service;
diff --git a/src/services/constants.ts b/src/services/constants.ts
deleted file mode 100644
index 1461d9c..0000000
--- a/src/services/constants.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export const operationNames = {
- in: 'Приход',
- out: 'Расход',
-};
-
-export const waybillStatusNames = {
- waiting: 'Ожидание',
- executed: 'Проведена',
- cancelled: 'Отменена',
-};
-
diff --git a/src/services/contractors/ContractorPanel.tsx b/src/services/contractors/ContractorPanel.tsx
index ce94c48..a3650ef 100644
--- a/src/services/contractors/ContractorPanel.tsx
+++ b/src/services/contractors/ContractorPanel.tsx
@@ -1,13 +1,9 @@
import React from 'react';
-import { useHistory } from 'react-router-dom';
import Button from '../../components/Button';
-import { patch, baseURL } from '../../requests';
import { PanelProps } from '../../containers/Service/ServiceContext';
-const ContractorPanel: React.FC<PanelProps> = ({ item, mutate }) => {
- const history = useHistory();
-
+const ContractorPanel: React.FC<PanelProps> = ({ item }) => {
return (
<div className="lg:m-4 p-4 flex flex-col lg:pl-16 lg:border-l">
<span className="text-lg mb-10">
diff --git a/src/services/contractors/index.ts b/src/services/contractors/index.ts
index 124e338..c9e71a1 100644
--- a/src/services/contractors/index.ts
+++ b/src/services/contractors/index.ts
@@ -1,7 +1,8 @@
import Form from './ContractorForm';
import Panel from './ContractorPanel';
+import { ServiceParams } from '../../containers/Service/ServiceContext';
-const service = {
+const service: ServiceParams = {
route: 'contractors',
name: 'Контрагенты',
nameSingular: 'Контрагент',
diff --git a/src/services/index.ts b/src/services/index.ts
index 7f559f2..9d3471b 100644
--- a/src/services/index.ts
+++ b/src/services/index.ts
@@ -12,9 +12,9 @@ const services = [
waybills,
transfers,
account,
-] as ServiceParams[];
+];
-services.forEach((service: any) => registerServiceHooks(service.route));
+services.forEach(service => registerServiceHooks(service.route));
export default services;
diff --git a/src/services/products/index.ts b/src/services/products/index.ts
index 7e1509a..8d42c56 100644
--- a/src/services/products/index.ts
+++ b/src/services/products/index.ts
@@ -1,6 +1,7 @@
import Form from './ProductForm';
+import { ServiceParams } from '../../containers/Service/ServiceContext';
-const service = {
+const service: ServiceParams = {
route: 'products',
name: 'Товары',
nameSingular: 'Товар',
diff --git a/src/services/transfers/TransfersUpload.tsx b/src/services/transfers/TransfersUpload.tsx
index 1c81b08..18a33b8 100644
--- a/src/services/transfers/TransfersUpload.tsx
+++ b/src/services/transfers/TransfersUpload.tsx
@@ -3,7 +3,8 @@ import { useHistory } from 'react-router-dom';
import { Form, Formik } from 'formik';
import Button from '../../components/Button';
import Input from '../../components/Input';
-import Page, { Action } from '../../containers/Page';
+import Page from '../../containers/Page';
+import { Action } from '../../containers/Service/ServiceContext';
import { post } from '../../requests';
const TransfersUpload: React.FC = () => {
diff --git a/src/services/transfers/index.ts b/src/services/transfers/index.ts
index 09f6e04..51be7e3 100644
--- a/src/services/transfers/index.ts
+++ b/src/services/transfers/index.ts
@@ -1,16 +1,17 @@
import Form from './TransferForm';
import UploadPage from './TransfersUpload';
+import { transformOperation } from '../transforms';
+import { ServiceParams } from '../../containers/Service/ServiceContext';
-import { operationNames } from '../constants';
-const service = {
+const service: ServiceParams = {
route: 'transfers',
name: 'Переводы',
nameSingular: 'Перевод',
tableFields: [
- { key: 'date', label: 'Дата', transform: (date: string) => new Date(date).toLocaleDateString() },
+ { key: 'date', label: 'Дата', transform: date => new Date(date).toLocaleDateString() },
{ key: 'contractor.name', label: 'Контрагент' },
- { key: 'operation', label: 'Операция', transform: (op: 'in' | 'out') => operationNames[op] },
+ { key: 'operation', label: 'Операция', transform: transformOperation },
{ key: 'amount', label: 'Сумма' },
],
actions: [
diff --git a/src/services/transforms.ts b/src/services/transforms.ts
new file mode 100644
index 0000000..2eea46f
--- /dev/null
+++ b/src/services/transforms.ts
@@ -0,0 +1,21 @@
+import _ from 'lodash';
+import { Field } from '../components/ListTable';
+
+type Transformer = Field['transform'];
+
+const transformer = (hash: Record<string, string | JSX.Element>): Transformer => {
+ return value => _.get(hash, value, value);
+};
+
+
+export const transformOperation = transformer({
+ in: 'Приход',
+ out: 'Расход',
+});
+
+export const transformStatus = transformer({
+ waiting: 'Ожидание',
+ executed: 'Проведена',
+ cancelled: 'Отменена',
+});
+
diff --git a/src/services/waybills/index.ts b/src/services/waybills/index.ts
index f8a4be6..4e50f54 100644
--- a/src/services/waybills/index.ts
+++ b/src/services/waybills/index.ts
@@ -1,18 +1,15 @@
import Form from './WaybillForm';
import Panel from './WaybillPanel';
-import { waybillStatusNames, operationNames } from '../constants';
+import { transformOperation, transformStatus } from '../transforms';
+import { ServiceParams } from '../../containers/Service/ServiceContext';
-const service = {
+const service: ServiceParams = {
route: 'waybills',
name: 'Накладные',
nameSingular: 'Накладная',
tableFields: [
- {
- key: 'status',
- label: 'Статус',
- transform: (status: 'waiting' | 'executed' | 'cancelled') => waybillStatusNames[status],
- },
- { key: 'operation', label: 'Операция', transform: (op: 'in' | 'out') => operationNames[op] },
+ { key: 'status', label: 'Статус', transform: transformStatus },
+ { key: 'operation', label: 'Операция', transform: transformOperation },
{ key: 'total', label: 'Сумма' },
{ key: 'contractor.name', label: 'Контрагент' },
],