diff options
author | eug-vs <eug-vs@keemail.me> | 2021-03-21 13:10:32 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2021-03-21 13:11:55 +0300 |
commit | a7e97f33ae31dd2be1d7c04ecb8f2439ffebf921 (patch) | |
tree | ac325cc0f1b6eef9243bb0c1c2a247ad60fff5bf | |
parent | 84623c73b826d22d9b7b3103796bc754e7433b96 (diff) | |
download | commercel-ui-a7e97f33ae31dd2be1d7c04ecb8f2439ffebf921.tar.gz |
feat: add useQuery hook
-rw-r--r-- | src/containers/ContractorPanel.tsx | 4 | ||||
-rw-r--r-- | src/containers/Service/ServiceItem.tsx | 4 | ||||
-rw-r--r-- | src/hooks/useQuery.ts | 9 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/containers/ContractorPanel.tsx b/src/containers/ContractorPanel.tsx index 02e11ba..b68adec 100644 --- a/src/containers/ContractorPanel.tsx +++ b/src/containers/ContractorPanel.tsx @@ -14,13 +14,13 @@ const ContractorPanel: React.FC<PanelProps> = ({ item, mutate }) => { <Button route={`/waybills?contractorId=${item._id}`} variant="outlined"> Показать накладные </Button> - <Button route="/waybills/add"> + <Button route={`/waybills/add?contractorId=${item._id}`}> Новая накладная </Button> <Button route={`/transfers?contractorId=${item._id}`} variant="outlined"> Показать переводы </Button> - <Button route="/transfers/add"> + <Button route={`/transfers/add?contractorId=${item._id}`}> Новый перевод </Button> </div> diff --git a/src/containers/Service/ServiceItem.tsx b/src/containers/Service/ServiceItem.tsx index 22357c7..f833227 100644 --- a/src/containers/Service/ServiceItem.tsx +++ b/src/containers/Service/ServiceItem.tsx @@ -4,6 +4,7 @@ import { Formik } from 'formik'; import _ from 'lodash'; import Page, { Action } from '../Page'; import hooks from '../../hooks/useAPIClient'; +import useQuery from '../../hooks/useQuery'; import { post, patch, del } from '../../requests'; import ServiceContext from './ServiceContext'; @@ -14,6 +15,7 @@ interface Params { const ServiceItem: React.FC = () => { const service = useContext(ServiceContext); const history = useHistory(); + const query = useQuery(); const { id } = useParams<Params>(); const { data: item, mutate } = hooks[service.route].useItem(id); @@ -44,7 +46,7 @@ const ServiceItem: React.FC = () => { > {(!id || item) && ( <Formik - initialValues={_.defaults(item, service.default)} + initialValues={_.defaults(item, query, service.default)} onSubmit={onSubmit} children={service.Form} /> diff --git a/src/hooks/useQuery.ts b/src/hooks/useQuery.ts new file mode 100644 index 0000000..b2cb628 --- /dev/null +++ b/src/hooks/useQuery.ts @@ -0,0 +1,9 @@ +import { useLocation } from 'react-router-dom'; + +const useQuery = () => { + const location = useLocation(); + const searchParams = new URLSearchParams(location.search); + return Object.fromEntries(searchParams); +}; + +export default useQuery; |