// CareerOnboarding.js import React, { useState, useEffect } from 'react'; import { useLocation } from 'react-router-dom'; // 1) Import your CareerSearch component import CareerSearch from '../CareerSearch.js'; // adjust path as necessary const Req = () => *; const CareerOnboarding = ({ nextStep, prevStep, data, setData, finishNow }) => { // We store local state for “are you working,” “selectedCareer,” etc. const location = useLocation(); const navCareerObj = location.state?.selectedCareer; const [careerObj, setCareerObj] = useState(() => { if (navCareerObj) return navCareerObj; try { return JSON.parse(localStorage.getItem('selectedCareer') || 'null'); } catch { return null; } }); const [currentlyWorking, setCurrentlyWorking] = useState(''); const [collegeStatus, setCollegeStatus] = useState(''); const [showFinPrompt, setShowFinPrompt] = useState(false); /* ── 2. derived helpers ───────────────────────────────────── */ const selectedCareerTitle = careerObj?.title || ''; const ready = selectedCareerTitle && currentlyWorking && collegeStatus; const inCollege = ['currently_enrolled', 'prospective_student'] .includes(collegeStatus); const skipFin = !!data.skipFinancialStep; // 1) Grab the location state values, if any const { socCode, cipCodes, careerTitle, // <--- we passed this from handleSelectForEducation userZip, userState, } = location.state || {}; /* ── 3. side‑effects when route brings a new career object ── */ useEffect(() => { if (!navCareerObj?.title) return; setCareerObj(navCareerObj); localStorage.setItem('selectedCareer', JSON.stringify(navCareerObj)); setData(prev => ({ ...prev, career_name : navCareerObj.title, soc_code : navCareerObj.soc_code || '' })); // eslint-disable-next-line react-hooks/exhaustive-deps }, [navCareerObj]); // ← run once per navigation change // Called whenever other change const handleChange = (e) => { setData(prev => ({ ...prev, [e.target.name]: e.target.value })); }; /* ── 4. callbacks ─────────────────────────────────────────── */ function handleCareerSelected(obj) { setCareerObj(obj); localStorage.setItem('selectedCareer', JSON.stringify(obj)); setData(prev => ({ ...prev, career_name: obj.title, soc_code: obj.soc_code || '' })); } function handleSubmit() { if (!ready) return alert('Fill all required fields.'); const inCollege = ['currently_enrolled', 'prospective_student'].includes(collegeStatus); setData(prev => ({ ...prev, career_name : selectedCareerTitle, college_enrollment_status : collegeStatus, currently_working : currentlyWorking, inCollege, })); /* — where do we go? — */ if (skipFin && !inCollege) { /* user said “Skip” AND is not in college ⇒ jump to Review */ finishNow(); // ← the helper we just injected via props } else { nextStep(); // ordinary flow } } const nextLabel = skipFin ? inCollege ? 'College →' : 'Finish →' : inCollege ? 'College →' : 'Financial →'; return (

Career Details

(We ask this to understand your financial picture. This won’t affect how we track your progress toward your target career.)

{/* 2) Replace old local “Search for Career” with */}

Target Career

This should be the career you are striving for — whether it’s a new goal or the one you're already in.

{selectedCareerTitle && (

Selected Career: {selectedCareerTitle}

)}
{showFinPrompt && (

We can give you step-by-step milestones right away.
If you’d also like a personal cash-flow & tuition projection,
add a few financial details now—or skip and do it later.

)}