summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-16 01:38:54 +0300
committereug-vs <eug-vs@keemail.me>2021-03-16 01:38:54 +0300
commit49a44a5762a2863566267689002834ee88d06abb (patch)
treeb471b6ace58355f8d08e024e7546bf57057fe8fb
parent6a200e57d4a0be0532587b9648ff8d58f97e91e8 (diff)
downloadcommercel-ui-49a44a5762a2863566267689002834ee88d06abb.tar.gz
feat: add WaybillPanel
-rw-r--r--src/containers/Service/Service.tsx6
-rw-r--r--src/containers/Service/ServiceContext.tsx5
-rw-r--r--src/containers/Service/ServiceItem.tsx (renamed from src/containers/Service/ServiceForm.tsx)25
-rw-r--r--src/containers/Service/ServiceList.tsx2
-rw-r--r--src/containers/WaybillForm.tsx40
-rw-r--r--src/containers/WaybillPanel.tsx44
-rw-r--r--src/index.tsx2
7 files changed, 90 insertions, 34 deletions
diff --git a/src/containers/Service/Service.tsx b/src/containers/Service/Service.tsx
index 3a7cbee..162fce0 100644
--- a/src/containers/Service/Service.tsx
+++ b/src/containers/Service/Service.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import { Route, Switch, useRouteMatch } from 'react-router-dom';
import ServiceList from './ServiceList';
-import ServiceForm from './ServiceForm';
+import ServiceItem from './ServiceItem';
const Service: React.FC = () => {
@@ -10,8 +10,8 @@ const Service: React.FC = () => {
return (
<Switch>
<Route exact path={path} component={ServiceList} />
- <Route path={`${path}/add`} component={ServiceForm} />
- <Route path={`${path}/edit/:id`} component={ServiceForm} />
+ <Route path={`${path}/add`} component={ServiceItem} />
+ <Route path={`${path}/:id`} component={ServiceItem} />
</Switch>
);
};
diff --git a/src/containers/Service/ServiceContext.tsx b/src/containers/Service/ServiceContext.tsx
index c035417..b4200a0 100644
--- a/src/containers/Service/ServiceContext.tsx
+++ b/src/containers/Service/ServiceContext.tsx
@@ -1,6 +1,10 @@
import React from 'react';
import { FormikProps } from 'formik';
+export interface PanelProps {
+ item: any;
+}
+
export interface ServiceParams {
route: string;
name: string;
@@ -8,6 +12,7 @@ export interface ServiceParams {
tableFields: any[];
default: Record<string, any>;
Form?: React.FC<FormikProps>;
+ Panel?: React.FC<PanelProps>;
}
const ServiceContext = React.createContext<ServiceParams>({
diff --git a/src/containers/Service/ServiceForm.tsx b/src/containers/Service/ServiceItem.tsx
index 0c02cbd..bd449f9 100644
--- a/src/containers/Service/ServiceForm.tsx
+++ b/src/containers/Service/ServiceItem.tsx
@@ -11,7 +11,7 @@ interface Params {
id: string;
}
-const ServiceForm: React.FC = () => {
+const ServiceItem: React.FC = () => {
const service = useContext(ServiceContext);
const history = useHistory();
const { id } = useParams<Params>();
@@ -31,22 +31,29 @@ const ServiceForm: React.FC = () => {
};
const actions: Action[] = [
- { name: 'Назад', variant: 'outlined', route: '..' },
+ { name: 'Назад', variant: 'outlined', onClick: history.goBack },
{ name: 'Удалить', variant: 'outlined', onClick: handleDelete },
{ name: 'Сохранить', type: 'submit', form: 'form' },
];
return (
- <Page title={id ? item?.name : `Новый ${service.nameSingular}`} actions={actions}>
+ <Page
+ title={id ? item?.name : `Новый ${service.nameSingular}`}
+ actions={actions}
+ className="flex"
+ >
{(!id || item) && (
- <Formik
- initialValues={_.defaults(item, service.default)}
- onSubmit={onSubmit}
- children={service.Form}
- />
+ <div className="w-1/3">
+ <Formik
+ initialValues={_.defaults(item, service.default)}
+ onSubmit={onSubmit}
+ children={service.Form}
+ />
+ </div>
)}
+ {item && service.Panel && <service.Panel item={item} />}
</Page>
);
};
-export default ServiceForm;
+export default ServiceItem;
diff --git a/src/containers/Service/ServiceList.tsx b/src/containers/Service/ServiceList.tsx
index 6af2d1b..b7054eb 100644
--- a/src/containers/Service/ServiceList.tsx
+++ b/src/containers/Service/ServiceList.tsx
@@ -15,7 +15,7 @@ const ServiceList: React.FC = () => {
const handleRowClick = (index: number) => {
const item = data && data[index];
- history.push(`/${service.route}/edit/${item?._id}`);
+ history.push(`/${service.route}/${item?._id}`);
};
return (
diff --git a/src/containers/WaybillForm.tsx b/src/containers/WaybillForm.tsx
index 1e3276f..fedc9c4 100644
--- a/src/containers/WaybillForm.tsx
+++ b/src/containers/WaybillForm.tsx
@@ -10,27 +10,25 @@ const WaybillForm: React.FC<FormikProps> = ({ setFieldValue, values }) => {
return (
<Form id="form">
- <div className="max-w-lg">
- <Select
- name="contractorId"
- label="Контрагент"
- options={contractorOptions}
- />
- <Select
- name="productId"
- label="Товар"
- options={productOptions}
- />
- <Select
- name="operation"
- label="Операция"
- options={[
- { key: 'in', label: 'Приход' },
- { key: 'out', label: 'Расход' },
- ]}
- />
- <Input name="quantity" type="number" label="Количество" />
- </div>
+ <Select
+ name="contractorId"
+ label="Контрагент"
+ options={contractorOptions}
+ />
+ <Select
+ name="productId"
+ label="Товар"
+ options={productOptions}
+ />
+ <Select
+ name="operation"
+ label="Операция"
+ options={[
+ { key: 'in', label: 'Приход' },
+ { key: 'out', label: 'Расход' },
+ ]}
+ />
+ <Input name="quantity" type="number" label="Количество" />
</Form>
);
};
diff --git a/src/containers/WaybillPanel.tsx b/src/containers/WaybillPanel.tsx
new file mode 100644
index 0000000..ca40169
--- /dev/null
+++ b/src/containers/WaybillPanel.tsx
@@ -0,0 +1,44 @@
+import React from 'react';
+import { useHistory } from 'react-router-dom';
+import Input from '../components/Input';
+import Button from '../components/Button';
+import Paper from '../components/Paper';
+import { post } from '../requests';
+import { PanelProps } from './Service/ServiceContext';
+
+
+const WaybillPanel: React.FC<PanelProps> = ({ item }) => {
+ const history = useHistory();
+
+ const handleExecute = () => post(`/waybills/${item._id}/execute`)
+ .then(() => history.push('/waybills'));
+
+ const handleCancel = () => post(`/waybills/${item._id}/cancel`)
+ .then(() => history.push('/waybills'));
+
+ const executed = item.status === 'executed';
+ const total = item.product.price * item.quantity;
+
+ return (
+ <div className="m-4 p-4 pl-16 border-l flex flex-col">
+ <p className="text-lg">
+ Итоговая сумма: ${total}
+ </p>
+ <div>
+ <Button route={`/contractors/${item.contractorId}`} variant="outlined">
+ Перейти к контрагенту
+ </Button>
+ <Button route={`/products/${item.productId}`} variant="outlined">
+ Перейти к продукту
+ </Button>
+ </div>
+ {
+ executed
+ ? <Button onClick={handleCancel}>Откатить</Button>
+ : <Button onClick={handleExecute}>Провести</Button>
+ }
+ </div>
+ );
+};
+
+export default WaybillPanel;
diff --git a/src/index.tsx b/src/index.tsx
index e637e68..68f3222 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -12,12 +12,14 @@ import Service from './containers/Service/Service';
import { ServiceProvider } from './containers/Service/ServiceContext';
import services from './services';
import WaybillForm from './containers/WaybillForm';
+import WaybillPanel from './containers/WaybillPanel';
import ContractorForm from './containers/ContractorForm';
import ProductForm from './containers/ProductForm';
services[0].Form = ProductForm;
services[1].Form = ContractorForm;
services[2].Form = WaybillForm;
+services[2].Panel = WaybillPanel;
const navigation = [