init
This commit is contained in:
commit
913e5a87d2
18 files changed
+5139
No files matched your search
@@ -0,0 +1,59 @@
|
||||
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<string>();
|
||||
|
||||
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 (
|
||||
<Form
|
||||
navigationTitle={`${timesheet.activity.name} stoppen`}
|
||||
actions={
|
||||
<ActionPanel>
|
||||
<Action.SubmitForm title="Stoppen" icon={Icon.Stop} onSubmit={submit} />
|
||||
</ActionPanel>
|
||||
}
|
||||
>
|
||||
<Form.Description title="Tätigkeit" text={timesheet.activity.name} />
|
||||
<Form.Description title="Projekt" text={timesheetSubtitle(timesheet)} />
|
||||
<Form.Description title="Seit" text={`${formatTime(timesheet.begin)} Uhr`} />
|
||||
<Form.TextArea
|
||||
id="description"
|
||||
title="Beschreibung"
|
||||
placeholder="Was wurde gemacht?"
|
||||
defaultValue={timesheet.description ?? ""}
|
||||
error={descriptionError}
|
||||
onChange={() => setDescriptionError(undefined)}
|
||||
autoFocus
|
||||
/>
|
||||
<Form.TextField
|
||||
id="tags"
|
||||
title="Tags"
|
||||
placeholder="Optional, kommagetrennt"
|
||||
defaultValue={timesheet.tags.join(", ")}
|
||||
/>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user