Skip to content

Commit

Permalink
fix: issue with some edge cases not working
Browse files Browse the repository at this point in the history
  • Loading branch information
tlebon committed Oct 31, 2023
1 parent 224a75b commit 1adf54e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/script/auth/page/ConversationJoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,9 +74,8 @@ const ConversationJoinComponent = ({
const nameInput = React.useRef<HTMLInputElement>(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<boolean>(false);
const [conversationCode, setConversationCode] = useState<string>();
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand All @@ -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);
}
Expand Down Expand Up @@ -249,7 +252,7 @@ const ConversationJoinComponent = ({
error={conversationError || generalError}
isLoading={isFetching}
conversationName={conversationInfo?.name}
onSubmitPassword={submitJoinCodeWithPassword}
onSubmitPassword={selfName ? getConversationInfoAndJoin : submitJoinCodeWithPassword}
/>
)}
<WirelessContainer
Expand Down

0 comments on commit 1adf54e

Please sign in to comment.