Skip to content

Commit 2021009

Browse files
committed
feat: enhance CV loading logic in CVBuilder component
1 parent b255452 commit 2021009

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

backend/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dotenv.config();
66

77
const app = express();
88
app.use(cors({
9-
origin: process.env.CORS_ORIGIN,
9+
origin: 'http://localhost:5173',
1010
credentials: true
1111
}));
1212
app.use(express.json());

frontend/src/components/Dashboard/CVBuilder/CVBuilder.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,21 @@ const CVBuilder = ({ onPreview, user }) => {
6464
}
6565
}, [user]);
6666

67+
68+
useEffect(() => {
69+
let checked = false;
70+
if (user?._id && !checked) {
71+
setLoading(true);
72+
checkExistingCV();
73+
checked = true;
74+
} else {
75+
setLoading(false);
76+
}
77+
}, [user?._id]);
78+
6779
const checkExistingCV = async () => {
6880
try {
6981
const response = await api.get(`/cv/${user._id}`);
70-
console.log(response);
7182
if (response.data.success) {
7283
setFormData(response.data.data);
7384
setCvExists(true);

frontend/src/components/Dashboard/CVBuilder/CVPreview.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// src/components/Dashboard/CVBuilder/CVPreview.jsx
21
import React from 'react';
32
import { ArrowLeft, Download } from 'lucide-react';
43

frontend/src/components/Dashboard/CVBuilder/CVStatus.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// src/components/Dashboard/CVBuilder/CVStatus.jsx
21
import React from 'react';
32
import { Download, FileText, Edit, Calendar } from 'lucide-react';
43

frontend/src/components/Register/Register.jsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState } from 'react';
22
import { User, Mail, Phone, Lock, Eye, EyeOff, ArrowLeft, GraduationCap } from 'lucide-react';
3+
import api from '../../utils/api';
34

45
const Register = ({ onRegister, onNavigateToLogin }) => {
56
const [formData, setFormData] = useState({
@@ -18,10 +19,10 @@ const Register = ({ onRegister, onNavigateToLogin }) => {
1819

1920
const handleSubmit = async (e) => {
2021
e.preventDefault();
21-
22+
2223
const requiredFields = Object.keys(formData);
2324
const emptyFields = requiredFields.filter(field => !formData[field].trim());
24-
25+
2526
if (emptyFields.length > 0) {
2627
setError('Please fill in all fields');
2728
return;
@@ -41,21 +42,15 @@ const Register = ({ onRegister, onNavigateToLogin }) => {
4142
setError('');
4243

4344
try {
44-
const response = await fetch('/api/auth/register', {
45-
method: 'POST',
46-
headers: { 'Content-Type': 'application/json' },
47-
body: JSON.stringify(formData)
48-
});
49-
50-
if (response.ok) {
51-
const userData = await response.json();
52-
onRegister(userData);
45+
const response = await api.post('/users/register', formData);
46+
onRegister(response.data);
47+
} catch (err) {
48+
console.error(err);
49+
if (err.response) {
50+
setError(err.response.data?.message || 'Registration failed');
5351
} else {
54-
const errorData = await response.json();
55-
setError(errorData.message || 'Registration failed');
52+
setError('Network error. Please try again.');
5653
}
57-
} catch (err) {
58-
setError('Network error. Please try again.');
5954
} finally {
6055
setLoading(false);
6156
}
@@ -65,9 +60,9 @@ const Register = ({ onRegister, onNavigateToLogin }) => {
6560
<div className="min-h-screen bg-gradient-to-r from-[#04445E] to-[#169AB4] flex items-center justify-center p-4">
6661
<div className="bg-white rounded-2xl shadow-2xl p-6 w-full max-w-5xl">
6762
<div className="text-left mb-6">
68-
<img
69-
src="/NEXT-STEPS-LOGO.png"
70-
alt="Next Steps Logo"
63+
<img
64+
src="/NEXT-STEPS-LOGO.png"
65+
alt="Next Steps Logo"
7166
className="h-12 mb-3"
7267
/>
7368
<h1 className="text-2xl font-bold text-[#04445E] mb-1">Create Your Account</h1>

0 commit comments

Comments
 (0)