Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
78c7e16db0
commit
51b6a3f5e8
@@ -25,6 +25,8 @@ import { Download, FileText, Save, Loader2, Plus, Trash2, PenLine, Users, Variab
|
||||
import { applyVars, buildChips, buildVarMap, loadPleadingContext, type LoadedContext, type VarChip } from "@/lib/pleading-variables";
|
||||
import { promptFilename } from "@/lib/prompt-filename";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { SaveToCaseDialog } from "@/components/forms/save-to-case-dialog";
|
||||
import { savePdfToDocuments } from "@/lib/forms-shared";
|
||||
|
||||
export const Route = createFileRoute("/documents/pleading/new")({
|
||||
component: PleadingNewPage,
|
||||
@@ -53,6 +55,7 @@ function PleadingNewPage() {
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [serviceList, setServiceList] = useState<ServiceContact[]>([]);
|
||||
const [serviceListTitle, setServiceListTitle] = useState("SERVICE LIST");
|
||||
const [saveToCaseOpen, setSaveToCaseOpen] = useState(false);
|
||||
|
||||
// Client/case linkage for variable substitution
|
||||
const [clientId, setClientId] = useState<string>("");
|
||||
@@ -257,6 +260,45 @@ function PleadingNewPage() {
|
||||
await downloadPleadingPdf(input, name);
|
||||
};
|
||||
|
||||
const onSaveToCase = async ({
|
||||
caseId: targetCaseId,
|
||||
name,
|
||||
format,
|
||||
folder,
|
||||
}: { caseId: string; name: string; format: "pdf" | "docx" | "csv"; folder: string }) => {
|
||||
try {
|
||||
let blob: Blob;
|
||||
let mimeType: string;
|
||||
let ext: string;
|
||||
if (format === "docx") {
|
||||
const doc = buildPleadingDoc(input);
|
||||
blob = await Packer.toBlob(doc);
|
||||
mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||
ext = "docx";
|
||||
} else {
|
||||
// Generate PDF blob via downloadPleadingPdf path — but we need the bytes,
|
||||
// so build it inline mirroring the helper. The helper saves directly,
|
||||
// so we use a workaround: dynamically import jsPDF output.
|
||||
const { buildPleadingPdfBlob } = await import("@/lib/pdf-pleading");
|
||||
blob = await buildPleadingPdfBlob(input);
|
||||
mimeType = "application/pdf";
|
||||
ext = "pdf";
|
||||
}
|
||||
const filename = name.endsWith(`.${ext}`) ? name : `${name}.${ext}`;
|
||||
await savePdfToDocuments({
|
||||
blob,
|
||||
caseId: targetCaseId,
|
||||
name: filename,
|
||||
folder,
|
||||
mimeType,
|
||||
});
|
||||
toast.success("Saved to case files");
|
||||
} catch (e: any) {
|
||||
toast.error(e.message ?? "Save failed");
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
const onSave = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user