summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-17 03:56:06 +0300
committereug-vs <eug-vs@keemail.me>2021-03-17 03:56:06 +0300
commit0ddde9acc170a42e0a2564c57e8ba9421bc90df4 (patch)
treeb61853897c31c31eaa61fcab691216344001ef64 /src
parent2305464999fdccdb809ce425cda8346ddc3df493 (diff)
downloadcommercel-ui-0ddde9acc170a42e0a2564c57e8ba9421bc90df4.tar.gz
feat: mutate item after changing status
Diffstat (limited to 'src')
-rw-r--r--src/containers/Service/ServiceContext.tsx1
-rw-r--r--src/containers/Service/ServiceItem.tsx2
-rw-r--r--src/containers/WaybillPanel.tsx13
3 files changed, 10 insertions, 6 deletions
diff --git a/src/containers/Service/ServiceContext.tsx b/src/containers/Service/ServiceContext.tsx
index b4200a0..f9e1605 100644
--- a/src/containers/Service/ServiceContext.tsx
+++ b/src/containers/Service/ServiceContext.tsx
@@ -3,6 +3,7 @@ import { FormikProps } from 'formik';
export interface PanelProps {
item: any;
+ mutate: (item: any) => void;
}
export interface ServiceParams {
diff --git a/src/containers/Service/ServiceItem.tsx b/src/containers/Service/ServiceItem.tsx
index bd449f9..585f609 100644
--- a/src/containers/Service/ServiceItem.tsx
+++ b/src/containers/Service/ServiceItem.tsx
@@ -51,7 +51,7 @@ const ServiceItem: React.FC = () => {
/>
</div>
)}
- {item && service.Panel && <service.Panel item={item} />}
+ {item && service.Panel && <service.Panel item={item} mutate={mutate} />}
</Page>
);
};
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';