fix pagination Manage Menu
- set params page to 1
This commit is contained in:
@ -193,9 +193,8 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
|||||||
|
|
||||||
if (parent.link === '/') {
|
if (parent.link === '/') {
|
||||||
if (!parents.find((el: any) => el.id === parent.id))
|
if (!parents.find((el: any) => el.id === parent.id))
|
||||||
setParents((el: any) => [...el, { id: parent.id, name: parent.name }]); // GET PARENTS
|
setParents((el: any) => [...el, { id: parent.id, name: parent.name }]);
|
||||||
|
|
||||||
// Menambahkan parent ke dalam result meskipun tidak memiliki children
|
|
||||||
result.push({
|
result.push({
|
||||||
id: parent.id,
|
id: parent.id,
|
||||||
module: parent.module,
|
module: parent.module,
|
||||||
@ -208,7 +207,6 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jika parent tidak memiliki children, langsung return hasil yang sudah ada
|
|
||||||
if (!parent.children || parent.children.length === 0) {
|
if (!parent.children || parent.children.length === 0) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -230,7 +228,6 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Gabungkan parent dengan children yang sudah diflatten
|
|
||||||
return [...result, ...childrenFlattened];
|
return [...result, ...childrenFlattened];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -241,7 +238,7 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
|||||||
|
|
||||||
const response = await GetData(`${API_URL}/menus/list`, {
|
const response = await GetData(`${API_URL}/menus/list`, {
|
||||||
limit,
|
limit,
|
||||||
page: page + 1,
|
page: 1,
|
||||||
with_deleted: false,
|
with_deleted: false,
|
||||||
order_field: sorting[0].id,
|
order_field: sorting[0].id,
|
||||||
order_direction: sorting[0].desc ? 'DESC' : 'ASC',
|
order_direction: sorting[0].desc ? 'DESC' : 'ASC',
|
||||||
@ -255,10 +252,11 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode })
|
|||||||
);
|
);
|
||||||
|
|
||||||
const total_count = transformedData.length;
|
const total_count = transformedData.length;
|
||||||
const paginatedData = transformedData.slice(page * limit, (page + 1) * limit);
|
|
||||||
|
|
||||||
console.log('data', paginatedData);
|
// **Pagination di frontend saja (tanpa hit API ulang)**
|
||||||
// setMenus(transformedData);
|
const paginatedData = transformedData.slice(page * limit, (page + 1) * limit);
|
||||||
|
const totalPages = Math.ceil(total_count / limit);
|
||||||
|
|
||||||
return { data: paginatedData, totalCount: total_count };
|
return { data: paginatedData, totalCount: total_count };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching Menus', error);
|
console.error('Error fetching Menus', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user