warehouse locations

This commit is contained in:
Dobromir Popov
2024-12-01 22:26:41 +02:00
parent e67fb399cd
commit c06b93f6ad
13 changed files with 129 additions and 25 deletions

View File

@ -112,20 +112,35 @@ export default function Sidebar({ isSidebarOpen, toggleSidebar }) {
useEffect(() => {
const fetchLocations = async () => {
try {
if (session) { // Don't fetch locations if the user is not authenticated
// if (session)
{ // Don't fetch locations if the user is not authenticated
const response = await axiosInstance.get('/api/data/locations'); // Adjust the API endpoint as needed
const locationsData = response.data
.filter(location => location.isActive === true)
const subMenuLocations = response.data
.filter(location => location.isActive === true && location.isOnMainMenu === false)
.map(location => ({
text: location.name,
url: `/cart/locations/${location.id}`,
isOnMainMenu: location.isOnMainMenu,
}));
const mainMenuLocations = response.data.filter(l => l.isOnMainMenu === true)
.map(location => ({
key: location.name,
text: t('location.' + location.name + '.menu') || location.name,
url: location.url,
}));
console.log("locationsData: ", response.data);
console.log("subMenuLocations: ", subMenuLocations);
console.log("mainMenuLocations: ", mainMenuLocations);
// Find the "Locations" menu item and populate its children with locationsData
const menuIndex = sidemenu.findIndex(item => item.id === "locations");
if (menuIndex !== -1) {
sidemenu[menuIndex].children = locationsData;
sidemenu[menuIndex].children = subMenuLocations;
}
// insert main menu items after the locations (sidemenu[menuIndex+1])
sidemenu.splice(menuIndex + 1, 0, ...mainMenuLocations);
//setLocations(locationsData); // Optional, if you need to use locations elsewhere
}
} catch (error) {