cambio en lisatdo de clientes
This commit is contained in:
@@ -70,8 +70,8 @@ function App() {
|
|||||||
|
|
||||||
const handleClientChange = (clientId) => {
|
const handleClientChange = (clientId) => {
|
||||||
setSelectedClient(clientId);
|
setSelectedClient(clientId);
|
||||||
// Optionally reset store when client changes if they are not compatible
|
// Reset store when client changes to avoid country mismatch
|
||||||
// setSelectedStore(null);
|
setSelectedStore(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleExecute = async (sql) => {
|
const handleExecute = async (sql) => {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export default function StoreSelector({ selectedStore, onSelect, onClientChange
|
|||||||
const loadStoresWithStatus = async () => {
|
const loadStoresWithStatus = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
setStores([]); // IMPORTANT: Clear stores list when loading new data/client
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch both store list and status in parallel
|
// Fetch both store list and status in parallel
|
||||||
@@ -36,19 +37,27 @@ export default function StoreSelector({ selectedStore, onSelect, onClientChange
|
|||||||
fetchStoreStatus(selectedClient)
|
fetchStoreStatus(selectedClient)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Merge store data with status information
|
// Merge store data with status information and DE-DUPLICATE by ID
|
||||||
const mergedStores = storeList.map(store => {
|
const storeMap = new Map();
|
||||||
|
|
||||||
|
storeList.forEach(store => {
|
||||||
const statusInfo = statusData.find(s => s.store_id === parseInt(store.id));
|
const statusInfo = statusData.find(s => s.store_id === parseInt(store.id));
|
||||||
return {
|
const mergedStore = {
|
||||||
...store,
|
...store,
|
||||||
connectivity: statusInfo?.connectivity || 'OFFLINE',
|
connectivity: statusInfo?.connectivity || 'OFFLINE',
|
||||||
last_ping: statusInfo?.last_ping,
|
last_ping: statusInfo?.last_ping,
|
||||||
seconds_since_ping: statusInfo?.seconds_since_ping,
|
seconds_since_ping: statusInfo?.seconds_since_ping,
|
||||||
status: statusInfo?.connectivity === 'ONLINE' ? 'online' : 'offline'
|
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) {
|
} catch (err) {
|
||||||
setError("Error cargando tiendas: " + err.message);
|
setError("Error cargando tiendas: " + err.message);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user