35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { RelationshipType, type CampaignId, type Document } from "@/lib/types";
|
|
import { SecretForm } from "./secret/SecretForm";
|
|
import { TreasureForm } from "./treasure/TreasureForm";
|
|
import { SceneForm } from "./scene/SceneForm";
|
|
|
|
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";
|
|
case RelationshipType.Treasures:
|
|
return <TreasureForm campaign={campaignId} onCreate={onCreate} />;
|
|
case RelationshipType.Scenes:
|
|
return <SceneForm campaign={campaignId} onCreate={onCreate} />;
|
|
}
|
|
|
|
return assertUnreachable(relationshipType);
|
|
};
|