()
| 17 | } from "@/components/ui/alert-dialog"; |
| 18 | |
| 19 | export function SeedDataButton() { |
| 20 | const [isLoading, setIsLoading] = useState(false); |
| 21 | const [showResetDialog, setShowResetDialog] = useState(false); |
| 22 | |
| 23 | const handleSeedData = async (resetFirst: boolean = false) => { |
| 24 | setIsLoading(true); |
| 25 | try { |
| 26 | await seedUserData(resetFirst); |
| 27 | toast.success("Sample data created successfully!", { |
| 28 | description: |
| 29 | "Your dashboard now has realistic financial data to explore.", |
| 30 | }); |
| 31 | // Refresh the page to show new data |
| 32 | window.location.reload(); |
| 33 | } catch (error) { |
| 34 | console.error("Error seeding data:", error); |
| 35 | |
| 36 | if ( |
| 37 | error instanceof Error && |
| 38 | error.message.includes("already has financial data") |
| 39 | ) { |
| 40 | setShowResetDialog(true); |
| 41 | } else { |
| 42 | toast.error("Failed to create sample data", { |
| 43 | description: |
| 44 | error instanceof Error ? error.message : "Please try again later.", |
| 45 | }); |
| 46 | } |
| 47 | } finally { |
| 48 | setIsLoading(false); |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | const handleResetAndSeed = async () => { |
| 53 | setShowResetDialog(false); |
| 54 | await handleSeedData(true); |
| 55 | }; |
| 56 | |
| 57 | const handleResetOnly = async () => { |
| 58 | setIsLoading(true); |
| 59 | try { |
| 60 | await resetUserData(); |
| 61 | toast.success("Financial data reset successfully!", { |
| 62 | description: "All your financial data has been cleared.", |
| 63 | }); |
| 64 | // Refresh the page to show empty state |
| 65 | window.location.reload(); |
| 66 | } catch (error) { |
| 67 | console.error("Error resetting data:", error); |
| 68 | toast.error("Failed to reset data", { |
| 69 | description: |
| 70 | error instanceof Error ? error.message : "Please try again later.", |
| 71 | }); |
| 72 | } finally { |
| 73 | setIsLoading(false); |
| 74 | } |
| 75 | }; |
| 76 |
nothing calls this directly
no test coverage detected