@@ -37,6 +37,7 @@ const InitiativeStores: React.FC = () => {
3737 const [ stores , setStores ] = useState < Array < PointOfSaleDTO > > ( [ ] ) ;
3838 const [ storesPagination , setStoresPagination ] = useState < any > ( { } ) ;
3939 const [ storesLoading , setStoresLoading ] = useState ( false ) ;
40+ const [ currentSort , setCurrentSort ] = useState < string > ( 'asc' ) ;
4041 const { t } = useTranslation ( ) ;
4142 const history = useHistory ( ) ;
4243 const { id } = useParams < RouteParams > ( ) ;
@@ -157,7 +158,12 @@ const InitiativeStores: React.FC = () => {
157158 } ) ;
158159
159160 const handleFiltersApplied = ( values : GetPointOfSalesFilters ) => {
160- fetchStores ( values ) . catch ( error => {
161+ const filtersWithSort = {
162+ ...values ,
163+ sort : currentSort ,
164+ page : 0
165+ } ;
166+ fetchStores ( filtersWithSort ) . catch ( error => {
161167 console . error ( 'Error fetching stores:' , error ) ;
162168 } ) ;
163169
@@ -183,23 +189,27 @@ const InitiativeStores: React.FC = () => {
183189 const handleSortModelChange = async ( newSortModel : GridSortModel ) => {
184190 if ( newSortModel . length > 0 ) {
185191 const { field, sort } = newSortModel [ 0 ] ;
192+ const sortKey = field === 'referent' ? `contactName,${ sort } ` : `${ field } ,${ sort } ` ;
193+ setCurrentSort ( sortKey ) ;
186194 await fetchStores ( {
187195 ...formik . values ,
188- sort : ` ${ field } , ${ sort } ` ,
196+ sort : sortKey ,
189197 } , true ) . catch ( error => {
190198 console . error ( 'Error fetching stores:' , error ) ;
191199 } ) ;
192-
200+
193201 } else {
194202 console . log ( 'Ordinamento rimosso.' ) ;
203+ setCurrentSort ( 'asc' ) ;
195204 }
196205 } ;
197206
198207 const handlePaginationPageChange = ( page : number ) => {
199208 setStoresPagination ( page ) ;
200209 fetchStores ( {
201210 ...formik . values ,
202- page
211+ page,
212+ sort : currentSort
203213 } ) . catch ( error => {
204214 console . error ( 'Error fetching stores:' , error ) ;
205215 } ) ;
0 commit comments