From e8967d04f2d5b1620948ea3b01da8c97a8f96ea4 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/i18n/en-US.json | 1 + src/script/auth/page/ConversationJoin.tsx | 26 +++++++++++------------ src/script/auth/page/Login.tsx | 11 +++++++++- src/script/strings.ts | 4 ++++ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/i18n/en-US.json b/src/i18n/en-US.json index a65b1d9dbc7..7fa325f6158 100644 --- a/src/i18n/en-US.json +++ b/src/i18n/en-US.json @@ -8,6 +8,7 @@ "BackendError.LABEL.CONVERSATION_CODE_NOT_FOUND": "This link is no longer valid. Ask the person who invited you how to join.", "BackendError.LABEL.CONVERSATION_NOT_FOUND": "CONVERSATION_NOT_FOUND", "BackendError.LABEL.CONVERSATION_TOO_MANY_MEMBERS": "This conversation has reached the limit of participants", + "BackendErrorLabel.INVALID_CONVERSATION_PASSWORD": "The password is incorrect, please try again.", "BackendError.LABEL.EMAIL_EXISTS": "This email address is already in use. {supportEmailExistsLink}", "BackendError.LABEL.EMAIL_REQUIRED": "You can’t use your username as two-factor authentication is activated. Please log in with your email instead.", "BackendError.LABEL.HANDLE_EXISTS": "This username is already taken", diff --git a/src/script/auth/page/ConversationJoin.tsx b/src/script/auth/page/ConversationJoin.tsx index a2d1e258c6b..e883cc914f8 100644 --- a/src/script/auth/page/ConversationJoin.tsx +++ b/src/script/auth/page/ConversationJoin.tsx @@ -23,7 +23,6 @@ import type {RegisterData} from '@wireapp/api-client/lib/auth'; import {BackendErrorLabel} from '@wireapp/api-client/lib/http'; import {useIntl} from 'react-intl'; import {connect} from 'react-redux'; -import {Navigate} from 'react-router'; import {AnyAction, Dispatch} from 'redux'; import {UrlUtil} from '@wireapp/commons'; @@ -50,7 +49,7 @@ import {bindActionCreators, RootState} from '../module/reducer'; import * as AuthSelector from '../module/selector/AuthSelector'; import * as ConversationSelector from '../module/selector/ConversationSelector'; import * as SelfSelector from '../module/selector/SelfSelector'; -import {QUERY_KEY, ROUTE} from '../route'; +import {QUERY_KEY} from '../route'; import * as AccentColor from '../util/AccentColor'; type Props = React.HTMLProps; @@ -75,8 +74,7 @@ const ConversationJoinComponent = ({ const {formatMessage: _} = useIntl(); const conversationHasPassword = conversationInfo?.has_password; - const invalidConversationPassword = - conversationError && conversationError.label === BackendErrorLabel.INVALID_CONVERSATION_PASSWORD; + const [accentColor] = useState(AccentColor.STRONG_BLUE); const [isJoinGuestLinkPasswordModalOpen, setIsJoinGuestLinkPasswordModalOpen] = useState(false); const [conversationCode, setConversationCode] = useState(); @@ -95,10 +93,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 +123,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'); @@ -138,10 +136,15 @@ const ConversationJoinComponent = ({ * That means that when the webapp loads and tries to fetch the notificationStream is will get the join event once again and will try to handle it * Here we set the core's lastEventDate so that it knows that this duplicated event should be skipped */ - await setLastEventDate(new Date(conversationEvent.time)); + await setLastEventDate(conversationEvent.time ? new Date(conversationEvent.time) : new Date()); routeToApp(conversationEvent.conversation, conversationEvent.qualified_conversation?.domain ?? ''); } catch (error) { + setIsSubmitingName(false); + if (error.label === BackendErrorLabel.INVALID_CONVERSATION_PASSWORD) { + setIsJoinGuestLinkPasswordModalOpen(true); + return; + } console.warn('Unable to join conversation', error); setShowEntropyForm(false); } @@ -234,9 +237,6 @@ const ConversationJoinComponent = ({ await handleSubmit(undefined, password); }; - if (!isValidLink) { - return ; - } if (isFullConversation) { return ; } @@ -249,7 +249,7 @@ const ConversationJoinComponent = ({ error={conversationError || generalError} isLoading={isFetching} conversationName={conversationInfo?.name} - onSubmitPassword={submitJoinCodeWithPassword} + onSubmitPassword={selfName && !enteredName ? getConversationInfoAndJoin : submitJoinCodeWithPassword} /> )} } {isLinkPasswordModalOpen && ( setIsLinkPasswordModalOpen(false)} + onClose={() => { + setIsLinkPasswordModalOpen(false); + void resetAuthError(); + setValidationErrors([]); + }} error={conversationError} conversationName={conversationInfo?.name} isLoading={isFetching || conversationInfoFetching} diff --git a/src/script/strings.ts b/src/script/strings.ts index 47936704b55..cdd12e1c955 100644 --- a/src/script/strings.ts +++ b/src/script/strings.ts @@ -685,6 +685,10 @@ export const errorHandlerStrings = defineMessages({ defaultMessage: 'This email cannot be used for enterprise login. Please enter the SSO code to proceed.', id: 'BackendErrorLabel.CUSTOM_BACKEND_NOT_FOUND', }, + [BackendErrorLabel.INVALID_CONVERSATION_PASSWORD]: { + defaultMessage: 'Password is incorrect, please try again.', + id: 'BackendErrorLabel.INVALID_CONVERSATION_PASSWORD', + }, learnMore: { defaultMessage: 'Learn more', id: 'BackendError.learnMore',