diff --git a/src/actions/experiences.js b/src/actions/experiences.js index dfef09a69..d7140ef76 100644 --- a/src/actions/experiences.js +++ b/src/actions/experiences.js @@ -7,6 +7,7 @@ import { postWorkExperience as postWorkExperienceApi, postWorkExperienceWithRating as postWorkExperienceWithRatingApi, } from 'apis/workExperiencesApi'; +import { queryMyPublishIds } from './me'; export const SET_COUNT = '@@EXPERIENCES/SET_COUNT'; @@ -34,35 +35,53 @@ export const queryExperienceCountIfUnfetched = () => async ( } }; -export const createInterviewExperience = ({ body }) => (dispatch, getState) => { +export const createInterviewExperience = ({ body }) => async ( + dispatch, + getState, +) => { const state = getState(); const token = tokenSelector(state); - return postInterviewExperienceApi({ + const result = await postInterviewExperienceApi({ body, token, }); + + await dispatch(queryMyPublishIds()); + + return result; }; -export const createWorkExperience = ({ body }) => (dispatch, getState) => { +export const createWorkExperience = ({ body }) => async ( + dispatch, + getState, +) => { const state = getState(); const token = tokenSelector(state); - return postWorkExperienceApi({ + const result = await postWorkExperienceApi({ body, token, }); + + await dispatch(queryMyPublishIds()); + + return result; }; -export const createWorkExperienceWithRating = ({ body }) => ( +export const createWorkExperienceWithRating = ({ body }) => async ( dispatch, getState, ) => { const state = getState(); const token = tokenSelector(state); - return postWorkExperienceWithRatingApi({ + const result = await postWorkExperienceWithRatingApi({ body, token, }); + + await dispatch(queryMyPublishIds()); + + return result; }; diff --git a/src/actions/me.js b/src/actions/me.js new file mode 100644 index 000000000..1457cd80b --- /dev/null +++ b/src/actions/me.js @@ -0,0 +1,43 @@ +import { queryMyPublishIdsApi } from 'apis/me'; +import { tokenSelector } from 'selectors/authSelector'; +import { myPublishIdsSelector } from 'selectors/me'; +import { + isUnfetched, + isError, + getError, + getFetched, + toFetching, +} from 'utils/fetchBox'; + +export const SET_MY_PUBLISH_IDS = '@@me/SET_MY_PUBLISH_IDS'; + +const setMyPublishIds = box => ({ + type: SET_MY_PUBLISH_IDS, + box, +}); + +export const queryMyPublishIdsIfNeeded = () => async (dispatch, getState) => { + const myPublishIdsBox = myPublishIdsSelector(getState()); + + if (isUnfetched(myPublishIdsBox) || isError(myPublishIdsBox)) { + dispatch(queryMyPublishIds()); + } +}; + +export const queryMyPublishIds = () => async (dispatch, getState) => { + const token = tokenSelector(getState()); + + if (!token) { + // If user has not logged in, it's assumed to have no publishes. + dispatch(setMyPublishIds(getFetched([]))); + return; + } + + dispatch(setMyPublishIds(toFetching())); + try { + const myPublishIds = await queryMyPublishIdsApi({ token }); + dispatch(setMyPublishIds(getFetched(myPublishIds))); + } catch (error) { + dispatch(setMyPublishIds(getError(error))); + } +}; diff --git a/src/actions/timeAndSalary.js b/src/actions/timeAndSalary.js index 849bb18ab..3eb183889 100644 --- a/src/actions/timeAndSalary.js +++ b/src/actions/timeAndSalary.js @@ -3,6 +3,7 @@ import { tokenSelector } from 'selectors/authSelector'; import { salaryWorkTimeCountBoxSelector } from 'selectors/countSelector'; import { postWorkings as postWorkingsApi } from 'apis/timeAndSalaryApi'; import { querySalaryWorkTimeCountApi } from 'apis/salaryWorkTimeApi'; +import { queryMyPublishIds } from './me'; export const SET_COUNT = '@@SALARY_WORK_TIME/SET_COUNT'; @@ -30,12 +31,19 @@ export const querySalaryWorkTimeCountIfUnfetched = () => async ( } }; -export const createSalaryWorkTime = ({ body }) => (dispatch, getState) => { +export const createSalaryWorkTime = ({ body }) => async ( + dispatch, + getState, +) => { const state = getState(); const token = tokenSelector(state); - return postWorkingsApi({ + const result = await postWorkingsApi({ body, token, }); + + await dispatch(queryMyPublishIds()); + + return result; }; diff --git a/src/apis/me.js b/src/apis/me.js index 0af13a029..49f466fcc 100644 --- a/src/apis/me.js +++ b/src/apis/me.js @@ -2,6 +2,7 @@ import graphqlClient from 'utils/graphqlClient'; import { queryMeGql, + queryMyPublishIdsGql, queryMyPublishesGql, queryMyPermissionGql, } from 'graphql/me'; @@ -18,5 +19,11 @@ export const queryHasSearchPermissionApi = ({ token }) => export const queryMeApi = ({ token }) => graphqlClient({ query: queryMeGql, token }).then(data => data.me); +export const queryMyPublishIdsApi = ({ token }) => + graphqlClient({ query: queryMyPublishIdsGql, token }).then(data => [ + ...data.me.experiences.map(({ id }) => id), + ...data.me.salary_work_times.map(({ id }) => id), + ]); + export const queryMyPublishesApi = ({ token }) => graphqlClient({ query: queryMyPublishesGql, token }); diff --git a/src/components/CompanyAndJobTitle/InterviewExperiences/InterviewExperiences.js b/src/components/CompanyAndJobTitle/InterviewExperiences/InterviewExperiences.js index 5fe7c5a1a..93fce2c0e 100644 --- a/src/components/CompanyAndJobTitle/InterviewExperiences/InterviewExperiences.js +++ b/src/components/CompanyAndJobTitle/InterviewExperiences/InterviewExperiences.js @@ -10,6 +10,7 @@ import EmptyView from '../EmptyView'; import ExperienceEntry from './ExperienceEntry'; import { useQuery } from 'hooks/routing'; +import usePermission from 'hooks/usePermission'; const InterviewExperiences = ({ pageType, @@ -19,9 +20,9 @@ const InterviewExperiences = ({ page, pageSize, totalCount, - canView, }) => { const queryParams = useQuery(); + const [, , canViewPublishId] = usePermission(); if (data.length === 0) { return ( @@ -39,7 +40,7 @@ const InterviewExperiences = ({ key={d.id} pageType={pageType} data={d} - canView={canView} + canView={canViewPublishId(d.id)} /> ))} ( ); @@ -53,7 +51,6 @@ const InterviewExperiences = ({ ); InterviewExperiences.propTypes = { - canView: PropTypes.bool.isRequired, interviewExperiences: PropTypes.arrayOf(PropTypes.object), page: PropTypes.number.isRequired, pageName: PropTypes.string.isRequired, diff --git a/src/components/CompanyAndJobTitle/Overview/Overview.js b/src/components/CompanyAndJobTitle/Overview/Overview.js index cdf9bbbd2..fefe33a38 100644 --- a/src/components/CompanyAndJobTitle/Overview/Overview.js +++ b/src/components/CompanyAndJobTitle/Overview/Overview.js @@ -9,6 +9,7 @@ import WorkExperienceEntry from '../WorkExperiences/ExperienceEntry'; import InterviewExperienceEntry from '../InterviewExperiences/ExperienceEntry'; import { tabType as TAB_TYPE, generateTabURL } from 'constants/companyJobTitle'; import SummaryBlock from './SummaryBlock'; +import usePermission from 'hooks/usePermission'; const Overview = ({ pageType, @@ -23,8 +24,9 @@ const Overview = ({ jobAverageSalaries, averageWeekWorkTime, overtimeFrequencyCount, - canView, }) => { + const [, , canViewPublishId] = usePermission(); + return (
- + ))} @@ -92,7 +90,7 @@ const Overview = ({ key={d.id} pageType={pageType} data={d} - canView={canView} + canView={canViewPublishId(d.id)} /> ))} @@ -102,7 +100,6 @@ const Overview = ({ Overview.propTypes = { averageWeekWorkTime: PropTypes.number.isRequired, - canView: PropTypes.bool.isRequired, interviewExperiences: PropTypes.arrayOf(PropTypes.object), interviewExperiencesCount: PropTypes.number.isRequired, jobAverageSalaries: PropTypes.array, diff --git a/src/components/CompanyAndJobTitle/Overview/index.js b/src/components/CompanyAndJobTitle/Overview/index.js index 81e1da0f4..c2f65c981 100644 --- a/src/components/CompanyAndJobTitle/Overview/index.js +++ b/src/components/CompanyAndJobTitle/Overview/index.js @@ -5,14 +5,7 @@ import { BoxStatusRenderer } from '../StatusRenderer'; import OverviewSection from './Overview'; import Helmet from './Helmet'; -const Overview = ({ - pageType, - pageName, - tabType, - overviewBox, - page, - canView, -}) => ( +const Overview = ({ pageType, pageName, tabType, overviewBox, page }) => ( ); @@ -58,7 +50,6 @@ const Overview = ({ ); Overview.propTypes = { - canView: PropTypes.bool.isRequired, overviewBox: PropTypes.shape({ data: PropTypes.shape({ averageWeekWorkTime: PropTypes.number.isRequired, diff --git a/src/components/CompanyAndJobTitle/TimeAndSalary/TimeAndSalary.js b/src/components/CompanyAndJobTitle/TimeAndSalary/TimeAndSalary.js index 07431b6ef..a9050f73d 100644 --- a/src/components/CompanyAndJobTitle/TimeAndSalary/TimeAndSalary.js +++ b/src/components/CompanyAndJobTitle/TimeAndSalary/TimeAndSalary.js @@ -20,7 +20,7 @@ const TimeAndSalary = ({ pageSize, totalCount, }) => { - const [, fetchPermission, canView] = usePermission(); + const [, fetchPermission] = usePermission(); useEffect(() => { fetchPermission(); }, [fetchPermission]); @@ -31,12 +31,7 @@ const TimeAndSalary = ({
{(salaryWorkTimes.length > 0 && ( - + { +const WorkingHourBlock = ({ data, pageType }) => { return (
- +
); @@ -21,7 +17,6 @@ const WorkingHourBlock = ({ data, hideContent, pageType }) => { WorkingHourBlock.propTypes = { data: PropTypes.array, - hideContent: PropTypes.bool.isRequired, pageType: PropTypes.string, }; diff --git a/src/components/CompanyAndJobTitle/TimeAndSalary/WorkingHourTable.js b/src/components/CompanyAndJobTitle/TimeAndSalary/WorkingHourTable.js index 3e8eb6a4b..d44ac6615 100644 --- a/src/components/CompanyAndJobTitle/TimeAndSalary/WorkingHourTable.js +++ b/src/components/CompanyAndJobTitle/TimeAndSalary/WorkingHourTable.js @@ -19,6 +19,7 @@ import { formatDate, } from '../../TimeAndSalary/common/formatter'; import injectHideContentBlock from '../../TimeAndSalary/common/injectHideContentBlock'; +import usePermission from 'hooks/usePermission'; const SalaryHeader = ({ isInfoSalaryModalOpen, toggleInfoSalaryModal }) => ( @@ -127,7 +128,7 @@ const columnProps = [ }, ]; -const WorkingHourTable = ({ data, hideContent, pageType }) => { +const WorkingHourTable = ({ data, pageType }) => { const [isInfoSalaryModalOpen, setInfoSalaryModalOpen] = useState(false); const [isInfoTimeModalOpen, setInfoTiimeModalOpen] = useState(false); @@ -147,7 +148,7 @@ const WorkingHourTable = ({ data, hideContent, pageType }) => { [pageType], ); - const hideRange = useMemo( + const [fromCol, toCol] = useMemo( () => [ R.findIndex(R.propEq('permissionRequiredStart', true))( filteredColumnProps, @@ -157,14 +158,20 @@ const WorkingHourTable = ({ data, hideContent, pageType }) => { [filteredColumnProps], ); + const [, , canViewPublishId] = usePermission(); + const postProcessRows = useCallback( - rows => { - if (hideContent) { - injectHideContentBlock(hideRange)(rows); - } + (rows, data) => { + injectHideContentBlock({ + rows, + data, + fromCol, + toCol, + canViewPublishId, + }); return rows; }, - [hideContent, hideRange], + [canViewPublishId, fromCol, toCol], ); return ( @@ -193,7 +200,6 @@ const WorkingHourTable = ({ data, hideContent, pageType }) => { WorkingHourTable.propTypes = { data: PropTypes.array.isRequired, - hideContent: PropTypes.bool.isRequired, pageType: PropTypes.oneOf([ pageTypeMapping.COMPANY, pageTypeMapping.JOB_TITLE, diff --git a/src/components/CompanyAndJobTitle/WorkExperiences/WorkExperiences.js b/src/components/CompanyAndJobTitle/WorkExperiences/WorkExperiences.js index 2b81d1dc3..9054f14ef 100644 --- a/src/components/CompanyAndJobTitle/WorkExperiences/WorkExperiences.js +++ b/src/components/CompanyAndJobTitle/WorkExperiences/WorkExperiences.js @@ -8,6 +8,7 @@ import { Section } from 'common/base'; import Pagination from 'common/Pagination'; import NotFoundStatus from 'common/routing/NotFound'; import { useQuery } from 'hooks/routing'; +import usePermission from 'hooks/usePermission'; const WorkExperiences = ({ pageType, @@ -17,9 +18,9 @@ const WorkExperiences = ({ page, pageSize, totalCount, - canView, }) => { const queryParams = useQuery(); + const [, , canViewPublishId] = usePermission(); if (data.length === 0) { return ( @@ -37,7 +38,7 @@ const WorkExperiences = ({ key={d.id} pageType={pageType} data={d} - canView={canView} + canView={canViewPublishId(d.id)} /> ))} ( ); @@ -53,7 +51,6 @@ const WorkExperiences = ({ ); WorkExperiences.propTypes = { - canView: PropTypes.bool.isRequired, page: PropTypes.number.isRequired, pageName: PropTypes.string.isRequired, pageSize: PropTypes.number.isRequired, diff --git a/src/components/ExperienceDetail/MoreExperiencesBlock/index.js b/src/components/ExperienceDetail/MoreExperiencesBlock/index.js index 2f0d14e86..56ca71890 100644 --- a/src/components/ExperienceDetail/MoreExperiencesBlock/index.js +++ b/src/components/ExperienceDetail/MoreExperiencesBlock/index.js @@ -51,7 +51,7 @@ const MoreExperiencesBlock = ({ experience }) => { const location = useLocation(); const { state: { pageType = PAGE_TYPE.COMPANY } = {} } = location; - const [, , canView] = usePermission(); + const [, , canViewPublishId] = usePermission(); const handleLoadMore = useCallback( () => dispatch(loadMoreRelatedExperiences()), [dispatch], @@ -83,7 +83,7 @@ const MoreExperiencesBlock = ({ experience }) => { key={e.id} pageType={pageType} data={e} - canView={canView} + canView={canViewPublishId(e.id)} /> ))} {hasMore && } diff --git a/src/components/ExperienceDetail/index.js b/src/components/ExperienceDetail/index.js index b37ca4f39..ecbb657e1 100644 --- a/src/components/ExperienceDetail/index.js +++ b/src/components/ExperienceDetail/index.js @@ -89,7 +89,9 @@ const ExperienceDetail = ({ ...props }) => { dispatch(queryExperienceIfUnfetched(experienceId)); }, [dispatch, experienceId]); - const [, fetchPermission, canView] = usePermission(); + const [, fetchPermission, canViewPublishId] = usePermission({ + publishId: experienceId, + }); useEffect(() => { fetchPermission(); @@ -241,7 +243,7 @@ const ExperienceDetail = ({ ...props }) => { {reportZone}
diff --git a/src/components/TimeAndSalary/common/injectHideContentBlock.js b/src/components/TimeAndSalary/common/injectHideContentBlock.js index 5975c5305..fdcaa3cf0 100644 --- a/src/components/TimeAndSalary/common/injectHideContentBlock.js +++ b/src/components/TimeAndSalary/common/injectHideContentBlock.js @@ -4,18 +4,21 @@ import styles from './injectHideContentBlock.module.css'; import cn from 'classnames'; import { useShareLink } from 'hooks/experiments'; -export default hideRange => rows => { - const hideIndex = hideRange[0]; - const nHides = hideRange.length; +export default ({ rows, data, fromCol, toCol, canViewPublishId }) => { + const nHides = toCol - fromCol + 1; const shareLink = useShareLink(); // Replace original cells with locked cells // on small screens - rows.forEach(row => { + rows.forEach((row, i) => { + const d = data[i]; + const isMyPublish = canViewPublishId(d.id); + if (isMyPublish) return; + row.props.children.splice( - hideIndex, + fromCol, nHides, - ...row.props.children.slice(hideIndex, hideIndex + nHides).map(col => { + ...row.props.children.slice(fromCol, fromCol + nHides).map(col => { return React.cloneElement( col, { @@ -34,8 +37,13 @@ export default hideRange => rows => { // that spans multiple columns if (rows.length > 0) { for (let i = 0; i < rows.length; i++) { - rows[i].props.children.splice( - hideIndex, + const d = data[i]; + const isMyPublish = canViewPublishId(d.id); + if (isMyPublish) continue; + + const row = rows[i]; + row.props.children.splice( + fromCol, 0, {record}; }); - const postRecords = postProcessRows(records); + const postRecords = postProcessRows(records, data); return ( diff --git a/src/graphql/me.js b/src/graphql/me.js index daa40bd61..1a934f556 100644 --- a/src/graphql/me.js +++ b/src/graphql/me.js @@ -19,6 +19,19 @@ export const queryMeGql = /* GraphQL */ ` } `; +export const queryMyPublishIdsGql = /* GraphQL */ ` + query MyPublishes { + me { + experiences { + id + } + salary_work_times { + id + } + } + } +`; + export const queryMyPublishesGql = /* GraphQL */ ` query MyPublishes { me { diff --git a/src/hooks/useIsMyPublishId.js b/src/hooks/useIsMyPublishId.js new file mode 100644 index 000000000..c56d581cb --- /dev/null +++ b/src/hooks/useIsMyPublishId.js @@ -0,0 +1,32 @@ +import { useCallback, useEffect } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import { myPublishIdsSelector } from 'selectors/me'; +import { queryMyPublishIdsIfNeeded } from 'actions/me'; +import { isFetched } from 'utils/fetchBox'; +import { useLogin } from './login'; + +const useIsMyPublishId = () => { + const [isLoggedIn] = useLogin(); + const myPublishIdsBox = useSelector(myPublishIdsSelector); + const dispatch = useDispatch(); + + useEffect(() => { + dispatch(queryMyPublishIdsIfNeeded()); + }, [dispatch, isLoggedIn]); + + const isMyPublishId = useCallback( + publishId => { + if (!isFetched(myPublishIdsBox)) { + return false; + } + + const myPublishIds = myPublishIdsBox.data; + return myPublishIds.includes(publishId); + }, + [myPublishIdsBox], + ); + + return isMyPublishId; +}; + +export default useIsMyPublishId; diff --git a/src/hooks/usePermission.js b/src/hooks/usePermission.js index 2dfb0e7af..b3d1a4db1 100644 --- a/src/hooks/usePermission.js +++ b/src/hooks/usePermission.js @@ -2,6 +2,7 @@ import { useContext, useCallback } from 'react'; import PermissionContext from 'contexts/PermissionContext'; import { useToken } from 'hooks/auth'; import { queryHasSearchPermissionApi } from 'apis/me'; +import useIsMyPublishId from './useIsMyPublishId'; const useGetSearchPermission = ({ token }) => { return useCallback(async () => { @@ -11,7 +12,7 @@ const useGetSearchPermission = ({ token }) => { }, [token]); }; -export default () => { +const usePermission = () => { const token = useToken(); const { canView, permissionFetched, setPermissionState } = useContext( PermissionContext, @@ -36,5 +37,15 @@ export default () => { } } }, [getSearchPermission, setPermissionState]); - return [permissionFetched, fetchPermission, canView]; + + const isMyPublishId = useIsMyPublishId(); + + const canViewPublishId = useCallback( + publishId => isMyPublishId(publishId) || canView, + [canView, isMyPublishId], + ); + + return [permissionFetched, fetchPermission, canViewPublishId]; }; + +export default usePermission; diff --git a/src/pages/Company/CompanyInterviewExperiencesProvider.js b/src/pages/Company/CompanyInterviewExperiencesProvider.js index 68f9e3b58..07a838c20 100644 --- a/src/pages/Company/CompanyInterviewExperiencesProvider.js +++ b/src/pages/Company/CompanyInterviewExperiencesProvider.js @@ -58,7 +58,7 @@ const CompanyInterviewExperiencesProvider = () => { ); }, [dispatch, pageName, jobTitle, start, limit]); - const [, fetchPermission, canView] = usePermission(); + const [, fetchPermission] = usePermission(); useEffect(() => { fetchPermission(); }, [pageType, pageName, fetchPermission]); @@ -76,7 +76,6 @@ const CompanyInterviewExperiencesProvider = () => { page={page} pageSize={PAGE_SIZE} totalCount={interviewExperiencesCount} - canView={canView} tabType={tabType.INTERVIEW_EXPERIENCE} status={status} interviewExperiences={interviewExperiences} diff --git a/src/pages/Company/CompanyOverviewProvider.js b/src/pages/Company/CompanyOverviewProvider.js index 7bafd5ad1..bf84551cc 100644 --- a/src/pages/Company/CompanyOverviewProvider.js +++ b/src/pages/Company/CompanyOverviewProvider.js @@ -48,7 +48,7 @@ const CompanyOverviewProvider = () => { dispatch(queryCompanyOverview(pageName)); }, [dispatch, pageName]); - const [, fetchPermission, canView] = usePermission(); + const [, fetchPermission] = usePermission(); useEffect(() => { fetchPermission(); }, [pageType, pageName, fetchPermission]); @@ -62,7 +62,6 @@ const CompanyOverviewProvider = () => { tabType={tabType.OVERVIEW} overviewBox={overviewBox} page={page} - canView={canView} /> ); }; diff --git a/src/pages/Company/CompanyWorkExperiencesProvider.js b/src/pages/Company/CompanyWorkExperiencesProvider.js index d17630aed..01bee67f3 100644 --- a/src/pages/Company/CompanyWorkExperiencesProvider.js +++ b/src/pages/Company/CompanyWorkExperiencesProvider.js @@ -57,7 +57,7 @@ const CompanyWorkExperiencesProvider = () => { ); }, [dispatch, pageName, jobTitle, start, limit]); - const [, fetchPermission, canView] = usePermission(); + const [, fetchPermission] = usePermission(); useEffect(() => { fetchPermission(); }, [pageType, pageName, fetchPermission]); @@ -75,7 +75,6 @@ const CompanyWorkExperiencesProvider = () => { page={page} pageSize={PAGE_SIZE} totalCount={workExperiencesCount} - canView={canView} tabType={tabType.WORK_EXPERIENCE} status={status} workExperiences={workExperiences} diff --git a/src/pages/JobTitle/JobTitleInterviewExperiencesProvider.js b/src/pages/JobTitle/JobTitleInterviewExperiencesProvider.js index 4b61c8e0a..b64bb1ab8 100644 --- a/src/pages/JobTitle/JobTitleInterviewExperiencesProvider.js +++ b/src/pages/JobTitle/JobTitleInterviewExperiencesProvider.js @@ -59,7 +59,7 @@ const JobTitleTimeAndSalaryProvider = () => { ); }, [dispatch, pageName, companyName, start, limit]); - const [, fetchPermission, canView] = usePermission(); + const [, fetchPermission] = usePermission(); useEffect(() => { fetchPermission(); }, [pageType, pageName, fetchPermission]); @@ -77,7 +77,6 @@ const JobTitleTimeAndSalaryProvider = () => { page={page} pageSize={PAGE_SIZE} totalCount={interviewExperiencesCount} - canView={canView} tabType={tabType.INTERVIEW_EXPERIENCE} status={status} interviewExperiences={interviewExperiences} diff --git a/src/pages/JobTitle/JobTitleOverviewProvider.js b/src/pages/JobTitle/JobTitleOverviewProvider.js index 6c2ebb23c..8b9d8b8b9 100644 --- a/src/pages/JobTitle/JobTitleOverviewProvider.js +++ b/src/pages/JobTitle/JobTitleOverviewProvider.js @@ -48,7 +48,7 @@ const JobTitleOverviewProvider = () => { dispatch(queryJobTitleOverview(pageName)); }, [dispatch, pageName]); - const [, fetchPermission, canView] = usePermission(); + const [, fetchPermission] = usePermission(); useEffect(() => { fetchPermission(); }, [pageType, pageName, fetchPermission]); @@ -62,7 +62,6 @@ const JobTitleOverviewProvider = () => { tabType={tabType.OVERVIEW} overviewBox={overviewBox} page={page} - canView={canView} /> ); }; diff --git a/src/pages/JobTitle/JobTitleWorkExperiencesProvider.js b/src/pages/JobTitle/JobTitleWorkExperiencesProvider.js index f7faa5473..17b720449 100644 --- a/src/pages/JobTitle/JobTitleWorkExperiencesProvider.js +++ b/src/pages/JobTitle/JobTitleWorkExperiencesProvider.js @@ -57,7 +57,7 @@ const JobTitleWorkExperiencesProvider = () => { ); }, [dispatch, pageName, companyName, start, limit]); - const [, fetchPermission, canView] = usePermission(); + const [, fetchPermission] = usePermission(); useEffect(() => { fetchPermission(); }, [pageType, pageName, fetchPermission]); @@ -75,7 +75,6 @@ const JobTitleWorkExperiencesProvider = () => { page={page} pageSize={PAGE_SIZE} totalCount={workExperiencesCount} - canView={canView} tabType={tabType.WORK_EXPERIENCE} status={status} workExperiences={workExperiences} diff --git a/src/reducers/index.js b/src/reducers/index.js index 854f57e06..53da2c421 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -3,6 +3,7 @@ import { persistReducer } from 'redux-persist'; import storage from 'redux-persist/lib/storage'; import auth from './auth'; +import me from './me'; import experience from './experience'; import experiences from './experiences'; import laborRights from './laborRights'; @@ -26,6 +27,7 @@ const persistConfig = { const rootReducer = combineReducers({ auth, + me, experience, experiences, laborRights, diff --git a/src/reducers/me.js b/src/reducers/me.js new file mode 100644 index 000000000..a61fad46c --- /dev/null +++ b/src/reducers/me.js @@ -0,0 +1,21 @@ +import createReducer from 'utils/createReducer'; +import { SET_MY_PUBLISH_IDS } from 'actions/me'; +import { getUnfetched } from 'utils/fetchBox'; +import { SET_LOGIN } from 'actions/auth'; + +const preloadedState = { + myPublishIds: getUnfetched(), +}; + +const me = createReducer(preloadedState, { + [SET_MY_PUBLISH_IDS]: (state, { box }) => ({ + ...state, + myPublishIds: box, + }), + [SET_LOGIN]: state => ({ + ...state, + myPublishIds: getUnfetched(), + }), +}); + +export default me; diff --git a/src/selectors/me.js b/src/selectors/me.js new file mode 100644 index 000000000..54f5755bc --- /dev/null +++ b/src/selectors/me.js @@ -0,0 +1 @@ +export const myPublishIdsSelector = state => state.me.myPublishIds;