import React, { useState } from 'react'; import { Button, TextField, Dialog, DialogTitle, DialogContent, DialogActions, CircularProgress, Alert } from '@mui/material'; const NewMeetingDialog = ({ open, onClose, onCreate }) => { const [topic, setTopic] = useState(''); const [meetingDate, setMeetingDate] = useState(new Date().toISOString().split('T')[0]); // Defaults to today const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleCreate = async () => { if (!topic || !meetingDate) { setError('Both topic and date are required.'); return; } setError(''); setLoading(true); try { // The onCreate prop is expected to be an async function // that returns the newly created meeting. await onCreate(topic, meetingDate); handleClose(); // Close the dialog on success } catch (err) { setError(err.message || 'Failed to create meeting.'); } finally { setLoading(false); } }; const handleClose = () => { if (loading) return; // Prevent closing while loading setTopic(''); setMeetingDate(new Date().toISOString().split('T')[0]); setError(''); onClose(); // Call the parent's onClose handler }; return ( Create a New Meeting {error && {error}} setTopic(e.target.value)} sx={{ mt: 2 }} /> setMeetingDate(e.target.value)} InputLabelProps={{ shrink: true, }} sx={{ mt: 2 }} /> ); }; export default NewMeetingDialog;