diff --git a/backend/server3.js b/backend/server3.js index a7d6164..20df849 100644 --- a/backend/server3.js +++ b/backend/server3.js @@ -216,8 +216,9 @@ app.post('/api/premium/career-profile', authenticatePremiumUser, async (req, res projected_end_date, college_enrollment_status, currently_working, - // The new field: career_goals, + retirement_start_date, + desired_retirement_income_monthly, // planned fields planned_monthly_expenses, @@ -248,7 +249,9 @@ app.post('/api/premium/career-profile', authenticatePremiumUser, async (req, res projected_end_date, college_enrollment_status, currently_working, - career_goals, -- ADD THIS + career_goals, + retirement_start_date, + desired_retirement_income_monthly, planned_monthly_expenses, planned_monthly_debt_payments, planned_monthly_retirement_contribution, @@ -257,14 +260,16 @@ app.post('/api/premium/career-profile', authenticatePremiumUser, async (req, res planned_surplus_retirement_pct, planned_additional_income ) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE status = VALUES(status), start_date = VALUES(start_date), projected_end_date = VALUES(projected_end_date), college_enrollment_status = VALUES(college_enrollment_status), currently_working = VALUES(currently_working), - career_goals = VALUES(career_goals), -- ADD THIS + career_goals = VALUES(career_goals), + retirement_start_date = VALUES(retirement_start_date), + desired_retirement_income_monthly = VALUES(desired_retirement_income_monthly), planned_monthly_expenses = VALUES(planned_monthly_expenses), planned_monthly_debt_payments = VALUES(planned_monthly_debt_payments), planned_monthly_retirement_contribution = VALUES(planned_monthly_retirement_contribution), @@ -285,7 +290,9 @@ app.post('/api/premium/career-profile', authenticatePremiumUser, async (req, res projected_end_date || null, college_enrollment_status || null, currently_working || null, - career_goals || null, // pass career_goals here + career_goals || null, + retirement_start_date || null, + desired_retirement_income_monthly || null, planned_monthly_expenses ?? null, planned_monthly_debt_payments ?? null, planned_monthly_retirement_contribution ?? null, diff --git a/src/components/ScenarioContainer.js b/src/components/ScenarioContainer.js index 70d2fe8..16e583b 100644 --- a/src/components/ScenarioContainer.js +++ b/src/components/ScenarioContainer.js @@ -286,6 +286,13 @@ export default function ScenarioContainer({ surplusEmergencyAllocation: scenarioOverrides.surplusEmergencyAllocation, surplusRetirementAllocation: scenarioOverrides.surplusRetirementAllocation, additionalIncome: scenarioOverrides.additionalIncome, + retirement_start_date: localScenario.retirement_start_date + || localScenario.projected_end_date + || null, + desired_retirement_income_monthly: parseScenarioOverride( + localScenario.desired_retirement_income_monthly, + 0 + ), studentLoanAmount: collegeData.studentLoanAmount, interestRate: collegeData.interestRate, @@ -931,6 +938,8 @@ export default function ScenarioContainer({ show={showScenarioModal} onClose={() => setShowScenarioModal(false)} scenario={localScenario} + collegeProfile={collegeProfile} + financialProfile={financialProfile} onSave={handleScenarioSave} /> diff --git a/src/components/ScenarioEditModal.js b/src/components/ScenarioEditModal.js index 73e8269..52766b6 100644 --- a/src/components/ScenarioEditModal.js +++ b/src/components/ScenarioEditModal.js @@ -13,7 +13,8 @@ export default function ScenarioEditModal({ show, onClose, scenario, - collegeProfile + collegeProfile, + financialProfile }) { /********************************************************* * 1) CIP / IPEDS data states @@ -128,53 +129,58 @@ export default function ScenarioEditModal({ const s = scenario || {}; const c = collegeProfile || {}; + const safe = v => + v === null || v === undefined ? '' : v; setFormData({ // scenario portion - scenario_title: s.scenario_title || '', - career_name: s.career_name || '', - status: s.status || 'planned', - start_date: s.start_date || '', - projected_end_date: s.projected_end_date || '', - college_enrollment_status: s.college_enrollment_status || 'not_enrolled', - currently_working: s.currently_working || 'no', + scenario_title : safe(s.scenario_title), + career_name : safe(s.career_name), + status : safe(s.status || 'planned'), + start_date : safe(s.start_date), + projected_end_date : safe(s.projected_end_date), + retirement_start_date: safe( + (s.retirement_start_date || s.projected_end_date || '') + .toString() // handles Date objects + .substring(0, 10) // keep YYYY-MM-DD + ), + desired_retirement_income_monthly : + safe(s.desired_retirement_income_monthly + ?? financialProfile?.monthly_expenses), - planned_monthly_expenses: s.planned_monthly_expenses ?? null, - planned_monthly_debt_payments: s.planned_monthly_debt_payments ?? null, - planned_monthly_retirement_contribution: - s.planned_monthly_retirement_contribution ?? null, - planned_monthly_emergency_contribution: - s.planned_monthly_emergency_contribution ?? null, - planned_surplus_emergency_pct: s.planned_surplus_emergency_pct ?? null, - planned_surplus_retirement_pct: s.planned_surplus_retirement_pct ?? null, - planned_additional_income: s.planned_additional_income ?? null, + planned_monthly_expenses : safe(s.planned_monthly_expenses), + planned_monthly_debt_payments : safe(s.planned_monthly_debt_payments), + planned_monthly_retirement_contribution: safe(s.planned_monthly_retirement_contribution), + planned_monthly_emergency_contribution : safe(s.planned_monthly_emergency_contribution), + planned_surplus_emergency_pct : safe(s.planned_surplus_emergency_pct), + planned_surplus_retirement_pct : safe(s.planned_surplus_retirement_pct), + planned_additional_income : safe(s.planned_additional_income), // college portion - college_profile_id: c.id || null, - selected_school: c.selected_school || '', - selected_program: c.selected_program || '', - program_type: c.program_type || '', - academic_calendar: c.academic_calendar || 'monthly', + college_profile_id: safe(c.id || null), + selected_school: safe(c.selected_school || ''), + selected_program: safe(c.selected_program || ''), + program_type: safe(c.program_type || ''), + academic_calendar: safe(c.academic_calendar || 'monthly'), - is_in_state: !!c.is_in_state, - is_in_district: !!c.is_in_district, - is_online: !!c.is_online, - college_enrollment_status_db: c.college_enrollment_status || 'not_enrolled', + is_in_state: safe(!!c.is_in_state), + is_in_district: safe(!!c.is_in_district), + is_online: safe(!!c.is_online), + college_enrollment_status_db: safe(c.college_enrollment_status || 'not_enrolled'), - annual_financial_aid: c.annual_financial_aid ?? '', - existing_college_debt: c.existing_college_debt ?? '', - tuition_paid: c.tuition_paid ?? 0, - loan_deferral_until_graduation: !!c.loan_deferral_until_graduation, - loan_term: c.loan_term ?? 10, - interest_rate: c.interest_rate ?? 5, - extra_payment: c.extra_payment ?? 0, - credit_hours_per_year: c.credit_hours_per_year ?? '', - hours_completed: c.hours_completed ?? '', - program_length: c.program_length ?? '', - credit_hours_required: c.credit_hours_required ?? '', - enrollment_date: c.enrollment_date ? c.enrollment_date.substring(0, 10): '', - expected_graduation: c.expected_graduation ? c.expected_graduation.substring(0, 10): '', - expected_salary: c.expected_salary ?? '' + annual_financial_aid : safe(c.annual_financial_aid), + existing_college_debt : safe(c.existing_college_debt), + tuition_paid : safe(c.tuition_paid), + loan_term : safe(c.loan_term ?? 10), + interest_rate : safe(c.interest_rate ?? 5), + extra_payment : safe(c.extra_payment), + credit_hours_per_year: safe(c.credit_hours_per_year ?? ''), + hours_completed: safe(c.hours_completed ?? ''), + program_length: safe(c.program_length ?? ''), + credit_hours_required: safe(c.credit_hours_required ?? ''), + enrollment_date: safe(c.enrollment_date ? c.enrollment_date.substring(0, 10): ''), + expected_graduation: safe(c.expected_graduation ? c.expected_graduation.substring(0, 10): ''), + expected_salary: safe(c.expected_salary ?? '') }); // Manual / auto tuition @@ -479,6 +485,8 @@ async function handleSave() { status : s(formData.status), start_date : s(formData.start_date), projected_end_date : s(formData.projected_end_date), + retirement_start_date : s(formData.retirement_start_date), + desired_retirement_income_monthly : n(formData.desired_retirement_income_monthly), planned_monthly_expenses : n(formData.planned_monthly_expenses), planned_monthly_debt_payments : n(formData.planned_monthly_debt_payments), @@ -650,6 +658,41 @@ async function handleSave() { + {/* Retirement date */} +
+ + +
+ + {/* Desired retirement income (monthly) */} +
+ + + {formData.desired_retirement_income_monthly && ( +

+ ≈ $ + {(formData.desired_retirement_income_monthly*12) + .toLocaleString()} per year +

+ )} +
+ {/* College Enrollment Status */}