Oksana Stepanenko
2 years ago
10 changed files with 147 additions and 47 deletions
@ -1,7 +1,17 @@
@@ -1,7 +1,17 @@
|
||||
import { IChat, IChatDetails, IPaginationResult } from '@/shared'; |
||||
import { IChat, IChatDetails, IPaginationResult } from '@/shared' |
||||
|
||||
export type NewChatGroupId = number |
||||
|
||||
export interface IFetchChatList extends IPaginationResult<IChat> { } |
||||
export interface IFetchChatList extends IPaginationResult<IChat> {} |
||||
|
||||
export interface IFetchChatDetail extends IChatDetails {} |
||||
export interface IFetchChatDetail extends IChatDetails {} |
||||
|
||||
export interface IPotentialChatMember { |
||||
userId: number |
||||
firstName: string |
||||
middleName: string |
||||
lastName: string |
||||
avatarUrl: string |
||||
} |
||||
export interface IFetchPotentialChatMembersResponse |
||||
extends IPaginationResult<IPotentialChatMember> {} |
||||
|
@ -1,31 +1,56 @@
@@ -1,31 +1,56 @@
|
||||
import { usersService } from '@/services/domain/users.service' |
||||
import { useEffect, useState } from 'react' |
||||
import { IUser, useFlatList } from '@/shared' |
||||
import { useEffect } from 'react' |
||||
import { useState } from 'react' |
||||
import { IShortUser, useFlatList } from '@/shared' |
||||
import { chatsService, tasksService } from '@/services/domain' |
||||
import { ITaskExecutorResponse } from '@/api/tasks/responses.interface' |
||||
import { transformExecutorsToShortUsers } from '@/api/tasks/transform' |
||||
import _ from 'lodash' |
||||
|
||||
export const useFetchUsers = () => { |
||||
const [searchString, setSearchVal] = useState<string>() |
||||
interface IProps { |
||||
type?: 'executors' | 'all' |
||||
} |
||||
|
||||
const api = { |
||||
executors: tasksService.getTaskExecutors, |
||||
all: params => chatsService.getUsersForChat.bind(chatsService)(params), |
||||
} |
||||
|
||||
export const useFetchUsersList = ({ type }: IProps) => { |
||||
const [searchString, setSearchVal] = useState<string>(null) |
||||
|
||||
const { items, isLoading, isLoadingNext, loadMore, resetFlatList } = |
||||
useFlatList({ |
||||
fetchItems: params => usersService.fetch({ ...params }), |
||||
needInit: false, |
||||
loadParams: { |
||||
sort: 'DESC', |
||||
sortField: 'id', |
||||
}, |
||||
limit: 20, |
||||
}) |
||||
const { |
||||
items, |
||||
isLoading, |
||||
isLoadingNext, |
||||
loadMore, |
||||
setLoadParams, |
||||
loadAll, |
||||
isLoadedAll, |
||||
} = useFlatList<IShortUser>({ |
||||
fetchItems: api[_.defaultTo(type, 'executors')], |
||||
needInit: true, |
||||
serrializatorItems: (_items: ITaskExecutorResponse[]) => |
||||
transformExecutorsToShortUsers(_items), |
||||
loadParams: { |
||||
sort: 'DESC', |
||||
sortField: 'id', |
||||
}, |
||||
limit: 10, |
||||
clearWhenReload: false, |
||||
}) |
||||
|
||||
useEffect(() => { |
||||
resetFlatList() |
||||
if (searchString !== null) setLoadParams({ searchString }) |
||||
}, [searchString]) |
||||
|
||||
return { |
||||
items: items as IUser[], |
||||
items: items as IShortUser[], |
||||
isLoading, |
||||
isLoadingNext, |
||||
searchString, |
||||
loadMore, |
||||
setSearchVal, |
||||
loadAll, |
||||
isLoadedAll, |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue