From c5c93697a6f7b95503091f6d4fd240e622b22e21 Mon Sep 17 00:00:00 2001 From: Kiryl Budnik Date: Tue, 12 Sep 2023 15:47:38 +0300 Subject: [PATCH] redirect to the common about page if user is not a member of the parent common --- src/pages/commonFeed/CommonFeed.tsx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pages/commonFeed/CommonFeed.tsx b/src/pages/commonFeed/CommonFeed.tsx index d19b4729b7..54943aa6f0 100644 --- a/src/pages/commonFeed/CommonFeed.tsx +++ b/src/pages/commonFeed/CommonFeed.tsx @@ -38,6 +38,7 @@ import { selectRecentStreamId, selectSharedFeedItem, } from "@/store/states"; +import { useCommonMember } from "../OldCommon/hooks"; import { NewDiscussionCreation, NewProposalCreation, @@ -120,6 +121,11 @@ const CommonFeedComponent: FC = (props) => { loading: areCommonPinnedFeedItemsLoading, fetch: fetchCommonPinnedFeedItems, } = useCommonPinnedFeedItems(commonId, pinnedItemIds); + const { + data: parentCommonMember, + fetched: isParentCommonMemberFetched, + fetchCommonMember: fetchParentCommonMember, + } = useCommonMember(); const commonFeedItemIdsForNotListening = useMemo(() => { const items: string[] = []; @@ -159,7 +165,9 @@ const CommonFeedComponent: FC = (props) => { return items; }, [sharedFeedItem, sharedFeedItemId, commonPinnedFeedItems]); const firstItem = commonFeedItems?.[0]; - const isDataFetched = isCommonDataFetched; + const isDataFetched = + isCommonDataFetched && + (parentCommonId ? isParentCommonMemberFetched : true); const hasPublicItem = true; const fetchData = () => { @@ -193,6 +201,18 @@ const CommonFeedComponent: FC = (props) => { [dispatch], ); + useEffect(() => { + if (parentCommonId) { + fetchParentCommonMember(parentCommonId, {}, true); + } + }, [parentCommonId]); + + useEffect(() => { + if (isParentCommonMemberFetched && !parentCommonMember) { + history.replace(getCommonPageAboutTabPath(commonId)); + } + }, [parentCommonMember?.id, isParentCommonMemberFetched, commonId]); + useEffect(() => { if (!isCommonDataFetched || !isGlobalDataFetched || commonMember) { return;