import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import { DatePicker, Select, Input } from 'antd';
import {
ArrowLeft,
Calendar,
Users,
DollarSign,
Target,
Clock,
FileText
} from 'feather-icons-react';
import { LoadingButton } from '../../components/Loading';
import dayjs from 'dayjs';
const { Option } = Select;
const { TextArea } = Input;
const CreateProject = () => {
const [loading, setLoading] = useState(false);
const [formData, setFormData] = useState({
projectName: '',
description: '',
category: '',
priority: 'medium',
status: 'planning',
startDate: dayjs(),
endDate: dayjs().add(1, 'month'),
budget: '',
client: '',
manager: [],
teamMembers: [],
tags: [],
attachments: []
});
const [errors, setErrors] = useState({});
// Avatar component with initials fallback
const UserAvatar = ({ initials, name }) => (
{initials}
);
// Sample data
const categories = [
{ value: 'web-development', label: 'Web Development', color: 'blue' },
{ value: 'mobile-app', label: 'Mobile App', color: 'green' },
{ value: 'design', label: 'Design', color: 'purple' },
{ value: 'marketing', label: 'Marketing', color: 'orange' },
{ value: 'devops', label: 'DevOps', color: 'cyan' },
{ value: 'data-science', label: 'Data Science', color: 'red' }
];
const managers = [
{ value: 'john-smith', label: 'John Smith', initials: 'JS' },
{ value: 'sarah-johnson', label: 'Sarah Johnson', initials: 'SJ' },
{ value: 'mike-wilson', label: 'Mike Wilson', initials: 'MW' },
{ value: 'lisa-chen', label: 'Lisa Chen', initials: 'LC' }
];
const teamMembers = [
{ value: 'alex-rodriguez', label: 'Alex Rodriguez', initials: 'AR' },
{ value: 'maria-garcia', label: 'Maria Garcia', initials: 'MG' },
{ value: 'david-brown', label: 'David Brown', initials: 'DB' },
{ value: 'emma-davis', label: 'Emma Davis', initials: 'ED' },
{ value: 'james-miller', label: 'James Miller', initials: 'JM' }
];
const handleInputChange = (field, value) => {
setFormData(prev => ({
...prev,
[field]: value
}));
// Clear error when user starts typing
if (errors[field]) {
setErrors(prev => ({
...prev,
[field]: ''
}));
}
};
const validateForm = () => {
const newErrors = {};
if (!formData.projectName.trim()) {
newErrors.projectName = 'Project name is required';
}
if (!formData.description.trim()) {
newErrors.description = 'Project description is required';
}
if (!formData.category) {
newErrors.category = 'Please select a category';
}
if (!formData.client.trim()) {
newErrors.client = 'Client name is required';
}
if (!formData.budget.trim()) {
newErrors.budget = 'Budget is required';
}
if (formData.manager.length === 0) {
newErrors.manager = 'Please assign at least one manager';
}
if (dayjs(formData.endDate).isBefore(dayjs(formData.startDate))) {
newErrors.endDate = 'End date must be after start date';
}
setErrors(newErrors);
return Object.keys(newErrors).length === 0;
};
const handleSubmit = async (e) => {
e.preventDefault();
if (!validateForm()) {
return;
}
setLoading(true);
try {
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 2000));
console.log('Project created:', formData);
// Reset form or redirect
alert('Project created successfully!');
} catch (error) {
console.error('Error creating project:', error);
alert('Error creating project. Please try again.');
} finally {
setLoading(false);
}
};
return (
{/* Header */}
Create New Project
Add a new project to your workspace
{/* Form */}
);
};
export default CreateProject;