Skip to content

Commit c24a60c

Browse files
authored
Fix: [EBE-103] Fix tables order (#93)
2 parents dbab539 + 6e6ae46 commit c24a60c

File tree

3 files changed

+26
-159
lines changed

3 files changed

+26
-159
lines changed

.devops/code-review-pipelines.yml_old

Lines changed: 0 additions & 153 deletions
This file was deleted.

src/pages/initiativeStores/InitiativeStores.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

src/pages/initiativeStores/initiativeStoreDetail.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const InitiativeStoreDetail = () => {
4747
const { t } = useTranslation();
4848
const { id, store_id } = useParams<RouteParams>();
4949
const addError = useErrorDispatcher();
50+
const [sortModel, setSortModel] = useState<GridSortModel>([]);
5051

5152

5253
useEffect(() => {
@@ -197,6 +198,7 @@ const InitiativeStoreDetail = () => {
197198
};
198199

199200
const handleSortModelChange = async (newSortModel: GridSortModel) => {
201+
setSortModel(newSortModel);
200202
if (newSortModel.length > 0) {
201203
const { field, sort } = newSortModel[0];
202204
await fetchStoreTransactions({
@@ -248,12 +250,20 @@ const InitiativeStoreDetail = () => {
248250
};
249251

250252
const handlePaginationPageChange = (page: number) => {
251-
setPaginationModel({
253+
setPaginationModel((prev: any) => ({
254+
...prev,
252255
page,
253-
});
256+
}));
257+
258+
const sortParam =
259+
sortModel.length > 0
260+
? `${sortModel[0].field !== 'fiscalCode' ? sortModel[0].field : 'userId'},${sortModel[0].sort}`
261+
: undefined;
262+
254263
fetchStoreTransactions({
255264
...transactionsFilters,
256265
page,
266+
...(sortParam && { sort: sortParam }),
257267
}).catch(error => {
258268
console.error('Error fetching stores:', error);
259269
});

0 commit comments

Comments
 (0)