Browse Source

FIX | Exclude account user from users list on create group chat screen

chats/fix
Oksana Stepanenko 2 years ago
parent
commit
3d39f340d9
  1. 6
      src/modules/chats/screens/chats.screen.tsx
  2. 27
      src/modules/users/components/users-select-list-with-search.component.tsx
  3. 3
      src/modules/users/screens/select-user-list.screen.tsx

6
src/modules/chats/screens/chats.screen.tsx

@ -4,11 +4,14 @@ import { useTheme } from '@/shared/hooks/use-theme.hook' @@ -4,11 +4,14 @@ import { useTheme } from '@/shared/hooks/use-theme.hook'
import { Platform, StyleSheet } from 'react-native'
import { HeaderRightBtn } from '../atoms'
import { SmartChatsList } from '../smart-components'
import { useSelector } from 'react-redux'
import { selectId } from '@/store/account'
interface IProps extends IRouteParams { }
interface IProps extends IRouteParams {}
export const ChatsScreen: FC<IProps> = ({ navigation }) => {
const { styles } = useTheme(createStyles)
const accountId = useSelector(selectId)
const onPressHeaderBtn = () =>
navigation.navigate(RouteKey.SelectUsersScreen, {
@ -17,6 +20,7 @@ export const ChatsScreen: FC<IProps> = ({ navigation }) => { @@ -17,6 +20,7 @@ export const ChatsScreen: FC<IProps> = ({ navigation }) => {
footerBtnTitle: 'Далі',
onSubmit: () => navigation.navigate(RouteKey.CreateGroup),
useChatBtnColors: true,
excludeIds: [accountId],
})
return (

27
src/modules/users/components/users-select-list-with-search.component.tsx

@ -23,6 +23,7 @@ interface IProps { @@ -23,6 +23,7 @@ interface IProps {
selectAllTextStyle?: StyleProp<TextStyle>
selectAllBtnStyle?: ViewStyle
disableIds?: number[]
excludeIds?: number[]
}
export const UsersSelectListWithSearch: FC<IProps> = ({
@ -33,6 +34,7 @@ export const UsersSelectListWithSearch: FC<IProps> = ({ @@ -33,6 +34,7 @@ export const UsersSelectListWithSearch: FC<IProps> = ({
selectAllTextStyle,
selectAllBtnStyle,
disableIds,
excludeIds,
}) => {
const { styles } = useTheme(createStyles)
@ -58,12 +60,22 @@ export const UsersSelectListWithSearch: FC<IProps> = ({ @@ -58,12 +60,22 @@ export const UsersSelectListWithSearch: FC<IProps> = ({
return textA < textB ? -1 : textA > textB ? 1 : 0
})
return sortedUsers
}, [selectedUsers, items])
const filteredUsers = sortedUsers?.filter(
it => !_.includes(excludeIds, it.id),
)
return filteredUsers
}, [selectedUsers, items, excludeIds])
const handleSelectAll = async () => {
if (isLoadedAll) {
selectAll(_.filter(items, it => !_.includes(disableIds, it.id)))
selectAll(
_.filter(
items,
it =>
!_.includes(disableIds, it.id) &&
!_.includes(excludeIds, it.id),
),
)
} else {
setLoadSelectAll(true)
await loadAll()
@ -72,7 +84,14 @@ export const UsersSelectListWithSearch: FC<IProps> = ({ @@ -72,7 +84,14 @@ export const UsersSelectListWithSearch: FC<IProps> = ({
useEffect(() => {
if (loadSelectAll) {
selectAll(_.filter(items, it => !_.includes(disableIds, it.id)))
selectAll(
_.filter(
items,
it =>
!_.includes(disableIds, it.id) &&
!_.includes(excludeIds, it.id),
),
)
setLoadSelectAll(false)
}
}, [items])

3
src/modules/users/screens/select-user-list.screen.tsx

@ -25,6 +25,7 @@ interface IProps extends IRouteParams { @@ -25,6 +25,7 @@ interface IProps extends IRouteParams {
onSubmit: () => void
useChatBtnColors?: boolean
disableIds?: number[]
excludeIds?: number[]
}
}
}
@ -39,6 +40,7 @@ export const SelectUserList: FC<IProps> = ({ @@ -39,6 +40,7 @@ export const SelectUserList: FC<IProps> = ({
onSubmit,
useChatBtnColors,
disableIds,
excludeIds,
},
},
}) => {
@ -80,6 +82,7 @@ export const SelectUserList: FC<IProps> = ({ @@ -80,6 +82,7 @@ export const SelectUserList: FC<IProps> = ({
<UsersSelectListWithSearch
selectedUsers={selectedUsers}
excludeIds={excludeIds}
selectAll={items => simpleDispatch(new SelectAll({ items }))}
selectOne={user => simpleDispatch(new SelectUser({ user }))}
unselectOne={id => simpleDispatch(new UnselectUser({ id }))}

Loading…
Cancel
Save