|
|
|
|
@ -1,21 +1,24 @@ |
|
|
|
|
import { useUserId, useSetting, useUser } from '@rocket.chat/ui-contexts'; |
|
|
|
|
import { useUserId, useSetting } from '@rocket.chat/ui-contexts'; |
|
|
|
|
import type { ReactElement, ReactNode } from 'react'; |
|
|
|
|
import React, { useCallback } from 'react'; |
|
|
|
|
|
|
|
|
|
import { useReactiveValue } from '../../../hooks/useReactiveValue'; |
|
|
|
|
import { useUserInfoQuery } from '../../../hooks/useUserInfoQuery'; |
|
|
|
|
import PasswordChangeCheck from './PasswordChangeCheck'; |
|
|
|
|
import RegisterUsername from './RegisterUsername'; |
|
|
|
|
|
|
|
|
|
const UsernameCheck = ({ children }: { children: ReactNode }): ReactElement => { |
|
|
|
|
const uid = useUserId(); |
|
|
|
|
const user = useUser(); |
|
|
|
|
const hasUserInCollection = !!user; |
|
|
|
|
const username = user?.username; |
|
|
|
|
const userId = useUserId(); |
|
|
|
|
const { data: userData, isLoading } = useUserInfoQuery({ userId: userId || '' }); |
|
|
|
|
|
|
|
|
|
const allowAnonymousRead = useSetting<boolean>('Accounts_AllowAnonymousRead') ?? false; |
|
|
|
|
|
|
|
|
|
const shouldRegisterUsername = useReactiveValue( |
|
|
|
|
useCallback(() => { |
|
|
|
|
if (!uid) { |
|
|
|
|
const hasUserInCollection = !!userData?.user; |
|
|
|
|
const hasUsername = !!userData?.user?.username; |
|
|
|
|
|
|
|
|
|
if (!userId) { |
|
|
|
|
return !allowAnonymousRead; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -23,11 +26,11 @@ const UsernameCheck = ({ children }: { children: ReactNode }): ReactElement => { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return !username; |
|
|
|
|
}, [uid, hasUserInCollection, username, allowAnonymousRead]), |
|
|
|
|
return !hasUsername; |
|
|
|
|
}, [userData?.user, userId, allowAnonymousRead]), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (shouldRegisterUsername) { |
|
|
|
|
if (!isLoading && shouldRegisterUsername) { |
|
|
|
|
return <RegisterUsername />; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|