@esvndev/es-react-template-chat 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -26230,51 +26230,6 @@ const getToken = () => {
26230
26230
  return accessToken;
26231
26231
  };
26232
26232
 
26233
- // import requester from '../requester'
26234
- const { URL_API } = CHAT;
26235
- const chatApi = {
26236
- getHistory: async (params) => {
26237
- const queryString = new URLSearchParams(params).toString();
26238
- const response = await fetch(`${URL_API.GET_HISTORY_API}?${queryString}`, {
26239
- headers: {
26240
- 'Authorization': `Bearer ${getToken()}`,
26241
- 'Content-Type': 'application/json'
26242
- }
26243
- });
26244
- if (!response.ok)
26245
- throw new Error(`Error: ${response.status}`);
26246
- return response.json();
26247
- }
26248
- //getHistoryActive: (params: any) => requester.get(URL_API.GET_HISTORY_API, params, config),
26249
- //getHistory: (params: any) => requester.get(URL_API.GET_HISTORY_API, params, config)
26250
- // getHistory: (params: any) => {
26251
- // console.log('getHistory params', params)
26252
- // return params
26253
- // }
26254
- // getMessageByGroupCursor: (id:string, params: any) => requester.get(`${URL_API.GET_MESSAGE_BY_GROUP_CURSOR_API}/${id}`, params, config),
26255
- // getInfo: (params: any) => requester.get(URL_API.GET_INFO_API, params, config),
26256
- // groups: (params: any) => requester.post(URL_API.GROUP_API, params, config),
26257
- // addMemberGroup: (params: any) => requester.post(`${URL_API.ADD_MEMBER_GROUP}`, params, config),
26258
- // senMessage: (id: string, params: any, tickerDto?: any) => requester.post(`${URL_API.SEN_MESSAGE_API}/${id}`, { ...params, tickerDto }, config),
26259
- // deleteMessage: (id: string, chatRoomId: string) => requester.delete(`${URL_API.MESSAGE_API}/${chatRoomId}/delete-message/${id}`, {}, config),
26260
- // recallMessage: (id: string, chatRoomId: string) => requester.put(`${URL_API.MESSAGE_API}/${chatRoomId}/recall-message/${id}`, {}, config),
26261
- // updateGroupAvatar: (params: any) => requester.put(URL_API.UPDATE_GROUP_AVATAR_API, params, config),
26262
- // getMessageByGroup: (params: any, paging: any) => requester.get(`${URL_API.GET_MESSAGE_BY_GROUP_API}/${params}`, paging, config),
26263
- // getMessageByContact: (params: any, paging: any) => requester.get(`${URL_API.GET_MESSAGE_BY_CONTACT_API}/${params}`, paging, config),
26264
- // contactAdd: (params: any) => requester.post(URL_API.CONTACT_ADD_API, params, config),
26265
- // getProfile: () => requester.get(URL_API.GET_PROFILE, {}, config),
26266
- // getUsers: (params: any) => requester.get(URL_API.GET_USERS, params, config),
26267
- // getContact: (params: any) => requester.get(URL_API.GET_CONTACT_API, params, config),
26268
- // updateChatRoomMember: (params: any) => requester.put(`${URL_API.CHAT_ROOM_MEMBER_API}/${params}`, {}, config),
26269
- // getPagingEmployeeApi: (params: any) => requester.get(URL_API.GET_PAGING_EMPLOYEE_API, params, config),
26270
- // connectChatRoomMemberApi: (params: any) => requester.post(URL_API.CONNECT_CHAT_ROOM_MEMBER_API, params, config),
26271
- // pinMessageChatRoomApi: (params: any) => requester.post(`${URL_API.PIN_MESSAGE_CHAT_ROOM_API}/${params.id}`, params, config),
26272
- // getPinMessagesByRoomApi: (chatRoomId: string) => requester.get(`${URL_API.GET_PIN_MESSAGE_CHAT_ROOM_API}/${chatRoomId}`, {}, config),
26273
- // deletePinMessageApi: (pinId: string) => requester.delete(`${URL_API.PIN_MESSAGE_CHAT_ROOM_API}/${pinId}`, {}, config),
26274
- // updateGroupTagApi: (params: any) => requester.put(URL_API.UPDATE_GROUP_TAG_API, params, config),
26275
- // createReminderApi: (params: any) => requester.post(URL_API.CREATE_REMINDER_API, params, config)
26276
- };
26277
-
26278
26233
  // ** Redux Imports
26279
26234
  // Convert 1 bản ghi PinMessage từ backend thành object message dùng cho UI ghim
26280
26235
  const mapPinRecordToMessage = (record) => {
@@ -26319,10 +26274,22 @@ const initialState = {
26319
26274
  };
26320
26275
  const get_history = createAsyncThunk(CHAT.ACTION_TYPES.GET_HISTORY, async (params, thunkAPI) => {
26321
26276
  try {
26322
- return await chatApi.getHistory(params);
26277
+ const queryString = new URLSearchParams(params).toString();
26278
+ const response = await fetch(`${CHAT.URL_API.GET_HISTORY_API}?${queryString}`, {
26279
+ method: 'GET',
26280
+ headers: {
26281
+ 'Authorization': `Bearer ${getToken()}`,
26282
+ 'Content-Type': 'application/json'
26283
+ }
26284
+ });
26285
+ if (!response.ok) {
26286
+ throw new Error(`HTTP error! status: ${response.status}`);
26287
+ }
26288
+ const data = await response.json();
26289
+ return data;
26323
26290
  }
26324
26291
  catch (error) {
26325
- return thunkAPI.rejectWithValue({ error: error.response.data });
26292
+ return thunkAPI.rejectWithValue({ error: error.message });
26326
26293
  }
26327
26294
  });
26328
26295
  // export const get_history = createAsyncThunk<any, any>(CHAT.ACTION_TYPES.GET_HISTORY, async (params, thunkAPI) => {
@@ -26834,9 +26801,9 @@ const appChatSlice = createSlice({
26834
26801
  // builder.addCase(update_chat_room_member.fulfilled, (state: IFState) => {
26835
26802
  // state.checkInit = !state.checkInit
26836
26803
  // })
26837
- // builder.addCase(get_history.fulfilled, (state: IFState, action) => {
26838
- // state.listHistory = action.payload?.items
26839
- // })
26804
+ builder.addCase(get_history.fulfilled, (state, action) => {
26805
+ state.listHistory = action.payload?.items;
26806
+ });
26840
26807
  // builder.addCase(getPinMessageChatRoomApi.fulfilled, (state: IFState, action) => {
26841
26808
  // // Backend trả về danh sách PinMessage (mảng / items / data)
26842
26809
  // const payload = action.payload as any
@@ -26867,12 +26834,27 @@ const appChatSlice = createSlice({
26867
26834
  });
26868
26835
  appChatSlice.actions;
26869
26836
 
26837
+ //import * as chatStore from '../store'
26870
26838
  const useChat = () => {
26871
26839
  const dispatch = useAppDispatch();
26872
26840
  const { active, checkInit, chatRoomId, userLogin, listContact, contactId, typeChat, loadChat, messageByGroup, listHistory, listChatType, archiveStore, checkScroll, listGeneralGroup, pinnedMessages, typingUsers } = useAppSelector((state) => state.chat);
26873
26841
  const getHistoryApi = (params) => {
26874
26842
  return dispatch(get_history(params));
26875
26843
  };
26844
+ // const getHistoryApi = async (params: any) => {
26845
+ // const queryString = new URLSearchParams(params).toString()
26846
+ // const response = await fetch(`${CHAT.URL_API.GET_HISTORY_API}?${queryString}`, {
26847
+ // method: 'GET',
26848
+ // headers: {
26849
+ // 'Authorization': `Bearer ${getToken()}`,
26850
+ // 'Content-Type': 'application/json'
26851
+ // }
26852
+ // })
26853
+ // if (!response.ok) {
26854
+ // throw new Error(`HTTP error! status: ${response.status}`)
26855
+ // }
26856
+ // return response.json()
26857
+ // }
26876
26858
  // const get_message_by_group_cursor_api = (params: any) => {
26877
26859
  // return dispatch(chatStore.get_message_by_group_cursor(params))
26878
26860
  // }
@@ -26995,15 +26977,15 @@ const useChat = () => {
26995
26977
  };
26996
26978
 
26997
26979
  const AppChat = () => {
26998
- const { active,
26980
+ const { active,
26999
26981
  // contactId,
27000
- // typeChat,
26982
+ typeChat,
27001
26983
  // chatRoomId,
27002
26984
  // messageByGroup,
27003
26985
  // listHistory,
27004
26986
  // checkInit,
27005
26987
  // setScroll,
27006
- // getHistoryApi,
26988
+ getHistoryApi,
27007
26989
  // getProfileApi,
27008
26990
  // getInfoApi,
27009
26991
  // getContactApi,
@@ -27019,27 +27001,27 @@ const AppChat = () => {
27019
27001
  // const [dataProfile, setDataProfile] = useState({})
27020
27002
  // const [sidebarRight, setSidebarRight] = useState(false)
27021
27003
  // const handleSidebarRight = () => setSidebarRight(!sidebarRight)
27022
- // const [tagFilter] = useState<string>('')
27023
- // const [filterTab] = useState<'all' | 'unread' | 'tag'>('all')
27004
+ const [tagFilter] = useState('');
27005
+ const [filterTab] = useState('all');
27024
27006
  // const [openModalGroupInfo, setOpenModalGroupInfo] = useState(false)
27025
27007
  // const [openModalAddUserGroup, setOpenModalAddUserGroup] = useState(false)
27026
27008
  // const [windowSize, setWindowSize] = useState(getWindowSize())
27027
- // const [search] = useState('')
27009
+ const [search] = useState('');
27028
27010
  // const [contact, setContact] = useState([])
27029
27011
  // // ** Set user function for Right Sidebar
27030
27012
  // const handleModalAddUserGroup = () => setOpenModalAddUserGroup(!openModalAddUserGroup)
27031
27013
  // const handleModalGroupInfo = () => setOpenModalGroupInfo(!openModalGroupInfo)
27032
- // const getData = () => {
27033
- // const paging = {
27034
- // keyword: search,
27035
- // filter: filterTab === 'unread' ? 'unread' : '',
27036
- // order: '',
27037
- // pageNumber: 1,
27038
- // pageSize: 20,
27039
- // tag: tagFilter || undefined
27040
- // }
27041
- // getHistoryApi(paging)
27042
- // }
27014
+ const getData = () => {
27015
+ const paging = {
27016
+ keyword: search,
27017
+ filter: filterTab === 'unread' ? 'unread' : '',
27018
+ order: '',
27019
+ pageNumber: 1,
27020
+ pageSize: 20,
27021
+ tag: tagFilter || undefined
27022
+ };
27023
+ getHistoryApi(paging);
27024
+ };
27043
27025
  // const getContact = () => {
27044
27026
  // getContactApi({
27045
27027
  // keyword: search,
@@ -27056,14 +27038,12 @@ const AppChat = () => {
27056
27038
  // .then((rs: any) => setDataProfile(rs))
27057
27039
  // .catch((ex: any) => console.log(ex))
27058
27040
  // }
27059
- // useEffect(() => {
27060
- // if (typeChat !== 'CONTACT') {
27061
- // getData()
27062
- // } else {
27063
- // getContact()
27064
- // }
27065
- // getDataProfile()
27066
- // }, [typeChat, search, checkInit, tagFilter, filterTab])
27041
+ useEffect(() => {
27042
+ if (typeChat !== 'CONTACT') {
27043
+ getData();
27044
+ }
27045
+ //getDataProfile()
27046
+ }, [typeChat, search, tagFilter, filterTab]);
27067
27047
  // useEffect(() => {
27068
27048
  // const handleWindowResize = () => {
27069
27049
  // setWindowSize(getWindowSize())