From ab323798e97989fdeccbac97e471f03b98765ed1 Mon Sep 17 00:00:00 2001 From: Drew Haven Date: Wed, 24 Sep 2025 15:52:02 -0700 Subject: [PATCH] Threads done with generic forms. --- src/components/documents/DocumentLink.tsx | 4 +- src/components/documents/GenericEditForm.tsx | 12 +-- .../documents/GenericNewDocumentForm.tsx | 75 ++++++++----------- .../documents/session/NewSessionForm.tsx | 60 +++------------ src/components/form/ToggleInput.tsx | 29 +++++++ src/lib/documents.ts | 25 +++++++ 6 files changed, 106 insertions(+), 99 deletions(-) create mode 100644 src/components/form/ToggleInput.tsx create mode 100644 src/lib/documents.ts diff --git a/src/components/documents/DocumentLink.tsx b/src/components/documents/DocumentLink.tsx index 5cfe017..5303677 100644 --- a/src/components/documents/DocumentLink.tsx +++ b/src/components/documents/DocumentLink.tsx @@ -1,6 +1,6 @@ -import { makeDocumentPath, useDocumentPath } from "@/lib/documentPath"; +import { makeDocumentPath } from "@/lib/documentPath"; import type { DocumentId } from "@/lib/types"; -import { Link, useParams, useSearch } from "@tanstack/react-router"; +import { Link } from "@tanstack/react-router"; export type Props = React.PropsWithChildren<{ childDocId: DocumentId; diff --git a/src/components/documents/GenericEditForm.tsx b/src/components/documents/GenericEditForm.tsx index 922415c..6765a04 100644 --- a/src/components/documents/GenericEditForm.tsx +++ b/src/components/documents/GenericEditForm.tsx @@ -7,6 +7,7 @@ import { type DocumentField, type FieldType, } from "@/lib/fields"; +import { ToggleInput } from "../form/ToggleInput"; export type GenericFieldType = "multiline" | "singleline" | "checkbox"; @@ -70,12 +71,11 @@ const GenericEditFormField = ({ ); case "toggle": return ( - saveField(!!e.target.value)} - className="accent-emerald-500 w-5 h-5" - id={field.name} + ); } diff --git a/src/components/documents/GenericNewDocumentForm.tsx b/src/components/documents/GenericNewDocumentForm.tsx index 5b51c69..0fb8e74 100644 --- a/src/components/documents/GenericNewDocumentForm.tsx +++ b/src/components/documents/GenericNewDocumentForm.tsx @@ -1,5 +1,5 @@ -import { AutoSaveTextarea } from "@/components/AutoSaveTextarea"; import { useDocumentCache } from "@/context/document/hooks"; +import { DocumentTypeLabel } from "@/lib/documents"; import { getFieldsForType, type DocumentField, @@ -14,6 +14,10 @@ import { type DocumentType, } from "@/lib/types"; import { useCallback, useState } from "react"; +import { BaseForm } from "../form/BaseForm"; +import { MultiLineInput } from "../form/MultiLineInput"; +import { SingleLineInput } from "../form/SingleLineInput"; +import { ToggleInput } from "../form/ToggleInput"; export type GenericFieldType = "multiline" | "singleline" | "checkbox"; @@ -69,83 +73,68 @@ export const GenericNewDocumentForm = ({ setIsLoading(false); }, [campaignId, setIsLoading, setError, docData]); + // TODO: display name for docType return ( -
- {error && ( - // TODO: class and style for errors -
{error}
- )} - { + ( )) } - -
+ /> ); }; const GenericNewFormField = ({ field, value, + isLoading, onUpdate, }: { field: DocumentField; value: ValueForFieldType; - onUpdate: (value: ValueForFieldType) => void; -}) => { - return ( -
- - -
- ); -}; - -const GenericNewFormInput = ({ - field, - value, - onUpdate, -}: { - field: DocumentField; - value: ValueForFieldType; + isLoading: boolean; onUpdate: (value: ValueForFieldType) => void; }) => { switch (field.fieldType) { case "longText": return ( -