Skip to content

Commit

Permalink
put hide-content in permission
Browse files Browse the repository at this point in the history
  • Loading branch information
peteranny committed Sep 19, 2024
1 parent 42e8ff8 commit ad12698
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
26 changes: 2 additions & 24 deletions src/components/ExperienceDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import { generateBreadCrumbData } from '../CompanyAndJobTitle/utils';
import styles from './ExperienceDetail.module.css';
import { experienceBoxSelectorAtId } from 'selectors/experienceSelector';
import Button from 'common/button/Button';
import useIsMyPublishId from 'hooks/useIsMyPublishId';

const MODAL_TYPE = {
REPORT_DETAIL: 'REPORT_TYPE',
Expand Down Expand Up @@ -80,27 +79,6 @@ const useExperienceBox = experienceId => {
return useSelector(selector);
};

const useHideContent = ({ experienceId }) => {
const isMyExperienceId = useIsMyPublishId();

const isMyPublish = useMemo(() => isMyExperienceId(experienceId), [
isMyExperienceId,
experienceId,
]);

const [, fetchPermission, canView] = usePermission();

useEffect(() => {
fetchPermission();
}, [experienceId, fetchPermission]);

const hideContent = useMemo(() => {
return !isMyPublish && !canView;
}, [isMyPublish, canView]);

return hideContent;
};

const ExperienceDetail = ({ ...props }) => {
const experienceId = useExperienceId();
const experienceBox = useExperienceBox(experienceId);
Expand All @@ -111,7 +89,7 @@ const ExperienceDetail = ({ ...props }) => {
dispatch(queryExperienceIfUnfetched(experienceId));
}, [dispatch, experienceId]);

const hideContent = useHideContent({ experienceId });
const [, , canView] = usePermission({ publishId: experienceId });

const [{ isModalOpen, modalType, modalPayload = {} }, setModal] = useState({
isModalOpen: false,
Expand Down Expand Up @@ -259,7 +237,7 @@ const ExperienceDetail = ({ ...props }) => {
{reportZone}
<Article
experience={experienceBox.data}
hideContent={hideContent}
hideContent={!canView}
onClickMsgButton={scrollToCommentZone}
/>
</Fragment>
Expand Down
15 changes: 12 additions & 3 deletions src/hooks/usePermission.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useContext, useCallback } from 'react';
import { useContext, useCallback, useMemo } 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 () => {
Expand All @@ -11,7 +12,13 @@ const useGetSearchPermission = ({ token }) => {
}, [token]);
};

export default () => {
const usePermission = ({ publishId } = {}) => {
const isMyPublishId = useIsMyPublishId();
const isMyPublish = useMemo(() => !!publishId && isMyPublishId(publishId), [
isMyPublishId,
publishId,
]);

const token = useToken();
const { canView, permissionFetched, setPermissionState } = useContext(
PermissionContext,
Expand All @@ -36,5 +43,7 @@ export default () => {
}
}
}, [getSearchPermission, setPermissionState]);
return [permissionFetched, fetchPermission, canView];
return [permissionFetched, fetchPermission, isMyPublish || canView];
};

export default usePermission;

0 comments on commit ad12698

Please sign in to comment.