import React, { useState, useEffect } from 'react'; import { XIcon } from './icons/XIcon'; import { useUser } from '../contexts/UserContext'; interface CreateProjectModalProps { isOpen: boolean; onClose: () => void; onAddProject: (projectData: { name: string; workfrontId: string; clientLead: string; }) => void; } export const CreateProjectModal: React.FC = ({ isOpen, onClose, onAddProject }) => { const { user } = useUser(); const [name, setName] = useState(''); const [workfrontId, setWorkfrontId] = useState(''); const [clientLead, setClientLead] = useState(''); const [error, setError] = useState(null); useEffect(() => { // Reset form when modal opens if (isOpen) { setName(''); setWorkfrontId(''); setClientLead(''); setError(null); } }, [isOpen]); const validateWorkfrontId = (id: string): boolean => { const isValid = /^#WF_\d+$/.test(id); if (!isValid && id.length > 0) { setError("Workfront Project ID must be in the format '#WF_12345'"); } else { setError(null); } return isValid || id.length === 0; }; const handleWorkfrontIdChange = (e: React.ChangeEvent) => { const newId = e.target.value; setWorkfrontId(newId); validateWorkfrontId(newId); }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const isIdValidOnSubmit = /^#WF_\d+$/.test(workfrontId); if (!name.trim() || !clientLead.trim() || !workfrontId.trim()) { return; } if (!isIdValidOnSubmit) { setError("Workfront Project ID must be in the format '#WF_12345'"); return; } setError(null); onAddProject({ name, workfrontId, clientLead }); onClose(); }; if (!isOpen) return null; const isFormInvalid = !name.trim() || !workfrontId.trim() || !clientLead.trim(); return (
e.stopPropagation()} >

Create New Project

setName(e.target.value)} className="mt-1 block w-full p-2 border-2 border-oliver-azure rounded-[10px] shadow-sm focus:ring-oliver-azure focus:border-oliver-azure transition bg-white text-oliver-black" required />
{error &&

{error}

}
setClientLead(e.target.value)} className="mt-1 block w-full p-2 border-2 border-oliver-azure rounded-[10px] shadow-sm focus:ring-oliver-azure focus:border-oliver-azure transition bg-white text-oliver-black" required />
); };