-
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
537 additions
and
91 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
108 changes: 108 additions & 0 deletions
108
src/components/Company/CompanyInterviewExperiencesProvider.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,108 @@ | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import InterviewExperiences from '../CompanyAndJobTitle/InterviewExperiences'; | ||
import { paramsSelector, querySelector } from 'common/routing/selectors'; | ||
import usePermission from 'hooks/usePermission'; | ||
import { usePage } from 'hooks/routing/page'; | ||
import { tabType, pageType as PAGE_TYPE } from 'constants/companyJobTitle'; | ||
import { queryCompanyInterviewExperiences } from 'actions/company'; | ||
import { | ||
interviewExperiences as interviewExperiencesSelector, | ||
interviewExperiencesCount as interviewExperiencesCountSelector, | ||
status as statusSelector, | ||
companyInterviewExperiencesBoxSelectorByName, | ||
} from 'selectors/companyAndJobTitle'; | ||
import { usePageName, pageNameSelector } from './usePageName'; | ||
import { | ||
searchTextFromQuerySelector, | ||
useSearchTextFromQuery, | ||
} from 'components/CompanyAndJobTitle/useSearchbar'; | ||
import { pageFromQuerySelector } from 'selectors/routing/page'; | ||
|
||
const useInterviewExperiencesBox = pageName => { | ||
const selector = useCallback( | ||
state => { | ||
const company = companyInterviewExperiencesBoxSelectorByName(pageName)( | ||
state, | ||
); | ||
return { | ||
status: statusSelector(company), | ||
interviewExperiences: interviewExperiencesSelector(company), | ||
interviewExperiencesCount: interviewExperiencesCountSelector(company), | ||
}; | ||
}, | ||
[pageName], | ||
); | ||
return useSelector(selector); | ||
}; | ||
|
||
const PAGE_SIZE = 10; | ||
|
||
const CompanyInterviewExperiencesProvider = () => { | ||
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( | ||
queryCompanyInterviewExperiences({ | ||
companyName: pageName, | ||
jobTitle: jobTitle || undefined, | ||
start, | ||
limit, | ||
}), | ||
); | ||
}, [dispatch, pageName, jobTitle, start, limit]); | ||
|
||
const [, fetchPermission, canView] = usePermission(); | ||
useEffect(() => { | ||
fetchPermission(); | ||
}, [pageType, pageName, fetchPermission]); | ||
|
||
const { | ||
status, | ||
interviewExperiences, | ||
interviewExperiencesCount, | ||
} = useInterviewExperiencesBox(pageName); | ||
|
||
return ( | ||
<InterviewExperiences | ||
pageType={pageType} | ||
pageName={pageName} | ||
page={page} | ||
pageSize={PAGE_SIZE} | ||
totalCount={interviewExperiencesCount} | ||
canView={canView} | ||
tabType={tabType.INTERVIEW_EXPERIENCE} | ||
status={status} | ||
interviewExperiences={interviewExperiences} | ||
/> | ||
); | ||
}; | ||
|
||
CompanyInterviewExperiencesProvider.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( | ||
queryCompanyInterviewExperiences({ | ||
companyName: pageName, | ||
jobTitle, | ||
start, | ||
limit, | ||
}), | ||
); | ||
}; | ||
|
||
export default CompanyInterviewExperiencesProvider; |
Oops, something went wrong.