@@ -32,11 +32,6 @@ import { useToast } from 'hooks/useToast';
32
32
import { apiDev } from 'services/api' ;
33
33
import useStore from 'store' ;
34
34
import { Controller , useForm } from 'react-hook-form' ;
35
- import {
36
- getFromLocalStorage ,
37
- setToLocalStorage ,
38
- } from 'utils/local-storage-utils' ;
39
- import { CHAT_HISTORY_PREFERENCES_KEY } from 'constants/config' ;
40
35
import { useLocation , useSearchParams } from 'react-router-dom' ;
41
36
import { unifyDateFromat } from './unfiyDate' ;
42
37
import withAuthorization from 'hoc/with-authorization' ;
@@ -54,9 +49,6 @@ const ChatHistory: FC = () => {
54
49
const passedStartDate = params . get ( 'start' ) ;
55
50
const passedEndDate = params . get ( 'end' ) ;
56
51
const passedCustomerSupportIds = params . getAll ( 'customerSupportIds' ) ;
57
- const preferences = getFromLocalStorage (
58
- CHAT_HISTORY_PREFERENCES_KEY
59
- ) as string [ ] ;
60
52
const [ search , setSearch ] = useState ( '' ) ;
61
53
const [ selectedChat , setSelectedChat ] = useState < ChatType | null > ( null ) ;
62
54
const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
@@ -83,10 +75,9 @@ const ChatHistory: FC = () => {
83
75
> ( [ ] ) ;
84
76
85
77
const [ messagesTrigger , setMessagesTrigger ] = useState ( false ) ;
86
- const [ selectedColumns , setSelectedColumns ] = useState < string [ ] > (
87
- preferences ?? [ ]
88
- ) ;
78
+ const [ selectedColumns , setSelectedColumns ] = useState < string [ ] > ( [ ] ) ;
89
79
const [ customerSupportAgents , setCustomerSupportAgents ] = useState < any [ ] > ( [ ] ) ;
80
+ const [ counterKey , setCounterKey ] = useState < number > ( 0 )
90
81
91
82
const { control, watch } = useForm < {
92
83
startDate : Date | string ;
@@ -141,9 +132,12 @@ const ChatHistory: FC = () => {
141
132
} ,
142
133
} ) ;
143
134
if ( response . data . pageResults !== undefined ) {
135
+ const newSelectedColumns = response . data ?. selectedColumns . length === 1 && response . data ?. selectedColumns [ 0 ] === "" ? [ ] : response . data ?. selectedColumns ;
136
+ setSelectedColumns ( newSelectedColumns )
144
137
const updatedPagination = updatePagePreference (
145
- response . data . pageResults
138
+ response . data . pageResults ?? 10
146
139
) ;
140
+ setCounterKey ( counterKey + 1 )
147
141
getAllEndedChats . mutate ( {
148
142
startDate : format ( new Date ( startDate ) , 'yyyy-MM-dd' ) ,
149
143
endDate : format ( new Date ( endDate ) , 'yyyy-MM-dd' ) ,
@@ -179,18 +173,22 @@ const ChatHistory: FC = () => {
179
173
search,
180
174
} ) ;
181
175
}
182
- } , [ ] ) ;
176
+ } , [ selectedColumns ] ) ;
183
177
184
178
useEffect ( ( ) => {
185
179
listCustomerSupportAgents . mutate ( ) ;
186
180
} , [ ] ) ;
187
181
188
- const updatePageSize = useMutation ( {
189
- mutationFn : ( data : { page_results : number } ) => {
182
+ const updatePagePreferences = useMutation ( {
183
+ mutationFn : ( data : {
184
+ page_results : number ;
185
+ selected_columns : string [ ] ;
186
+ } ) => {
190
187
return apiDev . post ( 'accounts/update-page-preference' , {
191
188
user_id : userInfo ?. idCode ,
192
189
page_name : window . location . pathname ,
193
190
page_results : data . page_results ,
191
+ selected_columns : `{"${ data . selected_columns . join ( '","' ) } "}`
194
192
} ) ;
195
193
} ,
196
194
} ) ;
@@ -210,6 +208,8 @@ const ChatHistory: FC = () => {
210
208
sortBy = `${ sorting [ 0 ] . id } ${ sortType } ` ;
211
209
}
212
210
211
+ console . log ( 'data' , data , data . pagination , data . pagination . pageSize )
212
+
213
213
return apiDev . post ( 'agents/chats/ended' , {
214
214
customerSupportIds : data . customerSupportIds ,
215
215
startDate : data . startDate ,
@@ -693,6 +693,7 @@ const ChatHistory: FC = () => {
693
693
/>
694
694
</ Track >
695
695
< FormMultiselect
696
+ key = { counterKey }
696
697
name = "visibleColumns"
697
698
label = { t ( '' ) }
698
699
placeholder = { t ( 'chat.history.chosenColumn' ) }
@@ -703,7 +704,7 @@ const ChatHistory: FC = () => {
703
704
onSelectionChange = { ( selection ) => {
704
705
const columns = selection ?. map ( ( s ) => s . value ) ?? [ ] ;
705
706
setSelectedColumns ( columns ) ;
706
- setToLocalStorage ( CHAT_HISTORY_PREFERENCES_KEY , columns ) ;
707
+ updatePagePreferences . mutate ( { page_results : pagination . pageSize , selected_columns : columns } )
707
708
} }
708
709
/>
709
710
< FormMultiselect
@@ -727,9 +728,9 @@ const ChatHistory: FC = () => {
727
728
setPagination ( { pageIndex : 0 , pageSize : pagination . pageSize } ) ;
728
729
729
730
getAllEndedChats . mutate ( {
730
- customerSupportIds : selection ?. map ( ( s ) => s . value ) ,
731
731
startDate,
732
732
endDate,
733
+ customerSupportIds : selection ?. map ( ( s ) => s . value ) || [ ] ,
733
734
pagination : { pageIndex : 0 , pageSize : pagination . pageSize } ,
734
735
sorting,
735
736
search,
@@ -758,7 +759,7 @@ const ChatHistory: FC = () => {
758
759
)
759
760
return ;
760
761
setPagination ( state ) ;
761
- updatePageSize . mutate ( { page_results : state . pageSize } ) ;
762
+ updatePagePreferences . mutate ( { page_results : state . pageSize , selected_columns : selectedColumns } ) ;
762
763
getAllEndedChats . mutate ( {
763
764
startDate : format ( new Date ( startDate ) , 'yyyy-MM-dd' ) ,
764
765
endDate : format ( new Date ( endDate ) , 'yyyy-MM-dd' ) ,
0 commit comments