Skip to content

Commit

Permalink
check only registered users
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Sep 27, 2023
1 parent 3b96e40 commit 61a9437
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LoadingButton } from '../ui/LoadingButton/LoadingButton'
import { TextInput } from '../../forms/components/textInput'
import { userNameField } from '../../forms/fields/createUserFields'
import { parseName } from '@quiet/common'
import { User } from '@quiet/types'
import { UserData } from '@quiet/types'

const PREFIX = 'CreateUsernameComponent-'

Expand Down Expand Up @@ -150,7 +150,7 @@ export interface CreateUsernameComponentProps {
certificateRegistrationError?: string
certificate?: string | null
handleClose: () => void
allUsers?: Record<string, User>
registeredUsers?: Record<string, UserData>
currentUsername?: string
variant?: UsernameVariant
}
Expand All @@ -162,7 +162,7 @@ export const CreateUsernameComponent: React.FC<CreateUsernameComponentProps> = (
certificate,
handleClose,
currentUsername,
allUsers,
registeredUsers,
variant = UsernameVariant.NEW,
}) => {
const isNewUser = variant === UsernameVariant.NEW
Expand Down Expand Up @@ -209,8 +209,8 @@ export const CreateUsernameComponent: React.FC<CreateUsernameComponentProps> = (
const parsedName = parseName(name)
setUserName(parsedName)
setParsedNameDiffers(name !== parsedName)
if (allUsers && !isNewUser) {
const allUsersArr = Object.values(allUsers).map(user => user.username)
if (registeredUsers && !isNewUser) {
const allUsersArr = Object.values(registeredUsers).map(user => user.username)
if (allUsersArr.includes(name)) {
setError('userName', { message: `${name} is already taken` })
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorCodes, ErrorMessages, errors, identity, SocketActionTypes, users } from '@quiet/state-manager'
import { identity, users } from '@quiet/state-manager'
import React, { useCallback, useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useModal } from '../../../containers/hooks'
Expand All @@ -10,7 +10,7 @@ const UsernameTakenModalContainer = () => {

const isUsernameTaken = useSelector(identity.selectors.usernameTaken)
const usernameTakenModal = useModal(ModalName.usernameTakenModal)
const allUsers = useSelector(users.selectors.allUsers)
const registeredUsers = useSelector(users.selectors.certificatesMapping)
const user = useSelector(identity.selectors.currentIdentity)

const registerUsername = useCallback(
Expand Down Expand Up @@ -40,7 +40,7 @@ const UsernameTakenModalContainer = () => {
currentUsername={user?.nickname}
registerUsername={registerUsername}
variant={UsernameVariant.TAKEN}
allUsers={allUsers}
registeredUsers={registeredUsers}
{...usernameTakenModal}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createSelector } from '@reduxjs/toolkit'
import { identityAdapter } from './identity.adapter'
import { type CreatedSelectors, type StoreState } from '../store.types'
import { communitiesSelectors, selectCommunities } from '../communities/communities.selectors'
import { certificatesMapping, csrsMapping } from '../users/users.selectors'
import { certificatesMapping } from '../users/users.selectors'

const identitySlice: CreatedSelectors[StoreKeys.Identity] = (state: StoreState) => state[StoreKeys.Identity]

Expand Down

0 comments on commit 61a9437

Please sign in to comment.