summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/ListTable.tsx12
-rw-r--r--src/services.js16
2 files changed, 25 insertions, 3 deletions
diff --git a/src/components/ListTable.tsx b/src/components/ListTable.tsx
index c333698..7c316ed 100644
--- a/src/components/ListTable.tsx
+++ b/src/components/ListTable.tsx
@@ -4,6 +4,7 @@ import _ from 'lodash';
interface Field {
key: string;
label: string;
+ transform?: (text: string) => string;
}
interface Props {
@@ -12,6 +13,11 @@ interface Props {
handleRowClick?: (index: number) => void;
}
+const getItemField = (item: any, field: Field) => {
+ const value = _.get(item, field.key);
+ return field.transform ? field.transform(value) : value;
+};
+
const ListTable: React.FC<Props> = ({ items = [], fields, handleRowClick = () => {} }) => {
if (!items.length) return <div className="text-center p-6">No data</div>;
@@ -29,7 +35,11 @@ const ListTable: React.FC<Props> = ({ items = [], fields, handleRowClick = () =>
className={`border-b hover:bg-gray-100 cursor-pointer ${index % 2 && 'bg-gray-50'}`}
onClick={() => handleRowClick(index)}
>
- {fields.map(field => <td key={`${item._id} ${field.label}`} className="p-3">{_.get(item, field.key)}</td>)}
+ {fields.map(field => (
+ <td key={`${item._id} ${field.label}`} className="p-3">
+ {getItemField(item, field)}
+ </td>
+ ))}
</tr>
))}
</tbody>
diff --git a/src/services.js b/src/services.js
index b9c2ecf..bebf07f 100644
--- a/src/services.js
+++ b/src/services.js
@@ -1,5 +1,17 @@
import { ServiceParams } from './containers/Service/ServiceContext';
+
+const waybillStatusNames = {
+ waiting: 'Ожидание',
+ executed: 'Проведена',
+ cancelled: 'Отменена',
+};
+
+const operationNames = {
+ in: 'Приход',
+ out: 'Расход',
+};
+
const services: ServiceParams[] = [
{
route: 'products',
@@ -36,10 +48,10 @@ const services: ServiceParams[] = [
name: 'Накладные',
nameSingular: 'Накладная',
tableFields: [
- { key: 'operation', label: 'Операция' },
+ { key: 'operation', label: 'Операция', transform: op => operationNames[op] },
{ key: 'product.name', label: 'Товар' },
{ key: 'contractor.name', label: 'Поставщик' },
- { key: 'status', label: 'Статус' },
+ { key: 'status', label: 'Статус', transform: status => waybillStatusNames[status] },
{ key: 'quantity', label: 'Количество' },
],
default: {