warehouse locations
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user