@buerokratt-ria/common-gui-components 0.0.1

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.
Files changed (122) hide show
  1. package/.eslintrc.json +18 -0
  2. package/CHANGELOG.md +7 -0
  3. package/MAKING_CHANGES.md +8 -0
  4. package/README.md +49 -0
  5. package/assets/ding.mp3 +0 -0
  6. package/assets/logo-white.svg +29 -0
  7. package/assets/logo.svg +31 -0
  8. package/assets/newMessageSound.mp3 +0 -0
  9. package/constants/config.ts +12 -0
  10. package/constants/index.ts +1 -0
  11. package/context/index.ts +1 -0
  12. package/context/toastContext.tsx +60 -0
  13. package/hooks/index.ts +3 -0
  14. package/hooks/useAudio.tsx +30 -0
  15. package/hooks/useDocumentEscapeListener.tsx +17 -0
  16. package/hooks/useToast.tsx +5 -0
  17. package/i18n.ts +26 -0
  18. package/index.ts +6 -0
  19. package/package.json +122 -0
  20. package/project.json +52 -0
  21. package/services/api.ts +74 -0
  22. package/services/index.ts +3 -0
  23. package/services/sse-service.ts +30 -0
  24. package/services/users.ts +58 -0
  25. package/store/index.ts +253 -0
  26. package/templates/history-page/index.ts +1 -0
  27. package/templates/history-page/src/History.scss +47 -0
  28. package/templates/history-page/src/index.tsx +998 -0
  29. package/templates/history-page/src/unfiyDate.tsx +7 -0
  30. package/translations/en/common.json +467 -0
  31. package/translations/et/common.json +467 -0
  32. package/tsconfig.base.json +21 -0
  33. package/tsconfig.json +17 -0
  34. package/tsconfig.spec.json +19 -0
  35. package/types/authorities.ts +8 -0
  36. package/types/botConfig.ts +7 -0
  37. package/types/chat.ts +126 -0
  38. package/types/customerSupportActivity.ts +5 -0
  39. package/types/deleteChatSettings.ts +9 -0
  40. package/types/emergencyNotice.ts +10 -0
  41. package/types/establishment.ts +4 -0
  42. package/types/index.ts +18 -0
  43. package/types/mainNavigation.ts +11 -0
  44. package/types/message.ts +74 -0
  45. package/types/organizationWorkingTime.ts +27 -0
  46. package/types/router.ts +4 -0
  47. package/types/service.ts +6 -0
  48. package/types/session.ts +7 -0
  49. package/types/skmConfig.ts +8 -0
  50. package/types/user.ts +40 -0
  51. package/types/userInfo.ts +16 -0
  52. package/types/userProfileSettings.ts +10 -0
  53. package/types/widgetConfig.ts +8 -0
  54. package/ui-components/Button/Button.scss +150 -0
  55. package/ui-components/Button/index.tsx +41 -0
  56. package/ui-components/ButtonMessage/ButtonMessage.scss +16 -0
  57. package/ui-components/ButtonMessage/index.tsx +19 -0
  58. package/ui-components/Card/Card.scss +69 -0
  59. package/ui-components/Card/index.tsx +39 -0
  60. package/ui-components/Chat/Chat.scss +447 -0
  61. package/ui-components/Chat/ChatMessage.tsx +270 -0
  62. package/ui-components/Chat/ChatTextArea.scss +110 -0
  63. package/ui-components/Chat/ChatTextArea.tsx +97 -0
  64. package/ui-components/Chat/LoaderOverlay.tsx +39 -0
  65. package/ui-components/Chat/Markdownify.tsx +49 -0
  66. package/ui-components/Chat/PreviewMessage.tsx +39 -0
  67. package/ui-components/Chat/Typing.scss +46 -0
  68. package/ui-components/Chat/index.tsx +1111 -0
  69. package/ui-components/ChatEvent/Chat.scss +40 -0
  70. package/ui-components/ChatEvent/index.tsx +216 -0
  71. package/ui-components/DataTable/CloseIcon.tsx +22 -0
  72. package/ui-components/DataTable/DataTable.scss +188 -0
  73. package/ui-components/DataTable/DeboucedInput.scss +11 -0
  74. package/ui-components/DataTable/DebouncedInput.tsx +54 -0
  75. package/ui-components/DataTable/Filter.tsx +121 -0
  76. package/ui-components/DataTable/index.tsx +432 -0
  77. package/ui-components/Dialog/Dialog.scss +63 -0
  78. package/ui-components/Dialog/index.tsx +44 -0
  79. package/ui-components/Drawer/Drawer.scss +40 -0
  80. package/ui-components/Drawer/index.tsx +42 -0
  81. package/ui-components/FormElements/FormCheckbox/FormCheckbox.scss +57 -0
  82. package/ui-components/FormElements/FormCheckbox/index.tsx +39 -0
  83. package/ui-components/FormElements/FormCheckboxes/FormCheckboxes.scss +63 -0
  84. package/ui-components/FormElements/FormCheckboxes/index.tsx +44 -0
  85. package/ui-components/FormElements/FormDatepicker/FormDatepicker.scss +154 -0
  86. package/ui-components/FormElements/FormDatepicker/index.tsx +123 -0
  87. package/ui-components/FormElements/FormInput/FormInput.scss +90 -0
  88. package/ui-components/FormElements/FormInput/index.tsx +47 -0
  89. package/ui-components/FormElements/FormRadios/FormRadios.scss +72 -0
  90. package/ui-components/FormElements/FormRadios/index.tsx +36 -0
  91. package/ui-components/FormElements/FormSelect/FormMultiselect.tsx +124 -0
  92. package/ui-components/FormElements/FormSelect/FormSelect.scss +121 -0
  93. package/ui-components/FormElements/FormSelect/index.tsx +100 -0
  94. package/ui-components/FormElements/FormTextarea/FormTextarea.scss +109 -0
  95. package/ui-components/FormElements/FormTextarea/index.tsx +154 -0
  96. package/ui-components/FormElements/Switch/Switch.scss +69 -0
  97. package/ui-components/FormElements/Switch/index.tsx +65 -0
  98. package/ui-components/FormElements/SwitchBox/SwitchBox.scss +45 -0
  99. package/ui-components/FormElements/SwitchBox/index.tsx +44 -0
  100. package/ui-components/FormElements/index.tsx +23 -0
  101. package/ui-components/HistoricalChat/ChatMessage.tsx +67 -0
  102. package/ui-components/HistoricalChat/HistoricalChat.scss +225 -0
  103. package/ui-components/HistoricalChat/index.tsx +282 -0
  104. package/ui-components/Icon/Icon.scss +17 -0
  105. package/ui-components/Icon/index.tsx +26 -0
  106. package/ui-components/Label/Label.scss +76 -0
  107. package/ui-components/Label/index.tsx +40 -0
  108. package/ui-components/OptionMessage/OptionMessage.scss +16 -0
  109. package/ui-components/OptionMessage/index.tsx +16 -0
  110. package/ui-components/Toast/Toast.scss +73 -0
  111. package/ui-components/Toast/index.tsx +54 -0
  112. package/ui-components/Tooltip/Tooltip.scss +17 -0
  113. package/ui-components/Tooltip/index.tsx +28 -0
  114. package/ui-components/Track/index.tsx +57 -0
  115. package/ui-components/index.tsx +53 -0
  116. package/utils/constants.ts +19 -0
  117. package/utils/format-bytes.ts +8 -0
  118. package/utils/generateUEID.ts +8 -0
  119. package/utils/local-storage-utils.ts +17 -0
  120. package/utils/parse-utils.ts +23 -0
  121. package/utils/state-management-utils.ts +13 -0
  122. package/vite.config.ts +67 -0
@@ -0,0 +1,58 @@
1
+ import { apiDev } from './api';
2
+ import { User, UserDTO } from 'types/user';
3
+
4
+ export async function createUser(userData: UserDTO) {
5
+ const authorities = userData.authorities
6
+ .map((e) => (e as any).value)
7
+ .filter((item) => item);
8
+ const fullName = userData.fullName?.trim();
9
+ const { data } = await apiDev.post<User>('accounts/admin/add', {
10
+ firstName: fullName?.split(' ').slice(0, 1).join(' ') ?? '',
11
+ lastName: fullName?.split(' ').slice(1, 2).join(' ') ?? '',
12
+ userIdCode: userData.idCode,
13
+ displayName: userData.displayName,
14
+ csaTitle: userData.csaTitle,
15
+ csa_email: userData.csaEmail,
16
+ roles:
17
+ authorities.length === 0
18
+ ? Object.values(userData.authorities)
19
+ : authorities,
20
+ department: userData.department,
21
+ });
22
+ return data;
23
+ }
24
+
25
+ export async function checkIfUserExists(userData: UserDTO) {
26
+ const { data } = await apiDev.post('accounts/admin/exists', {
27
+ userIdCode: userData.idCode,
28
+ });
29
+ return data;
30
+ }
31
+
32
+ export async function editUser(id: string | number, userData: UserDTO) {
33
+ const authorities = userData.authorities
34
+ .map((e: any) => e.value)
35
+ .filter((item) => item);
36
+ const fullName = userData.fullName?.trim();
37
+ const { data } = await apiDev.post<User>('accounts/admin/edit', {
38
+ firstName: fullName?.split(' ').slice(0, 1).join(' ') ?? '',
39
+ lastName: fullName?.split(' ').slice(1, 2).join(' ') ?? '',
40
+ userIdCode: id,
41
+ displayName: userData.displayName,
42
+ csaTitle: userData.csaTitle,
43
+ csa_email: userData.csaEmail,
44
+ roles:
45
+ authorities.length === 0
46
+ ? Object.values(userData.authorities)
47
+ : authorities,
48
+ department: userData.department,
49
+ });
50
+ return data;
51
+ }
52
+
53
+ export async function deleteUser(id: string | number) {
54
+ const { data } = await apiDev.post<User>('accounts/admin/delete', {
55
+ userIdCode: id,
56
+ });
57
+ return data;
58
+ }
package/store/index.ts ADDED
@@ -0,0 +1,253 @@
1
+ import { create } from 'zustand';
2
+ import { UserInfo } from '../types/userInfo';
3
+ import {
4
+ CHAT_STATUS,
5
+ Chat as ChatType,
6
+ GroupedChat,
7
+ GroupedPendingChat,
8
+ } from '../types/chat';
9
+ import { apiDev } from '../services/api';
10
+
11
+ interface StoreState {
12
+ userInfo: UserInfo | null;
13
+ userId: string;
14
+ activeChats: ChatType[];
15
+ pendingChats: ChatType[];
16
+ selectedChatId: string | null;
17
+ chatCsaActive: boolean;
18
+ setActiveChats: (chats: ChatType[]) => void;
19
+ setPendingChats: (chats: ChatType[]) => void;
20
+ setUserInfo: (info: UserInfo) => void;
21
+ setSelectedChatId: (id: string | null) => void;
22
+ setChatCsaActive: (active: boolean) => void;
23
+ selectedChat: () => ChatType | null | undefined;
24
+ selectedPendingChat: () => ChatType | null | undefined;
25
+ unansweredChats: () => ChatType[];
26
+ forwordedChats: () => ChatType[];
27
+ unansweredChatsLength: () => number;
28
+ forwordedChatsLength: () => number;
29
+ loadActiveChats: () => Promise<void>;
30
+ getGroupedActiveChats: () => GroupedChat;
31
+ getGroupedUnansweredChats: () => GroupedChat;
32
+ loadPendingChats: () => Promise<void>;
33
+ getGroupedPendingChats: () => GroupedPendingChat;
34
+ }
35
+
36
+ const useStore = create<StoreState>((set, get, store) => ({
37
+ userInfo: null,
38
+ userId: '',
39
+ activeChats: [],
40
+ pendingChats: [],
41
+ selectedChatId: null,
42
+ chatCsaActive: false,
43
+ setActiveChats: (chats) => set({ activeChats: chats }),
44
+ setPendingChats: (chats) => set({ pendingChats: chats }),
45
+ setUserInfo: (data) => set({ userInfo: data, userId: data?.idCode || '' }),
46
+ setSelectedChatId: (id) => set({ selectedChatId: id }),
47
+ setChatCsaActive: (active) => {
48
+ set({
49
+ chatCsaActive: active,
50
+ });
51
+ get().loadActiveChats();
52
+ get().loadPendingChats();
53
+ },
54
+ selectedChat: () => {
55
+ const selectedChatId = get().selectedChatId;
56
+ return get().activeChats.find((c) => c.id === selectedChatId);
57
+ },
58
+ selectedPendingChat: () => {
59
+ const selectedChatId = get().selectedChatId;
60
+ return get().pendingChats.find((c) => c.id === selectedChatId);
61
+ },
62
+ unansweredChats: () => {
63
+ return get().activeChats?.filter?.((c) => c.customerSupportId === '') ?? [];
64
+ },
65
+ forwordedChats: () => {
66
+ const userId = get().userId;
67
+ return (
68
+ get().activeChats?.filter(
69
+ (c) =>
70
+ c.status === CHAT_STATUS.REDIRECTED && c.customerSupportId === userId
71
+ ) || []
72
+ );
73
+ },
74
+ unansweredChatsLength: () => get().unansweredChats().length,
75
+ forwordedChatsLength: () => get().forwordedChats().length,
76
+
77
+ loadActiveChats: async () => {
78
+ const res = await apiDev.get('agents/chats/active');
79
+ const chats: ChatType[] = res.data.response ?? [];
80
+ const selectedChatId = get().selectedChatId;
81
+ const isChatStillExists = chats?.filter(
82
+ (e: any) => e.id === selectedChatId
83
+ );
84
+ if (isChatStillExists.length === 0 && get().activeChats.length > 0) {
85
+ setTimeout(() => get().setActiveChats(chats), 3000);
86
+ } else {
87
+ get().setActiveChats(chats);
88
+ }
89
+ },
90
+ loadPendingChats: async () => {
91
+ const res = await apiDev.get('agents/chats/pending');
92
+ const chats: ChatType[] = res.data.response ?? [];
93
+ const selectedChatId = get().selectedChatId;
94
+ const isChatStillExists = chats?.filter(
95
+ (e: any) => e.id === selectedChatId
96
+ );
97
+ if (isChatStillExists.length === 0 && get().pendingChats.length > 0) {
98
+ setTimeout(() => get().setPendingChats(chats), 3000);
99
+ } else {
100
+ get().setPendingChats(chats);
101
+ }
102
+ },
103
+ getGroupedActiveChats: () => {
104
+ const activeChats = get().activeChats;
105
+ const userInfo = get().userInfo;
106
+ const chatCsaActive = get().chatCsaActive;
107
+
108
+ const grouped: GroupedChat = {
109
+ myChats: [],
110
+ otherChats: [],
111
+ };
112
+
113
+ if (!activeChats) return grouped;
114
+
115
+ if (
116
+ chatCsaActive === false &&
117
+ !userInfo?.authorities.includes('ROLE_ADMINISTRATOR')
118
+ ) {
119
+ if (get().selectedChatId !== null) {
120
+ get().setSelectedChatId(null);
121
+ }
122
+ return grouped;
123
+ }
124
+
125
+ activeChats.forEach((c) => {
126
+ if (c.customerSupportId === userInfo?.idCode) {
127
+ grouped.myChats.push(c);
128
+ return;
129
+ }
130
+
131
+ const groupIndex = grouped.otherChats.findIndex(
132
+ (x) => x.groupId === c.customerSupportId
133
+ );
134
+
135
+ if (c.customerSupportId !== '') {
136
+ if (groupIndex === -1) {
137
+ grouped.otherChats.push({
138
+ groupId: c.customerSupportId ?? '',
139
+ name: c.customerSupportDisplayName ?? '',
140
+ chats: [c],
141
+ });
142
+ } else {
143
+ grouped.otherChats[groupIndex].chats.push(c);
144
+ }
145
+ }
146
+ });
147
+
148
+ grouped.otherChats.sort((a, b) => a.name.localeCompare(b.name));
149
+ return grouped;
150
+ },
151
+
152
+ getGroupedUnansweredChats: () => {
153
+ const activeChats = get().activeChats;
154
+ const userInfo = get().userInfo;
155
+ const chatCsaActive = get().chatCsaActive;
156
+
157
+ const grouped: GroupedChat = {
158
+ myChats: [],
159
+ otherChats: [],
160
+ };
161
+
162
+ if (!activeChats) return grouped;
163
+
164
+ if (chatCsaActive === true) {
165
+ activeChats.forEach((c) => {
166
+ if (c.customerSupportId === '') {
167
+ grouped.myChats.push(c);
168
+ }
169
+ });
170
+ } else {
171
+ activeChats.forEach((c) => {
172
+ if (
173
+ c.customerSupportId === userInfo?.idCode ||
174
+ c.customerSupportId === ''
175
+ ) {
176
+ grouped.myChats.push(c);
177
+ return;
178
+ }
179
+
180
+ grouped.myChats.sort((a, b) => a.created.localeCompare(b.created));
181
+ const groupIndex = grouped.otherChats.findIndex(
182
+ (x) => x.groupId === c.customerSupportId
183
+ );
184
+ if (c.customerSupportId !== '') {
185
+ if (groupIndex === -1) {
186
+ grouped.otherChats.push({
187
+ groupId: c.customerSupportId ?? '',
188
+ name: c.customerSupportDisplayName ?? '',
189
+ chats: [c],
190
+ });
191
+ } else {
192
+ grouped.otherChats[groupIndex].chats.push(c);
193
+ }
194
+ }
195
+ });
196
+
197
+ grouped.otherChats.sort((a, b) => a.name.localeCompare(b.name));
198
+ }
199
+
200
+ return grouped;
201
+ },
202
+ getGroupedPendingChats: () => {
203
+ const pendingChats = get().pendingChats;
204
+ const userInfo = get().userInfo;
205
+ const chatCsaActive = get().chatCsaActive;
206
+
207
+ const grouped: GroupedPendingChat = {
208
+ newChats: [],
209
+ inProcessChats: [],
210
+ myChats: [],
211
+ otherChats: [],
212
+ };
213
+
214
+ if (!pendingChats) return grouped;
215
+
216
+ if (chatCsaActive) {
217
+ pendingChats.forEach((c) => {
218
+ if (c.customerSupportId === 'chatbot') {
219
+ grouped.newChats.push(c);
220
+ } else {
221
+ grouped.inProcessChats.push(c);
222
+ }
223
+ });
224
+
225
+ grouped.inProcessChats.forEach((c) => {
226
+ if (c.customerSupportId === userInfo?.idCode) {
227
+ grouped.myChats.push(c);
228
+ return;
229
+ }
230
+
231
+ grouped.myChats.sort((a, b) => a.created.localeCompare(b.created));
232
+ const groupIndex = grouped.otherChats.findIndex(
233
+ (x) => x.groupId === c.customerSupportId
234
+ );
235
+ if (c.customerSupportId !== '') {
236
+ if (groupIndex === -1) {
237
+ grouped.otherChats.push({
238
+ groupId: c.customerSupportId ?? '',
239
+ name: c.customerSupportDisplayName ?? '',
240
+ chats: [c],
241
+ });
242
+ } else {
243
+ grouped.otherChats[groupIndex].chats.push(c);
244
+ }
245
+ }
246
+ grouped.otherChats.sort((a, b) => a.name.localeCompare(b.name));
247
+ });
248
+ }
249
+ return grouped;
250
+ },
251
+ }));
252
+
253
+ export default useStore;
@@ -0,0 +1 @@
1
+ export { default as ChatHistory } from './src';
@@ -0,0 +1,47 @@
1
+ @import 'src/styles/tools/spacing';
2
+ @import 'src/styles/tools/color';
3
+ @import 'src/styles/settings/variables/typography';
4
+
5
+ .input-wrapper {
6
+ width: 40%;
7
+ }
8
+
9
+ .card-drawer-container {
10
+ display: flex;
11
+ width: 100%;
12
+ height: 100vh;
13
+ box-sizing: border-box;
14
+ }
15
+
16
+ .card-wrapper {
17
+ flex: 1;
18
+ overflow: auto;
19
+ transition: flex 0.3s ease;
20
+ }
21
+
22
+ .drawer-container {
23
+ flex: 1;
24
+ height: 100%;
25
+ overflow-y: auto;
26
+ box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
27
+ border: 1px solid get-color(black-coral-2);
28
+ }
29
+
30
+ .drawer-container > * {
31
+ position: static !important;
32
+ width: 100%;
33
+ height: 100%;
34
+ }
35
+
36
+ .side-meta {
37
+ background-color: get-color(white);
38
+ border: 1px solid get-color(black-coral-2);
39
+ color: get-color(black-coral-12);
40
+ display: flex;
41
+ flex: 0 0 288px;
42
+ flex-direction: column;
43
+ font-size: $veera-font-size-80;
44
+ gap: 4px;
45
+ overflow-y: auto;
46
+ padding: get-spacing(haapsalu);
47
+ }