@buerokratt-ria/common-gui-components 0.0.22 → 0.0.24

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.24] - 14-08-2025
8
+
9
+ - Modified Start and End dates to send them in payload in iso format
10
+
11
+ ## [0.0.23] - 21-07-2025
12
+
13
+ - Initial support of multidomains
14
+ - Added updated key to force fetching on domain change
15
+ - Updated store params
16
+ - Made store export state for reusability
17
+
7
18
  ## [0.0.22] - 01-07-2025
8
19
 
9
20
  - Handled Previous Messages Edge Case in Buttons
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerokratt-ria/common-gui-components",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
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,
@@ -2,7 +2,7 @@ import React, {FC, PropsWithChildren, useEffect, useRef, useMemo, useState} from
2
2
  import {useTranslation} from 'react-i18next';
3
3
  import {useMutation} from '@tanstack/react-query';
4
4
  import {ColumnPinningState, createColumnHelper, PaginationState, SortingState,} from '@tanstack/react-table';
5
- import {format} from 'date-fns';
5
+ import { format, startOfDay, endOfDay, formatISO } from "date-fns";
6
6
  import {AxiosError} from 'axios';
7
7
  import './History.scss';
8
8
  import {MdOutlineRemoveRedEye} from 'react-icons/md';
@@ -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,
@@ -67,8 +72,8 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
67
72
  const routerLocation = useLocation();
68
73
  const params = new URLSearchParams(routerLocation.search);
69
74
  let passedChatId = new URLSearchParams(routerLocation.search).get('chat');
70
- const passedStartDate = delegatedStartDate ?? params.get('start');
71
- const passedEndDate = delegatedStartDate ?? params.get('end');
75
+ const passedStartDate = delegatedStartDate ?? params.get("start");
76
+ const passedEndDate = delegatedEndDate ?? params.get("end");
72
77
  const skipNextSelectedColumnsEffect = useRef(false);
73
78
  const passedCustomerSupportIds = params.getAll('customerSupportIds');
74
79
  const [search, setSearch] = useState('');
@@ -100,25 +105,27 @@ 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
+
113
+ const parseDateParam = (dateString: string | null) => {
114
+ if (!dateString) return new Date();
115
+ return new Date(dateString.split("+")[0]);
116
+ };
117
+
103
118
  const {control, setValue, watch} = useForm<{
104
119
  startDate: Date | string;
105
120
  endDate: Date | string;
106
121
  }>({
107
122
  defaultValues: {
108
123
  startDate: passedStartDate
109
- ? unifyDateFromat(passedStartDate)
110
- : new Date(
111
- new Date().getUTCFullYear(),
112
- new Date().getUTCMonth(),
113
- new Date().getUTCDate()
114
- ),
115
- endDate: passedEndDate
116
- ? unifyDateFromat(passedEndDate)
117
- : new Date(
118
- new Date().getUTCFullYear(),
119
- new Date().getUTCMonth(),
120
- new Date().getUTCDate()
121
- ),
124
+ ? parseDateParam(passedStartDate)
125
+ : new Date(new Date().setUTCHours(0, 0, 0, 0)),
126
+ endDate: passedEndDate
127
+ ? parseDateParam(passedEndDate)
128
+ : new Date(new Date().setUTCHours(23, 59, 59, 999)),
122
129
  },
123
130
  });
124
131
 
@@ -127,8 +134,8 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
127
134
 
128
135
  const debouncedGetAllEnded = useDebouncedCallback((search) => {
129
136
  getAllEndedChats.mutate({
130
- startDate: format(new Date(startDate), 'yyyy-MM-dd'),
131
- endDate: format(new Date(endDate), 'yyyy-MM-dd'),
137
+ startDate: formatISO(startOfDay(new Date(startDate))),
138
+ endDate: formatISO(endOfDay(new Date(endDate))),
132
139
  customerSupportIds: passedCustomerSupportIds,
133
140
  pagination,
134
141
  sorting,
@@ -136,6 +143,14 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
136
143
  });
137
144
  }, 500);
138
145
 
146
+ if(multiDomainEnabled) {
147
+ useStore.subscribe((state, prevState) => {
148
+ if(JSON.stringify(state.userDomains) !== JSON.stringify(prevState.userDomains)) {
149
+ setUpdateKey(prevState => prevState + 1);
150
+ }
151
+ });
152
+ }
153
+
139
154
  useEffect(() => {
140
155
  if (passedChatId != null) {
141
156
  getChatById.mutate();
@@ -159,8 +174,8 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
159
174
  fetchData()
160
175
  } else {
161
176
  getAllEndedChats.mutate({
162
- startDate: hasStart ? unifyDateFromat(delegatedStartDate) : format(new Date(startDate), 'yyyy-MM-dd'),
163
- endDate: hasEnd ? unifyDateFromat(delegatedEndDate) : format(new Date(endDate), 'yyyy-MM-dd'),
177
+ startDate: hasStart ? unifyDateFromat(delegatedStartDate) : formatISO(startOfDay(new Date(startDate))),
178
+ endDate: hasEnd ? unifyDateFromat(delegatedEndDate) : formatISO(endOfDay(new Date(endDate))),
164
179
  customerSupportIds: passedCustomerSupportIds,
165
180
  pagination,
166
181
  sorting,
@@ -168,7 +183,7 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
168
183
  });
169
184
  }
170
185
  }
171
- }, [delegatedStartDate, delegatedEndDate]);
186
+ }, [delegatedStartDate, delegatedEndDate, updateKey]);
172
187
 
173
188
 
174
189
  const fetchData = async () => {
@@ -196,8 +211,8 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
196
211
  setCounterKey(prev => prev + 1);
197
212
 
198
213
  getAllEndedChats.mutate({
199
- startDate: format(new Date(startDate), 'yyyy-MM-dd'),
200
- endDate: format(new Date(endDate), 'yyyy-MM-dd'),
214
+ startDate: formatISO(startOfDay(new Date(startDate))),
215
+ endDate: formatISO(endOfDay(new Date(endDate))),
201
216
  customerSupportIds: passedCustomerSupportIds,
202
217
  pagination: updatedPagination,
203
218
  sorting,
@@ -225,8 +240,8 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
225
240
  skipNextSelectedColumnsEffect.current = false;
226
241
  } else {
227
242
  getAllEndedChats.mutate({
228
- startDate: format(new Date(startDate), 'yyyy-MM-dd'),
229
- endDate: format(new Date(endDate), 'yyyy-MM-dd'),
243
+ startDate: formatISO(startOfDay(new Date(startDate))),
244
+ endDate: formatISO(endOfDay(new Date(endDate))),
230
245
  customerSupportIds: passedCustomerSupportIds,
231
246
  pagination,
232
247
  sorting,
@@ -270,8 +285,9 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
270
285
 
271
286
  return apiDev.post('agents/chats/ended', {
272
287
  customerSupportIds: data.customerSupportIds,
273
- startDate: format(new Date(data.startDate), 'yyyy-MM-dd'),
274
- endDate: format(new Date(data.endDate), 'yyyy-MM-dd'),
288
+ startDate: formatISO(startOfDay(new Date(data.startDate))),
289
+ endDate: formatISO(endOfDay(new Date(data.endDate))),
290
+ urls: getDomainsArray(currentDomains),
275
291
  page: data.pagination.pageIndex + 1,
276
292
  page_size: data.pagination.pageSize,
277
293
  sorting: sortBy,
@@ -378,8 +394,8 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
378
394
  onSuccess: () => {
379
395
  setMessagesTrigger(!messagesTrigger);
380
396
  getAllEndedChats.mutate({
381
- startDate: format(new Date(startDate), 'yyyy-MM-dd'),
382
- endDate: format(new Date(endDate), 'yyyy-MM-dd'),
397
+ startDate: formatISO(startOfDay(new Date(startDate))),
398
+ endDate: formatISO(endOfDay(new Date(endDate))),
383
399
  customerSupportIds: passedCustomerSupportIds,
384
400
  pagination,
385
401
  sorting,
@@ -774,14 +790,14 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
774
790
  value={field.value ?? new Date()}
775
791
  onChange={(v) => {
776
792
  field.onChange(v);
777
- const start = format(new Date(v), 'yyyy-MM-dd');
793
+ const start = formatISO(startOfDay(new Date(v)));
778
794
  setSearchParams((params) => {
779
795
  params.set('start', start);
780
796
  return params;
781
797
  });
782
798
  getAllEndedChats.mutate({
783
799
  startDate: start,
784
- endDate: format(new Date(endDate), 'yyyy-MM-dd'),
800
+ endDate: formatISO(endOfDay(new Date(endDate))),
785
801
  customerSupportIds: passedCustomerSupportIds,
786
802
  pagination,
787
803
  sorting,
@@ -806,13 +822,13 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
806
822
  value={field.value ?? new Date()}
807
823
  onChange={(v) => {
808
824
  field.onChange(v);
809
- const end = format(new Date(v), 'yyyy-MM-dd');
825
+ const end = formatISO(endOfDay(new Date(v)));
810
826
  setSearchParams((params) => {
811
827
  params.set('end', end);
812
828
  return params;
813
829
  });
814
830
  getAllEndedChats.mutate({
815
- startDate: format(new Date(startDate), 'yyyy-MM-dd'),
831
+ startDate: formatISO(startOfDay(new Date(startDate))),
816
832
  endDate: end,
817
833
  customerSupportIds: passedCustomerSupportIds,
818
834
  pagination,
@@ -909,8 +925,8 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
909
925
  selected_columns: selectedColumns
910
926
  });
911
927
  getAllEndedChats.mutate({
912
- startDate: format(new Date(startDate), 'yyyy-MM-dd'),
913
- endDate: format(new Date(endDate), 'yyyy-MM-dd'),
928
+ startDate: formatISO(startOfDay(new Date(startDate))),
929
+ endDate: formatISO(endOfDay(new Date(endDate))),
914
930
  customerSupportIds: passedCustomerSupportIds,
915
931
  pagination: state,
916
932
  sorting,
@@ -920,8 +936,8 @@ const ChatHistory: FC<PropsWithChildren<HistoryProps>> = ({
920
936
  setSorting={(state: SortingState) => {
921
937
  setSorting(state);
922
938
  getAllEndedChats.mutate({
923
- startDate: format(new Date(startDate), 'yyyy-MM-dd'),
924
- endDate: format(new Date(endDate), 'yyyy-MM-dd'),
939
+ startDate: formatISO(startOfDay(new Date(startDate))),
940
+ endDate: formatISO(endOfDay(new Date(endDate))),
925
941
  customerSupportIds: passedCustomerSupportIds,
926
942
  pagination,
927
943
  sorting: state,
@@ -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
+ }