diff --git a/src/components/CareerExplorer.js b/src/components/CareerExplorer.js index 50b2485..aaa3232 100644 --- a/src/components/CareerExplorer.js +++ b/src/components/CareerExplorer.js @@ -151,47 +151,63 @@ function CareerExplorer({ handleCareerClick, userState, areaTitle }) { }; useEffect(() => { - const fetchUserProfile = async () => { - try { - const token = localStorage.getItem('token'); - const res = await axios.get(`${apiUrl}/user-profile`, { - headers: { Authorization: `Bearer ${token}` }, - }); - - if (res.status === 200) { - const profileData = res.data; - setUserProfile(profileData); - - if (profileData.career_list) { - try { + const fetchUserProfile = async () => { + try { + const token = localStorage.getItem('token'); + const res = await axios.get(`${apiUrl}/user-profile`, { + headers: { Authorization: `Bearer ${token}` }, + }); + + if (res.status === 200) { + const profileData = res.data; + setUserProfile(profileData); + + // Explicitly set careerList from saved data + if (profileData.career_list) { setCareerList(JSON.parse(profileData.career_list)); - } catch (err) { - console.error('Error parsing career_list:', err); } - } - - const priorities = profileData.career_priorities - ? JSON.parse(profileData.career_priorities) - : {}; - - const allAnswered = ['interests', 'meaning', 'stability', 'growth', 'balance', 'recognition'].every( - (key) => priorities[key] - ); - - if (!allAnswered) { - setShowModal(true); - } - } else { - setShowModal(true); // profile not found, show modal by default + + // Check explicitly for Interest Inventory answers + if (profileData.interest_inventory_answers) { + const answers = profileData.interest_inventory_answers; + const careerSuggestionsRes = await axios.post(`${apiUrl}/onet/submit_answers`, { + answers, + state: profileData.state, + area: profileData.area, + }); + + // Destructure `careers` from the server response + const { careers = [] } = careerSuggestionsRes.data || {}; + + // Flatten in case it's a nested array (or just a no-op if already flat) + setCareerSuggestions(careers.flat()); + } else { + // No interest inventory answers: fallback to an empty list + setCareerSuggestions([]); + } + + const priorities = profileData.career_priorities + ? JSON.parse(profileData.career_priorities) + : {}; + + const allAnswered = ['interests', 'meaning', 'stability', 'growth', 'balance', 'recognition'].every( + (key) => priorities[key] + ); + + if (!allAnswered) { + setShowModal(true); } - } catch (err) { - console.error('Error fetching user profile:', err); - setShowModal(true); // on error, default to showing modal + } else { + setShowModal(true); } - }; - - fetchUserProfile(); - }, [apiUrl]); + } catch (err) { + console.error('Error fetching user profile:', err); + setShowModal(true); + } + }; + + fetchUserProfile(); +}, [apiUrl]); // Load suggestions from Interest Inventory if provided (optional) useEffect(() => { @@ -202,26 +218,29 @@ function CareerExplorer({ handleCareerClick, userState, areaTitle }) { // Fetch Job Zones if suggestions are provided useEffect(() => { - const fetchJobZones = async () => { - if (!careerSuggestions.length) return; + const fetchJobZones = async () => { + if (!careerSuggestions.length) return; - const flatSuggestions = careerSuggestions.flat(); - const socCodes = flatSuggestions.map((career) => career.code); - try { - const response = await axios.post(`${apiUrl}/job-zones`, { socCodes }); - const jobZoneData = response.data; - const updatedCareers = flatSuggestions.map((career) => ({ - ...career, - job_zone: jobZoneData[career.code.slice(0, -3)]?.job_zone || null, - })); - setCareersWithJobZone(updatedCareers); - } catch (error) { - console.error('Error fetching job zone information:', error); - } - }; + const flatSuggestions = careerSuggestions.flat(); + const socCodes = flatSuggestions.map((career) => career.code); - fetchJobZones(); - }, [careerSuggestions, apiUrl]); + try { + const response = await axios.post(`${apiUrl}/job-zones`, { socCodes }); + const jobZoneData = response.data; + const updatedCareers = flatSuggestions.map((career) => ({ + ...career, + job_zone: jobZoneData[career.code.slice(0, -3)]?.job_zone || null, + })); + + // IMPORTANT: Ensure this actually sets a new array + setCareersWithJobZone([...updatedCareers]); + } catch (error) { + console.error('Error fetching job zone information:', error); + } + }; + + fetchJobZones(); +}, [careerSuggestions, apiUrl]); // Filtering logic (Job Zone and Fit) const filteredCareers = useMemo(() => { diff --git a/user_profile.db b/user_profile.db index 7271ab0..4125014 100644 Binary files a/user_profile.db and b/user_profile.db differ