diff --git a/src/App.js b/src/App.js index b2eaef0..f9cbd8a 100644 --- a/src/App.js +++ b/src/App.js @@ -7,6 +7,7 @@ import SignUp from './components/SignUp.js'; import InterestInventory from './components/InterestInventory.js'; import Dashboard from './components/Dashboard.js'; import UserProfile from './components/UserProfile.js'; +import FinancialProfileForm from './components/FinancialProfileForm.js'; import MilestoneTracker from "./components/MilestoneTracker.js"; import './App.css'; @@ -48,6 +49,11 @@ function App() { path="/milestone-tracker" element={isAuthenticated ? : } /> + : } + /> + {/* Catch-all for unknown routes */} } /> diff --git a/src/components/FinancialProfileForm.js b/src/components/FinancialProfileForm.js new file mode 100644 index 0000000..834b41c --- /dev/null +++ b/src/components/FinancialProfileForm.js @@ -0,0 +1,161 @@ +import React, { useState, useEffect } from "react"; +import { useLocation, useNavigate } from 'react-router-dom'; + +export default function FinancialProfileForm() { + const location = useLocation(); + const navigate = useNavigate(); + console.log("🔍 FinancialProfileForm mounted"); + console.log("🔍 location.state:", location.state); + const initialCareer = location?.state?.selectedCareer; + const [selectedCareer, setSelectedCareer] = useState(initialCareer || null); + const userId = localStorage.getItem("userId"); + const [formData, setFormData] = useState({ + currentSalary: "", + additionalIncome: "", + monthlyExpenses: "", + monthlyDebtPayments: "", + retirementSavings: "", + retirementContribution: "", + emergencyFund: "", + inCollege: false, + expectedGraduation: "", + partTimeIncome: "", + tuitionPaid: "", + collegeLoanTotal: "" + }); + + useEffect(() => { + console.log("✅ selectedCareer in useEffect:", selectedCareer); + }, [selectedCareer]); + + // Fetch existing data on mount + useEffect(() => { + async function fetchProfile() { + try { + const res = await fetch(`/api/premium/financial-profile?user_id=${userId}`); + if (res.ok) { + const data = await res.json(); + setFormData((prev) => ({ ...prev, ...data })); + } + } catch (err) { + console.error("Failed to fetch financial profile", err); + } + } + + fetchProfile(); + }, [userId]); + + const handleChange = (e) => { + const { name, value, type, checked } = e.target; + setFormData((prev) => ({ + ...prev, + [name]: type === "checkbox" ? checked : value + })); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + try { + const res = await fetch("/api/premium/financial-profile", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ user_id: userId, ...formData }) + }); + + if (res.ok) { + navigate('/milestone-tracker', { + state: { selectedCareer } + }); + } + } catch (err) { + console.error("Error submitting financial profile:", err); + } + }; + + return ( +
+

Your Financial Profile

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + {formData.inCollege && ( + <> +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + )} + +
+ +
+
+ ); +} diff --git a/src/components/PopoutPanel.js b/src/components/PopoutPanel.js index a5ac562..37cfb79 100644 --- a/src/components/PopoutPanel.js +++ b/src/components/PopoutPanel.js @@ -149,7 +149,7 @@ function PopoutPanel({ if (decision) { - navigate('/milestone-tracker', { + navigate('/financial-profile', { state: { selectedCareer: { career_path_id: match.id, career_name: data.title } } }); return; @@ -172,7 +172,7 @@ function PopoutPanel({ if (!newResponse.ok) throw new Error('Failed to create new career path.'); - navigate('/milestone-tracker', { + navigate('/financial-profile', { state: { selectedCareer: { career_path_id: newCareerPath.career_path_id, career_name: data.title } } }); diff --git a/user_profile.db b/user_profile.db index 0148c9d..5b5debd 100644 Binary files a/user_profile.db and b/user_profile.db differ