@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,65 @@
1
+ import React, { forwardRef, useId } from 'react';
2
+ import * as RadixSwitch from '@radix-ui/react-switch';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { ControllerRenderProps } from 'react-hook-form';
5
+
6
+ import './Switch.scss';
7
+
8
+ type SwitchProps = Partial<ControllerRenderProps> & {
9
+ onLabel?: string;
10
+ offLabel?: string;
11
+ onColor?: string;
12
+ name?: string;
13
+ label: string;
14
+ checked?: boolean;
15
+ defaultChecked?: boolean;
16
+ hideLabel?: boolean;
17
+ onCheckedChange?: (checked: boolean) => void;
18
+ };
19
+
20
+ const Switch = forwardRef<HTMLButtonElement, SwitchProps>(
21
+ (
22
+ {
23
+ onLabel,
24
+ offLabel,
25
+ onColor,
26
+ name,
27
+ label,
28
+ checked,
29
+ hideLabel,
30
+ onCheckedChange,
31
+ defaultChecked,
32
+ },
33
+ ref
34
+ ) => {
35
+ const id = useId();
36
+ const { t } = useTranslation();
37
+ const onValueLabel = onLabel || t('global.on');
38
+ const offValueLabel = offLabel || t('global.off');
39
+
40
+ return (
41
+ <div className="switch" style={{ [`${'--active-color'}`]: onColor }}>
42
+ {label && !hideLabel && (
43
+ <label htmlFor={id} className="switch__label">
44
+ {label}
45
+ </label>
46
+ )}
47
+ <RadixSwitch.Root
48
+ ref={ref}
49
+ id={id}
50
+ className="switch__button"
51
+ name={name}
52
+ onCheckedChange={onCheckedChange}
53
+ checked={checked}
54
+ defaultChecked={defaultChecked}
55
+ >
56
+ <RadixSwitch.Thumb className="switch__thumb" />
57
+ <span className="switch__on">{onValueLabel}</span>
58
+ <span className="switch__off">{offValueLabel}</span>
59
+ </RadixSwitch.Root>
60
+ </div>
61
+ );
62
+ }
63
+ );
64
+
65
+ export default Switch;
@@ -0,0 +1,45 @@
1
+ @import 'src/styles/tools/spacing';
2
+ @import 'src/styles/tools/color';
3
+ @import 'src/styles/settings/variables/other';
4
+ @import 'src/styles/settings/variables/typography';
5
+
6
+ .switchbox {
7
+ $self: &;
8
+ width: 100%;
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: space-between;
12
+
13
+ &__button {
14
+ width: 48px;
15
+ height: 8px;
16
+ border-radius: 4px;
17
+ background-color: get-color(black-coral-6);
18
+ position: relative;
19
+
20
+ &[aria-checked=true] {
21
+ background-color: get-color(sapphire-blue-4);
22
+
23
+ #{$self} {
24
+ &__thumb {
25
+ transform: translate(24px, -50%);
26
+ background-color: get-color(sapphire-blue-10);
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ &__thumb {
33
+ position: absolute;
34
+ width: 24px;
35
+ height: 24px;
36
+ border-radius: 50%;
37
+ background-color: get-color(white);
38
+ border: 1px solid get-color(black-coral-2);
39
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.14);
40
+ left: 0;
41
+ top: 50%;
42
+ transform: translateY(-50%);
43
+ transition: all .25s ease-out;
44
+ }
45
+ }
@@ -0,0 +1,44 @@
1
+ import React, { forwardRef, useId } from 'react';
2
+ import * as RadixSwitch from '@radix-ui/react-switch';
3
+ import { ControllerRenderProps } from 'react-hook-form';
4
+
5
+ import './SwitchBox.scss';
6
+
7
+ type SwitchBoxProps = Partial<ControllerRenderProps> & {
8
+ name?: string;
9
+ label: string;
10
+ checked?: boolean;
11
+ hideLabel?: boolean;
12
+ onCheckedChange?: (checked: boolean) => void;
13
+ }
14
+
15
+ const SwitchBox = forwardRef<HTMLButtonElement, SwitchBoxProps>((
16
+ {
17
+ name,
18
+ label,
19
+ checked,
20
+ hideLabel,
21
+ onCheckedChange,
22
+ },
23
+ ref,
24
+ ) => {
25
+ const id = useId();
26
+
27
+ return (
28
+ <div className='switchbox'>
29
+ {label && !hideLabel && <label htmlFor={id} className='switch__label'>{label}</label>}
30
+ <RadixSwitch.Root
31
+ ref={ref}
32
+ id={id}
33
+ name={name}
34
+ className='switchbox__button'
35
+ onCheckedChange={onCheckedChange}
36
+ defaultChecked={checked}
37
+ >
38
+ <RadixSwitch.Thumb className='switchbox__thumb' />
39
+ </RadixSwitch.Root>
40
+ </div>
41
+ );
42
+ });
43
+
44
+ export default SwitchBox;
@@ -0,0 +1,23 @@
1
+ import FormInput from './FormInput';
2
+ import FormTextarea from './FormTextarea';
3
+ import FormSelect from './FormSelect';
4
+ import FormMultiselect from './FormSelect/FormMultiselect';
5
+ import Switch from './Switch';
6
+ import FormCheckboxes from './FormCheckboxes';
7
+ import FormRadios from './FormRadios';
8
+ import FormCheckbox from './FormCheckbox';
9
+ import FormDatepicker from './FormDatepicker';
10
+ import SwitchBox from './SwitchBox';
11
+
12
+ export {
13
+ FormInput,
14
+ FormTextarea,
15
+ FormSelect,
16
+ FormMultiselect,
17
+ Switch,
18
+ FormCheckboxes,
19
+ FormRadios,
20
+ FormCheckbox,
21
+ FormDatepicker,
22
+ SwitchBox,
23
+ };
@@ -0,0 +1,67 @@
1
+ import React, { FC, useMemo } from 'react';
2
+ import { format } from 'date-fns';
3
+ import { Message } from '../../types/message';
4
+ import Markdownify from '../Chat/Markdownify';
5
+ import { parseButtons, parseOptions } from '../../utils/parse-utils';
6
+ import ButtonMessage from '../ButtonMessage';
7
+ import OptionMessage from '../OptionMessage';
8
+ import {useTranslation} from "react-i18next";
9
+ import { ToastContextType } from "../../context";
10
+
11
+ type ChatMessageProps = {
12
+ message: Message;
13
+ onMessageClick?: (message: Message) => void;
14
+ toastContext: ToastContextType | null;
15
+ };
16
+
17
+ const ChatMessage: FC<ChatMessageProps> = ({ message, onMessageClick, toastContext }) => {
18
+ const buttons = useMemo(() => parseButtons(message), [message.buttons]);
19
+ const options = useMemo(() => parseOptions(message), [message.options]);
20
+ const { t } = useTranslation();
21
+ const toast = toastContext;
22
+
23
+ const handleContextMenu = (event: React.MouseEvent<HTMLButtonElement>) => {
24
+ event.preventDefault();
25
+ const content = message.content ?? '';
26
+ navigator.clipboard
27
+ .writeText(content)
28
+ .then(() => {
29
+ toast?.open({
30
+ type: 'success',
31
+ title: t('global.notification'),
32
+ message: t('toast.copied'),
33
+ });
34
+ })
35
+ .catch((err) => {
36
+ toast?.open({
37
+ type: 'error',
38
+ title: t('global.notification'),
39
+ message: err?.message,
40
+ });
41
+ });
42
+ };
43
+
44
+ return (
45
+ <>
46
+ <div className="historical-chat__message">
47
+ <button
48
+ className="historical-chat__message-text"
49
+ onClick={onMessageClick ? () => onMessageClick(message) : undefined}
50
+ onContextMenu={handleContextMenu}
51
+ >
52
+ <Markdownify message={message.content ?? ''} />
53
+ </button>
54
+ <time
55
+ dateTime={message.created}
56
+ className="historical-chat__message-date"
57
+ >
58
+ {format(new Date(message.created ?? ''), 'HH:mm:ss')}
59
+ </time>
60
+ </div>
61
+ {buttons.length > 0 && <ButtonMessage buttons={buttons} />}
62
+ {options.length > 0 && <OptionMessage options={options} />}
63
+ </>
64
+ );
65
+ };
66
+
67
+ export default ChatMessage;
@@ -0,0 +1,225 @@
1
+ @import 'src/styles/tools/spacing';
2
+ @import 'src/styles/tools/color';
3
+ @import 'src/styles/settings/variables/other';
4
+ @import 'src/styles/settings/variables/typography';
5
+
6
+ .historical-chat {
7
+ $self: &;
8
+ display: flex;
9
+ justify-content: flex-end;
10
+ position: relative;
11
+ height: 100%;
12
+ white-space: pre-wrap;
13
+
14
+ &__body {
15
+ flex: 1;
16
+ display: flex;
17
+ flex-direction: column;
18
+ height: 100%;
19
+ position: absolute;
20
+ top: 0;
21
+ bottom: 0;
22
+ left: 0;
23
+ right: 0;
24
+ }
25
+
26
+ &__header {
27
+ padding: get-spacing(haapsalu);
28
+ background-color: get-color(extra-light);
29
+ border-bottom: 1px solid get-color(black-coral-2);
30
+ }
31
+
32
+ &__group-wrapper {
33
+ flex: 1;
34
+ padding: get-spacing(haapsalu) get-spacing(haapsalu) 0;
35
+ overflow: auto;
36
+ overflow-anchor: none;
37
+
38
+ #anchor {
39
+ overflow-anchor: auto;
40
+ height: 1px;
41
+ margin-top: 16px;
42
+ }
43
+ }
44
+
45
+ &__toolbar-row {
46
+ border-top: 1px solid get-color(black-coral-2);
47
+ padding: get-spacing(paldiski) get-spacing(haapsalu);
48
+ }
49
+
50
+ &__group {
51
+ display: flex;
52
+ flex-direction: column;
53
+ gap: 4px;
54
+ padding-left: 56px;
55
+ position: relative;
56
+
57
+ &:not(:last-child) {
58
+ margin-bottom: 8px;
59
+ }
60
+
61
+ &--buerokratt,
62
+ &--chatbot {
63
+ #{$self} {
64
+ &__group-initials {
65
+ background-color: get-color(sapphire-blue-10);
66
+ left: 0;
67
+ top: 0;
68
+ }
69
+
70
+ &__group-name {
71
+ color: get-color(sapphire-blue-10);
72
+ text-align: left;
73
+ margin-left: 0;
74
+ font-size: $veera-font-size-100;
75
+ }
76
+
77
+ &__messages {
78
+ display: flex;
79
+ flex-direction: column;
80
+ gap: 4px;
81
+ align-items: flex-start;
82
+ }
83
+
84
+ &__message-text {
85
+ background-color: get-color(sapphire-blue-10);
86
+ color: get-color(white);
87
+ margin-left: 0;
88
+
89
+ :any-link {
90
+ color: get-color(white);
91
+ }
92
+
93
+ &:hover {
94
+ background-color: get-color(sapphire-blue-13);
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ &--backoffice-user {
101
+ #{$self} {
102
+ &__group-initials {
103
+ background-color: get-color(black-coral-10);
104
+ color: get-color(white);
105
+ left: 0;
106
+ }
107
+
108
+ &__group-name {
109
+ text-align: left;
110
+ margin-left: 0;
111
+ font-size: $veera-font-size-100;
112
+ }
113
+
114
+ &__messages {
115
+ display: flex;
116
+ flex-direction: column;
117
+ gap: 4px;
118
+ align-items: flex-start;
119
+ }
120
+
121
+ &__message-text {
122
+ background-color: get-color(black-coral-10);
123
+ color: get-color(white);
124
+ margin-left: 0;
125
+
126
+ :any-link {
127
+ color: get-color(white);
128
+ }
129
+
130
+ &:hover {
131
+ background-color: #535665;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+
138
+ &__group-initials {
139
+ display: flex;
140
+ align-items: center;
141
+ justify-content: center;
142
+ width: 40px;
143
+ height: 40px;
144
+ background-color: get-color(black-coral-1);
145
+ border-radius: 50%;
146
+ font-size: $veera-font-size-80;
147
+ line-height: $veera-line-height-500;
148
+ font-weight: $veera-font-weight-delta;
149
+ color: get-color(black-coral-6);
150
+ position: absolute;
151
+ right: 0;
152
+ top: 0;
153
+ }
154
+
155
+ &__group-name {
156
+ font-size: $veera-font-size-100;
157
+ line-height: $veera-line-height-500;
158
+ font-weight: $veera-font-weight-delta;
159
+ text-transform: capitalize;
160
+ margin-left: 10rem;
161
+ margin-right: 3rem;
162
+ text-align: right;
163
+ padding-top: 7px;
164
+ }
165
+
166
+ &__messages {
167
+ display: flex;
168
+ flex-direction: column;
169
+ gap: 4px;
170
+ align-items: flex-end;
171
+ }
172
+
173
+ &__message {
174
+ display: flex;
175
+ align-items: center;
176
+ gap: 8px;
177
+ }
178
+
179
+ &__message-text {
180
+ display: flex;
181
+ align-items: center;
182
+ padding: 4px 8px;
183
+ background-color: get-color(black-coral-0);
184
+ border-radius: 8px 8px 8px 4px;
185
+ font-size: $veera-font-size-100;
186
+ line-height: $veera-line-height-500;
187
+ transition: all .25s ease-out;
188
+ cursor: pointer;
189
+
190
+ :any-link {
191
+ text-decoration: underline;
192
+ }
193
+
194
+ &:hover {
195
+ background-color: get-color(black-coral-1);
196
+ }
197
+ }
198
+
199
+ &__message-date {
200
+ color: get-color(black-coral-6);
201
+ font-size: 11px;
202
+ line-height: 20px;
203
+ }
204
+
205
+ &__comment-text {
206
+ color: get-color(black);
207
+
208
+ &.placeholder {
209
+ color: get-color(black-coral-6);
210
+ }
211
+ }
212
+ }
213
+
214
+ .header-link {
215
+ text-decoration: none;
216
+ padding: 15px 35px;
217
+ font-family: Roboto , sans-serif;
218
+ font-weight: 400;
219
+ }
220
+
221
+ .title {
222
+ font-size: 14px;
223
+ color: get-color(black-coral-6);
224
+ padding-top: 4px;
225
+ }