Merge pull request 'Issue 6 : sync linked plan status when module is toggled active or inactive' (#12) from fix-inactive-module-storefront into main

Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-web-ui/pulls/12
Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
Amit Salunke 2026-10-10 09:53:38 +00:00
commit 56cb400c19
1 changed files with 25 additions and 0 deletions

View File

@ -459,6 +459,30 @@ export default function App() {
{ is_active: newActive, status: newStatus },
{ headers: { Authorization: `Bearer ${userToken}` } }
);
const linkedPlans = adminPlansList.filter((p) =>
p.base_code?.toLowerCase() === mod.code?.toLowerCase() ||
p.module_ids?.includes(mod.id) ||
p.modules?.some((m: any) => m.id === mod.id || m.slug === mod.slug)
);
for (const plan of linkedPlans) {
if (plan.is_active !== newActive) {
try {
await axios.patch(
`${API_BASE}/api/admin/plans/${plan.base_code}/status`,
{ is_active: newActive },
{ headers: { Authorization: `Bearer ${userToken}` } }
);
setAdminPlansList((prev) =>
prev.map((p) => (p.base_code === plan.base_code ? { ...p, is_active: newActive } : p))
);
} catch (planErr) {
console.error('Failed to sync linked plan status:', planErr);
}
}
}
setAdminLogs((prev) => [`[Catalog] ${mod.name} is now ${newActive ? 'Active' : 'Inactive'}`, ...prev]);
} catch (err: any) {
setAdminModulesList((prev) =>
@ -468,6 +492,7 @@ export default function App() {
}
};
const handleOpenEditModule = (mod: any) => {
setSelectedEditModule(mod);
setEditModuleName(mod.name || '');