import React from "react"; import api from "../api.js"; import {useState, useEffect} from "react"; export default function ProjectCreateModal({loc}) { const modalId = `modal-${loc.id.replace(/\s+/g, '-')}`; const [notes, setNotes] = useState(''); const [showSecondVisit, setShowSecondVisit] = useState(false); const [teamMembers, setTeamMembers] = useState([]); useEffect(() => { const fetchTeamMembers = async () => { try { const response = await api.get('team/'); if (response.status === 200) { setTeamMembers(response.data); } } catch (error) { console.error('Error fetching team members:', error); } }; fetchTeamMembers(); }, []); const handleNotes = (e) => { setNotes(e.target.value); } const [start1, setStart1] = useState(''); const handleStart1 = (e) => { setStart1(e.target.value); } const [end1, setEnd1] = useState(''); const handleEnd1 = (e) => { setEnd1(e.target.value); } const [serviceType, setServiceType] = useState(''); const handleServiceType = (e) => { setServiceType(e.target.value); } const [secondVisit, setSecondVisit] = useState(''); const handleSecondVisit = (e) => { setShowSecondVisit(e.target.value === 'Yes'); setSecondVisit(e.target.value); } const [start2, setStart2] = useState(''); const handleStart2 = (e) => { setStart2(e.target.value); } const [end2, setEnd2] = useState(''); const handleEnd2 = (e) => { setEnd2(e.target.value); } const [attendees, setAttendees] = useState([]); const handleAttendees = (e) => { const attendee = (e.target.value); if (e.target.checked) { setAttendees([...attendees, attendee]); } else { setAttendees(attendees.filter(a => a !== attendee)); } } const handleSubmit = async (e) => { e.preventDefault(); try { const response = await api.post('calendar/', { id: loc.id, store: loc.store, summary: `#${loc.store} - ${loc.city}: ${serviceType}`, description: `${serviceType} : ${notes}`, location: `${loc.street_address}, ${loc.city}, ${loc.state} ${loc.zip_code}`, start1: start1, end1: end1, serviceType: serviceType, secondVisit: secondVisit, start2: start2, end2: end2, attendees: attendees, }); if (response.status === 200) { onSuccess() } } catch (error) { alert(error.detail); } } const onSuccess = () => { alert('Project created and calendar invites sent!'); window.location.reload(); } return (
) }