Makes a generic document form
This commit is contained in:
28
src/components/documents/DocumentForm.tsx
Normal file
28
src/components/documents/DocumentForm.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { RelationshipType, type CampaignId, type Document } from "@/lib/types";
|
||||
import { SecretForm } from "./secret/SecretForm";
|
||||
|
||||
function assertUnreachable(_x: never): never {
|
||||
throw new Error("DocumentForm switch is not exhaustive");
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a form for any document type depending on the relationship.
|
||||
*/
|
||||
export const DocumentForm = ({
|
||||
campaignId,
|
||||
relationshipType,
|
||||
onCreate,
|
||||
}: {
|
||||
campaignId: CampaignId;
|
||||
relationshipType: RelationshipType;
|
||||
onCreate: (document: Document) => Promise<void>;
|
||||
}) => {
|
||||
switch (relationshipType) {
|
||||
case RelationshipType.Secrets:
|
||||
return <SecretForm campaign={campaignId} onCreate={onCreate} />;
|
||||
case RelationshipType.DiscoveredIn:
|
||||
return "Form not supported here";
|
||||
}
|
||||
|
||||
return assertUnreachable(relationshipType);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
// SecretForm.tsx
|
||||
// Form for adding a new secret to a session.
|
||||
import { useState } from "react";
|
||||
import type { Secret } from "@/lib/types";
|
||||
import type { CampaignId, Secret } from "@/lib/types";
|
||||
import { pb } from "@/lib/pocketbase";
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ export const SecretForm = ({
|
||||
campaign,
|
||||
onCreate,
|
||||
}: {
|
||||
campaign: string;
|
||||
campaign: CampaignId;
|
||||
onCreate: (secret: Secret) => Promise<void>;
|
||||
}) => {
|
||||
const [newSecret, setNewSecret] = useState("");
|
||||
|
||||
Reference in New Issue
Block a user