Skip to content

Commit

Permalink
redirect to the common about page if user is not a member of the pare…
Browse files Browse the repository at this point in the history
…nt common
  • Loading branch information
budnik9 committed Sep 12, 2023
1 parent 0a8bb23 commit c5c9369
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/pages/commonFeed/CommonFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
selectRecentStreamId,
selectSharedFeedItem,
} from "@/store/states";
import { useCommonMember } from "../OldCommon/hooks";
import {
NewDiscussionCreation,
NewProposalCreation,
Expand Down Expand Up @@ -120,6 +121,11 @@ const CommonFeedComponent: FC<CommonFeedProps> = (props) => {
loading: areCommonPinnedFeedItemsLoading,
fetch: fetchCommonPinnedFeedItems,
} = useCommonPinnedFeedItems(commonId, pinnedItemIds);
const {
data: parentCommonMember,
fetched: isParentCommonMemberFetched,
fetchCommonMember: fetchParentCommonMember,
} = useCommonMember();

const commonFeedItemIdsForNotListening = useMemo(() => {
const items: string[] = [];
Expand Down Expand Up @@ -159,7 +165,9 @@ const CommonFeedComponent: FC<CommonFeedProps> = (props) => {
return items;
}, [sharedFeedItem, sharedFeedItemId, commonPinnedFeedItems]);
const firstItem = commonFeedItems?.[0];
const isDataFetched = isCommonDataFetched;
const isDataFetched =
isCommonDataFetched &&
(parentCommonId ? isParentCommonMemberFetched : true);
const hasPublicItem = true;

const fetchData = () => {
Expand Down Expand Up @@ -193,6 +201,18 @@ const CommonFeedComponent: FC<CommonFeedProps> = (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;
Expand Down

0 comments on commit c5c9369

Please sign in to comment.