diff --git a/src/components/admin/AddEmployee.jsx b/src/components/admin/AddEmployee.jsx index 9c7af44..36c330a 100644 --- a/src/components/admin/AddEmployee.jsx +++ b/src/components/admin/AddEmployee.jsx @@ -1,11 +1,32 @@ import React, { useState, useEffect } from 'react'; import { Link, useNavigate } from 'react-router-dom'; -import Sidebar from '../sidebar/Sidebar'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faChevronLeft } from '@fortawesome/free-solid-svg-icons'; +import Sidebar from '../sidebar/Sidebar'; import axiosInstance from '../../api/axiosConfig'; -import { styles } from '../../styles/classNames'; -import '../../styles/AddEmployee.css'; + +const CLASSES = { + container: 'flex flex-row', + mainContent: 'w-full flex flex-col min-h-screen text-black', + innerContent: 'min-h-screen text-gray-800 p-6', + header: 'flex justify-between items-center', + headerTitle: 'flex items-center', + backButton: 'text-[#0e355b] text-xl', + title: 'text-2xl font-semibold text-[#0e355b]', + formGrid: 'grid grid-cols-1 md:grid-cols-3 gap-6', + imageSection: 'space-y-6', + imageWrapper: 'text-center', + imageContainer: 'inline-block relative', + imagePreview: 'bg-gray-300 w-24 h-24 rounded-full mx-auto overflow-hidden', + noImage: 'w-full h-full flex items-center justify-center text-gray-500', + hiddenInput: 'hidden', + uploadButton: 'absolute bottom-0 left-1/2 transform -translate-x-1/2 bg-gray-700 text-white text-xs px-2 py-1 rounded-full', + formSection: 'md:col-span-2 space-y-4', + formGroup: 'text-gray-800 font-medium', + formInput: 'p-2 border-b border-gray-400 focus:border-gray-700', + formSelect: 'p-2 border-b border-gray-400 focus:border-gray-700', + submitButton: 'bg-[#0e355b] text-white py-2 px-4 rounded-md', +}; const AddEmployee = () => { const navigate = useNavigate(); @@ -15,6 +36,7 @@ const AddEmployee = () => { age: '', gender: '', email: '', + mobile: '', address: { address_line_1: '', address_line_2: '', @@ -22,36 +44,34 @@ const AddEmployee = () => { pincode: '', city_id: '', }, - mobile: '', image: null, }); const [cities, setCities] = useState([]); const [imagePreview, setImagePreview] = useState(null); - // Uncomment to fetch cities data from backend - // useEffect(() => { - // const fetchCities = async () => { - // try { - // const response = await axiosInstance.get('/cities'); - // if (Array.isArray(response.data)) { - // setCities(response.data); - // } else { - // console.error('Error: Data is not an array', response.data); - // } - // } catch (error) { - // console.error('Error fetching cities:', error.response || error.message); - // } - // }; + useEffect(() => { + const fetchCities = async () => { + try { + const response = await axiosInstance.get('/cities'); + if (Array.isArray(response.data)) { + setCities(response.data); + } else { + console.error('Error: Data is not an array', response.data); + } + } catch (error) { + console.error('Error fetching cities:', error.response ? error.response.data : error.message); + } + }; - // fetchCities(); - // }, []); + fetchCities(); + }, []); const handleInputChange = (e) => { const { name, value } = e.target; - setEmployeeData({ - ...employeeData, + setEmployeeData((prevData) => ({ + ...prevData, [name]: value, - }); + })); }; const handleImageChange = (e) => { @@ -73,7 +93,7 @@ const AddEmployee = () => { }); try { - await axiosInstance.post('http://localhost:5000/employees', formData, { + await axiosInstance.post('/employees', formData, { headers: { 'Content-Type': 'multipart/form-data', }, @@ -85,209 +105,165 @@ const AddEmployee = () => { }; return ( -