import { Action, ActionPanel, Form, showToast, Toast, useNavigation } from "@raycast/api"; import { calendar } from "@appy/api"; import { useEffect, useState } from "react"; type Cal = { id: string; title: string; writable: boolean }; export default function NewEvent(props: { date?: Date }) { const { pop } = useNavigation(); const base = props.date ?? new Date(); const start = new Date(base.getFullYear(), base.getMonth(), base.getDate(), 9, 0); const [cals, setCals] = useState([]); const [allDay, setAllDay] = useState(false); useEffect(() => { calendar.list().then((all: Cal[]) => setCals(all.filter((c) => c.writable))).catch(() => {}); }, []); async function save(v: { title: string; start: Date; end?: Date; allDay: boolean; calendar: string; location: string }) { try { await calendar.create({ title: v.title, start: v.start, end: v.end ?? undefined, allDay: v.allDay, calendar: v.calendar || undefined, location: v.location || undefined }); await showToast({ style: Toast.Style.Success, title: "Added " + v.title }); pop(); } catch (e: any) { await showToast({ style: Toast.Style.Failure, title: "Couldn't add the event", message: e.message }); } } return (
}> {cals.map((c) => )} ); }