import { Action, ActionPanel, closeMainWindow, Form, Icon, PopToRootType, useNavigation } from "@raycast/api"; import { useState } from "react"; import { stopTimesheet } from "./actions"; import { Timesheet } from "./api"; import { formatTime, timesheetSubtitle } from "./utils"; interface Props { timesheet: Timesheet; onStopped?: () => void; /** opened directly via launch context (e.g. from the menu bar): close Raycast afterwards instead of popping */ isRoot?: boolean; } /** Stopping always requires a description */ export function StopForm({ timesheet, onStopped, isRoot }: Props) { const { pop } = useNavigation(); const [descriptionError, setDescriptionError] = useState(); async function submit(v: { description: string; tags: string }) { if (!v.description.trim()) { setDescriptionError("Beschreibung ist Pflicht"); return false; } if (!(await stopTimesheet(timesheet, v.description.trim(), v.tags))) return false; onStopped?.(); if (isRoot) await closeMainWindow({ popToRootType: PopToRootType.Immediate }); else pop(); } return (
} > setDescriptionError(undefined)} autoFocus /> ); }