diff options
Diffstat (limited to 'src/containers')
-rw-r--r-- | src/containers/Service/ServiceList.tsx | 25 | ||||
-rw-r--r-- | src/containers/TransfersUpload.tsx | 3 |
2 files changed, 13 insertions, 15 deletions
diff --git a/src/containers/Service/ServiceList.tsx b/src/containers/Service/ServiceList.tsx index 7d30c14..a0536b5 100644 --- a/src/containers/Service/ServiceList.tsx +++ b/src/containers/Service/ServiceList.tsx @@ -1,29 +1,28 @@ import React, { useContext } from 'react'; -import { useHistory } from 'react-router-dom'; +import { useHistory, useLocation } from 'react-router-dom'; import Page from '../Page'; import ListTable from '../../components/ListTable'; import hooks from '../../hooks/useAPIClient'; import ServiceContext from './ServiceContext'; - const ServiceList: React.FC = () => { const service = useContext(ServiceContext); const history = useHistory(); - const { data } = hooks[service.route].useList(); + const location = useLocation(); + const { data } = hooks[service.route].useList(location.search); - const actions = [ - ...( - service.actions?.map(action => ({ - ...action, - route: `/${service.route}/${action.route}`, - })) || [] - ), - { name: 'Добавить', route: `/${service.route}/add` }, - ]; + const actions = service.actions || [{ + name: 'Добавить', + route: `/${service.route}/add`, + }]; const handleRowClick = (index: number) => { const item = data && data[index]; - history.push(`/${service.route}/${item?._id}`); + const route = service.rowLink + ? service.rowLink(item) + : `/${service.route}/${item?._id}`; + + history.push(route); }; return ( diff --git a/src/containers/TransfersUpload.tsx b/src/containers/TransfersUpload.tsx index 8239ab9..bddd0ad 100644 --- a/src/containers/TransfersUpload.tsx +++ b/src/containers/TransfersUpload.tsx @@ -15,8 +15,7 @@ const TransfersUpload: React.FC = () => { reader.readAsDataURL(file); reader.onload = (e: any) => { const uri = e.target.result; - post('/uploads', { uri }) - .then(() => history.push('/transfers')); + post('/uploads', { uri }).then(history.goBack); }; }; |