Forms now update documents directly.
This commit is contained in:
@@ -5,6 +5,7 @@ import type { CampaignId, Secret } 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 secret. Calls onCreate with the new secret document.
|
||||
@@ -16,6 +17,7 @@ export const NewSecretForm = ({
|
||||
campaign: CampaignId;
|
||||
onCreate: (secret: Secret) => Promise<void>;
|
||||
}) => {
|
||||
const { dispatch } = useDocument();
|
||||
const [newSecret, setNewSecret] = useState("");
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -35,6 +37,7 @@ export const NewSecretForm = ({
|
||||
},
|
||||
});
|
||||
setNewSecret("");
|
||||
dispatch({ type: "setDocument", doc: secretDoc as Secret});
|
||||
await onCreate(secretDoc);
|
||||
} catch (e: any) {
|
||||
setError(e?.message || "Failed to add secret.");
|
||||
|
||||
Reference in New Issue
Block a user