Fixed careerSuggestions on refresh/login
This commit is contained in:
parent
b71920f68e
commit
7bb176c12a
@ -162,12 +162,28 @@ function CareerExplorer({ handleCareerClick, userState, areaTitle }) {
|
||||
const profileData = res.data;
|
||||
setUserProfile(profileData);
|
||||
|
||||
// Explicitly set careerList from saved data
|
||||
if (profileData.career_list) {
|
||||
try {
|
||||
setCareerList(JSON.parse(profileData.career_list));
|
||||
} catch (err) {
|
||||
console.error('Error parsing career_list:', err);
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -182,16 +198,16 @@ function CareerExplorer({ handleCareerClick, userState, areaTitle }) {
|
||||
setShowModal(true);
|
||||
}
|
||||
} else {
|
||||
setShowModal(true); // profile not found, show modal by default
|
||||
setShowModal(true);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching user profile:', err);
|
||||
setShowModal(true); // on error, default to showing modal
|
||||
setShowModal(true);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUserProfile();
|
||||
}, [apiUrl]);
|
||||
}, [apiUrl]);
|
||||
|
||||
// Load suggestions from Interest Inventory if provided (optional)
|
||||
useEffect(() => {
|
||||
@ -207,6 +223,7 @@ function CareerExplorer({ handleCareerClick, userState, areaTitle }) {
|
||||
|
||||
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;
|
||||
@ -214,14 +231,16 @@ function CareerExplorer({ handleCareerClick, userState, areaTitle }) {
|
||||
...career,
|
||||
job_zone: jobZoneData[career.code.slice(0, -3)]?.job_zone || null,
|
||||
}));
|
||||
setCareersWithJobZone(updatedCareers);
|
||||
|
||||
// IMPORTANT: Ensure this actually sets a new array
|
||||
setCareersWithJobZone([...updatedCareers]);
|
||||
} catch (error) {
|
||||
console.error('Error fetching job zone information:', error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchJobZones();
|
||||
}, [careerSuggestions, apiUrl]);
|
||||
}, [careerSuggestions, apiUrl]);
|
||||
|
||||
// Filtering logic (Job Zone and Fit)
|
||||
const filteredCareers = useMemo(() => {
|
||||
|
BIN
user_profile.db
BIN
user_profile.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user