From 9d6e6e43c167baa7cbbf61af40fdf40242701e83 Mon Sep 17 00:00:00 2001 From: Maruf Bepary Date: Wed, 10 Dec 2025 21:18:02 +0000 Subject: [PATCH 1/3] FEATURE: Implemented restricted community functionality - Only show posts and comments - Cannot create posts or comments until subscribed - Hidind UI when no permissions --- components/community/CreatePostLink.tsx | 10 +++++++++ components/navbar/right-content/Icons.tsx | 22 ++++++++++++++++++- components/posts/comments/CommentItem.tsx | 4 +++- components/posts/comments/Comments.tsx | 24 +++++++++++++++------ hooks/comments/useCreateComment.ts | 23 ++++++++++++++++++++ hooks/community/useCommunityPermissions.tsx | 20 +++++++++++++++-- hooks/posts/useCreatePost.ts | 23 ++++++++++++++++++++ lib/community/communityPermissions.ts | 22 +++++++++++++++++++ 8 files changed, 137 insertions(+), 11 deletions(-) create mode 100644 lib/community/communityPermissions.ts diff --git a/components/community/CreatePostLink.tsx b/components/community/CreatePostLink.tsx index 683ee17..912b43f 100644 --- a/components/community/CreatePostLink.tsx +++ b/components/community/CreatePostLink.tsx @@ -4,6 +4,8 @@ import React from "react"; import { BsLink45Deg } from "react-icons/bs"; import { IoIosCreate } from "react-icons/io"; import { IoImageOutline } from "react-icons/io5"; +import useCommunityState from "@/hooks/community/useCommunityState"; +import useCommunityPermissions from "@/hooks/community/useCommunityPermissions"; type CreatePostProps = {}; @@ -14,6 +16,14 @@ type CreatePostProps = {}; */ const CreatePostLink: React.FC = () => { const { onClick } = useCallCreatePost(); // hook for creating a new post + const { communityStateValue } = useCommunityState(); + const { canPost } = useCommunityPermissions( + communityStateValue.currentCommunity + ); + + if (communityStateValue.currentCommunity && !canPost) { + return null; + } return ( { const { onClick } = useCallCreatePost(); const { colorMode, toggleColorMode } = useColorMode(); const setSavedPostState = useSetAtom(savedPostStateAtom); + const { communityStateValue } = useCommunityState(); + const { canPost } = useCommunityPermissions( + communityStateValue.currentCommunity + ); + const showToast = useCustomToast(); + + const handleCreatePostClick = () => { + if (communityStateValue.currentCommunity && !canPost) { + showToast({ + title: "Restricted Community", + description: "You must be a member to post in this community.", + status: "error", + }); + return; + } + onClick(); + }; return ( @@ -52,7 +72,7 @@ const icons: React.FC = () => { aria-label="Create post" variant="ghost" fontSize={22} - onClick={onClick} + onClick={handleCreatePostClick} mr={1.5} ml={1.5} > diff --git a/components/posts/comments/CommentItem.tsx b/components/posts/comments/CommentItem.tsx index 37dbb0b..fef7d1e 100644 --- a/components/posts/comments/CommentItem.tsx +++ b/components/posts/comments/CommentItem.tsx @@ -35,6 +35,7 @@ type CommentItemProps = { depth: number ) => Promise; user?: User; + canComment?: boolean; }; /** @@ -60,6 +61,7 @@ const CommentItem: React.FC = ({ isCommunityAdmin, onCreateComment, user, + canComment = true, }) => { const [isReplying, setIsReplying] = useState(false); const [replyText, setReplyText] = useState(""); @@ -111,7 +113,7 @@ const CommentItem: React.FC = ({ borderColor={{ base: "gray.100", _dark: "gray.600" }} > - {(comment.depth || 0) < 2 && ( + {(comment.depth || 0) < 2 && canComment && ( + {canPost && ( + + )} {isJoined && (