@buerokratt-ria/common-gui-components 0.0.21 → 0.0.23

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/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ All changes to this project will be documented in this file.
4
4
 
5
5
  ## Template [MajorVersion.MediterraneanVersion.MinorVersion] - DD-MM-YYYY
6
6
 
7
+ ## [0.0.23] - 21-07-2025
8
+
9
+ - Initial support of multidomains
10
+ - Added updated key to force fetching on domain change
11
+ - Updated store params
12
+ - Made store export state for reusability
13
+
14
+ ## [0.0.22] - 01-07-2025
15
+
16
+ - Handled Previous Messages Edge Case in Buttons
17
+
7
18
  ## [0.0.21] - 30-06-2025
8
19
 
9
20
  - Fix Message With Buttons View.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerokratt-ria/common-gui-components",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "Common GUI components and pre defined templates.",
5
5
  "main": "index.ts",
6
6
  "author": "ExiRai",
package/store/index.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  } from '../types/chat';
9
9
  import { apiDev } from '../services/api';
10
10
 
11
- interface StoreState {
11
+ export interface StoreState {
12
12
  userInfo: UserInfo | null;
13
13
  userId: string;
14
14
  activeChats: ChatType[];
@@ -31,6 +31,8 @@ interface StoreState {
31
31
  getGroupedUnansweredChats: () => GroupedChat;
32
32
  loadPendingChats: () => Promise<void>;
33
33
  getGroupedPendingChats: () => GroupedPendingChat;
34
+ userDomains: string[];
35
+ setUserDomains: (domains: string[]) => void;
34
36
  }
35
37
 
36
38
  const useStore = create<StoreState>((set, get, store) => ({
@@ -38,12 +40,14 @@ const useStore = create<StoreState>((set, get, store) => ({
38
40
  userId: '',
39
41
  activeChats: [],
40
42
  pendingChats: [],
43
+ userDomains: [],
41
44
  selectedChatId: null,
42
45
  chatCsaActive: false,
43
46
  setActiveChats: (chats) => set({ activeChats: chats }),
44
47
  setPendingChats: (chats) => set({ pendingChats: chats }),
45
48
  setUserInfo: (data) => set({ userInfo: data, userId: data?.idCode || '' }),
46
49
  setSelectedChatId: (id) => set({ selectedChatId: id }),
50
+ setUserDomains: (data: string[]) => set({ userDomains: data}),
47
51
  setChatCsaActive: (active) => {
48
52
  set({
49
53
  chatCsaActive: active,
@@ -32,8 +32,12 @@ import {useDebouncedCallback} from 'use-debounce';
32
32
  import {UserInfo} from "../../../types/userInfo";
33
33
  import {ToastContextType} from "../../../context";
34
34
 
35
+ import {getDomainsArray} from "../../../utils/multiDomain-utils";
36
+ import {StoreState} from "../../../store";
37
+
35
38
  type HistoryProps = {
36
39
  user: UserInfo | null;
40
+ userDomains: StoreState;
37
41
  toastContext: ToastContextType | null;
38
42
  onMessageClick?: (message: any) => void;
39
43
  showComment?: boolean;
@@ -49,6 +53,7 @@ type HistoryProps = {
49
53
 
50
54
  const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
51
55
  user,
56
+ userDomains,
52
57
  toastContext,
53
58
  onMessageClick,
54
59
  showComment = true,
@@ -100,6 +105,11 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
100
105
  const [customerSupportAgents, setCustomerSupportAgents] = useState<any[]>([]);
101
106
  const [counterKey, setCounterKey] = useState<number>(0)
102
107
 
108
+ const useStore = userDomains;
109
+ const [updateKey, setUpdateKey] = useState<number>(0)
110
+ const currentDomains = useStore.getState().userDomains;
111
+ const multiDomainEnabled = import.meta.env.REACT_APP_ENABLE_MULTI_DOMAIN.toLowerCase() === 'true';
112
+
103
113
  const {control, setValue, watch} = useForm<{
104
114
  startDate: Date | string;
105
115
  endDate: Date | string;
@@ -136,6 +146,14 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
136
146
  });
137
147
  }, 500);
138
148
 
149
+ if(multiDomainEnabled) {
150
+ useStore.subscribe((state, prevState) => {
151
+ if(JSON.stringify(state.userDomains) !== JSON.stringify(prevState.userDomains)) {
152
+ setUpdateKey(prevState => prevState + 1);
153
+ }
154
+ });
155
+ }
156
+
139
157
  useEffect(() => {
140
158
  if (passedChatId != null) {
141
159
  getChatById.mutate();
@@ -168,7 +186,7 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
168
186
  });
169
187
  }
170
188
  }
171
- }, [delegatedStartDate, delegatedEndDate]);
189
+ }, [delegatedStartDate, delegatedEndDate, updateKey]);
172
190
 
173
191
 
174
192
  const fetchData = async () => {
@@ -272,6 +290,7 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
272
290
  customerSupportIds: data.customerSupportIds,
273
291
  startDate: format(new Date(data.startDate), 'yyyy-MM-dd'),
274
292
  endDate: format(new Date(data.endDate), 'yyyy-MM-dd'),
293
+ urls: getDomainsArray(currentDomains),
275
294
  page: data.pagination.pageIndex + 1,
276
295
  page_size: data.pagination.pageSize,
277
296
  sorting: sortBy,
@@ -105,8 +105,10 @@ const HistoricalChat: FC<ChatProps> = ({
105
105
  const content = currentMessage.content?.trim() ?? "";
106
106
 
107
107
  if (content.startsWith("#service,") || content.startsWith("#common_service,")) {
108
- let buttons = messagesList[i - 1]?.buttons ? JSON.parse(messagesList[i - 1].buttons!) : [];
109
- currentMessage.content = buttons.find((b: any) => b.payload.includes(content))?.title ?? content;
108
+ const allPreviousButtons = messagesList
109
+ .slice(0, i)
110
+ .flatMap((msg) => (msg.buttons ? JSON.parse(msg.buttons) : []));
111
+ currentMessage.content = allPreviousButtons.find((b: any) => b.payload.includes(content))?.title ?? content;
110
112
  }
111
113
 
112
114
  const lastGroup = groupedMessages[groupedMessages.length - 1];
@@ -122,7 +124,7 @@ const HistoricalChat: FC<ChatProps> = ({
122
124
  content:
123
125
  currentMessage.event === CHAT_EVENTS.WAITING_VALIDATION
124
126
  ? t("chat.waiting_validation").toString()
125
- : content,
127
+ : currentMessage.content,
126
128
  });
127
129
  } else {
128
130
  groupedMessages.push({
@@ -0,0 +1,8 @@
1
+ import useStore from "../store";
2
+
3
+ export const getDomainsArray = (currentDomains) => {
4
+ const multiDomainEnabled = import.meta.env.REACT_APP_ENABLE_MULTI_DOMAIN.toLowerCase() === 'true';
5
+ const userDomains = currentDomains || [];
6
+
7
+ return multiDomainEnabled ? (userDomains?.length > 0 ? userDomains : [null]) : [];
8
+ }