From 1adf54e0be95ae81e96404767060265c897bf307 Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Thu, 26 Oct 2023 19:39:51 +0200 Subject: [PATCH] fix: issue with some edge cases not working --- src/script/auth/page/ConversationJoin.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/script/auth/page/ConversationJoin.tsx b/src/script/auth/page/ConversationJoin.tsx index a2d1e258c6b9..b8892e3b5525 100644 --- a/src/script/auth/page/ConversationJoin.tsx +++ b/src/script/auth/page/ConversationJoin.tsx @@ -17,7 +17,7 @@ * */ -import React, {useEffect, useState} from 'react'; +import React, {useEffect, useMemo, useState} from 'react'; import type {RegisterData} from '@wireapp/api-client/lib/auth'; import {BackendErrorLabel} from '@wireapp/api-client/lib/http'; @@ -74,9 +74,8 @@ const ConversationJoinComponent = ({ const nameInput = React.useRef(null); const {formatMessage: _} = useIntl(); - const conversationHasPassword = conversationInfo?.has_password; - const invalidConversationPassword = - conversationError && conversationError.label === BackendErrorLabel.INVALID_CONVERSATION_PASSWORD; + const conversationHasPassword = useMemo(() => conversationInfo?.has_password, [conversationInfo]); + const [accentColor] = useState(AccentColor.STRONG_BLUE); const [isJoinGuestLinkPasswordModalOpen, setIsJoinGuestLinkPasswordModalOpen] = useState(false); const [conversationCode, setConversationCode] = useState(); @@ -95,10 +94,6 @@ const ConversationJoinComponent = ({ const isWirePublicInstance = Config.getConfig().BRAND_NAME === 'Wire'; - useEffect(() => { - setIsJoinGuestLinkPasswordModalOpen(!!invalidConversationPassword); - }, [invalidConversationPassword]); - useEffect(() => { const localConversationCode = UrlUtil.getURLParameter(QUERY_KEY.CONVERSATION_CODE); const localConversationKey = UrlUtil.getURLParameter(QUERY_KEY.CONVERSATION_KEY); @@ -129,6 +124,10 @@ const ConversationJoinComponent = ({ }; const getConversationInfoAndJoin = async (password?: string) => { + if (!isJoinGuestLinkPasswordModalOpen && !!conversationHasPassword) { + setIsJoinGuestLinkPasswordModalOpen(true); + return; + } try { if (!conversationCode || !conversationKey) { throw Error('Conversation code or key missing'); @@ -142,6 +141,10 @@ const ConversationJoinComponent = ({ routeToApp(conversationEvent.conversation, conversationEvent.qualified_conversation?.domain ?? ''); } catch (error) { + if (conversationHasPassword && error.label === BackendErrorLabel.INVALID_CONVERSATION_PASSWORD && !password) { + setIsJoinGuestLinkPasswordModalOpen(true); + return; + } console.warn('Unable to join conversation', error); setShowEntropyForm(false); } @@ -249,7 +252,7 @@ const ConversationJoinComponent = ({ error={conversationError || generalError} isLoading={isFetching} conversationName={conversationInfo?.name} - onSubmitPassword={submitJoinCodeWithPassword} + onSubmitPassword={selfName ? getConversationInfoAndJoin : submitJoinCodeWithPassword} /> )}