summaryrefslogtreecommitdiff
path: root/src/containers/Contractors.tsx
blob: 5d589ea8bd81cd0a22dc9daf1b2388dbc7acc201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react';
import { useHistory } from 'react-router-dom';
import Page from './Page';
import ListTable from '../components/ListTable';
import { useContractors } from '../hooks/useAPIClient';

const fields = [
  { key: 'vatId', label: 'УНП' },
  { key: 'name', label: 'Название' },
  { key: 'debt', label: 'Долг' },
];

const actions = [
  { name: 'Добавить', route: 'contractors/add' },
];

const Contractors: React.FC = () => {
  const history = useHistory();
  const { data: contractors } = useContractors();

  const handleRowClick = (index: number) => {
    const contractor = contractors && contractors[index];
    history.push(`/contractors/edit/${contractor?._id}`);
  };

  return (
    <Page title="Контрагенты" actions={actions}>
      <ListTable items={contractors} fields={fields} handleRowClick={handleRowClick} />
    </Page>
  );
};

export default Contractors;