summaryrefslogtreecommitdiff
path: root/src/containers
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers')
-rw-r--r--src/containers/ContractorForm.tsx14
-rw-r--r--src/containers/ContractorPanel.tsx34
-rw-r--r--src/containers/Page.tsx2
-rw-r--r--src/containers/ProductForm.tsx15
-rw-r--r--src/containers/Service/ServiceContext.tsx9
-rw-r--r--src/containers/TransferForm.tsx44
-rw-r--r--src/containers/TransfersUpload.tsx41
-rw-r--r--src/containers/WaybillForm.tsx86
-rw-r--r--src/containers/WaybillPanel.tsx42
9 files changed, 6 insertions, 281 deletions
diff --git a/src/containers/ContractorForm.tsx b/src/containers/ContractorForm.tsx
deleted file mode 100644
index 56d38be..0000000
--- a/src/containers/ContractorForm.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import React from 'react';
-import { Form } from 'formik';
-import Input from '../components/Input';
-
-const ContractorForm: React.FC = () => {
- return (
- <Form id="form">
- <Input name="name" label="Название" />
- <Input name="vatId" label="УНП" />
- </Form>
- );
-};
-
-export default ContractorForm;
diff --git a/src/containers/ContractorPanel.tsx b/src/containers/ContractorPanel.tsx
deleted file mode 100644
index 6a209c3..0000000
--- a/src/containers/ContractorPanel.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import React from 'react';
-import { useHistory } from 'react-router-dom';
-import Button from '../components/Button';
-import { patch, baseURL } from '../requests';
-import { PanelProps } from './Service/ServiceContext';
-
-
-const ContractorPanel: React.FC<PanelProps> = ({ item, mutate }) => {
- const history = useHistory();
-
- return (
- <div className="lg:m-4 p-4 flex flex-col lg:pl-16 lg:border-l">
- <span className="text-lg mb-10">
- Долг контрагента: <span className="font-bold">{item.debt}</span>
- </span>
- <div className="grid lg:grid-cols-2">
- <Button route={`/waybills?contractorId=${item._id}`} variant="outlined">
- Показать накладные
- </Button>
- <Button route={`/waybills/add?contractorId=${item._id}`}>
- Новая накладная
- </Button>
- <Button route={`/transfers?contractorId=${item._id}`} variant="outlined">
- Показать переводы
- </Button>
- <Button route={`/transfers/add?contractorId=${item._id}`}>
- Новый перевод
- </Button>
- </div>
- </div>
- );
-};
-
-export default ContractorPanel;
diff --git a/src/containers/Page.tsx b/src/containers/Page.tsx
index c4d4efd..d3a087a 100644
--- a/src/containers/Page.tsx
+++ b/src/containers/Page.tsx
@@ -16,7 +16,7 @@ const style = 'mb-2 flex justify-between md:flex-row md:items-center';
const Page: React.FC<Props> = ({ title, actions, className, children }) => (
<Paper className="xl:m-5">
- <div className={`${style} ${actions?.length > 1 ? 'flex-col items-start' : 'flex-row items-center'}`}>
+ <div className={`${style} ${(actions?.length || 0) > 1 ? 'flex-col items-start' : 'flex-row items-center'}`}>
<span className="text-2xl font-bold">{title}</span>
<div>
{actions?.map(action => (<Button {...action} key={action.name} size="sm">{action.name}</Button>))}
diff --git a/src/containers/ProductForm.tsx b/src/containers/ProductForm.tsx
deleted file mode 100644
index 6957916..0000000
--- a/src/containers/ProductForm.tsx
+++ /dev/null
@@ -1,15 +0,0 @@
-import React from 'react';
-import { Form } from 'formik';
-import Input from '../components/Input';
-
-
-const ProductForm: React.FC = () => {
- return (
- <Form id="form">
- <Input name="name" label="Название" />
- <Input name="price" type="number" label="Цена" />
- </Form>
- );
-};
-
-export default ProductForm;
diff --git a/src/containers/Service/ServiceContext.tsx b/src/containers/Service/ServiceContext.tsx
index 68ff907..75ac0fb 100644
--- a/src/containers/Service/ServiceContext.tsx
+++ b/src/containers/Service/ServiceContext.tsx
@@ -1,21 +1,22 @@
import React from 'react';
import { FormikProps } from 'formik';
+import { Action } from '../Page';
export interface PanelProps {
item: any;
mutate: (item: any) => void;
}
-type Route = Record<string, React.FC>;
-
export interface ServiceParams {
route: string;
name: string;
nameSingular: string;
tableFields: any[];
default: Record<string, any>;
- routes?: Route[];
- Form?: React.FC<FormikProps>;
+ routes?: Record<string, React.FC>;
+ actions?: Action[];
+ rowLink?: (item: any) => string;
+ Form?: React.FC<FormikProps<any>>;
Panel?: React.FC<PanelProps>;
}
diff --git a/src/containers/TransferForm.tsx b/src/containers/TransferForm.tsx
deleted file mode 100644
index 801150e..0000000
--- a/src/containers/TransferForm.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import React from 'react';
-import { Form, FormikProps } from 'formik';
-import moment from 'moment';
-import Input from '../components/Input';
-import Select from '../components/Select';
-import hooks from '../hooks/useAPIClient';
-
-
-const mapper = (item: any) => ({ key: item._id, label: item.name });
-
-
-const TransferForm: React.FC<FormikProps> = ({ setFieldValue, values }) => {
- const { data: contractors } = hooks.contractors.useList();
-
- if (!values.date) setFieldValue('date', moment().format('YYYY-MM-DD'));
- if (!values.contractorId && contractors?.length) setFieldValue('contractorId', contractors[0]._id);
-
- return (
- <Form id="form">
- <div className="grid grid-cols-2">
- <Select
- name="contractorId"
- label="Контрагент"
- options={contractors?.map(mapper)}
- required
- />
- <Input name="date" type="date" label="Дата" required />
- </div>
- <div className="grid grid-cols-2">
- <Select
- name="operation"
- label="Операция"
- options={[
- { key: 'in', label: 'Приход' },
- { key: 'out', label: 'Расход' },
- ]}
- />
- <Input name="amount" type="number" label="Сумма" required />
- </div>
- </Form>
- );
-};
-
-export default TransferForm;
diff --git a/src/containers/TransfersUpload.tsx b/src/containers/TransfersUpload.tsx
deleted file mode 100644
index bddd0ad..0000000
--- a/src/containers/TransfersUpload.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import React from 'react';
-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 './Page';
-import { post } from '../requests';
-
-const TransfersUpload: React.FC = () => {
- const history = useHistory();
-
- const handleSubmitFile = () => {
- const reader = new FileReader();
- const file = document.getElementById('file').files[0];
- reader.readAsDataURL(file);
- reader.onload = (e: any) => {
- const uri = e.target.result;
- post('/uploads', { uri }).then(history.goBack);
- };
- };
-
- const actions: Action[] = [
- { name: 'Назад', variant: 'outlined', onClick: history.goBack },
- { name: 'Загрузить', type: 'submit', form: 'form' },
- ];
-
- return (
- <Page
- title="Загрузить выписку"
- actions={actions}
- >
- <Formik onSubmit={handleSubmitFile} initialValues={{}}>
- <Form id="form">
- <Input name="file" type="file" accept=".pdf" label="Прикрепите файл" id="file" />
- </Form>
- </Formik>
- </Page>
- );
-};
-
-export default TransfersUpload;
diff --git a/src/containers/WaybillForm.tsx b/src/containers/WaybillForm.tsx
deleted file mode 100644
index a924cc5..0000000
--- a/src/containers/WaybillForm.tsx
+++ /dev/null
@@ -1,86 +0,0 @@
-import React from 'react';
-import { Form, FormikProps } from 'formik';
-import _ from 'lodash';
-import moment from 'moment';
-import Input from '../components/Input';
-import Button from '../components/Button';
-import Select from '../components/Select';
-import Paper from '../components/Paper';
-import hooks from '../hooks/useAPIClient';
-
-
-const mapper = (item: any) => ({ key: item._id, label: item.name });
-
-
-const WaybillForm: React.FC<FormikProps> = ({ setFieldValue, values }) => {
- const { data: products } = hooks.products.useList();
- const { data: contractors } = hooks.contractors.useList();
-
- if (!values.date) setFieldValue('date', moment().format('YYYY-MM-DD'));
- if (!values.contractorId && contractors?.length) setFieldValue('contractorId', contractors[0]._id);
-
- const handleAddRecord = () => setFieldValue('records', [...values.records, {
- productId: _.map(products, '_id').reduce((acc, id) => {
- return acc || (!_.map(values.records, 'productId').includes(id) && id);
- }, false),
- price: '',
- quantity: 1,
- }]);
-
- const handleRemoveRecord = (index: number) => () => {
- const records = [...values.records];
- records.splice(index, 1);
- setFieldValue('records', records);
- };
-
- return (
- <Form id="form">
- <Select
- name="contractorId"
- label="Контрагент"
- options={contractors?.map(mapper)}
- />
- <div className="grid grid-cols-2">
- <Select
- name="operation"
- label="Операция"
- options={[
- { key: 'in', label: 'Приход' },
- { key: 'out', label: 'Расход' },
- ]}
- />
- <Input name="date" type="date" label="Дата" />
- </div>
- {values.records.map((record, index) => (
- <Paper variant="outlined" className="my-4 md:mx-4" key={`${index}-${record.productId}`}>
- <Select
- name={`records.${index}.productId`}
- label="Товар"
- options={products?.map(mapper)}
- required
- />
- <div className="grid grid-cols-3">
- <Input
- name={`records.${index}.price`}
- type="number"
- label="Цена"
- required
- />
- <Input
- name={`records.${index}.quantity`}
- type="number"
- label="Количество"
- required
- />
- <div className="flex justify-end items-end">
- <Button onClick={handleRemoveRecord(index)} size="sm" variant="outlined">Удалить</Button>
- </div>
- </div>
- </Paper>
- ))}
- <Button onClick={handleAddRecord} variant="outlined" size="sm">Добавить товар</Button>
- </Form>
- );
-};
-
-export default WaybillForm;
diff --git a/src/containers/WaybillPanel.tsx b/src/containers/WaybillPanel.tsx
deleted file mode 100644
index b90447e..0000000
--- a/src/containers/WaybillPanel.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import React from 'react';
-import { useHistory } from 'react-router-dom';
-import Button from '../components/Button';
-import { patch, baseURL } from '../requests';
-import { PanelProps } from './Service/ServiceContext';
-
-
-const WaybillPanel: React.FC<PanelProps> = ({ item, mutate }) => {
- const history = useHistory();
-
- const handleChangeStatus = status => patch(`/waybills/${item._id}`, { status })
- .then(() => {
- history.push('/waybills');
- mutate({ ...item, status });
- });
-
- const handlePrint = () => window.open(`${baseURL}/spreadsheets/${item._id}`, '_blank');
-
- const handleExecute = () => handleChangeStatus('executed');
- const handleCancel = () => handleChangeStatus('cancelled');
-
- const executed = item.status === 'executed';
-
- return (
- <div className="lg:m-4 p-4 flex flex-col lg:pl-16 lg:border-l">
- <div className="grid lg:grid-cols-2">
- <Button route={`/contractors/${item.contractorId}`} variant="outlined">
- Перейти к контрагенту
- </Button>
- <Button onClick={handlePrint} variant="outlined">
- Печать
- </Button>
- <span className="text-lg text-center mt-4">Итоговая сумма: ${item.total}</span>
- <Button onClick={executed ? handleCancel : handleExecute} size="lg">
- {executed ? 'Откатить' : 'Провести'}
- </Button>
- </div>
- </div>
- );
-};
-
-export default WaybillPanel;