@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,57 @@
1
+ import React, { FC, HTMLAttributes, PropsWithChildren } from 'react';
2
+
3
+ type TrackProps = HTMLAttributes<HTMLDivElement> & {
4
+ gap?: number;
5
+ align?: 'left' | 'center' | 'right' | 'stretch';
6
+ justify?: 'start' | 'between' | 'center' | 'around' | 'end';
7
+ direction?: 'horizontal' | 'vertical';
8
+ isMultiline?: boolean;
9
+ }
10
+
11
+ const alignMap = {
12
+ left: 'flex-start',
13
+ center: 'center',
14
+ right: 'flex-end',
15
+ stretch: 'stretch',
16
+ };
17
+
18
+ const justifyMap = {
19
+ start: 'flex-start',
20
+ between: 'space-between',
21
+ center: 'center',
22
+ around: 'space-around',
23
+ end: 'flex-end',
24
+ };
25
+
26
+ const Track: FC<PropsWithChildren<TrackProps>> = (
27
+ {
28
+ gap = 0,
29
+ align = 'center',
30
+ justify = 'start',
31
+ direction = 'horizontal',
32
+ isMultiline = false,
33
+ children,
34
+ style,
35
+ ...rest
36
+ },
37
+ ) => {
38
+ return (
39
+ <div
40
+ className='track'
41
+ style={{
42
+ display: 'flex',
43
+ gap,
44
+ alignItems: alignMap[align],
45
+ justifyContent: justifyMap[justify],
46
+ flexDirection: direction === 'horizontal' ? 'row' : 'column',
47
+ flexWrap: isMultiline ? 'wrap' : undefined,
48
+ ...style,
49
+ }}
50
+ {...rest}
51
+ >
52
+ {children}
53
+ </div>
54
+ );
55
+ };
56
+
57
+ export default Track;
@@ -0,0 +1,53 @@
1
+ import Button from './Button';
2
+ import Icon from './Icon';
3
+ import Track from './Track';
4
+ import {
5
+ FormCheckbox,
6
+ FormCheckboxes,
7
+ FormDatepicker,
8
+ FormInput,
9
+ FormMultiselect,
10
+ FormRadios,
11
+ FormSelect,
12
+ FormTextarea,
13
+ Switch,
14
+ SwitchBox,
15
+ } from './FormElements';
16
+ import DataTable from './DataTable';
17
+ import Tooltip from './Tooltip';
18
+ import Toast from './Toast';
19
+ import Card from './Card';
20
+ import Chat from './Chat';
21
+ import OptionMessage from './OptionMessage';
22
+ import ButtonMessage from './ButtonMessage';
23
+ import Drawer from './Drawer';
24
+ import HistoricalChat from './HistoricalChat';
25
+ import Dialog from './Dialog';
26
+ import Label from './Label';
27
+
28
+ export {
29
+ Button,
30
+ Icon,
31
+ Track,
32
+ Tooltip,
33
+ DataTable,
34
+ FormInput,
35
+ FormTextarea,
36
+ FormSelect,
37
+ FormMultiselect,
38
+ FormDatepicker,
39
+ Switch,
40
+ SwitchBox,
41
+ Card,
42
+ OptionMessage,
43
+ ButtonMessage,
44
+ Chat,
45
+ FormCheckboxes,
46
+ FormRadios,
47
+ FormCheckbox,
48
+ Drawer,
49
+ HistoricalChat,
50
+ Dialog,
51
+ Toast,
52
+ Label
53
+ };
@@ -0,0 +1,19 @@
1
+ export const MESSAGE_FILE_SIZE_LIMIT = 10_000_000;
2
+
3
+ export enum ROLES {
4
+ ROLE_ADMINISTRATOR = 'ROLE_ADMINISTRATOR',
5
+ ROLE_SERVICE_MANAGER = 'ROLE_SERVICE_MANAGER',
6
+ ROLE_CUSTOMER_SUPPORT_AGENT = 'ROLE_CUSTOMER_SUPPORT_AGENT',
7
+ ROLE_CHATBOT_TRAINER = 'ROLE_CHATBOT_TRAINER',
8
+ ROLE_ANALYST = 'ROLE_ANALYST',
9
+ ROLE_UNAUTHENTICATED = 'ROLE_UNAUTHENTICATED',
10
+ }
11
+
12
+ export enum RUUTER_ENDPOINTS {
13
+ SEND_ATTACHMENT= '/attachments/add'
14
+ }
15
+
16
+ export enum AUTHOR_ROLES {
17
+ END_USER = 'end-user',
18
+ BACKOFFICE_USER = 'backoffice-user',
19
+ }
@@ -0,0 +1,8 @@
1
+ export default function formatBytes(bytes: number, decimals = 0) {
2
+ if (bytes === 0) return '0 Bytes';
3
+ const k = 1024;
4
+ const dm = decimals < 0 ? 0 : decimals;
5
+ const sizes = ['Bytes', 'kB', 'MB'];
6
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
7
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
8
+ }
@@ -0,0 +1,8 @@
1
+ export const generateUEID = () => {
2
+ let first: string | number = (Math.random() * 46656) | 0;
3
+ let second: string | number = (Math.random() * 46656) | 0;
4
+ first = ('000' + first.toString(36)).slice(-3);
5
+ second = ('000' + second.toString(36)).slice(-3);
6
+
7
+ return first + second;
8
+ };
@@ -0,0 +1,17 @@
1
+ export const getFromLocalStorage = (
2
+ key: string,
3
+ initialValue: any = null
4
+ ): any => {
5
+ try {
6
+ const item = localStorage.getItem(key);
7
+ return item ? JSON.parse(item) : initialValue;
8
+ } catch {
9
+ return initialValue;
10
+ }
11
+ };
12
+
13
+ export const setToLocalStorage = (key: string, value: any): void => {
14
+ try {
15
+ localStorage.setItem(key, JSON.stringify(value));
16
+ } catch {}
17
+ };
@@ -0,0 +1,23 @@
1
+ import { Message, MessageButton } from "../types/message";
2
+
3
+ export const parseOptions = (message: Message): string[] => {
4
+ try {
5
+ if(!message?.options || message.options === '')
6
+ return [];
7
+ return JSON.parse(message.options) as string[];
8
+ } catch(e) {
9
+ console.error(e);
10
+ return [];
11
+ }
12
+ }
13
+
14
+ export const parseButtons = (message: Message): MessageButton[] => {
15
+ try {
16
+ if(!message?.buttons || message.buttons === '')
17
+ return [];
18
+ return JSON.parse(message.buttons) as MessageButton[];
19
+ } catch(e) {
20
+ console.error(e);
21
+ return [];
22
+ }
23
+ }
@@ -0,0 +1,13 @@
1
+ import { CHAT_EVENTS } from "../types/chat";
2
+ import { Message } from "../types/message";
3
+
4
+ export const isStateChangingEventMessage = (msg: Message): boolean =>
5
+ msg.event === CHAT_EVENTS.GREETING ||
6
+ msg.event === CHAT_EVENTS.WAITING_VALIDATION ||
7
+ msg.event === CHAT_EVENTS.APPROVED_VALIDATION ||
8
+ msg.event === CHAT_EVENTS.ASK_PERMISSION_IGNORED ||
9
+ (msg.event === CHAT_EVENTS.CONTACT_INFORMATION && msg.content?.length === 0) ||
10
+ msg.event === CHAT_EVENTS.ANSWERED ||
11
+ msg.event === CHAT_EVENTS.READ ||
12
+ msg.event === CHAT_EVENTS.RATING ||
13
+ msg.event === CHAT_EVENTS.TERMINATED;
package/vite.config.ts ADDED
@@ -0,0 +1,67 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from 'vite';
3
+ import react from '@vitejs/plugin-react';
4
+ import tsconfigPaths from 'vite-tsconfig-paths';
5
+ import dts from 'vite-plugin-dts';
6
+ import { join, path } from 'path';
7
+
8
+ export default defineConfig({
9
+ plugins: [
10
+ dts({
11
+ tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
12
+ // Faster builds by skipping tests. Set this to false to enable type checking.
13
+ skipDiagnostics: true,
14
+ }),
15
+ react(),
16
+ tsconfigPaths({
17
+ root: './',
18
+ }),
19
+ ],
20
+ resolve: {
21
+ alias: {
22
+ '@': `${path.resolve(__dirname, './src')}`,
23
+ '~@fontsource': path.resolve(__dirname, 'node_modules/@fontsource'),
24
+ },
25
+ },
26
+ css: {
27
+ preprocessorOptions: {
28
+ scss: {
29
+ additionalData: `@import "@/styles/main.scss";`,
30
+ },
31
+ },
32
+ },
33
+
34
+ // Configuration for building your library.
35
+ // See: https://vitejs.dev/guide/build.html#library-mode
36
+ build: {
37
+ lib: {
38
+ // Could also be a dictionary or array of multiple entry points.
39
+ entry: 'src/index.tsx',
40
+ name: 'common-elements',
41
+ fileName: 'index',
42
+ // Change this to the formats you want to support.
43
+ // Don't forgot to update your package.json as well.
44
+ formats: ['es', 'cjs'],
45
+ },
46
+ rollupOptions: {
47
+ // External packages that should not be bundled into your library.
48
+ // external: ['react','react-dom', 'react/jsx-runtime'],
49
+ output: {
50
+ globals: {
51
+ react: 'React',
52
+ 'react-dom': 'ReactDOM',
53
+ },
54
+ },
55
+
56
+ },
57
+ },
58
+
59
+ test: {
60
+ globals: true,
61
+ cache: {
62
+ dir: '../../node_modules/.vitest',
63
+ },
64
+ environment: 'jsdom',
65
+ include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
66
+ },
67
+ });