@@ -10,9 +10,11 @@ import {
1010 SharedWithOthersIcon ,
1111} from "@formsflow/components" ;
1212import { useTranslation } from "react-i18next" ;
13- import { saveFilterPreference } from "../api/services/filterServices" ;
14- import { useSelector } from "react-redux" ;
13+ import { fetchBPMTaskCount , fetchFilterList , saveFilterPreference } from "../api/services/filterServices" ;
14+ import { useSelector , useDispatch } from "react-redux" ;
1515import { RootState } from "../reducers/index.js" ;
16+ import { setBPMFilterList } from "../actions/taskActions" ;
17+
1618
1719interface ReorderTaskFilterModalProps {
1820 showModal ?: boolean ;
@@ -28,6 +30,8 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
2830 ( state : RootState ) => state . task . userDetails
2931 ) ;
3032 const { t } = useTranslation ( ) ;
33+ const dispatch = useDispatch ( ) ;
34+
3135 const [ sortedFilterList , setSortedFilterList ] = useState < any [ ] > ( [
3236 filtersList ,
3337 ] ) ;
@@ -69,17 +73,28 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
6973 const handleDiscardChanges = ( ) => {
7074 onClose ( ) ;
7175 } ;
72- const handleSaveChanges = ( ) => {
73- // here need to call the saveFilterPreference api to save the updated filterList before
74- // payload only contains the id and sortOrder ,hide: the isChecked
75- const updatedFiltersPreference = sortedFilterList . map ( ( item ) => ( {
76- filterId : item . id ,
77- hide : item . isChecked ,
78- sortOrder : item . sortOrder ,
79- } ) ) ;
80- saveFilterPreference ( updatedFiltersPreference ) ;
81- setShowReorderFilterModal ( false ) ;
76+ const handleSaveChanges = async ( ) => {
77+ // saveFilterPreference payload only contains the id and sortOrder ,hide
78+ const updatedFiltersPreference = sortedFilterList . map (
79+ ( { id, isChecked, sortOrder } ) => ( {
80+ filterId : id ,
81+ hide : isChecked ,
82+ sortOrder,
83+ } )
84+ ) ;
85+
86+ try {
87+ await saveFilterPreference ( updatedFiltersPreference ) ;
88+
89+ const { data : { filters } } = await fetchFilterList ( ) ;
90+ dispatch ( fetchBPMTaskCount ( filters ) ) ;
91+ dispatch ( setBPMFilterList ( filters ) ) ;
92+ setShowReorderFilterModal ( false ) ;
93+ } catch ( error ) {
94+ console . error ( "Failed to save filter preferences:" , error ) ;
95+ }
8296 } ;
97+
8398 const isSaveBtnDisabled = useMemo ( ( ) => {
8499 const original = JSON . stringify (
85100 updateFilterList . map ( ( { id, isChecked, sortOrder } ) => ( {
@@ -145,3 +160,5 @@ export const ReorderTaskFilterModal: React.FC<ReorderTaskFilterModalProps> =
145160 ) ;
146161 }
147162 ) ;
163+
164+
0 commit comments