From 5d262f475cba0e8eea207872f415dde97da05d39 Mon Sep 17 00:00:00 2001 From: Makar Kotlov Date: Fri, 6 Sep 2019 00:31:03 +0300 Subject: [PATCH] Code refactored --- src/components/Search.jsx | 34 +++++++++++++++--------- src/components/TableComponent.jsx | 35 +++++++++++-------------- src/components/UserForm.jsx | 7 ++--- src/containers/EditUserFormContainer.js | 2 +- src/containers/TableContainer.js | 2 +- src/store/users/reducer.js | 2 +- 6 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/components/Search.jsx b/src/components/Search.jsx index 7a9dacf..e3a5e7f 100644 --- a/src/components/Search.jsx +++ b/src/components/Search.jsx @@ -3,24 +3,37 @@ import { Button, Input } from 'antd' const Search = ({ handleSearch, getData, dataIndex }) => { const [searchRef, setSearchRef] = useState({}) + const setSearch = () => c => { + setSearchRef(c) + } + const onSearch = phrase => { + if (phrase) { + handleSearch(dataIndex, phrase) + } + } + const handleSearchOnClick = () => { + const phrase = searchRef.input.state.value + if (phrase) { + handleSearch(dataIndex, phrase) + } + } + const resetSearch = () => { + searchRef.input.state.value = '' + getData() + } return (
{ - if (phrase) handleSearch(dataIndex, phrase) - }} - ref={c => setSearchRef(c)} + onSearch={onSearch} + ref={setSearch()} />
+ _deleteUser(record)} + onConfirm={handleDelete(record)} okText="Yes" cancelText="No" > @@ -114,7 +117,7 @@ const TableComponent = ({ const _handleSubmit = () => submitBtnRef.buttonNode.click() const _handleUpdate = () => updateBtnRef.buttonNode.click() const _handleChange = ({ current }) => { - setPageNumber(current) + _setPageNumber(current) fetchUsers(current) } @@ -132,13 +135,7 @@ const TableComponent = ({ onChange={_handleChange} /> - diff --git a/src/components/UserForm.jsx b/src/components/UserForm.jsx index ee96176..15d10c8 100644 --- a/src/components/UserForm.jsx +++ b/src/components/UserForm.jsx @@ -29,6 +29,7 @@ const UserForm = ({ } }) } + const getSubmitBtnRef = () => ref => _getSubmitBtnRef(ref) const { getFieldDecorator } = form const formItemLayout = { labelCol: { span: 6 }, @@ -70,11 +71,7 @@ const UserForm = ({ })()} -