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 Nov 1, 2023
1 parent 224a75b commit 1d8e6a5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 12 additions & 8 deletions src/script/auth/page/ConversationJoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,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<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 @@ -138,10 +137,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);
}
Expand Down Expand Up @@ -249,7 +253,7 @@ const ConversationJoinComponent = ({
error={conversationError || generalError}
isLoading={isFetching}
conversationName={conversationInfo?.name}
onSubmitPassword={submitJoinCodeWithPassword}
onSubmitPassword={selfName && enteredName ? getConversationInfoAndJoin : submitJoinCodeWithPassword}
/>
)}
<WirelessContainer
Expand Down
11 changes: 10 additions & 1 deletion src/script/auth/page/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ const LoginComponent = ({
} catch (error) {
if (isBackendError(error)) {
switch (error.label) {
case BackendErrorLabel.INVALID_CONVERSATION_PASSWORD: {
setConversationSubmitData(formLoginData);
setIsLinkPasswordModalOpen(true);
break;
}
case BackendErrorLabel.TOO_MANY_CLIENTS: {
await resetAuthError();
if (formLoginData?.verificationCode) {
Expand Down Expand Up @@ -359,7 +364,11 @@ const LoginComponent = ({
{!embedded && <AppAlreadyOpen />}
{isLinkPasswordModalOpen && (
<JoinGuestLinkPasswordModal
onClose={() => setIsLinkPasswordModalOpen(false)}
onClose={() => {
setIsLinkPasswordModalOpen(false);
void resetAuthError();
setValidationErrors([]);
}}
error={conversationError}
conversationName={conversationInfo?.name}
isLoading={isFetching || conversationInfoFetching}
Expand Down
4 changes: 4 additions & 0 deletions src/script/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 1d8e6a5

Please sign in to comment.