@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.js CHANGED
@@ -26253,51 +26253,6 @@ const getToken = () => {
26253
26253
  return accessToken;
26254
26254
  };
26255
26255
 
26256
- // import requester from '../requester'
26257
- const { URL_API } = CHAT;
26258
- const chatApi = {
26259
- getHistory: async (params) => {
26260
- const queryString = new URLSearchParams(params).toString();
26261
- const response = await fetch(`${URL_API.GET_HISTORY_API}?${queryString}`, {
26262
- headers: {
26263
- 'Authorization': `Bearer ${getToken()}`,
26264
- 'Content-Type': 'application/json'
26265
- }
26266
- });
26267
- if (!response.ok)
26268
- throw new Error(`Error: ${response.status}`);
26269
- return response.json();
26270
- }
26271
- //getHistoryActive: (params: any) => requester.get(URL_API.GET_HISTORY_API, params, config),
26272
- //getHistory: (params: any) => requester.get(URL_API.GET_HISTORY_API, params, config)
26273
- // getHistory: (params: any) => {
26274
- // console.log('getHistory params', params)
26275
- // return params
26276
- // }
26277
- // getMessageByGroupCursor: (id:string, params: any) => requester.get(`${URL_API.GET_MESSAGE_BY_GROUP_CURSOR_API}/${id}`, params, config),
26278
- // getInfo: (params: any) => requester.get(URL_API.GET_INFO_API, params, config),
26279
- // groups: (params: any) => requester.post(URL_API.GROUP_API, params, config),
26280
- // addMemberGroup: (params: any) => requester.post(`${URL_API.ADD_MEMBER_GROUP}`, params, config),
26281
- // senMessage: (id: string, params: any, tickerDto?: any) => requester.post(`${URL_API.SEN_MESSAGE_API}/${id}`, { ...params, tickerDto }, config),
26282
- // deleteMessage: (id: string, chatRoomId: string) => requester.delete(`${URL_API.MESSAGE_API}/${chatRoomId}/delete-message/${id}`, {}, config),
26283
- // recallMessage: (id: string, chatRoomId: string) => requester.put(`${URL_API.MESSAGE_API}/${chatRoomId}/recall-message/${id}`, {}, config),
26284
- // updateGroupAvatar: (params: any) => requester.put(URL_API.UPDATE_GROUP_AVATAR_API, params, config),
26285
- // getMessageByGroup: (params: any, paging: any) => requester.get(`${URL_API.GET_MESSAGE_BY_GROUP_API}/${params}`, paging, config),
26286
- // getMessageByContact: (params: any, paging: any) => requester.get(`${URL_API.GET_MESSAGE_BY_CONTACT_API}/${params}`, paging, config),
26287
- // contactAdd: (params: any) => requester.post(URL_API.CONTACT_ADD_API, params, config),
26288
- // getProfile: () => requester.get(URL_API.GET_PROFILE, {}, config),
26289
- // getUsers: (params: any) => requester.get(URL_API.GET_USERS, params, config),
26290
- // getContact: (params: any) => requester.get(URL_API.GET_CONTACT_API, params, config),
26291
- // updateChatRoomMember: (params: any) => requester.put(`${URL_API.CHAT_ROOM_MEMBER_API}/${params}`, {}, config),
26292
- // getPagingEmployeeApi: (params: any) => requester.get(URL_API.GET_PAGING_EMPLOYEE_API, params, config),
26293
- // connectChatRoomMemberApi: (params: any) => requester.post(URL_API.CONNECT_CHAT_ROOM_MEMBER_API, params, config),
26294
- // pinMessageChatRoomApi: (params: any) => requester.post(`${URL_API.PIN_MESSAGE_CHAT_ROOM_API}/${params.id}`, params, config),
26295
- // getPinMessagesByRoomApi: (chatRoomId: string) => requester.get(`${URL_API.GET_PIN_MESSAGE_CHAT_ROOM_API}/${chatRoomId}`, {}, config),
26296
- // deletePinMessageApi: (pinId: string) => requester.delete(`${URL_API.PIN_MESSAGE_CHAT_ROOM_API}/${pinId}`, {}, config),
26297
- // updateGroupTagApi: (params: any) => requester.put(URL_API.UPDATE_GROUP_TAG_API, params, config),
26298
- // createReminderApi: (params: any) => requester.post(URL_API.CREATE_REMINDER_API, params, config)
26299
- };
26300
-
26301
26256
  // ** Redux Imports
26302
26257
  // Convert 1 bản ghi PinMessage từ backend thành object message dùng cho UI ghim
26303
26258
  const mapPinRecordToMessage = (record) => {
@@ -26342,10 +26297,22 @@ const initialState = {
26342
26297
  };
26343
26298
  const get_history = toolkit.createAsyncThunk(CHAT.ACTION_TYPES.GET_HISTORY, async (params, thunkAPI) => {
26344
26299
  try {
26345
- return await chatApi.getHistory(params);
26300
+ const queryString = new URLSearchParams(params).toString();
26301
+ const response = await fetch(`${CHAT.URL_API.GET_HISTORY_API}?${queryString}`, {
26302
+ method: 'GET',
26303
+ headers: {
26304
+ 'Authorization': `Bearer ${getToken()}`,
26305
+ 'Content-Type': 'application/json'
26306
+ }
26307
+ });
26308
+ if (!response.ok) {
26309
+ throw new Error(`HTTP error! status: ${response.status}`);
26310
+ }
26311
+ const data = await response.json();
26312
+ return data;
26346
26313
  }
26347
26314
  catch (error) {
26348
- return thunkAPI.rejectWithValue({ error: error.response.data });
26315
+ return thunkAPI.rejectWithValue({ error: error.message });
26349
26316
  }
26350
26317
  });
26351
26318
  // export const get_history = createAsyncThunk<any, any>(CHAT.ACTION_TYPES.GET_HISTORY, async (params, thunkAPI) => {
@@ -26857,9 +26824,9 @@ const appChatSlice = toolkit.createSlice({
26857
26824
  // builder.addCase(update_chat_room_member.fulfilled, (state: IFState) => {
26858
26825
  // state.checkInit = !state.checkInit
26859
26826
  // })
26860
- // builder.addCase(get_history.fulfilled, (state: IFState, action) => {
26861
- // state.listHistory = action.payload?.items
26862
- // })
26827
+ builder.addCase(get_history.fulfilled, (state, action) => {
26828
+ state.listHistory = action.payload?.items;
26829
+ });
26863
26830
  // builder.addCase(getPinMessageChatRoomApi.fulfilled, (state: IFState, action) => {
26864
26831
  // // Backend trả về danh sách PinMessage (mảng / items / data)
26865
26832
  // const payload = action.payload as any
@@ -26890,12 +26857,27 @@ const appChatSlice = toolkit.createSlice({
26890
26857
  });
26891
26858
  appChatSlice.actions;
26892
26859
 
26860
+ //import * as chatStore from '../store'
26893
26861
  const useChat = () => {
26894
26862
  const dispatch = configureStore.useAppDispatch();
26895
26863
  const { active, checkInit, chatRoomId, userLogin, listContact, contactId, typeChat, loadChat, messageByGroup, listHistory, listChatType, archiveStore, checkScroll, listGeneralGroup, pinnedMessages, typingUsers } = configureStore.useAppSelector((state) => state.chat);
26896
26864
  const getHistoryApi = (params) => {
26897
26865
  return dispatch(get_history(params));
26898
26866
  };
26867
+ // const getHistoryApi = async (params: any) => {
26868
+ // const queryString = new URLSearchParams(params).toString()
26869
+ // const response = await fetch(`${CHAT.URL_API.GET_HISTORY_API}?${queryString}`, {
26870
+ // method: 'GET',
26871
+ // headers: {
26872
+ // 'Authorization': `Bearer ${getToken()}`,
26873
+ // 'Content-Type': 'application/json'
26874
+ // }
26875
+ // })
26876
+ // if (!response.ok) {
26877
+ // throw new Error(`HTTP error! status: ${response.status}`)
26878
+ // }
26879
+ // return response.json()
26880
+ // }
26899
26881
  // const get_message_by_group_cursor_api = (params: any) => {
26900
26882
  // return dispatch(chatStore.get_message_by_group_cursor(params))
26901
26883
  // }
@@ -27018,15 +27000,15 @@ const useChat = () => {
27018
27000
  };
27019
27001
 
27020
27002
  const AppChat = () => {
27021
- const { active,
27003
+ const { active,
27022
27004
  // contactId,
27023
- // typeChat,
27005
+ typeChat,
27024
27006
  // chatRoomId,
27025
27007
  // messageByGroup,
27026
27008
  // listHistory,
27027
27009
  // checkInit,
27028
27010
  // setScroll,
27029
- // getHistoryApi,
27011
+ getHistoryApi,
27030
27012
  // getProfileApi,
27031
27013
  // getInfoApi,
27032
27014
  // getContactApi,
@@ -27042,27 +27024,27 @@ const AppChat = () => {
27042
27024
  // const [dataProfile, setDataProfile] = useState({})
27043
27025
  // const [sidebarRight, setSidebarRight] = useState(false)
27044
27026
  // const handleSidebarRight = () => setSidebarRight(!sidebarRight)
27045
- // const [tagFilter] = useState<string>('')
27046
- // const [filterTab] = useState<'all' | 'unread' | 'tag'>('all')
27027
+ const [tagFilter] = React.useState('');
27028
+ const [filterTab] = React.useState('all');
27047
27029
  // const [openModalGroupInfo, setOpenModalGroupInfo] = useState(false)
27048
27030
  // const [openModalAddUserGroup, setOpenModalAddUserGroup] = useState(false)
27049
27031
  // const [windowSize, setWindowSize] = useState(getWindowSize())
27050
- // const [search] = useState('')
27032
+ const [search] = React.useState('');
27051
27033
  // const [contact, setContact] = useState([])
27052
27034
  // // ** Set user function for Right Sidebar
27053
27035
  // const handleModalAddUserGroup = () => setOpenModalAddUserGroup(!openModalAddUserGroup)
27054
27036
  // const handleModalGroupInfo = () => setOpenModalGroupInfo(!openModalGroupInfo)
27055
- // const getData = () => {
27056
- // const paging = {
27057
- // keyword: search,
27058
- // filter: filterTab === 'unread' ? 'unread' : '',
27059
- // order: '',
27060
- // pageNumber: 1,
27061
- // pageSize: 20,
27062
- // tag: tagFilter || undefined
27063
- // }
27064
- // getHistoryApi(paging)
27065
- // }
27037
+ const getData = () => {
27038
+ const paging = {
27039
+ keyword: search,
27040
+ filter: filterTab === 'unread' ? 'unread' : '',
27041
+ order: '',
27042
+ pageNumber: 1,
27043
+ pageSize: 20,
27044
+ tag: tagFilter || undefined
27045
+ };
27046
+ getHistoryApi(paging);
27047
+ };
27066
27048
  // const getContact = () => {
27067
27049
  // getContactApi({
27068
27050
  // keyword: search,
@@ -27079,14 +27061,12 @@ const AppChat = () => {
27079
27061
  // .then((rs: any) => setDataProfile(rs))
27080
27062
  // .catch((ex: any) => console.log(ex))
27081
27063
  // }
27082
- // useEffect(() => {
27083
- // if (typeChat !== 'CONTACT') {
27084
- // getData()
27085
- // } else {
27086
- // getContact()
27087
- // }
27088
- // getDataProfile()
27089
- // }, [typeChat, search, checkInit, tagFilter, filterTab])
27064
+ React.useEffect(() => {
27065
+ if (typeChat !== 'CONTACT') {
27066
+ getData();
27067
+ }
27068
+ //getDataProfile()
27069
+ }, [typeChat, search, tagFilter, filterTab]);
27090
27070
  // useEffect(() => {
27091
27071
  // const handleWindowResize = () => {
27092
27072
  // setWindowSize(getWindowSize())