From 5d5e5fb001da23b163a17d87fe75e8ecba239306 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 1 Apr 2025 13:12:20 +0000 Subject: [PATCH] Added FinancialProfileForm with navigation from Popoutpanel --- src/App.js | 6 + src/components/FinancialProfileForm.js | 161 +++++++++++++++++++++++++ src/components/PopoutPanel.js | 4 +- user_profile.db | Bin 57344 -> 57344 bytes 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 src/components/FinancialProfileForm.js 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 0148c9d0f9c9a5f2d9bd4bb7de385b4c7075cb6f..5b5debd058225d07b9b401547a1a70e53b531052 100644 GIT binary patch delta 833 zcmah{J&)5c7_KiON7FX#O$9L!@pVEvQSvpQ6GJEgRqFMsk_yCPxry7elsX}G(1oQP zkYKpsPy|2VW+w6j=)l0n&ce)Z0O@clZa~e6S9&e`eINUI{Md`7uviMmSGK}ZsU-6} zi{`r>eLF1OaY2ojYQj-Tek1p4zpKBhUn{+G`=Yq{O?)a|6OJzY$hI1y(0|>pZ8lpi z@OGb}k&nlOBI*+4!!QcQq@WFx6zcDp;0qPTGs zVanhP`6x;henMAyXg{)sT}Qc_1CZwtMgq!-33Y=hF2GC!$`1Sl;=>Tr8J?XBnJ3W0 zBL+j1OgU>2Fv5&PIPY>zFA1Ie2jp_@h>YS~V*xKeDVkvFCU6{6Z(e{P6uN=$;|W$e zJ;#1*5B@bEzm&_c2PYBoVzlDPZOqLHQN$o4Q+&QREMD2iuS`7UVBO!p+|UmYg)Csm zFVGl=9?B&krmSA@?1kFH!NBf0(CO^iPaJEnFWt6eu{ms|R{7G+wJ!kGwNf?REt}a3 z=@5vfBsM$O^PTC3^5yJjWqyx|CeW+AOdm%5HJEUC