import React, { useEffect, useState } from 'react' import { api } from '../api.js' import { notifyTelegramEnabled, prefillLastRoomDisabled } from '../settings.js' // Formats a Date as the value a `datetime-local` input expects, in local time // (YYYY-MM-DDTHH:mm). function toLocalInputValue(date) { const pad = (n) => String(n).padStart(2, '0') return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}` } // Dedicated page for planning a meeting. Kept separate from the meetings list // so creating a meeting is a deliberate, focused flow. On success the caller // is expected to navigate back to the meetings list. export default function PlanMeetingPage({ onCreated, onCancel }) { const [title, setTitle] = useState('') const [intent, setIntent] = useState('') const [room, setRoom] = useState('') // Prefill with the current date/time so the field is never empty by default. const [scheduledAt, setScheduledAt] = useState(() => toLocalInputValue(new Date())) // When checked the author is recorded as joining straight away. Checked by // default, since planning a meeting usually means you intend to attend. const [autoJoin, setAutoJoin] = useState(true) // When checked the Telegram bot announces the meeting. Off by default; the // profile's device-local preference decides whether it starts checked. const [hasNotification, setHasNotification] = useState(notifyTelegramEnabled) const [saving, setSaving] = useState(false) const [error, setError] = useState('') // Offer the most recently joined room as the default unless the device-local // preference disables it. The recent-rooms list is ordered newest first, and // the room field is only filled while it is still empty so a manual edit is // preserved. useEffect(() => { if (prefillLastRoomDisabled()) return let active = true api .listRooms() .then((rooms) => { const last = rooms?.[0]?.roomName if (active && last) setRoom((current) => current || last) }) .catch(() => { // Prefilling is best-effort; leave the field empty on failure. }) return () => { active = false } }, []) const create = async (event) => { event.preventDefault() setError('') if (!title.trim() || !scheduledAt) { setError('A title and a date/time are required.') return } setSaving(true) try { await api.createMeeting({ title, intent, room, // datetime-local is local time; toISOString() produces the RFC3339 UTC // instant the backend expects. scheduledAt: new Date(scheduledAt).toISOString(), autoJoin, hasNotification, }) onCreated?.() } catch (err) { setError(err.message) setSaving(false) } } return (

Plan a meeting