-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Rewrite CurrentChats to TS (#22424)
- Loading branch information
1 parent
a27d885
commit 3aa3f43
Showing
27 changed files
with
393 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { useCallback, useState } from 'react'; | ||
|
||
import { ILivechatAgentRecord } from '../../../../definition/ILivechatAgentRecord'; | ||
import { useEndpoint } from '../../../contexts/ServerContext'; | ||
import { useTranslation } from '../../../contexts/TranslationContext'; | ||
import { useScrollableRecordList } from '../../../hooks/lists/useScrollableRecordList'; | ||
import { useComponentDidUpdate } from '../../../hooks/useComponentDidUpdate'; | ||
import { RecordList } from '../../../lib/lists/RecordList'; | ||
|
||
type AgentsListOptions = { | ||
text: string; | ||
}; | ||
|
||
export const useAgentsList = ( | ||
options: AgentsListOptions, | ||
): { | ||
itemsList: RecordList<ILivechatAgentRecord>; | ||
initialItemCount: number; | ||
reload: () => void; | ||
loadMoreItems: (start: number, end: number) => void; | ||
} => { | ||
const t = useTranslation(); | ||
const [itemsList, setItemsList] = useState(() => new RecordList<ILivechatAgentRecord>()); | ||
const reload = useCallback(() => setItemsList(new RecordList<ILivechatAgentRecord>()), []); | ||
const endpoint = 'livechat/users/agent'; | ||
|
||
const getAgents = useEndpoint('GET', endpoint); | ||
|
||
useComponentDidUpdate(() => { | ||
options && reload(); | ||
}, [options, reload]); | ||
|
||
const fetchData = useCallback( | ||
async (start, end) => { | ||
const { users: agents, total } = await getAgents({ | ||
...(options.text && { text: options.text }), | ||
offset: start, | ||
count: end + start, | ||
sort: JSON.stringify({ name: 1 }), | ||
}); | ||
|
||
const items = agents.map((agent: any) => { | ||
agent._updatedAt = new Date(agent._updatedAt); | ||
agent.label = agent.username; | ||
agent.value = agent._id; | ||
return agent; | ||
}); | ||
items.unshift({ | ||
label: t('All'), | ||
value: 'all', | ||
_updatedAt: new Date(), | ||
}); | ||
|
||
return { | ||
items, | ||
itemCount: total + 1, | ||
}; | ||
}, | ||
[getAgents, options.text, t], | ||
); | ||
|
||
const { loadMoreItems, initialItemCount } = useScrollableRecordList(itemsList, fetchData, 25); | ||
|
||
return { | ||
reload, | ||
itemsList, | ||
loadMoreItems, | ||
initialItemCount, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
client/contexts/ServerContext/endpoints/v1/livechat/customFields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type LivechatCustomFieldsEndpoint = { | ||
GET: (params: {}) => { | ||
customFields: [ | ||
{ | ||
_id: string; | ||
label: string; | ||
}, | ||
]; | ||
}; | ||
}; |
15 changes: 15 additions & 0 deletions
15
client/contexts/ServerContext/endpoints/v1/livechat/rooms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export type LivechatRoomsEndpoint = { | ||
GET: (params: { | ||
guest: string; | ||
fname: string; | ||
servedBy: string[]; | ||
status: string; | ||
department: string; | ||
from: string; | ||
to: string; | ||
customFields: any; | ||
current: number; | ||
itemsPerPage: number; | ||
tags: string[]; | ||
}) => { value: any; reload: () => void }; | ||
}; |
Oops, something went wrong.