diff --git a/.env b/.env
new file mode 100644
index 0000000..b27ed78
--- /dev/null
+++ b/.env
@@ -0,0 +1 @@
+REACT_APP_OPENAI_API_KEY=your_api_key
diff --git a/package.json b/package.json
index bf489db..8466859 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
+ "axios": "^1.7.7",
"eslint": "^8.40.0",
"eslint-plugin-react": "^7.32.2",
diff --git a/src/RefineDescription.js b/src/RefineDescription.js
new file mode 100644
index 0000000..5db8a37
--- /dev/null
+++ b/src/RefineDescription.js
@@ -0,0 +1,49 @@
+import React, { useState } from 'react';
+import axios from 'axios';
+
+const RefineDescription = ({ description, setDescription }) => {
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState('');
+
+ const fetchRefinedDescription = async () => {
+ setLoading(true);
+ setError('');
+
+ try {
+ const response = await axios.post('https://api.openai.com/v1/chat/completions', {
+ model: "gpt-3.5-turbo",
+ messages: [{ role: "user", content: description }],
+ max_tokens: 50,
+ }, {
+ headers: {
+ 'Authorization': `Bearer ${process.env.REACT_APP_OPENAI_API_KEY}`,
+ 'Content-Type': 'application/json',
+ },
+ });
+
+ // Ensure response contains choices and a message
+ if (response.data.choices && response.data.choices.length > 0) {
+ setDescription(response.data.choices[0].message.content);
+ } else {
+ throw new Error('No choices received from the API.');
+ }
+ } catch (err) {
+ setError('Failed to fetch refined description. Please try again.');
+ console.error('Error fetching refined description:', err);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+
+ {loading &&
Loading...
}
+ {error &&
{error}
}
+
+
+ );
+};
+
+export default RefineDescription;
diff --git a/src/components/education/EducationForm.jsx b/src/components/education/EducationForm.jsx
index 9b9228d..894b0ef 100644
--- a/src/components/education/EducationForm.jsx
+++ b/src/components/education/EducationForm.jsx
@@ -1,106 +1,197 @@
-import { useState } from "react";
+import React, { useState, useRef, useEffect } from "react";
+import RefineDescription from "../../RefineDescription";
import Dropzone from "../Dropzone";
-const EducationForm = () => {
+function ExperienceForm({ onSubmit, onCancel }) {
const [formData, setFormData] = useState({
- course: "",
- school: "",
+ title: "",
+ company: "",
start_date: "",
end_date: "",
- grade: "",
+ description: "",
logo: "",
+ isCurrent: false,
});
- const handleChange = (field) => (e) => {
- e.preventDefault();
+ const [errors, setErrors] = useState({});
+
+ const modalRef = useRef();
+
+ const handleClickOutside = (e) => {
+ if (modalRef.current && !modalRef.current.contains(e.target)) {
+ onCancel(); // Close the form if clicked outside
+ }
+ };
+
+ useEffect(() => {
+ document.addEventListener("mousedown", handleClickOutside);
+ return () => {
+ document.removeEventListener("mousedown", handleClickOutside);
+ };
+ }, []);
+
+ const handleChange = (e) => {
+ const { name, value } = e.target;
+ setFormData({ ...formData, [name]: value });
+ };
+
+ const handleFileChange = (e) => {
+ const file = e.target.files[0];
+ if (file) {
+ const reader = new FileReader();
+ reader.onload = () => {
+ setFormData({ ...formData, logo: reader.result });
+ };
+ reader.readAsDataURL(file);
+ }
+ };
+
+ const handleCheckboxChange = () => {
+ setFormData((prev) => ({
+ ...prev,
+ isCurrent: !prev.isCurrent,
+ end_date: "",
+ }));
+ };
- setFormData({
- ...formData,
- [field]: e.currentTarget.value,
- });
+ const validateDates = () => {
+ if (!formData.isCurrent && formData.end_date) {
+ if (new Date(formData.end_date) < new Date(formData.start_date)) {
+ setErrors({ end_date: "End date cannot be earlier than start date" });
+ return false;
+ }
+ }
+ setErrors({});
+ return true;
};
const handleSubmit = (e) => {
e.preventDefault();
- fetch("http://127.0.0.1:5000/resume/education", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(formData),
- })
- .then((response) => response.json())
- .then((data) => {
- alert("Education successfully added!");
- })
- .catch((error) => {
- alert("Error: Education not added :(");
- });
+ if (!validateDates()) return;
+
+ const experienceData = {
+ title: formData.title,
+ company: formData.company,
+ start_date: formData.start_date,
+ end_date: formData.isCurrent ? "Present" : formData.end_date,
+ description: formData.description,
+ logo: formData.logo,
+ };
+
+ onSubmit(experienceData);
};
return (
- <>
-