56 lines
2.9 KiB
JavaScript
56 lines
2.9 KiB
JavaScript
const fs = require('fs');
|
|
|
|
let content = fs.readFileSync('c:/dev/gohorsejobs/frontend/src/app/dashboard/backoffice/page.tsx', 'utf8');
|
|
|
|
content = content.replace(
|
|
'import { Archive, CheckCircle, Copy, ExternalLink, PauseCircle, Plus, RefreshCw, XCircle } from "lucide-react"',
|
|
'import { Archive, CheckCircle, Copy, ExternalLink, PauseCircle, Plus, RefreshCw, XCircle } from "lucide-react"\r\nimport { ConfirmModal } from "@/components/confirm-modal"'
|
|
);
|
|
|
|
content = content.replace(
|
|
'const [editingPlanId, setEditingPlanId] = useState<string | null>(null)',
|
|
'const [editingPlanId, setEditingPlanId] = useState<string | null>(null)\r\n const [deletePlanId, setDeletePlanId] = useState<string | null>(null)'
|
|
);
|
|
|
|
const oldFunction = ` const handleDeletePlan = async (id: string) => {\r
|
|
if (!confirm("Delete this plan?")) return\r
|
|
try {\r
|
|
await plansApi.delete(id)\r
|
|
toast.success("Plan deleted")\r
|
|
loadBackoffice(true)\r
|
|
} catch (error) {\r
|
|
toast.error("Failed to delete plan")\r
|
|
}\r
|
|
}`;
|
|
|
|
const newFunction = ` const handleDeletePlan = async (id: string) => {\r
|
|
setDeletePlanId(id)\r
|
|
}\r
|
|
\r
|
|
const confirmDeletePlan = async () => {\r
|
|
if (!deletePlanId) return\r
|
|
try {\r
|
|
await plansApi.delete(deletePlanId)\r
|
|
toast.success("Plan deleted")\r
|
|
loadBackoffice(true)\r
|
|
} catch (error) {\r
|
|
toast.error("Failed to delete plan")\r
|
|
} finally {\r
|
|
setDeletePlanId(null)\r
|
|
}\r
|
|
}`;
|
|
|
|
content = content.replace(new RegExp(oldFunction.replace(/[.*+?^$\\{\\}()|[\\]\\\\]/g, '\\\\$&').replace(/\\r\\n/g, '\\r?\\n'), 'g'), newFunction);
|
|
|
|
content = content.replace(
|
|
' </TabsContent>\r\n </Tabs>\r\n </div>\r\n )\r\n}',
|
|
' </TabsContent>\r\n </Tabs>\r\n <ConfirmModal\r\n isOpen={!!deletePlanId}\r\n onClose={() => setDeletePlanId(null)}\r\n onConfirm={confirmDeletePlan}\r\n title="Are you sure you want to delete this plan?"\r\n description="This action cannot be undone."\r\n />\r\n </div>\r\n )\r\n}'
|
|
);
|
|
|
|
content = content.replace(
|
|
' </TabsContent>\n </Tabs>\n </div>\n )\n}',
|
|
' </TabsContent>\n </Tabs>\n <ConfirmModal\n isOpen={!!deletePlanId}\n onClose={() => setDeletePlanId(null)}\n onConfirm={confirmDeletePlan}\n title="Are you sure you want to delete this plan?"\n description="This action cannot be undone."\n />\n </div>\n )\n}'
|
|
);
|
|
|
|
fs.writeFileSync('c:/dev/gohorsejobs/frontend/src/app/dashboard/backoffice/page.tsx', content);
|
|
console.log('done');
|