2026-06-06 20:51:57 -07:00
|
|
|
import type { FormEvent, ReactNode } from "react";
|
|
|
|
|
|
2026-06-09 14:51:38 -04:00
|
|
|
import type { Library } from "@/api/types";
|
2026-06-06 20:51:57 -07:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
|
2026-06-09 14:51:38 -04:00
|
|
|
import { AdvancedFields, FolderFields, GeneralFields, MetadataFields } from "./LibraryFormSections";
|
|
|
|
|
import { useLibraryForm } from "./useLibraryForm";
|
2026-06-06 20:51:57 -07:00
|
|
|
|
|
|
|
|
export interface LibraryFormProps {
|
|
|
|
|
library: Library | null;
|
|
|
|
|
chapterThumbnailsSupported: boolean;
|
|
|
|
|
onClose?: () => void;
|
|
|
|
|
onSaved?: (library: Library) => void;
|
|
|
|
|
resetAfterCreate?: boolean;
|
|
|
|
|
submitLabel?: string;
|
|
|
|
|
savingLabel?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 14:51:38 -04:00
|
|
|
function FormSection({ title, children }: { title: string; children: ReactNode }) {
|
2026-06-06 20:51:57 -07:00
|
|
|
return (
|
2026-06-09 14:51:38 -04:00
|
|
|
<section className="space-y-3">
|
|
|
|
|
<h3 className="text-muted-foreground text-xs font-semibold tracking-[0.1em] uppercase">
|
|
|
|
|
{title}
|
|
|
|
|
</h3>
|
|
|
|
|
{children}
|
|
|
|
|
</section>
|
2026-06-06 20:51:57 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 14:51:38 -04:00
|
|
|
/**
|
|
|
|
|
* Inline (non-dialog) library form used by the setup wizard. The admin
|
|
|
|
|
* Libraries page uses LibraryEditorDialog, which renders the same sections
|
|
|
|
|
* behind a left-hand navigation rail.
|
|
|
|
|
*/
|
2026-06-06 20:51:57 -07:00
|
|
|
export function LibraryForm({
|
|
|
|
|
library,
|
|
|
|
|
chapterThumbnailsSupported,
|
|
|
|
|
onClose,
|
|
|
|
|
onSaved,
|
|
|
|
|
resetAfterCreate = false,
|
|
|
|
|
submitLabel = "Save",
|
|
|
|
|
savingLabel = "Saving...",
|
|
|
|
|
}: LibraryFormProps) {
|
2026-06-09 14:51:38 -04:00
|
|
|
const form = useLibraryForm({ library, onClose, onSaved, resetAfterCreate });
|
2026-06-06 20:51:57 -07:00
|
|
|
|
2026-06-09 14:51:38 -04:00
|
|
|
function handleSubmit(e: FormEvent) {
|
2026-06-06 20:51:57 -07:00
|
|
|
e.preventDefault();
|
2026-06-09 14:51:38 -04:00
|
|
|
form.submit();
|
2026-06-06 20:51:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-06-09 14:51:38 -04:00
|
|
|
<form onSubmit={handleSubmit} className="space-y-6">
|
|
|
|
|
<FormSection title="General">
|
|
|
|
|
<GeneralFields form={form} />
|
|
|
|
|
</FormSection>
|
|
|
|
|
<FormSection title="Folders">
|
|
|
|
|
<FolderFields form={form} />
|
|
|
|
|
</FormSection>
|
|
|
|
|
<FormSection title="Metadata">
|
|
|
|
|
<MetadataFields form={form} />
|
|
|
|
|
</FormSection>
|
|
|
|
|
<FormSection title="Advanced">
|
|
|
|
|
<AdvancedFields form={form} chapterThumbnailsSupported={chapterThumbnailsSupported} />
|
|
|
|
|
</FormSection>
|
|
|
|
|
<Button type="submit" className="w-full" disabled={form.isPending}>
|
|
|
|
|
{form.isPending ? savingLabel : submitLabel}
|
2026-06-06 20:51:57 -07:00
|
|
|
</Button>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|