summaryrefslogtreecommitdiff
path: root/src/services/waybills/WaybillPanel.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-25 23:09:49 +0300
committereug-vs <eug-vs@keemail.me>2021-03-25 23:09:49 +0300
commit062f10a25d43b875d187cf582b2ecf96d075ec26 (patch)
treec6b43379325ba22a051827e6a461a8f8fed98402 /src/services/waybills/WaybillPanel.tsx
parent77ac1549e2ab5ac68a1a7464ada9be7e2a2aad92 (diff)
downloadcommercel-ui-062f10a25d43b875d187cf582b2ecf96d075ec26.tar.gz
refactor: move services to separate folder
Diffstat (limited to 'src/services/waybills/WaybillPanel.tsx')
-rw-r--r--src/services/waybills/WaybillPanel.tsx42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/services/waybills/WaybillPanel.tsx b/src/services/waybills/WaybillPanel.tsx
new file mode 100644
index 0000000..101a871
--- /dev/null
+++ b/src/services/waybills/WaybillPanel.tsx
@@ -0,0 +1,42 @@
+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 WaybillPanel: React.FC<PanelProps> = ({ item, mutate }) => {
+ const history = useHistory();
+
+ const handleChangeStatus = (status: any) => 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;