From f912cca1962360a22af2436dff75abff575d6958 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Mon, 18 Sep 2023 17:11:02 +0300 Subject: [PATCH 01/22] make parent common name in the back page to be a link --- .../CommonEntranceJoin/CommonEntranceJoin.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonEntranceInfo/components/CommonEntranceJoin/CommonEntranceJoin.tsx b/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonEntranceInfo/components/CommonEntranceJoin/CommonEntranceJoin.tsx index 7bf4b3d441..41513abbb2 100644 --- a/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonEntranceInfo/components/CommonEntranceJoin/CommonEntranceJoin.tsx +++ b/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonEntranceInfo/components/CommonEntranceJoin/CommonEntranceJoin.tsx @@ -1,6 +1,8 @@ import React, { FC } from "react"; +import { NavLink } from "react-router-dom"; import { useJoinProjectAutomatically } from "@/pages/common/hooks"; import { useCommonDataContext } from "@/pages/common/providers"; +import { useRoutesContext } from "@/shared/contexts"; import { Common } from "@/shared/models"; import { Button, ButtonSize, ButtonVariant } from "@/shared/ui-kit"; import styles from "./CommonEntranceJoin.module.scss"; @@ -15,6 +17,7 @@ const CommonEntranceJoin: FC = (props) => { const { withJoinRequest = false, common, isProject } = props; const { parentCommon, commonMember, isJoinAllowed, onJoinCommon } = useCommonDataContext(); + const { getCommonPagePath } = useRoutesContext(); const { canJoinProjectAutomatically, isJoinPending, @@ -28,8 +31,12 @@ const CommonEntranceJoin: FC = (props) => { {isProject && parentCommon?.name && (

{common.name} is a space in the{" "} - {parentCommon.name} common. Only common members can - join the space. + + + {parentCommon.name} + + {" "} + common. Only common members can join the space.

)} {withJoinRequest && (isJoinAllowed || isJoinPending) && ( From d2563acdc0772bd11ea2393c82e31dbb1578e787 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Mon, 18 Sep 2023 18:05:10 +0300 Subject: [PATCH 02/22] check autojoin ability in spaces redirection --- src/pages/commonFeed/CommonFeed.tsx | 34 +++++++++++++------ .../commonFeed/hooks/useCommonData/index.ts | 11 +++--- .../commonFeed/hooks/useCommonData/types.ts | 2 +- src/shared/utils/checkIsAutomaticJoin.ts | 2 +- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/pages/commonFeed/CommonFeed.tsx b/src/pages/commonFeed/CommonFeed.tsx index 53b484b50c..2474ac972d 100644 --- a/src/pages/commonFeed/CommonFeed.tsx +++ b/src/pages/commonFeed/CommonFeed.tsx @@ -31,7 +31,10 @@ import { import { CommonSidenavLayoutTabs } from "@/shared/layouts"; import { CirclesPermissions, CommonFeed, CommonMember } from "@/shared/models"; import { Loader, NotFound, PureCommonTopNavigation } from "@/shared/ui-kit"; -import { getCommonPageAboutTabPath } from "@/shared/utils"; +import { + checkIsAutomaticJoin, + getCommonPageAboutTabPath, +} from "@/shared/utils"; import { commonActions, selectCommonAction, @@ -98,9 +101,12 @@ const CommonFeedComponent: FC = (props) => { fetchCommonData, } = useCommonData(userId); const parentCommonId = commonData?.common.directParent?.commonId; - const parentCommonMember = commonData?.parentCommonMember; const isRootCommon = !parentCommonId; const isRootCommonMember = Boolean(commonData?.rootCommonMember); + const isAutomaticAcceptance = checkIsAutomaticJoin(commonData?.governance); + const isRootCommonAutomaticAcceptance = checkIsAutomaticJoin( + commonData?.rootCommonGovernance, + ); const anotherCommonId = userCommonIds[0] === commonId ? userCommonIds[1] : userCommonIds[0]; const pinnedItemIds = useMemo( @@ -195,26 +201,32 @@ const CommonFeedComponent: FC = (props) => { ); useEffect(() => { - if (isCommonDataFetched && parentCommonId && !parentCommonMember) { - history.replace(getCommonPageAboutTabPath(commonId)); - } - }, [isCommonDataFetched, parentCommonMember?.id, commonId]); - - useEffect(() => { - if (!isCommonDataFetched || !isGlobalDataFetched || commonMember) { + if ( + !isCommonDataFetched || + !isGlobalDataFetched || + commonMember || + isRootCommon || + isRootCommonMember + ) { return; } - if (!hasPublicItem && !isRootCommon && !isRootCommonMember) { + if ( + !isAutomaticAcceptance || + !isRootCommonAutomaticAcceptance || + !hasPublicItem + ) { history.replace(getCommonPageAboutTabPath(commonId)); } }, [ isCommonDataFetched, isGlobalDataFetched, commonMember, - hasPublicItem, isRootCommon, isRootCommonMember, commonId, + isAutomaticAcceptance, + isRootCommonAutomaticAcceptance, + hasPublicItem, ]); useEffect(() => { diff --git a/src/pages/commonFeed/hooks/useCommonData/index.ts b/src/pages/commonFeed/hooks/useCommonData/index.ts index 1fe7a183c7..d85e1c20a5 100644 --- a/src/pages/commonFeed/hooks/useCommonData/index.ts +++ b/src/pages/commonFeed/hooks/useCommonData/index.ts @@ -69,18 +69,15 @@ export const useCommonData = (userId?: string): Return => { parentCommons, subCommons, rootCommonMember, - parentCommonMember, + rootCommonGovernance, ] = await Promise.all([ CommonService.getAllParentCommonsForCommon(common), CommonService.getCommonsByDirectParentIds([common.id]), rootCommonId && userId ? CommonService.getCommonMemberByUserId(rootCommonId, userId) : null, - common.directParent?.commonId && userId - ? CommonService.getCommonMemberByUserId( - common.directParent.commonId, - userId, - ) + rootCommonId + ? GovernanceService.getGovernanceByCommonId(rootCommonId) : null, ]); @@ -95,7 +92,7 @@ export const useCommonData = (userId?: string): Return => { commonMembersAmount, sharedFeedItem, rootCommonMember, - parentCommonMember, + rootCommonGovernance, parentCommon: last(parentCommons), }, }); diff --git a/src/pages/commonFeed/hooks/useCommonData/types.ts b/src/pages/commonFeed/hooks/useCommonData/types.ts index 599181ec31..715a04f76f 100644 --- a/src/pages/commonFeed/hooks/useCommonData/types.ts +++ b/src/pages/commonFeed/hooks/useCommonData/types.ts @@ -9,7 +9,7 @@ export interface Data { commonMembersAmount: number; sharedFeedItem: CommonFeed | null; rootCommonMember: CommonMember | null; - parentCommonMember: CommonMember | null; + rootCommonGovernance: Governance | null; parentCommon?: Common; } diff --git a/src/shared/utils/checkIsAutomaticJoin.ts b/src/shared/utils/checkIsAutomaticJoin.ts index 730e9d0990..0d5531ecbd 100644 --- a/src/shared/utils/checkIsAutomaticJoin.ts +++ b/src/shared/utils/checkIsAutomaticJoin.ts @@ -2,7 +2,7 @@ import { ProposalsTypes } from "@/shared/constants"; import { Governance } from "@/shared/models"; export const checkIsAutomaticJoin = ( - governance?: Pick, + governance?: Pick | null, ): boolean => governance?.proposals[ProposalsTypes.MEMBER_ADMITTANCE]?.global .votingDuration === 0; From 1087153a85c0d47b62b6b0b5e2cb564aad3707ef Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Mon, 18 Sep 2023 18:11:35 +0300 Subject: [PATCH 03/22] add rootCommonId to Common model --- src/pages/commonFeed/hooks/useCommonData/index.ts | 2 +- src/shared/models/Common.tsx | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/commonFeed/hooks/useCommonData/index.ts b/src/pages/commonFeed/hooks/useCommonData/index.ts index d85e1c20a5..7bf51ee407 100644 --- a/src/pages/commonFeed/hooks/useCommonData/index.ts +++ b/src/pages/commonFeed/hooks/useCommonData/index.ts @@ -64,7 +64,7 @@ export const useCommonData = (userId?: string): Return => { ); } - const rootCommonId = common.directParent?.commonId; + const { rootCommonId } = common; const [ parentCommons, subCommons, diff --git a/src/shared/models/Common.tsx b/src/shared/models/Common.tsx index 14a04fea5a..0d2a561e60 100644 --- a/src/shared/models/Common.tsx +++ b/src/shared/models/Common.tsx @@ -115,6 +115,10 @@ export interface Common extends BaseEntity { messages?: DiscussionMessage[]; pinnedFeedItems: FeedItem[]; + + hasPublicItems: boolean; + + rootCommonId?: string; } export interface Project extends Common { From 3e51f358f25fc38cff821209fed355581708889c Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Mon, 18 Sep 2023 18:12:44 +0300 Subject: [PATCH 04/22] add hasPublicItems field usage --- src/pages/commonFeed/CommonFeed.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/commonFeed/CommonFeed.tsx b/src/pages/commonFeed/CommonFeed.tsx index 2474ac972d..c7fe367f48 100644 --- a/src/pages/commonFeed/CommonFeed.tsx +++ b/src/pages/commonFeed/CommonFeed.tsx @@ -167,7 +167,7 @@ const CommonFeedComponent: FC = (props) => { }, [sharedFeedItem, sharedFeedItemId, commonPinnedFeedItems]); const firstItem = commonFeedItems?.[0]; const isDataFetched = isCommonDataFetched; - const hasPublicItem = true; + const hasPublicItems = commonData?.common.hasPublicItems ?? false; const fetchData = () => { fetchCommonData({ @@ -213,7 +213,7 @@ const CommonFeedComponent: FC = (props) => { if ( !isAutomaticAcceptance || !isRootCommonAutomaticAcceptance || - !hasPublicItem + !hasPublicItems ) { history.replace(getCommonPageAboutTabPath(commonId)); } @@ -226,7 +226,7 @@ const CommonFeedComponent: FC = (props) => { commonId, isAutomaticAcceptance, isRootCommonAutomaticAcceptance, - hasPublicItem, + hasPublicItems, ]); useEffect(() => { From f5055d6b6d39bab07c5d2cb491434070f58d252e Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 12:33:51 +0300 Subject: [PATCH 05/22] add renderChatInput prop to ChatComponent --- .../ChatComponent/ChatComponent.module.scss | 16 --- .../ChatComponent/ChatComponent.tsx | 132 +++++++++--------- .../components/DesktopChat/DesktopChat.tsx | 9 +- .../components/MobileChat/MobileChat.tsx | 9 +- 4 files changed, 70 insertions(+), 96 deletions(-) diff --git a/src/pages/common/components/ChatComponent/ChatComponent.module.scss b/src/pages/common/components/ChatComponent/ChatComponent.module.scss index f072d86ded..9a297227a9 100644 --- a/src/pages/common/components/ChatComponent/ChatComponent.module.scss +++ b/src/pages/common/components/ChatComponent/ChatComponent.module.scss @@ -64,22 +64,6 @@ align-items: flex-end; } -.loaderWrapper { - width: 100%; - display: flex; - align-items: center; - justify-content: center; -} - -.permissionsText { - font-size: $mobile-title; - color: var(--primary-fill); - margin-right: 0.3125rem; - width: 100%; - text-align: center; - cursor: pointer; -} - .messageInput { width: 100%; min-height: 2.625rem; diff --git a/src/pages/common/components/ChatComponent/ChatComponent.tsx b/src/pages/common/components/ChatComponent/ChatComponent.tsx index 8cdade8355..46f4a226f4 100644 --- a/src/pages/common/components/ChatComponent/ChatComponent.tsx +++ b/src/pages/common/components/ChatComponent/ChatComponent.tsx @@ -89,8 +89,7 @@ interface ChatComponentInterface { isHidden: boolean; onMessagesAmountChange?: (newMessagesAmount: number) => void; directParent?: DirectParent | null; - isJoinPending?: boolean; - onJoinCommon?: () => void; + renderChatInput?: () => ReactNode; onUserClick?: (userId: string) => void; onFeedItemClick?: (feedItemId: string) => void; onInternalLinkClick?: (data: InternalLinkData) => void; @@ -131,8 +130,7 @@ export default function ChatComponent({ isCommonMemberFetched, onMessagesAmountChange, directParent, - isJoinPending = false, - onJoinCommon, + renderChatInput: renderChatInputOuter, onUserClick, onFeedItemClick, onInternalLinkClick, @@ -569,19 +567,70 @@ export default function ChatComponent({ } }, [discussionMessages.length]); - const renderJoinCommonContent = (): ReactNode => { - if (isJoinPending) { - return ( -
- -
- ); + const renderChatInput = (): ReactNode => { + const shouldHideChatInput = !isChatChannel && (!hasAccess || isHidden); + + if (shouldHideChatInput) { + return null; + } + if (!isChatChannel) { + const chatInputEl = renderChatInputOuter?.(); + + if (chatInputEl || chatInputEl === null) { + return chatInputEl; + } } return ( - - Join - + <> + { + document.getElementById("file")?.click(); + }} + > + + + + + + ); }; @@ -627,60 +676,7 @@ export default function ChatComponent({ [styles.chatInputWrapperMultiLine]: isMultiLineInput, })} > - {!isChatChannel && (!commonMember || !hasAccess || isHidden) ? ( - renderJoinCommonContent() - ) : ( - <> - { - document.getElementById("file")?.click(); - }} - > - - - - - - - )} + {renderChatInput()} )} diff --git a/src/pages/commonFeed/components/FeedLayout/components/DesktopChat/DesktopChat.tsx b/src/pages/commonFeed/components/FeedLayout/components/DesktopChat/DesktopChat.tsx index 20fa4fcbf3..fe4b34d81d 100644 --- a/src/pages/commonFeed/components/FeedLayout/components/DesktopChat/DesktopChat.tsx +++ b/src/pages/commonFeed/components/FeedLayout/components/DesktopChat/DesktopChat.tsx @@ -30,8 +30,7 @@ interface ChatProps { titleRightContent?: ReactNode; onMessagesAmountChange?: (newMessagesAmount: number) => void; directParent?: DirectParent | null; - isJoinPending?: boolean; - onJoinCommon?: () => void; + renderChatInput?: () => ReactNode; onUserClick?: (userId: string) => void; onFeedItemClick?: (feedItemId: string) => void; onInternalLinkClick?: (data: InternalLinkData) => void; @@ -48,8 +47,7 @@ const DesktopChat: FC = (props) => { titleRightContent, onMessagesAmountChange, directParent, - isJoinPending, - onJoinCommon, + renderChatInput, onUserClick, onFeedItemClick, onInternalLinkClick, @@ -123,8 +121,7 @@ const DesktopChat: FC = (props) => { isAuthorized={Boolean(user)} onMessagesAmountChange={onMessagesAmountChange} directParent={directParent} - isJoinPending={isJoinPending} - onJoinCommon={onJoinCommon} + renderChatInput={renderChatInput} onUserClick={onUserClick} onFeedItemClick={onFeedItemClick} onInternalLinkClick={onInternalLinkClick} diff --git a/src/pages/commonFeed/components/FeedLayout/components/MobileChat/MobileChat.tsx b/src/pages/commonFeed/components/FeedLayout/components/MobileChat/MobileChat.tsx index c06977558f..0e1d97a49b 100644 --- a/src/pages/commonFeed/components/FeedLayout/components/MobileChat/MobileChat.tsx +++ b/src/pages/commonFeed/components/FeedLayout/components/MobileChat/MobileChat.tsx @@ -33,9 +33,8 @@ interface ChatProps { rightHeaderContent?: ReactNode; onMessagesAmountChange?: (newMessagesAmount: number) => void; directParent?: DirectParent | null; - isJoinPending?: boolean; + renderChatInput?: () => ReactNode; onClose: () => void; - onJoinCommon?: () => void; onUserClick?: (userId: string) => void; onFeedItemClick?: (feedItemId: string) => void; onInternalLinkClick?: (data: InternalLinkData) => void; @@ -54,8 +53,7 @@ const MobileChat: FC = (props) => { rightHeaderContent, onMessagesAmountChange, directParent, - isJoinPending, - onJoinCommon, + renderChatInput, onClose, onUserClick, onFeedItemClick, @@ -154,8 +152,7 @@ const MobileChat: FC = (props) => { lastSeenItem={chatItem.lastSeenItem} onMessagesAmountChange={onMessagesAmountChange} directParent={directParent} - isJoinPending={isJoinPending} - onJoinCommon={onJoinCommon} + renderChatInput={renderChatInput} onUserClick={onUserClick} onFeedItemClick={onFeedItemClick} onInternalLinkClick={onInternalLinkClick} From d4ba822749d79fbbc10f8f908246a000025bdc57 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 12:35:59 +0300 Subject: [PATCH 06/22] move join related logic to common feed page component --- src/pages/commonFeed/CommonFeed.module.scss | 16 ++++ src/pages/commonFeed/CommonFeed.tsx | 82 ++++++++++++++++++- .../components/FeedLayout/FeedLayout.tsx | 54 +----------- .../commonFeed/hooks/useCommonData/index.ts | 3 + .../commonFeed/hooks/useCommonData/types.ts | 1 + 5 files changed, 104 insertions(+), 52 deletions(-) diff --git a/src/pages/commonFeed/CommonFeed.module.scss b/src/pages/commonFeed/CommonFeed.module.scss index 68d3886211..443b1de73d 100644 --- a/src/pages/commonFeed/CommonFeed.module.scss +++ b/src/pages/commonFeed/CommonFeed.module.scss @@ -31,3 +31,19 @@ left: 0; padding-bottom: var(--safe-area-inset-bottom); } + +.chatInputLoaderWrapper { + width: 100%; + display: flex; + align-items: center; + justify-content: center; +} + +.chatInputText { + width: 100%; + margin-right: 0.3125rem; + font-size: 0.875rem; + color: var(--primary-fill); + text-align: center; + cursor: pointer; +} diff --git a/src/pages/commonFeed/CommonFeed.tsx b/src/pages/commonFeed/CommonFeed.tsx index c7fe367f48..502396c175 100644 --- a/src/pages/commonFeed/CommonFeed.tsx +++ b/src/pages/commonFeed/CommonFeed.tsx @@ -15,10 +15,13 @@ import { CommonEventToListener, } from "@/events"; import { selectUser } from "@/pages/Auth/store/selectors"; +import { MembershipRequestModal } from "@/pages/OldCommon/components"; import { FeedItemBaseContent, FeedItemBaseContentProps } from "@/pages/common"; +import { JoinProjectModal } from "@/pages/common/components/JoinProjectModal"; +import { useJoinProjectAutomatically } from "@/pages/common/hooks"; import { CommonAction, QueryParamKey } from "@/shared/constants"; import { useRoutesContext } from "@/shared/contexts"; -import { useQueryParams } from "@/shared/hooks"; +import { useAuthorizedModal, useQueryParams } from "@/shared/hooks"; import { useCommonFeedItems, useUserCommonIds } from "@/shared/hooks/useCases"; import { useCommonPinnedFeedItems } from "@/shared/hooks/useCases/useCommonPinnedFeedItems"; import { RightArrowThinIcon } from "@/shared/icons"; @@ -33,6 +36,7 @@ import { CirclesPermissions, CommonFeed, CommonMember } from "@/shared/models"; import { Loader, NotFound, PureCommonTopNavigation } from "@/shared/ui-kit"; import { checkIsAutomaticJoin, + checkIsProject, getCommonPageAboutTabPath, } from "@/shared/utils"; import { @@ -148,6 +152,31 @@ const CommonFeedComponent: FC = (props) => { fetch: fetchCommonFeedItems, } = useCommonFeedItems(commonId, commonFeedItemIdsForNotListening); + const { + isModalOpen: isCommonJoinModalOpen, + onOpen: onCommonJoinModalOpen, + onClose: onCommonJoinModalClose, + } = useAuthorizedModal(); + const { + isModalOpen: isProjectJoinModalOpen, + onOpen: onProjectJoinModalOpen, + onClose: onProjectJoinModalClose, + } = useAuthorizedModal(); + const { + canJoinProjectAutomatically, + isJoinPending, + onJoinProjectAutomatically, + } = useJoinProjectAutomatically( + commonMember, + commonData?.common, + commonData?.parentCommon, + ); + const onJoinCommon = checkIsProject(commonData?.common) + ? canJoinProjectAutomatically + ? onJoinProjectAutomatically + : onProjectJoinModalOpen + : onCommonJoinModalOpen; + const sharedFeedItem = useSelector(selectSharedFeedItem); const topFeedItems = useMemo(() => { const items: FeedLayoutItem[] = []; @@ -200,6 +229,31 @@ const CommonFeedComponent: FC = (props) => { [dispatch], ); + const renderChatInput = (): ReactNode => { + if (commonMember) { + return; + } + if (isJoinPending) { + return ( +
+ +
+ ); + } + + let joinButtonText = "Join"; + + if (commonData?.rootCommon && !isRootCommonMember) { + joinButtonText = `Join ${commonData?.rootCommon.name}`; + } + + return ( + onJoinCommon()}> + {joinButtonText} + + ); + }; + useEffect(() => { if ( !isCommonDataFetched || @@ -306,6 +360,12 @@ const CommonFeedComponent: FC = (props) => { getProfilePagePath, ]); + useEffect(() => { + if (commonMember && isCommonJoinModalOpen) { + onCommonJoinModalClose(); + } + }, [commonMember?.id]); + if (!isDataFetched) { return (
@@ -374,7 +434,6 @@ const CommonFeedComponent: FC = (props) => { } common={commonData.common} - parentCommon={commonData.parentCommon} governance={commonData.governance} commonMember={commonMember} topFeedItems={topFeedItems} @@ -388,8 +447,27 @@ const CommonFeedComponent: FC = (props) => { onActiveItemDataChange={onActiveItemDataChange} outerStyles={feedLayoutOuterStyles} settings={feedLayoutSettings} + renderChatInput={renderChatInput} /> + {commonData.common && commonData.governance && ( + <> + + null} + /> + + )} ); }; diff --git a/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx b/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx index d9ff6db159..63909afdf4 100644 --- a/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx +++ b/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx @@ -106,7 +106,6 @@ interface FeedLayoutProps { ) => ReactNode; topContent?: ReactNode; common?: Common; - parentCommon?: Common; governance?: Governance; commonMember: (CommonMember & CirclesPermissions) | null; feedItems: FeedLayoutItem[] | null; @@ -134,6 +133,7 @@ interface FeedLayoutProps { ) => void; outerStyles?: FeedLayoutOuterStyles; settings?: FeedLayoutSettings; + renderChatInput?: () => ReactNode; } const FeedLayout: ForwardRefRenderFunction = ( @@ -147,7 +147,6 @@ const FeedLayout: ForwardRefRenderFunction = ( common: outerCommon, governance: outerGovernance, commonMember: outerCommonMember, - parentCommon, feedItems, topFeedItems = [], loading, @@ -166,6 +165,7 @@ const FeedLayout: ForwardRefRenderFunction = ( onFeedItemSelect, outerStyles, settings, + renderChatInput, } = props; const { getCommonPagePath } = useRoutesContext(); const refsByItemId = useRef>({}); @@ -191,27 +191,7 @@ const FeedLayout: ForwardRefRenderFunction = ( } = useCommonMember({ shouldAutoReset: false, }); - const { - isModalOpen: isCommonJoinModalOpen, - onOpen: onCommonJoinModalOpen, - onClose: onCommonJoinModalClose, - } = useAuthorizedModal(); - const { - isModalOpen: isProjectJoinModalOpen, - onOpen: onProjectJoinModalOpen, - onClose: onProjectJoinModalClose, - } = useAuthorizedModal(); const commonMember = outerCommonMember || fetchedCommonMember; - const { - canJoinProjectAutomatically, - isJoinPending, - onJoinProjectAutomatically, - } = useJoinProjectAutomatically(commonMember, outerCommon, parentCommon); - const onJoinCommon = checkIsProject(outerCommon) - ? canJoinProjectAutomatically - ? onJoinProjectAutomatically - : onProjectJoinModalOpen - : onCommonJoinModalOpen; const userForProfile = useUserForProfile(); const governance = outerGovernance || fetchedGovernance; const maxChatSize = @@ -560,12 +540,6 @@ const FeedLayout: ForwardRefRenderFunction = ( [getCommonPagePath, handleFeedItemClick], ); - useEffect(() => { - if (commonMember && isCommonJoinModalOpen) { - onCommonJoinModalClose(); - } - }, [commonMember?.id]); - useEffect(() => { if (!outerGovernance && selectedItemCommonData?.id) { fetchGovernance(selectedItemCommonData.id); @@ -736,8 +710,7 @@ const FeedLayout: ForwardRefRenderFunction = ( titleRightContent={followFeedItemEl} onMessagesAmountChange={handleMessagesAmountChange} directParent={outerCommon?.directParent} - onJoinCommon={onJoinCommon} - isJoinPending={isJoinPending} + renderChatInput={renderChatInput} onUserClick={handleUserClick} onFeedItemClick={handleFeedItemClick} onInternalLinkClick={handleInternalLinkClick} @@ -762,8 +735,7 @@ const FeedLayout: ForwardRefRenderFunction = ( onMessagesAmountChange={handleMessagesAmountChange} directParent={outerCommon?.directParent} onClose={handleMobileChatClose} - onJoinCommon={onJoinCommon} - isJoinPending={isJoinPending} + renderChatInput={renderChatInput} onUserClick={handleUserClick} onFeedItemClick={handleFeedItemClick} onInternalLinkClick={handleInternalLinkClick} @@ -786,24 +758,6 @@ const FeedLayout: ForwardRefRenderFunction = ( )} )} - {governance && outerCommon && ( - <> - - null} - /> - - )} {userForProfile.userForProfileData && (!isTabletView ? ( { const [ parentCommons, subCommons, + rootCommon, rootCommonMember, rootCommonGovernance, ] = await Promise.all([ CommonService.getAllParentCommonsForCommon(common), CommonService.getCommonsByDirectParentIds([common.id]), + rootCommonId ? CommonService.getCommonById(rootCommonId) : null, rootCommonId && userId ? CommonService.getCommonMemberByUserId(rootCommonId, userId) : null, @@ -91,6 +93,7 @@ export const useCommonData = (userId?: string): Return => { subCommons, commonMembersAmount, sharedFeedItem, + rootCommon, rootCommonMember, rootCommonGovernance, parentCommon: last(parentCommons), diff --git a/src/pages/commonFeed/hooks/useCommonData/types.ts b/src/pages/commonFeed/hooks/useCommonData/types.ts index 715a04f76f..7c22aaf9e1 100644 --- a/src/pages/commonFeed/hooks/useCommonData/types.ts +++ b/src/pages/commonFeed/hooks/useCommonData/types.ts @@ -8,6 +8,7 @@ export interface Data { subCommons: Common[]; commonMembersAmount: number; sharedFeedItem: CommonFeed | null; + rootCommon?: Common | null; rootCommonMember: CommonMember | null; rootCommonGovernance: Governance | null; parentCommon?: Common; From c7249c0c470f337fe571e98d34cb25e35e4f695e Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 13:12:45 +0300 Subject: [PATCH 07/22] refactor root and parent common member fetches --- .../commonFeed/hooks/useCommonData/index.ts | 49 ++++++++++++++++--- .../commonFeed/hooks/useCommonData/types.ts | 1 + 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/pages/commonFeed/hooks/useCommonData/index.ts b/src/pages/commonFeed/hooks/useCommonData/index.ts index 5684979537..d4ba11b100 100644 --- a/src/pages/commonFeed/hooks/useCommonData/index.ts +++ b/src/pages/commonFeed/hooks/useCommonData/index.ts @@ -6,6 +6,7 @@ import { GovernanceService, } from "@/services"; import { useCommonSubscription } from "@/shared/hooks/useCases/useFullCommonData/useCommonSubscription"; +import { Common, CommonMember } from "@/shared/models"; import { State, CombinedState } from "./types"; import { useGovernanceSubscription } from "./useGovernanceSubscription"; @@ -19,6 +20,32 @@ interface Return extends CombinedState { resetCommonData: () => void; } +const getRootCommon = async ( + parentCommon?: Common | null, + rootCommonId?: string, +): Promise => { + if (parentCommon && parentCommon.id === rootCommonId) { + return parentCommon; + } + + return rootCommonId ? CommonService.getCommonById(rootCommonId) : null; +}; + +const getRootCommonMember = async ( + parentCommonMember?: CommonMember | null, + parentCommonId?: string, + rootCommonId?: string, + userId?: string, +): Promise => { + if (parentCommonMember && parentCommonId === rootCommonId) { + return parentCommonMember; + } + + return rootCommonId && userId + ? CommonService.getCommonMemberByUserId(rootCommonId, userId) + : null; +}; + export const useCommonData = (userId?: string): Return => { const [state, setState] = useState({ loading: false, @@ -65,23 +92,32 @@ export const useCommonData = (userId?: string): Return => { } const { rootCommonId } = common; + const parentCommonId = common.directParent?.commonId; const [ parentCommons, subCommons, - rootCommon, - rootCommonMember, + parentCommonMember, rootCommonGovernance, ] = await Promise.all([ CommonService.getAllParentCommonsForCommon(common), CommonService.getCommonsByDirectParentIds([common.id]), - rootCommonId ? CommonService.getCommonById(rootCommonId) : null, - rootCommonId && userId - ? CommonService.getCommonMemberByUserId(rootCommonId, userId) + parentCommonId && userId + ? CommonService.getCommonMemberByUserId(parentCommonId, userId) : null, rootCommonId ? GovernanceService.getGovernanceByCommonId(rootCommonId) : null, ]); + const parentCommon = last(parentCommons); + const [rootCommon, rootCommonMember] = await Promise.all([ + getRootCommon(parentCommon, rootCommonId), + getRootCommonMember( + parentCommonMember, + parentCommonId, + rootCommonId, + userId, + ), + ]); setState({ loading: false, @@ -96,7 +132,8 @@ export const useCommonData = (userId?: string): Return => { rootCommon, rootCommonMember, rootCommonGovernance, - parentCommon: last(parentCommons), + parentCommon, + parentCommonMember, }, }); } catch (error) { diff --git a/src/pages/commonFeed/hooks/useCommonData/types.ts b/src/pages/commonFeed/hooks/useCommonData/types.ts index 7c22aaf9e1..e5c323771e 100644 --- a/src/pages/commonFeed/hooks/useCommonData/types.ts +++ b/src/pages/commonFeed/hooks/useCommonData/types.ts @@ -12,6 +12,7 @@ export interface Data { rootCommonMember: CommonMember | null; rootCommonGovernance: Governance | null; parentCommon?: Common; + parentCommonMember: CommonMember | null; } export type State = LoadingState; From 3d83fa5d71bcf3c57930827664549da9c91d113b Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 13:15:01 +0300 Subject: [PATCH 08/22] add root common join logic --- src/pages/commonFeed/CommonFeed.tsx | 41 ++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/pages/commonFeed/CommonFeed.tsx b/src/pages/commonFeed/CommonFeed.tsx index 502396c175..8c3d4dfac8 100644 --- a/src/pages/commonFeed/CommonFeed.tsx +++ b/src/pages/commonFeed/CommonFeed.tsx @@ -157,6 +157,11 @@ const CommonFeedComponent: FC = (props) => { onOpen: onCommonJoinModalOpen, onClose: onCommonJoinModalClose, } = useAuthorizedModal(); + const { + isModalOpen: isRootCommonJoinModalOpen, + onOpen: onRootCommonJoinModalOpen, + onClose: onRootCommonJoinModalClose, + } = useAuthorizedModal(); const { isModalOpen: isProjectJoinModalOpen, onOpen: onProjectJoinModalOpen, @@ -171,11 +176,6 @@ const CommonFeedComponent: FC = (props) => { commonData?.common, commonData?.parentCommon, ); - const onJoinCommon = checkIsProject(commonData?.common) - ? canJoinProjectAutomatically - ? onJoinProjectAutomatically - : onProjectJoinModalOpen - : onCommonJoinModalOpen; const sharedFeedItem = useSelector(selectSharedFeedItem); const topFeedItems = useMemo(() => { @@ -241,15 +241,26 @@ const CommonFeedComponent: FC = (props) => { ); } - let joinButtonText = "Join"; - if (commonData?.rootCommon && !isRootCommonMember) { - joinButtonText = `Join ${commonData?.rootCommon.name}`; + return ( + onRootCommonJoinModalOpen()} + > + Join {commonData.rootCommon.name} + + ); } + const onJoinCommon = checkIsProject(commonData?.common) + ? canJoinProjectAutomatically + ? onJoinProjectAutomatically + : onProjectJoinModalOpen + : onCommonJoinModalOpen; + return ( onJoinCommon()}> - {joinButtonText} + Join ); }; @@ -364,6 +375,9 @@ const CommonFeedComponent: FC = (props) => { if (commonMember && isCommonJoinModalOpen) { onCommonJoinModalClose(); } + if (commonMember && isRootCommonJoinModalOpen) { + onRootCommonJoinModalClose(); + } }, [commonMember?.id]); if (!isDataFetched) { @@ -468,6 +482,15 @@ const CommonFeedComponent: FC = (props) => { /> )} + {commonData.rootCommon && commonData.rootCommonGovernance && ( + + )} ); }; From 9ec46320ed6512db2a775a69b8f723decca42f3c Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 14:06:01 +0300 Subject: [PATCH 09/22] add text to join parent common --- src/pages/commonFeed/CommonFeed.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/pages/commonFeed/CommonFeed.tsx b/src/pages/commonFeed/CommonFeed.tsx index 8c3d4dfac8..9ae7df76ae 100644 --- a/src/pages/commonFeed/CommonFeed.tsx +++ b/src/pages/commonFeed/CommonFeed.tsx @@ -9,6 +9,7 @@ import React, { } from "react"; import { useDispatch, useSelector } from "react-redux"; import { useHistory } from "react-router"; +import { NavLink } from "react-router-dom"; import { CommonEvent, CommonEventEmitter, @@ -233,6 +234,7 @@ const CommonFeedComponent: FC = (props) => { if (commonMember) { return; } + if (isJoinPending) { return (
@@ -252,6 +254,21 @@ const CommonFeedComponent: FC = (props) => { ); } + if ( + isRootCommonMember && + commonData?.parentCommon && + !commonData?.parentCommonMember + ) { + return ( + + To join this space you should first join{" "} + + {commonData.parentCommon.name} + + + ); + } + const onJoinCommon = checkIsProject(commonData?.common) ? canJoinProjectAutomatically ? onJoinProjectAutomatically From 49312bb3f41544f3878002af146057e93d3140dd Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 14:20:20 +0300 Subject: [PATCH 10/22] display chat input for non-authorized users --- .../ChatComponent/ChatComponent.tsx | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/pages/common/components/ChatComponent/ChatComponent.tsx b/src/pages/common/components/ChatComponent/ChatComponent.tsx index 46f4a226f4..61a68cfa88 100644 --- a/src/pages/common/components/ChatComponent/ChatComponent.tsx +++ b/src/pages/common/components/ChatComponent/ChatComponent.tsx @@ -580,6 +580,9 @@ export default function ChatComponent({ return chatInputEl; } } + if (!isAuthorized) { + return null; + } return ( <> @@ -667,19 +670,17 @@ export default function ChatComponent({ onInternalLinkClick={onInternalLinkClick} />
- {isAuthorized && ( -
- - -
- {renderChatInput()} -
+
+ + +
+ {renderChatInput()}
- )} +
); } From 293b8fd7f0c030cc9a4495b29de1bb48edbdd2d8 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 14:39:09 +0300 Subject: [PATCH 11/22] add root common member to the common back page --- src/pages/common/BaseCommon.tsx | 4 +++ .../hooks/useCases/useGlobalCommonData.ts | 35 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/pages/common/BaseCommon.tsx b/src/pages/common/BaseCommon.tsx index e50c3c8234..4d811bfc88 100644 --- a/src/pages/common/BaseCommon.tsx +++ b/src/pages/common/BaseCommon.tsx @@ -42,16 +42,19 @@ const BaseCommon: FC = (props) => { fetched: isCommonDataFetched, fetchCommonData, } = useFullCommonData(); + const rootCommonId = commonData?.common.rootCommonId; const parentCommonId = commonData?.common.directParent?.commonId; const parentCircleId = commonData?.common.directParent?.circleId; const { fetched: isGlobalDataFetched, fetchUserRelatedData, + fetchRootCommonMemberData, fetchParentCommonMemberData, data: { commonMember, parentCommonMember, isJoinPending }, setIsJoinPending, } = useGlobalCommonData({ commonId, + rootCommonId, parentCommonId, parentCircleId, governanceCircles: commonData?.governance.circles, @@ -86,6 +89,7 @@ const BaseCommon: FC = (props) => { useEffect(() => { if (isCommonDataFetched) { + fetchRootCommonMemberData(); fetchParentCommonMemberData(); } }, [userId, parentCommonId, parentCircleId, isCommonDataFetched]); diff --git a/src/shared/hooks/useCases/useGlobalCommonData.ts b/src/shared/hooks/useCases/useGlobalCommonData.ts index fed5a64f97..65d22052cb 100644 --- a/src/shared/hooks/useCases/useGlobalCommonData.ts +++ b/src/shared/hooks/useCases/useGlobalCommonData.ts @@ -6,6 +6,7 @@ import { useUserPendingJoin } from "./useUserPendingJoin"; interface UseGlobalCommonDataArguments { commonId: string; + rootCommonId?: string; parentCommonId?: string; parentCircleId?: string; governanceCircles?: Circles; @@ -13,12 +14,14 @@ interface UseGlobalCommonDataArguments { type State = LoadingState<{ commonMember: (CommonMember & CirclesPermissions) | null; + rootCommonMember: (CommonMember & CirclesPermissions) | null; parentCommonMember: (CommonMember & CirclesPermissions) | null; isJoinPending: boolean; }>; interface Return extends State { fetchUserRelatedData: () => void; + fetchRootCommonMemberData: () => void; fetchParentCommonMemberData: () => void; setIsJoinPending: (isJoinPending: boolean) => void; } @@ -26,7 +29,13 @@ interface Return extends State { export const useGlobalCommonData = ( data: UseGlobalCommonDataArguments, ): Return => { - const { commonId, parentCommonId, parentCircleId, governanceCircles } = data; + const { + commonId, + rootCommonId, + parentCommonId, + parentCircleId, + governanceCircles, + } = data; const { loading: isCommonMemberLoading, fetched: isCommonMemberFetched, @@ -38,6 +47,16 @@ export const useGlobalCommonData = ( commonId, governanceCircles, }); + const { + loading: isRootCommonMemberLoading, + fetched: isRootCommonMemberFetched, + data: rootCommonMember, + fetchCommonMember: fetchRootCommonMember, + setCommonMember: setRootCommonMember, + resetCommonMember: resetRootCommonMember, + } = useCommonMember({ + shouldAutoReset: false, + }); const { loading: isParentCommonMemberLoading, fetched: isParentCommonMemberFetched, @@ -58,13 +77,16 @@ export const useGlobalCommonData = ( const isGlobalDataLoading = isCommonMemberLoading || isPendingJoinCheckLoading || + isRootCommonMemberLoading || isParentCommonMemberLoading; const isGlobalDataFetched = isCommonMemberFetched && isPendingJoinCheckFinished && + isRootCommonMemberFetched && isParentCommonMemberFetched; const fetchUserRelatedData = useCallback(() => { + resetRootCommonMember(); resetParentCommonMember(); fetchCommonMember(commonId, {}, true); checkUserPendingJoin(commonId, { @@ -77,9 +99,18 @@ export const useGlobalCommonData = ( parentCircleId, fetchCommonMember, checkUserPendingJoin, + resetRootCommonMember, resetParentCommonMember, ]); + const fetchRootCommonMemberData = useCallback(() => { + if (rootCommonId) { + fetchRootCommonMember(rootCommonId, {}, true); + } else { + setRootCommonMember(null); + } + }, [rootCommonId, fetchRootCommonMember, setRootCommonMember]); + const fetchParentCommonMemberData = useCallback(() => { if (parentCommonId) { fetchParentCommonMember(parentCommonId, {}, true); @@ -93,10 +124,12 @@ export const useGlobalCommonData = ( fetched: isGlobalDataFetched, data: { commonMember, + rootCommonMember, parentCommonMember, isJoinPending, }, fetchUserRelatedData, + fetchRootCommonMemberData, fetchParentCommonMemberData, setIsJoinPending, }; From cb6453130e6b6e4c0d0156d79f8676c941511991 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 14:45:05 +0300 Subject: [PATCH 12/22] pass root common to the data provider of back page --- src/pages/common/BaseCommon.tsx | 1 + .../CommonContent/CommonContent.tsx | 3 +++ .../providers/CommonData/CommonData.tsx | 4 ++++ .../common/providers/CommonData/context.ts | 1 + .../hooks/useCases/useFullCommonData/index.ts | 20 ++++++++++++++++++- .../hooks/useCases/useFullCommonData/types.ts | 1 + 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/pages/common/BaseCommon.tsx b/src/pages/common/BaseCommon.tsx index 4d811bfc88..883fc84fe6 100644 --- a/src/pages/common/BaseCommon.tsx +++ b/src/pages/common/BaseCommon.tsx @@ -120,6 +120,7 @@ const BaseCommon: FC = (props) => { settings={settings} defaultTab={defaultTab} common={commonData.common} + rootCommon={commonData.rootCommon} parentCommon={commonData.parentCommon} governance={commonData.governance} parentCommons={commonData.parentCommons} diff --git a/src/pages/common/components/CommonContent/CommonContent.tsx b/src/pages/common/components/CommonContent/CommonContent.tsx index d057e043f0..c79a0a69d3 100644 --- a/src/pages/common/components/CommonContent/CommonContent.tsx +++ b/src/pages/common/components/CommonContent/CommonContent.tsx @@ -28,6 +28,7 @@ interface CommonContentProps { settings: CommonPageSettings; defaultTab: string; common: Common; + rootCommon: Common | null; parentCommon?: Common; governance: Governance; parentCommons: Common[]; @@ -51,6 +52,7 @@ const CommonContent: FC = (props) => { subCommons, isGlobalDataFetched, commonMember, + rootCommon, parentCommonMember, parentCommon, parentCommonSubCommons, @@ -99,6 +101,7 @@ const CommonContent: FC = (props) => { = (props) => { isGlobalDataFetched, parentCommons, subCommons, + rootCommon, parentCommon, parentCommonSubCommons, supportersData, @@ -219,6 +221,7 @@ const CommonData: FC = (props) => { governance, parentCommons, subCommons, + rootCommon, parentCommon, parentCommonSubCommons, supportersData, @@ -237,6 +240,7 @@ const CommonData: FC = (props) => { governance, parentCommons, subCommons, + rootCommon, parentCommon, parentCommonSubCommons, supportersData, diff --git a/src/pages/common/providers/CommonData/context.ts b/src/pages/common/providers/CommonData/context.ts index 2bd24b53a5..68e6767067 100644 --- a/src/pages/common/providers/CommonData/context.ts +++ b/src/pages/common/providers/CommonData/context.ts @@ -21,6 +21,7 @@ interface Data { governance: Governance; parentCommons: Common[]; subCommons: Common[]; + rootCommon: Common | null; parentCommon?: Common; parentCommonSubCommons: Common[]; supportersData: SupportersData | null; diff --git a/src/shared/hooks/useCases/useFullCommonData/index.ts b/src/shared/hooks/useCases/useFullCommonData/index.ts index 4f1be2da70..51cf684699 100644 --- a/src/shared/hooks/useCases/useFullCommonData/index.ts +++ b/src/shared/hooks/useCases/useFullCommonData/index.ts @@ -2,6 +2,7 @@ import { useCallback, useState } from "react"; import { last } from "lodash"; import { CommonService, GovernanceService } from "@/services"; import { useSupportersData } from "@/shared/hooks/useCases"; +import { Common } from "@/shared/models"; import { State, CombinedState } from "./types"; import { useCommonSubscription } from "./useCommonSubscription"; import { useGovernanceSubscription } from "./useGovernanceSubscription"; @@ -14,6 +15,17 @@ interface Return extends CombinedState { resetCommonData: () => void; } +const getRootCommon = async ( + parentCommon?: Common | null, + rootCommonId?: string, +): Promise => { + if (parentCommon && parentCommon.id === rootCommonId) { + return parentCommon; + } + + return rootCommonId ? CommonService.getCommonById(rootCommonId) : null; +}; + export const useFullCommonData = (): Return => { const [state, setState] = useState({ loading: false, @@ -62,6 +74,11 @@ export const useFullCommonData = (): Return => { ]) : [], ]); + const parentCommon = last(parentCommons); + const rootCommon = await getRootCommon( + parentCommon, + common.rootCommonId, + ); setState({ loading: false, @@ -71,7 +88,8 @@ export const useFullCommonData = (): Return => { governance, parentCommons, subCommons, - parentCommon: last(parentCommons), + rootCommon, + parentCommon, parentCommonSubCommons, }, }); diff --git a/src/shared/hooks/useCases/useFullCommonData/types.ts b/src/shared/hooks/useCases/useFullCommonData/types.ts index 2ed48b8cc8..ff56541d4b 100644 --- a/src/shared/hooks/useCases/useFullCommonData/types.ts +++ b/src/shared/hooks/useCases/useFullCommonData/types.ts @@ -6,6 +6,7 @@ export interface Data { governance: Governance; parentCommons: Common[]; subCommons: Common[]; + rootCommon: Common | null; parentCommon?: Common; parentCommonSubCommons: Common[]; } From 2c7d8b984197fc7d128efb93b9542da47706eef7 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 14:48:14 +0300 Subject: [PATCH 13/22] add root and parent common member to the back page context --- src/pages/common/BaseCommon.tsx | 3 ++- src/pages/common/components/CommonContent/CommonContent.tsx | 3 +++ src/pages/common/providers/CommonData/CommonData.tsx | 6 ++++++ src/pages/common/providers/CommonData/context.ts | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pages/common/BaseCommon.tsx b/src/pages/common/BaseCommon.tsx index 883fc84fe6..f49bdce588 100644 --- a/src/pages/common/BaseCommon.tsx +++ b/src/pages/common/BaseCommon.tsx @@ -50,7 +50,7 @@ const BaseCommon: FC = (props) => { fetchUserRelatedData, fetchRootCommonMemberData, fetchParentCommonMemberData, - data: { commonMember, parentCommonMember, isJoinPending }, + data: { commonMember, rootCommonMember, parentCommonMember, isJoinPending }, setIsJoinPending, } = useGlobalCommonData({ commonId, @@ -129,6 +129,7 @@ const BaseCommon: FC = (props) => { supportersData={commonData.supportersData} isGlobalDataFetched={isGlobalDataFetched} commonMember={commonMember} + rootCommonMember={rootCommonMember} parentCommonMember={parentCommonMember} isJoinPending={isJoinPending} setIsJoinPending={setIsJoinPending} diff --git a/src/pages/common/components/CommonContent/CommonContent.tsx b/src/pages/common/components/CommonContent/CommonContent.tsx index c79a0a69d3..ba1b9fad07 100644 --- a/src/pages/common/components/CommonContent/CommonContent.tsx +++ b/src/pages/common/components/CommonContent/CommonContent.tsx @@ -37,6 +37,7 @@ interface CommonContentProps { supportersData: SupportersData | null; isGlobalDataFetched: boolean; commonMember: (CommonMember & CirclesPermissions) | null; + rootCommonMember: CommonMember | null; parentCommonMember: CommonMember | null; isJoinPending: boolean; setIsJoinPending: (isJoinPending: boolean) => void; @@ -53,6 +54,7 @@ const CommonContent: FC = (props) => { isGlobalDataFetched, commonMember, rootCommon, + rootCommonMember, parentCommonMember, parentCommon, parentCommonSubCommons, @@ -105,6 +107,7 @@ const CommonContent: FC = (props) => { parentCommon={parentCommon} governance={governance} commonMember={commonMember} + rootCommonMember={rootCommonMember} parentCommonMember={parentCommonMember} isGlobalDataFetched={isGlobalDataFetched} parentCommons={parentCommons} diff --git a/src/pages/common/providers/CommonData/CommonData.tsx b/src/pages/common/providers/CommonData/CommonData.tsx index d80019e38b..08e80c7ec7 100644 --- a/src/pages/common/providers/CommonData/CommonData.tsx +++ b/src/pages/common/providers/CommonData/CommonData.tsx @@ -37,6 +37,7 @@ interface CommonDataProps { common: Common; governance: Governance; commonMember: (CommonMember & CirclesPermissions) | null; + rootCommonMember: CommonMember | null; parentCommonMember: CommonMember | null; isGlobalDataFetched: boolean; parentCommons: Common[]; @@ -55,6 +56,7 @@ const CommonData: FC = (props) => { common, governance, commonMember, + rootCommonMember, parentCommonMember, isGlobalDataFetched, parentCommons, @@ -222,7 +224,9 @@ const CommonData: FC = (props) => { parentCommons, subCommons, rootCommon, + rootCommonMember, parentCommon, + parentCommonMember, parentCommonSubCommons, supportersData, isJoinAllowed, @@ -241,7 +245,9 @@ const CommonData: FC = (props) => { parentCommons, subCommons, rootCommon, + rootCommonMember, parentCommon, + parentCommonMember, parentCommonSubCommons, supportersData, isJoinAllowed, diff --git a/src/pages/common/providers/CommonData/context.ts b/src/pages/common/providers/CommonData/context.ts index 68e6767067..7d6677c1f1 100644 --- a/src/pages/common/providers/CommonData/context.ts +++ b/src/pages/common/providers/CommonData/context.ts @@ -22,7 +22,9 @@ interface Data { parentCommons: Common[]; subCommons: Common[]; rootCommon: Common | null; + rootCommonMember: CommonMember | null; parentCommon?: Common; + parentCommonMember: CommonMember | null; parentCommonSubCommons: Common[]; supportersData: SupportersData | null; isJoinAllowed: boolean; From c9e659728654f697ea969b07e7afed2e6785eeb6 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 19 Sep 2023 15:13:28 +0300 Subject: [PATCH 14/22] display "Join via common page" on the back page --- .../CommonEntranceJoin/CommonEntranceJoin.tsx | 34 +++++++++++++++++-- .../providers/CommonData/CommonData.tsx | 2 ++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonEntranceInfo/components/CommonEntranceJoin/CommonEntranceJoin.tsx b/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonEntranceInfo/components/CommonEntranceJoin/CommonEntranceJoin.tsx index 41513abbb2..1a943c8789 100644 --- a/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonEntranceInfo/components/CommonEntranceJoin/CommonEntranceJoin.tsx +++ b/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonEntranceInfo/components/CommonEntranceJoin/CommonEntranceJoin.tsx @@ -15,9 +15,16 @@ interface CommonEntranceJoinProps { const CommonEntranceJoin: FC = (props) => { const { withJoinRequest = false, common, isProject } = props; - const { parentCommon, commonMember, isJoinAllowed, onJoinCommon } = - useCommonDataContext(); - const { getCommonPagePath } = useRoutesContext(); + const { + parentCommon, + parentCommonMember, + commonMember, + rootCommon, + rootCommonMember, + isJoinAllowed, + onJoinCommon, + } = useCommonDataContext(); + const { getCommonPagePath, getCommonPageAboutTabPath } = useRoutesContext(); const { canJoinProjectAutomatically, isJoinPending, @@ -39,6 +46,27 @@ const CommonEntranceJoin: FC = (props) => { common. Only common members can join the space.

)} + {!commonMember && rootCommon && !rootCommonMember && ( +

+ Join via{" "} + + common + {" "} + page +

+ )} + {!commonMember && + rootCommonMember && + parentCommon && + !parentCommonMember && ( +

+ Join via{" "} + + common + {" "} + page +

+ )} {withJoinRequest && (isJoinAllowed || isJoinPending) && (