cambio en lisatdo de clientes

This commit is contained in:
beseira13
2026-03-19 17:38:04 -03:00
parent 5f88cf598a
commit 2dc6a79d08
2 changed files with 15 additions and 6 deletions

View File

@@ -70,8 +70,8 @@ function App() {
const handleClientChange = (clientId) => {
setSelectedClient(clientId);
// Optionally reset store when client changes if they are not compatible
// setSelectedStore(null);
// Reset store when client changes to avoid country mismatch
setSelectedStore(null);
};
const handleExecute = async (sql) => {

View File

@@ -28,6 +28,7 @@ export default function StoreSelector({ selectedStore, onSelect, onClientChange
const loadStoresWithStatus = async () => {
setLoading(true);
setError(null);
setStores([]); // IMPORTANT: Clear stores list when loading new data/client
try {
// Fetch both store list and status in parallel
@@ -36,19 +37,27 @@ export default function StoreSelector({ selectedStore, onSelect, onClientChange
fetchStoreStatus(selectedClient)
]);
// Merge store data with status information
const mergedStores = storeList.map(store => {
// Merge store data with status information and DE-DUPLICATE by ID
const storeMap = new Map();
storeList.forEach(store => {
const statusInfo = statusData.find(s => s.store_id === parseInt(store.id));
return {
const mergedStore = {
...store,
connectivity: statusInfo?.connectivity || 'OFFLINE',
last_ping: statusInfo?.last_ping,
seconds_since_ping: statusInfo?.seconds_since_ping,
status: statusInfo?.connectivity === 'ONLINE' ? 'online' : 'offline'
};
// If the store ID isn't in our Map yet, add it
// This handles cases where the API returns the same store ID twice
if (!storeMap.has(store.id)) {
storeMap.set(store.id, mergedStore);
}
});
setStores(mergedStores);
setStores(Array.from(storeMap.values()));
} catch (err) {
setError("Error cargando tiendas: " + err.message);
} finally {