1.0.168 • Published 7 months ago

chat-frontend-library v1.0.168

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

Install

npm install chat-frontend-library --save

Usage

Create Redux store:

import { configureStore } from '@reduxjs/toolkit';
import { chatApi, chatAppSlice, commonApi } from 'chat-frontend-library';

 const store = configureStore({
  reducer: {
    [commonApi.reducerPath]: commonApi.reducer,
    [chatApi.reducerPath]: chatApi.reducer,
    [chatAppSlice.name]: chatAppSlice.reducer,
    ...
    //Add your reducers if necessary
  },
  middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(commonApi.middleware, chatApi.middleware, ...),
});
export default store;

Wrap your root component file in a Provider:

import store from './store';
import { Provider } from "react-redux";

 <Provider store={store}>
   <App />
 </Provider>

Imports

Import the components and constants from the package into the file:

import { Chat, ChatList, LS_TOKEN_KEY, LS_USER_ID } from "chat-frontend-library";

Important

After logging the user into your application, you should set the access token in the local storage of the browser for the chat components:

localStorage.setItem(LS_TOKEN_KEY, access_token);

After calling the function to refresh a token from your app, the new received token must be installed in local storage of the browser under the key LS_TOKEN_KEY and returned from the function.


Chat Component

import { Chat } from "chat-frontend-library";

  <Chat
    opponent_id="opponent_id"
    user_id="user_id"
    user_locale="locale"
    isOnlyChat={true}
    cbHandleCloseChat={cbCloseChat}
    handleRefreshToken={cbRefreshToken}
    classHeader="customCSSClass"
    classMessages="customCSSClass"
  />
Chat props
propdefaulttypedescription
opponent_idnonestringUser opponent ID
user_idnonestringUser id got from the access token by decoding
user_localeru/enstringChat interface language. The browser language is set by default
isOnlyChatnonebooleantrue value is set when only the chat close functionality is used. false allows more chat functionality
cbHandleCloseChatnonefunctionA callback function that is called when the user clicks the close chat button
handleRefreshTokennonefunctionAn asynchronous callback function that is called if the chat API call returns an error. Takes an axios error as an argument. Should return the new user token
classHeader" "stringAdds a custom style class for the Chat header
classMessages" "stringAdds a custom style class for the box with messages

ChatList Component

import { ChatList } from "chat-frontend-library";

  <ChatList
    user_id="user_id"
    user_locale="locale"
    isOnlyChatList={true}
    cbHandleCloseChatList={handleCloseList}
    handleRefreshToken={handleRefreshToken}
    classList="customCSSClass"
    cbHandleOpenChat={handleOpenChat}
  />
ChatList props
propdefaulttypedescription
user_idnonestringUser id got from the access token by decoding
user_localeru/enstringChatList interface language. The browser language is set by default.
isOnlyChatListnonebooleantrue value is set when only the chat list close functionality is used. false allows more chat list functionality.
cbHandleCloseChatListnonefunctionA callback function that is called when the user clicks the close chat button.
cbHandleOpenChatnonefunctionA callback function that is called when the user clicks on a specific chat in the list. Takes an object as a function argument: {chat_id:string; opponent_id:string}
handleRefreshTokennonefunctionAn asynchronous callback function that is called if the chat API call returns an error. Takes an axios error as an argument. Should return the new user token.
classList" "stringAdds a custom style class for the ChatList wrapper

1.0.165

7 months ago

1.0.166

7 months ago

1.0.168

7 months ago

1.0.147

7 months ago

1.0.146

7 months ago

1.0.149

7 months ago

1.0.148

7 months ago

1.0.164

7 months ago

1.0.161

7 months ago

1.0.160

7 months ago

1.0.163

7 months ago

1.0.162

7 months ago

1.0.154

7 months ago

1.0.153

7 months ago

1.0.156

7 months ago

1.0.155

7 months ago

1.0.150

7 months ago

1.0.152

7 months ago

1.0.151

7 months ago

1.0.158

7 months ago

1.0.157

7 months ago

1.0.159

7 months ago

1.0.143

8 months ago

1.0.142

8 months ago

1.0.145

8 months ago

1.0.144

8 months ago

1.0.141

8 months ago

1.0.140

8 months ago

1.0.132

8 months ago

1.0.131

8 months ago

1.0.134

8 months ago

1.0.133

8 months ago

1.0.130

8 months ago

1.0.139

8 months ago

1.0.136

8 months ago

1.0.135

8 months ago

1.0.138

8 months ago

1.0.137

8 months ago

1.0.121

8 months ago

1.0.120

8 months ago

1.0.123

8 months ago

1.0.122

8 months ago

1.0.129

8 months ago

1.0.128

8 months ago

1.0.125

8 months ago

1.0.124

8 months ago

1.0.127

8 months ago

1.0.126

8 months ago

1.0.119

8 months ago

1.0.118

8 months ago

1.0.117

8 months ago

1.0.116

8 months ago

1.0.107

9 months ago

1.0.106

9 months ago

1.0.109

9 months ago

1.0.108

9 months ago

1.0.105

9 months ago

1.0.104

9 months ago

1.0.110

9 months ago

1.0.112

9 months ago

1.0.111

9 months ago

1.0.114

9 months ago

1.0.113

9 months ago

1.0.115

9 months ago

1.0.101

9 months ago

1.0.100

9 months ago

1.0.103

9 months ago

1.0.102

9 months ago

1.0.99

9 months ago

1.0.84

9 months ago

1.0.83

9 months ago

1.0.82

9 months ago

1.0.81

9 months ago

1.0.88

9 months ago

1.0.87

9 months ago

1.0.86

9 months ago

1.0.85

9 months ago

1.0.89

9 months ago

1.0.91

9 months ago

1.0.90

9 months ago

1.0.95

9 months ago

1.0.94

9 months ago

1.0.93

9 months ago

1.0.92

9 months ago

1.0.98

9 months ago

1.0.97

9 months ago

1.0.96

9 months ago

1.0.77

10 months ago

1.0.79

10 months ago

1.0.78

10 months ago

1.0.80

9 months ago

1.0.66

10 months ago

1.0.65

10 months ago

1.0.69

10 months ago

1.0.68

10 months ago

1.0.67

10 months ago

1.0.73

10 months ago

1.0.72

10 months ago

1.0.71

10 months ago

1.0.70

10 months ago

1.0.76

10 months ago

1.0.75

10 months ago

1.0.74

10 months ago

1.0.64

10 months ago

1.0.63

10 months ago

1.0.62

10 months ago

1.0.61

10 months ago

1.0.60

10 months ago

1.0.51

11 months ago

1.0.55

11 months ago

1.0.54

11 months ago

1.0.53

11 months ago

1.0.52

11 months ago

1.0.59

10 months ago

1.0.58

11 months ago

1.0.57

11 months ago

1.0.56

11 months ago

1.0.50

11 months ago

1.0.49

11 months ago

1.0.48

11 months ago

1.0.47

11 months ago

1.0.45

11 months ago

1.0.43

11 months ago

1.0.42

11 months ago

1.0.41

11 months ago

1.0.40

11 months ago

1.0.39

11 months ago

1.0.38

11 months ago

1.0.37

11 months ago

1.0.36

11 months ago

1.0.35

11 months ago

1.0.34

11 months ago

1.0.33

11 months ago

1.0.32

11 months ago

1.0.31

11 months ago

1.0.30

11 months ago

1.0.29

11 months ago

1.0.28

11 months ago

1.0.27

11 months ago

1.0.26

11 months ago

1.0.25

11 months ago

1.0.24

11 months ago

1.0.23

11 months ago

1.0.22

11 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago