diff --git a/packages/next-common/components/articleMoreMenu/common/postHideMenu.jsx b/packages/next-common/components/articleMoreMenu/common/postHideMenu.jsx
index a26d55dafc..71e79c063a 100644
--- a/packages/next-common/components/articleMoreMenu/common/postHideMenu.jsx
+++ b/packages/next-common/components/articleMoreMenu/common/postHideMenu.jsx
@@ -12,16 +12,22 @@ const HidePopup = dynamicPopup(() =>
import("next-common/components/deletePopup/hidePopup"),
);
-export default function PostHideMenu({ setShow = noop }) {
+export default function PostHideMenu({
+ setShow = noop,
+ apiPath,
+ redirectPath = "/discussions",
+ itemName = "Post",
+}) {
const [showHidePopup, setShowHidePopup] = useState(false);
const post = usePost();
const dispatch = useDispatch();
const router = useRouter();
const hidden = !!post.hide;
+ const hideApi = apiPath || `posts/${post._id}/hide`;
const doHide = useCallback(async () => {
- const { error } = await nextApi.patch(`posts/${post._id}/hide`, {
+ const { error } = await nextApi.patch(hideApi, {
hide: !hidden,
});
if (error) {
@@ -32,11 +38,11 @@ export default function PostHideMenu({ setShow = noop }) {
setShowHidePopup(false);
if (!hidden) {
- router.replace("/discussions");
+ router.replace(redirectPath);
} else {
router.replace(router.asPath);
}
- }, [dispatch, hidden, post._id, router]);
+ }, [dispatch, hidden, hideApi, redirectPath, router]);
return (
@@ -48,7 +54,12 @@ export default function PostHideMenu({ setShow = noop }) {
}}
/>
{showHidePopup && (
-
+
)}
);
diff --git a/packages/next-common/components/articleMoreMenu/index.jsx b/packages/next-common/components/articleMoreMenu/index.jsx
index ae869fc3fb..cb65fc032c 100644
--- a/packages/next-common/components/articleMoreMenu/index.jsx
+++ b/packages/next-common/components/articleMoreMenu/index.jsx
@@ -12,13 +12,19 @@ import {
EditMenuItem,
ReportMenu,
LinkOrUnlinkMenu,
+ PostHideMenu,
} from "next-common/components/articleMoreMenu/common";
+import useIsAdmin from "next-common/hooks/useIsAdmin";
+import { usePost } from "next-common/context/post";
export default function ArticleMoreMenu(props) {
const postType = useDetailType();
if (postType === detailPageCategory.GOV2_REFERENDUM) {
return ;
}
+ if (postType === detailPageCategory.DEMOCRACY_REFERENDUM) {
+ return ;
+ }
if (postType === detailPageCategory.POST) {
return ;
}
@@ -31,8 +37,10 @@ export default function ArticleMoreMenu(props) {
return ;
}
-function CommonArticleMoreMenu({ isAuthor, editable, setIsEdit }) {
+function CommonArticleMoreMenu({ isAuthor, editable, setIsEdit, postType }) {
const [show, setShow] = useState(false);
+ const post = usePost();
+ const isAdmin = useIsAdmin();
const ref = useRef();
useClickAway(ref, () => setShow(false));
@@ -52,6 +60,14 @@ function CommonArticleMoreMenu({ isAuthor, editable, setIsEdit }) {
/>
)}
{editable && isAuthor && }
+ {isAdmin && postType === detailPageCategory.DEMOCRACY_REFERENDUM && (
+
+ )}
diff --git a/packages/next-common/components/articleMoreMenu/referendaArticleMoreMenu.jsx b/packages/next-common/components/articleMoreMenu/referendaArticleMoreMenu.jsx
index d5849cb74e..4a7abc5055 100644
--- a/packages/next-common/components/articleMoreMenu/referendaArticleMoreMenu.jsx
+++ b/packages/next-common/components/articleMoreMenu/referendaArticleMoreMenu.jsx
@@ -13,7 +13,10 @@ import {
CancelReferendumMenu,
KillReferendumMenu,
AppendReferendaMenu,
+ PostHideMenu,
} from "./common";
+import useIsAdmin from "next-common/hooks/useIsAdmin";
+import { usePost } from "next-common/context/post";
export default function ReferendaArticleMoreMenu({
isAuthor,
@@ -22,6 +25,8 @@ export default function ReferendaArticleMoreMenu({
}) {
const ref = useRef();
const [show, setShow] = useState(false);
+ const post = usePost();
+ const isAdmin = useIsAdmin();
const { appendants } = useReferendaAppendantsContext();
const { newProposalQuickStart: { cancelReferendum, killReferendum } = {} } =
useChainSettings();
@@ -48,6 +53,14 @@ export default function ReferendaArticleMoreMenu({
{editable && isAuthor && !appendants?.length && (
)}
+ {isAdmin && (
+
+ )}
{cancelReferendum && }
{killReferendum && }
diff --git a/packages/next-common/components/deletePopup/hidePopup.jsx b/packages/next-common/components/deletePopup/hidePopup.jsx
index da6e1d2fb8..ee4af3c9ef 100644
--- a/packages/next-common/components/deletePopup/hidePopup.jsx
+++ b/packages/next-common/components/deletePopup/hidePopup.jsx
@@ -10,6 +10,7 @@ export default function HidePopup({
hidden = false,
setShow = noop,
doHide = noop,
+ itemName = "Post",
}) {
const [isLoading, setIsLoading] = useState(false);
const { ensureLogin } = useEnsureLogin();
@@ -29,13 +30,13 @@ export default function HidePopup({
return (
setShow(false)}
>
{hidden
- ? "This post will be visible to everyone again."
- : "This post will be hidden from the list."}
+ ? `This ${itemName.toLowerCase()} will be visible to everyone again.`
+ : `This ${itemName.toLowerCase()} will be hidden from the list.`}
setShow(false)}>Cancel
diff --git a/packages/next-common/sima/components/contentMenu.js b/packages/next-common/sima/components/contentMenu.js
index 23f0b75ce9..c94a02f8fb 100644
--- a/packages/next-common/sima/components/contentMenu.js
+++ b/packages/next-common/sima/components/contentMenu.js
@@ -108,8 +108,25 @@ export function PostContextMenu({ isAuthor, canEdit, setIsAppend, setIsEdit }) {
const post = usePost();
const type = useDetailType();
const isSimaDiscussion = type === detailPageCategory.POST;
+ const isGov2Referendum = type === detailPageCategory.GOV2_REFERENDUM;
+ const isDemocracyReferendum =
+ type === detailPageCategory.DEMOCRACY_REFERENDUM;
+ const isReferendum = isGov2Referendum || isDemocracyReferendum;
const isAdmin = useIsAdmin();
+ const canHide = isReferendum ? isAdmin : isAuthor || isAdmin;
+ let hideApi = null;
+ if (isGov2Referendum) {
+ hideApi = `gov2/referendums/${post?._id}/hide`;
+ } else if (isDemocracyReferendum) {
+ hideApi = `democracy/referendums/${post?._id}/hide`;
+ }
+ const redirectPath = isGov2Referendum
+ ? "/referenda"
+ : isDemocracyReferendum
+ ? "/democracy/referenda"
+ : "/discussions";
+
useClickAway(ref, () => setShow(false));
let linkOrUnlinkMenuItem = (
@@ -159,7 +176,14 @@ export function PostContextMenu({ isAuthor, canEdit, setIsAppend, setIsEdit }) {
)}
>
)}
- {(isAuthor || isAdmin) && }
+ {canHide && (
+
+ )}
{showLinkPopup && }