-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
514 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/components/Company/CompanyWorkExperiencesProvider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import WorkExperiences from '../CompanyAndJobTitle/WorkExperiences'; | ||
import usePermission from 'hooks/usePermission'; | ||
import { usePage } from 'hooks/routing/page'; | ||
import { tabType, pageType as PAGE_TYPE } from 'constants/companyJobTitle'; | ||
import { | ||
queryCompanyTimeAndSalary, | ||
queryCompanyWorkExperiences, | ||
} from 'actions/company'; | ||
import { | ||
workExperiences as workExperiencesSelector, | ||
workExperiencesCount as workExperiencesCountSelector, | ||
status as statusSelector, | ||
companyWorkExperiencesBoxSelectorByName as workExperiencesBoxSelectorByName, | ||
} from 'selectors/companyAndJobTitle'; | ||
import { paramsSelector, querySelector } from 'common/routing/selectors'; | ||
import { usePageName, pageNameSelector } from './usePageName'; | ||
import { pageFromQuerySelector } from 'selectors/routing/page'; | ||
import { | ||
searchTextFromQuerySelector, | ||
useSearchTextFromQuery, | ||
} from 'components/CompanyAndJobTitle/useSearchbar'; | ||
|
||
const useWorkExperiencesBox = pageName => { | ||
const selector = useCallback( | ||
state => { | ||
const company = workExperiencesBoxSelectorByName(pageName)(state); | ||
return { | ||
status: statusSelector(company), | ||
workExperiences: workExperiencesSelector(company), | ||
workExperiencesCount: workExperiencesCountSelector(company), | ||
}; | ||
}, | ||
[pageName], | ||
); | ||
|
||
return useSelector(selector); | ||
}; | ||
|
||
const PAGE_SIZE = 10; | ||
|
||
const CompanyWorkExperiencesProvider = () => { | ||
const dispatch = useDispatch(); | ||
const pageType = PAGE_TYPE.COMPANY; | ||
const pageName = usePageName(); | ||
const [jobTitle] = useSearchTextFromQuery(); | ||
const page = usePage(); | ||
const start = (page - 1) * PAGE_SIZE; | ||
const limit = PAGE_SIZE; | ||
|
||
useEffect(() => { | ||
dispatch( | ||
queryCompanyWorkExperiences({ | ||
companyName: pageName, | ||
jobTitle: jobTitle || undefined, | ||
start, | ||
limit, | ||
}), | ||
); | ||
}, [dispatch, pageName, jobTitle, start, limit]); | ||
|
||
const [, fetchPermission, canView] = usePermission(); | ||
useEffect(() => { | ||
fetchPermission(); | ||
}, [pageType, pageName, fetchPermission]); | ||
|
||
const { | ||
status, | ||
workExperiences, | ||
workExperiencesCount, | ||
} = useWorkExperiencesBox(pageName); | ||
|
||
return ( | ||
<WorkExperiences | ||
pageType={pageType} | ||
pageName={pageName} | ||
page={page} | ||
pageSize={PAGE_SIZE} | ||
totalCount={workExperiencesCount} | ||
canView={canView} | ||
tabType={tabType.WORK_EXPERIENCE} | ||
status={status} | ||
workExperiences={workExperiences} | ||
/> | ||
); | ||
}; | ||
|
||
CompanyWorkExperiencesProvider.fetchData = ({ | ||
store: { dispatch }, | ||
...props | ||
}) => { | ||
const params = paramsSelector(props); | ||
const pageName = pageNameSelector(params); | ||
const query = querySelector(props); | ||
const page = pageFromQuerySelector(query); | ||
const jobTitle = searchTextFromQuerySelector(query) || undefined; | ||
const start = (page - 1) * PAGE_SIZE; | ||
const limit = PAGE_SIZE; | ||
return dispatch( | ||
queryCompanyTimeAndSalary({ | ||
companyName: pageName, | ||
jobTitle, | ||
start, | ||
limit, | ||
}), | ||
); | ||
}; | ||
|
||
export default CompanyWorkExperiencesProvider; |
Oops, something went wrong.