const fs = require('fs'); let code = fs.readFileSync('src/components/Dashboard.js', 'utf8'); const imports = `import SidebarControls from './dashboard/SidebarControls'; import StatsPanel from './dashboard/StatsPanel'; import ApprovalQueueModal from './dashboard/modals/ApprovalQueueModal'; import UserProvisioningModal from './dashboard/modals/UserProvisioningModal'; import DonationModal from './dashboard/modals/DonationModal'; import HubFormModal from './dashboard/modals/HubFormModal'; import HouseholdFormModal from './dashboard/modals/HouseholdFormModal'; `; code = code.replace("import { useRouter } from 'next/navigation';", "import { useRouter } from 'next/navigation';\n" + imports); const leftPanelStart = code.indexOf('{/* Left Panel (Controls) */}'); const leftPanelEnd = code.indexOf('{/* Right Panel (Stats) */}'); if (leftPanelStart > -1 && leftPanelEnd > -1) { const newLeftPanel = `{/* Left Panel (Controls) */}
Controls
`; code = code.substring(0, leftPanelStart) + newLeftPanel + code.substring(leftPanelEnd); } const rightPanelStart = code.indexOf('{/* Right Panel (Stats) */}'); const rightPanelEnd = code.indexOf('{/* Add Location Floating Button */}'); if (rightPanelStart > -1 && rightPanelEnd > -1) { const newRightPanel = `{/* Right Panel (Stats) */} `; code = code.substring(0, rightPanelStart) + newRightPanel + code.substring(rightPanelEnd); } const modalStartIndex = code.indexOf('{/* Hub Modal */}'); if (modalStartIndex > -1) { const newModals = ` ); }`; code = code.substring(0, modalStartIndex) + newModals; } fs.writeFileSync('src/components/Dashboard.js', code); console.log('Dashboard.js successfully refactored');