mirasim's picture
Add the tasks, judges, harness, app under test, docs and report; merge the repository README into the card (part 5)
3eb5a0c verified
Raw History Blame Contribute Delete
1.38 kB
import { useState } from "react";
import type { Priority, Task, TaskPatch } from "../types";
import { Modal } from "./Modal";
export function EditTaskDialog({
task,
onSave,
onClose,
}: {
task: Task;
onSave: (patch: TaskPatch) => Promise<void>;
onClose: () => void;
}) {
const [title, setTitle] = useState(task.title);
const [priority, setPriority] = useState<Priority>(task.priority);
const [saving, setSaving] = useState(false);
const save = async () => {
setSaving(true);
try {
await onSave({ title: title.trim(), priority });
} finally {
setSaving(false);
}
};
return (
<Modal title="Edit task" onClose={onClose}>
<label className="field">
Title
<input value={title} onChange={(e) => setTitle(e.target.value)} autoFocus />
</label>
<label className="field">
Priority
<select value={priority} onChange={(e) => setPriority(e.target.value as Priority)}>
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
</label>
<div className="actions">
<button onClick={onClose}>Cancel</button>
<button className="primary" onClick={() => void save()} disabled={!title.trim() || saving}>
Save
</button>
</div>
</Modal>
);
}