From 0ddde9acc170a42e0a2564c57e8ba9421bc90df4 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Wed, 17 Mar 2021 03:56:06 +0300
Subject: feat: mutate item after changing status

---
 src/containers/WaybillPanel.tsx | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src/containers/WaybillPanel.tsx')

diff --git a/src/containers/WaybillPanel.tsx b/src/containers/WaybillPanel.tsx
index 397b16b..a978ad3 100644
--- a/src/containers/WaybillPanel.tsx
+++ b/src/containers/WaybillPanel.tsx
@@ -7,14 +7,17 @@ import { patch } from '../requests';
 import { PanelProps } from './Service/ServiceContext';
 
 
-const WaybillPanel: React.FC<PanelProps> = ({ item }) => {
+const WaybillPanel: React.FC<PanelProps> = ({ item, mutate }) => {
   const history = useHistory();
 
-  const handleExecute = () => patch(`/waybills/${item._id}`, { status: 'executed' })
-    .then(() => history.push('/waybills'));
+  const handleChangeStatus = status => patch(`/waybills/${item._id}`, { status })
+    .then(() => {
+      history.push('/waybills');
+      mutate({ ...item, status });
+    });
 
-  const handleCancel = () => patch(`/waybills/${item._id}`, { status: 'cancelled' })
-    .then(() => history.push('/waybills'));
+  const handleExecute = () => handleChangeStatus('executed');
+  const handleCancel = () => handleChangeStatus('cancelled');
 
   const executed = item.status === 'executed';
 
-- 
cgit v1.2.3

