Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join common from a space #2076 #2091

Merged
merged 23 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f912cca
make parent common name in the back page to be a link
andreymikhadyuk Sep 18, 2023
d2563ac
check autojoin ability in spaces redirection
andreymikhadyuk Sep 18, 2023
1087153
add rootCommonId to Common model
andreymikhadyuk Sep 18, 2023
3e51f35
add hasPublicItems field usage
andreymikhadyuk Sep 18, 2023
f5055d6
add renderChatInput prop to ChatComponent
andreymikhadyuk Sep 19, 2023
d4ba822
move join related logic to common feed page component
andreymikhadyuk Sep 19, 2023
c7249c0
refactor root and parent common member fetches
andreymikhadyuk Sep 19, 2023
3d83fa5
add root common join logic
andreymikhadyuk Sep 19, 2023
9ec4632
add text to join parent common
andreymikhadyuk Sep 19, 2023
49312bb
display chat input for non-authorized users
andreymikhadyuk Sep 19, 2023
293b8fd
add root common member to the common back page
andreymikhadyuk Sep 19, 2023
cb64531
pass root common to the data provider of back page
andreymikhadyuk Sep 19, 2023
2c7d8b9
add root and parent common member to the back page context
andreymikhadyuk Sep 19, 2023
c9e6597
display "Join via common page" on the back page
andreymikhadyuk Sep 19, 2023
b22a08b
remove space's automatic acceptance check
andreymikhadyuk Sep 19, 2023
c403776
display root and parent common names in join text
andreymikhadyuk Sep 19, 2023
67e1515
move root common member check after auth to separate useEffect
andreymikhadyuk Sep 19, 2023
47e61d5
skip redirecting after log in for common feed pages
andreymikhadyuk Sep 19, 2023
e663da4
move root and parent common members fetch to global data
andreymikhadyuk Sep 19, 2023
6d9df4c
fix membership modals showing based on global data fetched flag
andreymikhadyuk Sep 19, 2023
4033e3d
Merge branch 'dev' into feature/CW-2076-join-common-from-space
andreymikhadyuk Sep 26, 2023
cfbc6da
remove getRootCommon duplication
andreymikhadyuk Sep 26, 2023
5e9c6c3
use parentCommons array to avoid extra root common fetch
andreymikhadyuk Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/pages/Login/containers/LoginContainer/LoginContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ErrorCode,
ScreenSize,
QueryParamKey,
ROUTE_PATHS,
} from "@/shared/constants";
import { useQueryParams, useRemoveQueryParams } from "@/shared/hooks";
import { ModalProps, ModalType } from "@/shared/interfaces";
Expand All @@ -24,6 +25,7 @@ import {
emptyFunction,
getInboxPagePath,
isGeneralError,
matchOneOfRoutes,
} from "@/shared/utils";
import { isFirebaseError } from "@/shared/utils/firebase";
import { LoginModalType } from "../../../Auth/interface";
Expand Down Expand Up @@ -104,9 +106,24 @@ const LoginContainer: FC = () => {
} else {
handleClose();
}
history.push(getInboxPagePath());
if (
!matchOneOfRoutes(
history.location.pathname,
[ROUTE_PATHS.COMMON, ROUTE_PATHS.V04_COMMON],
{
exact: false,
},
)
) {
history.push(getInboxPagePath());
}
},
[removeQueryParams, handleClose, shouldShowUserDetailsAfterSignUp],
[
removeQueryParams,
handleClose,
shouldShowUserDetailsAfterSignUp,
history.location.pathname,
],
);

const handleAuthButtonClick = useCallback(
Expand Down
8 changes: 7 additions & 1 deletion src/pages/common/BaseCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ const BaseCommon: FC<CommonProps> = (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 },
data: { commonMember, rootCommonMember, parentCommonMember, isJoinPending },
setIsJoinPending,
} = useGlobalCommonData({
commonId,
rootCommonId,
parentCommonId,
parentCircleId,
governanceCircles: commonData?.governance.circles,
Expand Down Expand Up @@ -86,6 +89,7 @@ const BaseCommon: FC<CommonProps> = (props) => {

useEffect(() => {
if (isCommonDataFetched) {
fetchRootCommonMemberData();
fetchParentCommonMemberData();
}
}, [userId, parentCommonId, parentCircleId, isCommonDataFetched]);
Expand Down Expand Up @@ -116,6 +120,7 @@ const BaseCommon: FC<CommonProps> = (props) => {
settings={settings}
defaultTab={defaultTab}
common={commonData.common}
rootCommon={commonData.rootCommon}
parentCommon={commonData.parentCommon}
governance={commonData.governance}
parentCommons={commonData.parentCommons}
Expand All @@ -124,6 +129,7 @@ const BaseCommon: FC<CommonProps> = (props) => {
supportersData={commonData.supportersData}
isGlobalDataFetched={isGlobalDataFetched}
commonMember={commonMember}
rootCommonMember={rootCommonMember}
parentCommonMember={parentCommonMember}
isJoinPending={isJoinPending}
setIsJoinPending={setIsJoinPending}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
157 changes: 77 additions & 80 deletions src/pages/common/components/ChatComponent/ChatComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -131,8 +130,7 @@ export default function ChatComponent({
isCommonMemberFetched,
onMessagesAmountChange,
directParent,
isJoinPending = false,
onJoinCommon,
renderChatInput: renderChatInputOuter,
onUserClick,
onFeedItemClick,
onInternalLinkClick,
Expand Down Expand Up @@ -569,19 +567,74 @@ export default function ChatComponent({
}
}, [discussionMessages.length]);

const renderJoinCommonContent = (): ReactNode => {
if (isJoinPending) {
return (
<div className={styles.loaderWrapper}>
<Loader />
</div>
);
const renderChatInput = (): ReactNode => {
const shouldHideChatInput = !isChatChannel && (!hasAccess || isHidden);

if (shouldHideChatInput) {
return null;
}
if (!isChatChannel) {
const chatInputEl = renderChatInputOuter?.();

if (chatInputEl || chatInputEl === null) {
return chatInputEl;
}
}
if (!isAuthorized) {
return null;
}

return (
<span className={styles.permissionsText} onClick={onJoinCommon}>
Join
</span>
<>
<ButtonIcon
className={styles.addFilesIcon}
onClick={() => {
document.getElementById("file")?.click();
}}
>
<PlusIcon />
</ButtonIcon>
<input
id="file"
type="file"
onChange={uploadFiles}
style={{ display: "none" }}
multiple
accept={ACCEPTED_EXTENSIONS}
/>
<BaseTextEditor
inputContainerRef={inputContainerRef}
emojiContainerClassName={classNames({
[styles.emojiContainer]: isMultiLineInput,
})}
size={TextEditorSize.Auto}
editorRef={editorRef}
className={classNames(styles.messageInput, {
[styles.messageInputEmpty]: checkIsTextEditorValueEmpty(message),
})}
classNameRtl={styles.messageInputRtl}
elementStyles={{
emoji: classNames({
[styles.singleEmojiText]: emojiCount.isSingleEmoji,
[styles.multipleEmojiText]: emojiCount.isMultipleEmoji,
}),
}}
value={message}
onChange={setMessage}
placeholder="What do you think?"
onKeyDown={onEnterKeyDown}
users={users}
shouldReinitializeEditor={shouldReinitializeEditor}
onClearFinished={onClearFinished}
/>
<button
className={styles.sendIcon}
onClick={sendChatMessage}
disabled={!canSendMessage}
>
<SendIcon />
</button>
</>
);
};

Expand Down Expand Up @@ -618,73 +671,17 @@ export default function ChatComponent({
onInternalLinkClick={onInternalLinkClick}
/>
</div>
{isAuthorized && (
<div className={styles.bottomChatContainer}>
<MessageReply users={users} />
<ChatFilePreview />
<div
className={classNames(styles.chatInputWrapper, {
[styles.chatInputWrapperMultiLine]: isMultiLineInput,
})}
>
{!isChatChannel && (!commonMember || !hasAccess || isHidden) ? (
renderJoinCommonContent()
) : (
<>
<ButtonIcon
className={styles.addFilesIcon}
onClick={() => {
document.getElementById("file")?.click();
}}
>
<PlusIcon />
</ButtonIcon>
<input
id="file"
type="file"
onChange={uploadFiles}
style={{ display: "none" }}
multiple
accept={ACCEPTED_EXTENSIONS}
/>
<BaseTextEditor
inputContainerRef={inputContainerRef}
emojiContainerClassName={classNames({
[styles.emojiContainer]: isMultiLineInput,
})}
size={TextEditorSize.Auto}
editorRef={editorRef}
className={classNames(styles.messageInput, {
[styles.messageInputEmpty]:
checkIsTextEditorValueEmpty(message),
})}
classNameRtl={styles.messageInputRtl}
elementStyles={{
emoji: classNames({
[styles.singleEmojiText]: emojiCount.isSingleEmoji,
[styles.multipleEmojiText]: emojiCount.isMultipleEmoji,
}),
}}
value={message}
onChange={setMessage}
placeholder="What do you think?"
onKeyDown={onEnterKeyDown}
users={users}
shouldReinitializeEditor={shouldReinitializeEditor}
onClearFinished={onClearFinished}
/>
<button
className={styles.sendIcon}
onClick={sendChatMessage}
disabled={!canSendMessage}
>
<SendIcon />
</button>
</>
)}
</div>
<div className={styles.bottomChatContainer}>
<MessageReply users={users} />
<ChatFilePreview />
<div
className={classNames(styles.chatInputWrapper, {
[styles.chatInputWrapperMultiLine]: isMultiLineInput,
})}
>
{renderChatInput()}
</div>
)}
</div>
</div>
);
}
6 changes: 6 additions & 0 deletions src/pages/common/components/CommonContent/CommonContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface CommonContentProps {
settings: CommonPageSettings;
defaultTab: string;
common: Common;
rootCommon: Common | null;
parentCommon?: Common;
governance: Governance;
parentCommons: Common[];
Expand All @@ -36,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;
Expand All @@ -51,6 +53,8 @@ const CommonContent: FC<CommonContentProps> = (props) => {
subCommons,
isGlobalDataFetched,
commonMember,
rootCommon,
rootCommonMember,
parentCommonMember,
parentCommon,
parentCommonSubCommons,
Expand Down Expand Up @@ -99,9 +103,11 @@ const CommonContent: FC<CommonContentProps> = (props) => {
<CommonDataProvider
settings={settings}
common={common}
rootCommon={rootCommon}
parentCommon={parentCommon}
governance={governance}
commonMember={commonMember}
rootCommonMember={rootCommonMember}
parentCommonMember={parentCommonMember}
isGlobalDataFetched={isGlobalDataFetched}
parentCommons={parentCommons}
Expand Down
Loading