corp-chat-library-antd-react-socket 1.2.0 → 1.2.2

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/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- The MIT License (MIT)
2
- Copyright (c) 2025 azzimandias
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
1
+ The MIT License (MIT)
2
+ Copyright (c) 2025 azzimandias
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md CHANGED
@@ -1,73 +1,440 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
-
10
- ## React Compiler
11
-
12
- The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
-
14
- ## Expanding the ESLint configuration
15
-
16
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17
-
18
- ```js
19
- export default defineConfig([
20
- globalIgnores(['dist']),
21
- {
22
- files: ['**/*.{ts,tsx}'],
23
- extends: [
24
- // Other configs...
25
-
26
- // Remove tseslint.configs.recommended and replace with this
27
- tseslint.configs.recommendedTypeChecked,
28
- // Alternatively, use this for stricter rules
29
- tseslint.configs.strictTypeChecked,
30
- // Optionally, add this for stylistic rules
31
- tseslint.configs.stylisticTypeChecked,
32
-
33
- // Other configs...
34
- ],
35
- languageOptions: {
36
- parserOptions: {
37
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
- tsconfigRootDir: import.meta.dirname,
39
- },
40
- // other options...
41
- },
42
- },
43
- ])
44
- ```
45
-
46
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
-
48
- ```js
49
- // eslint.config.js
50
- import reactX from 'eslint-plugin-react-x'
51
- import reactDom from 'eslint-plugin-react-dom'
52
-
53
- export default defineConfig([
54
- globalIgnores(['dist']),
55
- {
56
- files: ['**/*.{ts,tsx}'],
57
- extends: [
58
- // Other configs...
59
- // Enable lint rules for React
60
- reactX.configs['recommended-typescript'],
61
- // Enable lint rules for React DOM
62
- reactDom.configs.recommended,
63
- ],
64
- languageOptions: {
65
- parserOptions: {
66
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
- tsconfigRootDir: import.meta.dirname,
68
- },
69
- // other options...
70
- },
71
- },
72
- ])
73
- ```
1
+ # Chat based on React + TypeScript + Vite
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ npm install corp-chat-library-antd-react-socket
7
+ ```
8
+ ## Usage
9
+ ```tsx
10
+ import Chat from "corp-chat-library-antd-react-socket";
11
+
12
+ export default () => (
13
+ <Chat userdata={userdata}
14
+ httpParams={httpParams}
15
+ fetchParams={fetchParams}
16
+ socketSubscribe={socketSubscribe}
17
+ socketActions={socketActions}
18
+ />
19
+ );
20
+ ```
21
+ ## Props types
22
+ ```ts
23
+ export interface ChatParams {
24
+ userdata: UserData;
25
+ httpParams: HttpParams;
26
+ fetchParams: FetchParams;
27
+ socketSubscribe: SocketSubscribe;
28
+ socketActions: SocketActions;
29
+ }
30
+
31
+ export interface HttpParams {
32
+ CSRF_TOKEN: string;
33
+ PRODMODE: boolean;
34
+ HTTP_HOST: string;
35
+ BFF_PORT: number;
36
+ }
37
+
38
+ export interface FetchParams {
39
+ fetchChatsListPath: string;
40
+ fetchChatMessagesPath: string;
41
+ sendSmsPath: string;
42
+ markMessagesAsReadPath: string;
43
+ }
44
+
45
+ export interface SocketSubscribe {
46
+ subscribeToChat: string;
47
+ }
48
+
49
+ export interface SocketActions {
50
+ newSms: string;
51
+ updateSms: string;
52
+ }
53
+
54
+ export interface UserData {
55
+ acls: number[],
56
+ companies: Company[],
57
+ user: User,
58
+ mode: number,
59
+ duration: number,
60
+ status: number,
61
+ }
62
+
63
+ export interface Company {
64
+ id: number,
65
+ name: string,
66
+ description: string,
67
+ is_active: number,
68
+ template_prefix: string,
69
+ folder: string,
70
+ color: string,
71
+ ext_address_offers: string,
72
+ path_logo: string,
73
+ places: Place[],
74
+ }
75
+
76
+ export interface Place {
77
+ id: number,
78
+ name: string,
79
+ label: string,
80
+ accessgroup: number,
81
+ accessname: string,
82
+ position: number,
83
+ place: number,
84
+ }
85
+
86
+ export interface User {
87
+ id: number,
88
+ name: string,
89
+ surname: string,
90
+ secondname: string,
91
+ occupy: string,
92
+ passcard: string | null | undefined,
93
+ id_role: number,
94
+ email: string | null | undefined,
95
+ sales_role: number,
96
+ password2: string,
97
+ active_company: number,
98
+ id_departament: number,
99
+ id_company: number,
100
+ super?: number | null,
101
+ }
102
+ ```
103
+
104
+ ## HttpParams
105
+ CSRF_TOKEN - session token for backend;\
106
+ PRODMODE - use fetches and socked, or use mocks;\
107
+ HTTP_HOST - host;\
108
+ BFF_PORT - socket port (HTTP_HOST:BFF_PORT);
109
+
110
+ ## Fetches
111
+ ### "fetchChatsListPath"
112
+ payload:
113
+ ```ts
114
+ const payload = {
115
+ "data": {
116
+ "search": "" // search string
117
+ },
118
+ "_token": "jklgjl4494033gfgf342sddgLFRE"
119
+ }
120
+ ```
121
+
122
+ expected response format:
123
+ ```ts
124
+ export interface fetchChatsListPathResponse {
125
+ content: {
126
+ sms: ChatToList[], // last message from all chats
127
+ total_unread: number, // the number of all unread messages in all chats
128
+ }
129
+ }
130
+ ```
131
+ ---
132
+
133
+ ### "fetchChatMessagesPath"
134
+ When you scroll up the chat, a pack of older messages will be loaded.\
135
+ payload:
136
+ ```ts
137
+ const payload = {
138
+ "data": {
139
+ "last_id": null // ID of the oldest message in the pack, null on first time
140
+ },
141
+ "_token": "006GmuwH1vmrE8OdOIax4ySEd3FDreDD1u78t5ll"
142
+ }
143
+ ```
144
+
145
+ expected response format:
146
+ ```ts
147
+ export interface fetchChatMessagesPathResponse {
148
+ "content": {
149
+ "messages": [
150
+ {
151
+ "id": 626,
152
+ "from_id": 584,
153
+ "answer": null,
154
+ "text": "text",
155
+ "files": [
156
+ {
157
+ "id": 23,
158
+ "route": "files/files_1_644_check_1.png",
159
+ "extension": "png",
160
+ "name": "files_1_644_check_1.png"
161
+ }
162
+ ],
163
+ "status": true,
164
+ "created_at": 1762419672,
165
+ "updated_at": 1762420765
166
+ },
167
+ /* ... */
168
+ ],
169
+ "who": "Name Surname",
170
+ "total": 19
171
+ },
172
+ "message": "OK!"
173
+ }
174
+ ```
175
+ ---
176
+
177
+ ### "sendSmsPath"
178
+ When you scroll up the chat, a pack of older messages will be loaded.\
179
+ formData payload:
180
+ ```
181
+ ------WebKitFormBoundary3wAFUZxrYC6BqiuX
182
+ Content-Disposition: form-data; name="_token"
183
+
184
+ 006GmuwH1vmrE8OdOIax4ySEd3FDreDD1u78t5ll
185
+ ------WebKitFormBoundary3wAFUZxrYC6BqiuX
186
+ Content-Disposition: form-data; name="data"
187
+
188
+ {
189
+ "to":584,
190
+ "text":"text",
191
+ "answer":null,
192
+ "timestamp":1763373631
193
+ }
194
+ ------WebKitFormBoundary3wAFUZxrYC6BqiuX
195
+ Content-Disposition: form-data; name="file[]"; filename="211751_gear_icon.svg"
196
+ Content-Type: image/svg+xml
197
+
198
+
199
+ ------WebKitFormBoundary3wAFUZxrYC6BqiuX--
200
+ ```
201
+
202
+ expected response format:
203
+ ```ts
204
+ export interface sendSmsPathResponse {
205
+ "message": "OK!",
206
+ "id": 645,
207
+ "timestamp": 1763373631,
208
+ "left": {
209
+ "id": 645,
210
+ "chat_id": 584,
211
+ "from": {
212
+ "surname": "Surname",
213
+ "name": "Name",
214
+ "id": 566
215
+ },
216
+ "to": {
217
+ "surname": "Surname",
218
+ "name": "Name",
219
+ "id": 584
220
+ },
221
+ "text": "text",
222
+ "status": false,
223
+ "files": [],
224
+ "created_at": 1763373631,
225
+ "updated_at": 1763373631,
226
+ "count_unread": 1,
227
+ "total_unread": 1
228
+ },
229
+ "files": [
230
+ {
231
+ "id": 24,
232
+ "route": "files/files_1_646_211751_gear_icon.svg",
233
+ "extension": "svg",
234
+ "name": "files_1_646_211751_gear_icon.svg"
235
+ }
236
+ ]
237
+ }
238
+ ```
239
+ ---
240
+
241
+ ### "markMessagesAsReadPath"
242
+ payload:
243
+ ```ts
244
+ const payload = {
245
+ "_token": "kvZJHSrj3JPJjyIthLPaCmjiYkb7H1TvATqJlxgE"
246
+ }
247
+ ```
248
+
249
+ expected response format:
250
+ ```ts
251
+ export interface markMessagesAsReadPathResponse {
252
+ "message": "OK!",
253
+ "sms": {
254
+ "id": 646,
255
+ "from": 46,
256
+ "to": 584,
257
+ "answer_id": null,
258
+ "text": "text",
259
+ "status": true,
260
+ "created_at": 1763374396,
261
+ "updated_at": 1763374626,
262
+ "count_unread": 0,
263
+ "total_unread": 0
264
+ }
265
+ }
266
+ ```
267
+ ---
268
+
269
+ ## Socket
270
+ "subscribeToChat" expects the name of the event in which the user joins the room.\
271
+ Example:
272
+ ```js
273
+ socket.on('expamleSubscribeToChatName', (userId) => {
274
+ const userRoom = `user:${userId}`;
275
+ socket.join(userRoom);
276
+ console.log(`User ${socket.id} joined personal room ${userRoom}`);
277
+ socket.join('CHAT');
278
+ })
279
+ ```
280
+
281
+ ---
282
+
283
+ New message received event: "newSms"
284
+
285
+ The socket must return in this format:
286
+ ```ts
287
+ export interface NewSmsResponse {
288
+ left: ChatToList,
289
+ rigth: ChatMessage,
290
+ }
291
+ ```
292
+
293
+ Message format for the message list:
294
+ ```ts
295
+ export interface ChatToList {
296
+ id: number | undefined,
297
+ chat_id: number | undefined,
298
+ text: string,
299
+ files: string[],
300
+ status: boolean,
301
+ created_at: number,
302
+ updated_at: number,
303
+ count_unread: number,
304
+ from: From,
305
+ to: To,
306
+ to_id?: number,
307
+ from_id?: number,
308
+ last_message?: number,
309
+ }
310
+
311
+ export interface From {
312
+ id: number | undefined,
313
+ name: string,
314
+ surname: string,
315
+ }
316
+
317
+ export interface To {
318
+ id: number | undefined,
319
+ name: string,
320
+ surname: string,
321
+ }
322
+ ```
323
+ Message format for the opened chat:
324
+ ```ts
325
+ export interface ChatMessage {
326
+ id: number,
327
+ from_id: number,
328
+ answer: number | null,
329
+ text: string,
330
+ files: File[],
331
+ status: boolean,
332
+ created_at: number,
333
+ updated_at: number,
334
+ from?: number,
335
+ isLocal?: boolean,
336
+ isSending?: boolean,
337
+ }
338
+
339
+ export interface File {
340
+ id: number,
341
+ route: string,
342
+ extension: string,
343
+ name: string,
344
+ }
345
+ ```
346
+
347
+ ---
348
+ Updated message received event: "updateSms"
349
+
350
+ The socket must return in this format:
351
+ ```ts
352
+ export interface ChatMessage {
353
+ id: number,
354
+ from_id: number,
355
+ answer: number | null,
356
+ text: string,
357
+ files: File[],
358
+ status: boolean,
359
+ created_at: number,
360
+ updated_at: number,
361
+ from?: number,
362
+ isLocal?: boolean,
363
+ isSending?: boolean,
364
+ }
365
+ ```
366
+
367
+
368
+ ---
369
+ ## Generated md
370
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
371
+
372
+ Currently, two official plugins are available:
373
+
374
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
375
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
376
+
377
+ ## React Compiler
378
+
379
+ The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
380
+
381
+ ## Expanding the ESLint configuration
382
+
383
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
384
+
385
+ ```js
386
+ export default defineConfig([
387
+ globalIgnores(['dist']),
388
+ {
389
+ files: ['**/*.{ts,tsx}'],
390
+ extends: [
391
+ // Other configs...
392
+
393
+ // Remove tseslint.configs.recommended and replace with this
394
+ tseslint.configs.recommendedTypeChecked,
395
+ // Alternatively, use this for stricter rules
396
+ tseslint.configs.strictTypeChecked,
397
+ // Optionally, add this for stylistic rules
398
+ tseslint.configs.stylisticTypeChecked,
399
+
400
+ // Other configs...
401
+ ],
402
+ languageOptions: {
403
+ parserOptions: {
404
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
405
+ tsconfigRootDir: import.meta.dirname,
406
+ },
407
+ // other options...
408
+ },
409
+ },
410
+ ])
411
+ ```
412
+
413
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
414
+
415
+ ```js
416
+ // eslint.config.js
417
+ import reactX from 'eslint-plugin-react-x'
418
+ import reactDom from 'eslint-plugin-react-dom'
419
+
420
+ export default defineConfig([
421
+ globalIgnores(['dist']),
422
+ {
423
+ files: ['**/*.{ts,tsx}'],
424
+ extends: [
425
+ // Other configs...
426
+ // Enable lint rules for React
427
+ reactX.configs['recommended-typescript'],
428
+ // Enable lint rules for React DOM
429
+ reactDom.configs.recommended,
430
+ ],
431
+ languageOptions: {
432
+ parserOptions: {
433
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
434
+ tsconfigRootDir: import.meta.dirname,
435
+ },
436
+ // other options...
437
+ },
438
+ },
439
+ ])
440
+ ```
@@ -1,4 +1,6 @@
1
1
  import { Normalized } from '../types/types.ts';
2
- export default function ChatIncomingMsg({ message }: {
2
+ import { default as React } from 'react';
3
+ export default function ChatIncomingMsg({ message, pasteFileIcon }: {
3
4
  message: Normalized | undefined;
5
+ pasteFileIcon: (extension: string) => React.ReactNode;
4
6
  }): import("react/jsx-runtime").JSX.Element | null;
@@ -1,4 +1,6 @@
1
1
  import { Normalized } from '../types/types.ts';
2
- export default function ChatSelfMsg({ message }: {
2
+ import { default as React } from 'react';
3
+ export default function ChatSelfMsg({ message, pasteFileIcon }: {
3
4
  message: Normalized;
5
+ pasteFileIcon: (extension: string) => React.ReactNode;
4
6
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { AlertInfo, Chat, ChatToList, UserData } from '../types/types.ts';
3
- import { UploadFile } from 'antd';
4
- import * as React from 'react';
2
+ import { AlertInfo, Chat, ChatToList, toSendSms, UserData } from '../types/types.ts';
5
3
  interface ChatSocketContextType {
6
4
  connected: boolean;
7
5
  connectionStatus: string;
@@ -38,17 +36,6 @@ interface ChatSocketContextType {
38
36
  init: boolean;
39
37
  setInit: (bool: boolean) => void;
40
38
  }
41
- interface toSendSms {
42
- to: number;
43
- text: string;
44
- files?: UploadFile[];
45
- answer: number | null;
46
- timestamp: number;
47
- from_id: number;
48
- }
49
- export declare const ChatSocketContext: React.Context<ChatSocketContextType | undefined>;
50
- export declare const ChatSocketProvider: ({ children }: {
51
- children: React.ReactNode;
52
- }) => import("react/jsx-runtime").JSX.Element;
39
+ export declare const ChatSocketContext: import('react').Context<ChatSocketContextType | undefined>;
53
40
  export declare const useChatSocket: () => ChatSocketContextType;
54
41
  export {};
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ export declare const ChatSocketProvider: ({ children }: {
3
+ children: React.ReactNode;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -1,3 +1,4 @@
1
+ import { UploadFile } from 'antd';
1
2
  export interface ChatParams {
2
3
  userdata: UserData;
3
4
  httpParams: HttpParams;
@@ -143,3 +144,11 @@ export interface messagesWithDividersInterface {
143
144
  timestamp?: number;
144
145
  message?: Normalized;
145
146
  }
147
+ export interface toSendSms {
148
+ to: number;
149
+ text: string;
150
+ files?: UploadFile[];
151
+ answer: number | null;
152
+ timestamp: number;
153
+ from_id: number;
154
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as Chat } from './Chat';
2
2
  export { default as ChatBtn } from './CHAT/ChatBtn';
3
- export { ChatSocketProvider, useChatSocket } from './CHAT/context/ChatSocketContext';
3
+ export { useChatSocket } from './CHAT/context/ChatSocketContext';
4
+ export { ChatSocketProvider } from './CHAT/provider/ChatSocketProvider';
4
5
  export type { ChatParams } from './CHAT/types/types.ts';
5
6
  export { default } from './Chat';