import React, { useState, useEffect } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { DatePicker, Select, Input, message } from 'antd'; import { ArrowLeft, Calendar, Users, DollarSign, Target, FileText, CheckCircle, TrendingUp } from 'feather-icons-react'; import { LoadingButton } from '../../components/Loading'; import dayjs from 'dayjs'; const { Option } = Select; const { TextArea } = Input; const CreateProject = () => { const navigate = useNavigate(); const [loading, setLoading] = useState(false); const [categoriesLoading, setCategoriesLoading] = useState(true); const [usersLoading, setUsersLoading] = useState(true); const [formData, setFormData] = useState({ projectName: '', description: '', clientName: '', categoryId: '', priority: 'medium', status: 'planning', startDate: dayjs(), endDate: dayjs().add(1, 'month'), budget: '', progressPercentage: 0, managers: [], teamMembers: [], tags: [] }); const [errors, setErrors] = useState({}); const [categories, setCategories] = useState([]); const [users, setUsers] = useState([]); // Load categories from API const loadCategories = async () => { try { const apiBaseUrl = process.env.REACT_APP_API_BASE_URL || ''; const response = await fetch(`${apiBaseUrl}ProjectCategories`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } }); if (response.ok) { const result = await response.json(); setCategories(result.data || []); } else { console.error('Failed to load categories'); // Fallback to sample data setCategories([ { id: 1, name: 'Web Development', color: 'blue' }, { id: 2, name: 'Mobile App', color: 'green' }, { id: 3, name: 'Design', color: 'purple' }, { id: 4, name: 'Marketing', color: 'orange' } ]); } } catch (error) { console.error('Error loading categories:', error); // Fallback to sample data setCategories([ { id: 1, name: 'Web Development', color: 'blue' }, { id: 2, name: 'Mobile App', color: 'green' }, { id: 3, name: 'Design', color: 'purple' }, { id: 4, name: 'Marketing', color: 'orange' } ]); } finally { setCategoriesLoading(false); } }; // Load users from API const loadUsers = async () => { try { const apiBaseUrl = process.env.REACT_APP_API_BASE_URL || ''; const response = await fetch(`${apiBaseUrl}Users`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } }); if (response.ok) { const result = await response.json(); setUsers(result.data || []); } else { console.error('Failed to load users'); // Fallback to sample data setUsers([ { id: 1, fullName: 'John Smith', email: 'john@example.com' }, { id: 2, fullName: 'Sarah Johnson', email: 'sarah@example.com' }, { id: 3, fullName: 'Mike Wilson', email: 'mike@example.com' }, { id: 4, fullName: 'Lisa Chen', email: 'lisa@example.com' } ]); } } catch (error) { console.error('Error loading users:', error); // Fallback to sample data setUsers([ { id: 1, fullName: 'John Smith', email: 'john@example.com' }, { id: 2, fullName: 'Sarah Johnson', email: 'sarah@example.com' }, { id: 3, fullName: 'Mike Wilson', email: 'mike@example.com' }, { id: 4, fullName: 'Lisa Chen', email: 'lisa@example.com' } ]); } finally { setUsersLoading(false); } }; // Load data on component mount useEffect(() => { loadCategories(); loadUsers(); }, []); // Avatar component with initials fallback const UserAvatar = ({ initials, name }) => (