3719 |
stevensc |
1 |
import React, { useState } from 'react';
|
|
|
2 |
import { useSelector } from 'react-redux';
|
|
|
3 |
import Search from '@mui/icons-material/Search';
|
|
|
4 |
|
|
|
5 |
import { debounce } from '@utils';
|
|
|
6 |
import { useFetch, useSearchQuery } from '@hooks';
|
|
|
7 |
|
|
|
8 |
import Input from '@components/UI/inputs/Input';
|
|
|
9 |
import TitleSection from '@components/UI/TitleSection';
|
|
|
10 |
import MyCompaniesList from '@components/company/MyCompaniesList';
|
|
|
11 |
import AddCompanyModal from '@components/modals/AddCompanyModal';
|
|
|
12 |
|
|
|
13 |
const MyCompanies = () => {
|
|
|
14 |
const [showCompanyModal, setShowCompanyModal] = useState(false);
|
|
|
15 |
const labels = useSelector(({ intl }) => intl.labels);
|
|
|
16 |
|
|
|
17 |
const { getStringParams, setParam } = useSearchQuery();
|
|
|
18 |
const {
|
|
|
19 |
data: companies,
|
|
|
20 |
isLoading,
|
|
|
21 |
refetch
|
|
|
22 |
} = useFetch('/company/my-companies' + getStringParams());
|
|
|
23 |
|
|
|
24 |
const handleSearch = debounce((e) => setParam('search', e.target.value));
|
|
|
25 |
|
|
|
26 |
const toggleShowCompanyModal = () => setShowCompanyModal(!showCompanyModal);
|
|
|
27 |
|
|
|
28 |
return (
|
|
|
29 |
<>
|
|
|
30 |
<TitleSection
|
|
|
31 |
title={labels.my_companies}
|
|
|
32 |
onAdd={toggleShowCompanyModal}
|
|
|
33 |
addLabel={`${labels.add} ${labels.company?.toLowerCase()}`}
|
|
|
34 |
/>
|
|
|
35 |
<Input icon={<Search />} onChange={handleSearch} variant='search' />
|
|
|
36 |
<MyCompaniesList companies={companies} loading={isLoading} onComplete={refetch} />
|
|
|
37 |
<AddCompanyModal
|
|
|
38 |
show={showCompanyModal}
|
|
|
39 |
onHide={toggleShowCompanyModal}
|
|
|
40 |
fetchCompanies={refetch}
|
|
|
41 |
/>
|
|
|
42 |
</>
|
|
|
43 |
);
|
|
|
44 |
};
|
|
|
45 |
|
|
|
46 |
export default MyCompanies;
|