diff --git a/MilestoneTimeline.js b/MilestoneTimeline.js new file mode 100644 index 0000000..e69de29 diff --git a/backend/server3.js b/backend/server3.js index 7e7ab1e..8b70f2e 100644 --- a/backend/server3.js +++ b/backend/server3.js @@ -82,13 +82,19 @@ app.get('/api/premium/planned-path/all', authenticatePremiumUser, async (req, re // Save a new planned path app.post('/api/premium/planned-path', authenticatePremiumUser, async (req, res) => { - const { career_name } = req.body; + let { career_name } = req.body; if (!career_name) { return res.status(400).json({ error: 'Career name is required.' }); } try { + // Ensure that career_name is always a string + if (typeof career_name !== 'string') { + console.warn('career_name was not a string. Converting to string.'); + career_name = String(career_name); // Convert to string + } + // Check if the career path already exists for the user const existingCareerPath = await db.get( `SELECT id FROM career_path WHERE user_id = ? AND career_name = ?`, @@ -96,7 +102,6 @@ app.post('/api/premium/planned-path', authenticatePremiumUser, async (req, res) ); if (existingCareerPath) { - // Return the existing path β do NOT define or reuse newCareerPathId return res.status(200).json({ message: 'Career path already exists. Would you like to reload it or create a new one?', career_path_id: existingCareerPath.id, @@ -104,7 +109,7 @@ app.post('/api/premium/planned-path', authenticatePremiumUser, async (req, res) }); } - // Only define newCareerPathId *when* creating a new path + // Define a new career path id and insert into the database const newCareerPathId = uuidv4(); await db.run( `INSERT INTO career_path (id, user_id, career_name) VALUES (?, ?, ?)`, @@ -114,7 +119,7 @@ app.post('/api/premium/planned-path', authenticatePremiumUser, async (req, res) res.status(201).json({ message: 'Career path saved.', career_path_id: newCareerPathId, - action_required: 'new_created' // Action flag for newly created path + action_required: 'new_created' }); } catch (error) { console.error('Error saving career path:', error); @@ -123,6 +128,7 @@ app.post('/api/premium/planned-path', authenticatePremiumUser, async (req, res) }); + // Save a new milestone app.post('/api/premium/milestones', authenticatePremiumUser, async (req, res) => { const { diff --git a/src/components/AISuggestedMilestones.js b/src/components/AISuggestedMilestones.js new file mode 100644 index 0000000..751b15d --- /dev/null +++ b/src/components/AISuggestedMilestones.js @@ -0,0 +1,45 @@ +// src/components/AISuggestedMilestones.js +import React, { useEffect, useState } from 'react'; + +const AISuggestedMilestones = ({ career, careerPathId, authFetch }) => { + const [suggestedMilestones, setSuggestedMilestones] = useState([]); + + useEffect(() => { + if (!career) return; + setSuggestedMilestones([ + { title: `Entry-Level ${career}`, date: '2025-06-01', progress: 0 }, + { title: `Mid-Level ${career}`, date: '2027-01-01', progress: 0 }, + { title: `Senior-Level ${career}`, date: '2030-01-01', progress: 0 }, + ]); + }, [career]); + + const confirmMilestones = async () => { + for (const milestone of suggestedMilestones) { + await authFetch(`/api/premium/milestones`, { + method: 'POST', + body: JSON.stringify({ + milestone_type: 'Career', + title: milestone.title, + description: milestone.title, + date: milestone.date, + career_path_id: careerPathId, + progress: milestone.progress, + status: 'planned', + }), + }); + } + setSuggestedMilestones([]); + }; + + if (!suggestedMilestones.length) return null; + + return ( +
This career already has a career path. Do you want to reload it or create a new one?
- )} - {isCurrentCareer && ( -You are already on this career path.
- )} +Loading career paths...
+ ) : ( + + )} +Your session has expired or is invalid.
-Your session has expired or is invalid.
+{m.description}
+Date: {m.date}
+Progress: {m.progress}%
+Your session has expired or is invalid.
-Selected Career: {selectedCareer?.career_name || 'Not Selected'}
- {loading ?Loading...
:Career Path ID: {careerPathId}
} - -Please select a career before adding milestones.
-)} -Not sure about this career path? Choose a different one here.
-- Youβre about to start a brand new career path for:{" "} - {selectedCareer?.career_name || selectedCareer}. -
-This will reset your milestone plan. Do you want to continue?
+