Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[經驗單篇] 允許觀看自己的文章 #1438

Merged
merged 22 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/actions/experiences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
};
43 changes: 43 additions & 0 deletions src/actions/me.js
Original file line number Diff line number Diff line change
@@ -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([])));
peteranny marked this conversation as resolved.
Show resolved Hide resolved
return;
}

dispatch(setMyPublishIds(toFetching()));
try {
const myPublishIds = await queryMyPublishIdsApi({ token });
dispatch(setMyPublishIds(getFetched(myPublishIds)));
} catch (error) {
dispatch(setMyPublishIds(getError(error)));
}
peteranny marked this conversation as resolved.
Show resolved Hide resolved
};
12 changes: 10 additions & 2 deletions src/actions/timeAndSalary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
};
7 changes: 7 additions & 0 deletions src/apis/me.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import graphqlClient from 'utils/graphqlClient';

import {
queryMeGql,
queryMyPublishIdsGql,
queryMyPublishesGql,
queryMyPermissionGql,
} from 'graphql/me';
Expand All @@ -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 });
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,9 +20,9 @@ const InterviewExperiences = ({
page,
pageSize,
totalCount,
canView,
}) => {
const queryParams = useQuery();
const [, , canViewPublishId] = usePermission();

if (data.length === 0) {
return (
Expand All @@ -39,7 +40,7 @@ const InterviewExperiences = ({
key={d.id}
pageType={pageType}
data={d}
canView={canView}
canView={canViewPublishId(d.id)}
/>
))}
<Pagination
Expand All @@ -55,7 +56,6 @@ const InterviewExperiences = ({
};

InterviewExperiences.propTypes = {
canView: PropTypes.bool.isRequired,
data: PropTypes.arrayOf(PropTypes.object),
page: PropTypes.number.isRequired,
pageName: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const InterviewExperiences = ({
page,
pageSize,
totalCount,
canView,
}) => (
<CompanyAndJobTitleWrapper
pageType={pageType}
Expand Down Expand Up @@ -43,7 +42,6 @@ const InterviewExperiences = ({
page={page}
pageSize={pageSize}
totalCount={totalCount}
canView={canView}
/>
</Fragment>
);
Expand All @@ -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,
Expand Down
15 changes: 6 additions & 9 deletions src/components/CompanyAndJobTitle/Overview/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,8 +24,9 @@ const Overview = ({
jobAverageSalaries,
averageWeekWorkTime,
overtimeFrequencyCount,
canView,
}) => {
const [, , canViewPublishId] = usePermission();

return (
<Section Tag="main" paddingBottom>
<SnippetBlock
Expand All @@ -46,11 +48,7 @@ const Overview = ({
averageWeekWorkTime={averageWeekWorkTime}
overtimeFrequencyCount={overtimeFrequencyCount}
/>
<WorkingHourTable
data={salaryWorkTimes}
hideContent={!canView}
pageType={pageType}
/>
<WorkingHourTable data={salaryWorkTimes} pageType={pageType} />
</SnippetBlock>
<SnippetBlock
title="評價"
Expand All @@ -70,7 +68,7 @@ const Overview = ({
key={d.id}
pageType={pageType}
data={d}
canView={canView}
canView={canViewPublishId(d.id)}
/>
))}
</SnippetBlock>
Expand All @@ -92,7 +90,7 @@ const Overview = ({
key={d.id}
pageType={pageType}
data={d}
canView={canView}
canView={canViewPublishId(d.id)}
/>
))}
</SnippetBlock>
Expand All @@ -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,
Expand Down
11 changes: 1 addition & 10 deletions src/components/CompanyAndJobTitle/Overview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<CompanyAndJobTitleWrapper
pageType={pageType}
pageName={pageName}
Expand Down Expand Up @@ -48,7 +41,6 @@ const Overview = ({
averageWeekWorkTime={data.averageWeekWorkTime}
overtimeFrequencyCount={data.overtimeFrequencyCount}
page={page}
canView={canView}
/>
</Fragment>
);
Expand All @@ -58,7 +50,6 @@ const Overview = ({
);

Overview.propTypes = {
canView: PropTypes.bool.isRequired,
overviewBox: PropTypes.shape({
data: PropTypes.shape({
averageWeekWorkTime: PropTypes.number.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TimeAndSalary = ({
pageSize,
totalCount,
}) => {
const [, fetchPermission, canView] = usePermission();
const [, fetchPermission] = usePermission();
useEffect(() => {
fetchPermission();
}, [fetchPermission]);
Expand All @@ -31,12 +31,7 @@ const TimeAndSalary = ({
<Section Tag="main" paddingBottom>
{(salaryWorkTimes.length > 0 && (
<React.Fragment>
<WorkingHourBlock
data={salaryWorkTimes}
pageType={pageType}
pageName={pageName}
hideContent={!canView}
/>
<WorkingHourBlock data={salaryWorkTimes} pageType={pageType} />
<Pagination
totalCount={totalCount}
unit={pageSize}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@ import WorkingHourTable from './WorkingHourTable';

import styles from '../../TimeAndSalary/common/WorkingHourBlock.module.css';

const WorkingHourBlock = ({ data, hideContent, pageType }) => {
const WorkingHourBlock = ({ data, pageType }) => {
return (
<section className={styles.container}>
<div className={cn(styles.content, styles.expanded)}>
<WorkingHourTable
data={data}
hideContent={hideContent}
pageType={pageType}
/>
<WorkingHourTable data={data} pageType={pageType} />
</div>
</section>
);
};

WorkingHourBlock.propTypes = {
data: PropTypes.array,
hideContent: PropTypes.bool.isRequired,
pageType: PropTypes.string,
};

Expand Down
Loading