Forms now update documents directly.
This commit is contained in:
@@ -4,6 +4,7 @@ import { pb } from "@/lib/pocketbase";
|
||||
import { BaseForm } from "@/components/form/BaseForm";
|
||||
import { SingleLineInput } from "@/components/form/SingleLineInput";
|
||||
import { MultiLineInput } from "@/components/form/MultiLineInput";
|
||||
import { useDocument } from "@/context/document/DocumentContext";
|
||||
|
||||
/**
|
||||
* Renders a form to add a new npc. Calls onCreate with the new npc document.
|
||||
@@ -15,6 +16,7 @@ export const NewNpcForm = ({
|
||||
campaign: CampaignId;
|
||||
onCreate: (npc: Npc) => Promise<void>;
|
||||
}) => {
|
||||
const { dispatch } = useDocument();
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [adding, setAdding] = useState(false);
|
||||
@@ -36,6 +38,7 @@ export const NewNpcForm = ({
|
||||
});
|
||||
setName("");
|
||||
setDescription("");
|
||||
dispatch({ type: "setDocument", doc: npcDoc });
|
||||
await onCreate(npcDoc);
|
||||
} catch (e: any) {
|
||||
setError(e?.message || "Failed to add npc.");
|
||||
|
||||
Reference in New Issue
Block a user