Forms now update documents directly.
This commit is contained in:
@@ -3,6 +3,7 @@ import type { CampaignId, Monster } from "@/lib/types";
|
||||
import { pb } from "@/lib/pocketbase";
|
||||
import { BaseForm } from "@/components/form/BaseForm";
|
||||
import { SingleLineInput } from "@/components/form/SingleLineInput";
|
||||
import { useDocument } from "@/context/document/DocumentContext";
|
||||
|
||||
/**
|
||||
* Renders a form to add a new monster. Calls onCreate with the new monster document.
|
||||
@@ -14,6 +15,7 @@ export const NewMonsterForm = ({
|
||||
campaign: CampaignId;
|
||||
onCreate: (monster: Monster) => Promise<void>;
|
||||
}) => {
|
||||
const { dispatch } = useDocument();
|
||||
const [name, setName] = useState("");
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -32,6 +34,7 @@ export const NewMonsterForm = ({
|
||||
},
|
||||
});
|
||||
setName("");
|
||||
dispatch({ type: "setDocument", doc: monsterDoc });
|
||||
await onCreate(monsterDoc);
|
||||
} catch (e: any) {
|
||||
setError(e?.message || "Failed to add monster.");
|
||||
|
||||
Reference in New Issue
Block a user