Added editable recipient field

X-Lovable-Edit-ID: edt-fe742891-e445-46c9-8cc3-c0bc934c0a74
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 21:40:21 +00:00
co-authored by renee-png
+49 -9
View File
@@ -52,6 +52,8 @@ export function LetterGenerator() {
const [contacts, setContacts] = useState<ContactLite[]>([]);
const [caseContactIds, setCaseContactIds] = useState<Set<string>>(new Set());
const [recipientId, setRecipientId] = useState("");
const [recipientAddress, setRecipientAddress] = useState("");
const [recipientEdited, setRecipientEdited] = useState(false);
const [firm, setFirm] = useState<FirmInfo | null>(null);
const [logoDataUrl, setLogoDataUrl] = useState<string | null>(null);
const [attorneyName, setAttorneyName] = useState("");
@@ -76,6 +78,12 @@ export function LetterGenerator() {
return { linked, others };
}, [contacts, caseContactIds]);
// Auto-fill recipient address block from selected contact (unless user edited it).
useEffect(() => {
if (recipientEdited) return;
setRecipientAddress(contactMailingLines(recipient).join("\n"));
}, [recipient, recipientEdited]);
useEffect(() => {
fetchFirm().then(async (f) => {
setFirm(f);
@@ -244,13 +252,17 @@ export function LetterGenerator() {
doc.text(fmtDateLong(date), centerX, y, { align: "center" });
y += 28;
// ----- Recipient (from selected contact) -----
// ----- Recipient (editable address block) -----
doc.setFont(bodyFont, "normal");
doc.setFontSize(bodyFontSize);
contactMailingLines(recipient).forEach((l) => {
doc.text(l, margin, y);
y += lh - 1;
});
recipientAddress
.split("\n")
.map((l) => l.trimEnd())
.filter((l) => l.length > 0)
.forEach((l) => {
doc.text(l, margin, y);
y += lh - 1;
});
// Certified mail line (right-aligned, italic) — only when a number is provided
if (certifiedMailNumber.trim() && template.showCertifiedMail !== false) {
@@ -264,11 +276,12 @@ export function LetterGenerator() {
y += 18;
if (renderedSubject) {
doc.setFont(bodyFont, "bold");
const subjLines = doc.splitTextToSize(`Re: ${renderedSubject}`, maxW);
doc.text(subjLines, margin, y);
y += subjLines.length * lh + 14;
// Re: line — not bold, indented from the left margin.
doc.setFont(bodyFont, "normal");
const reIndent = 72; // ~1 inch indent
const subjLines = doc.splitTextToSize(`Re: ${renderedSubject}`, maxW - reIndent);
doc.text(subjLines, margin + reIndent, y);
y += subjLines.length * lh + 14;
}
// ----- Body (reserve room for footer) -----
@@ -397,6 +410,33 @@ export function LetterGenerator() {
</Select>
</div>
</div>
<div>
<div className="flex items-center justify-between">
<Label>Recipient address (editable)</Label>
{recipientEdited && recipient ? (
<button
type="button"
className="text-xs text-muted-foreground underline"
onClick={() => {
setRecipientEdited(false);
setRecipientAddress(contactMailingLines(recipient).join("\n"));
}}
>
Reset from contact
</button>
) : null}
</div>
<Textarea
rows={5}
value={recipientAddress}
onChange={(e) => {
setRecipientAddress(e.target.value);
setRecipientEdited(true);
}}
placeholder="Name&#10;Company&#10;Street&#10;City, State ZIP"
className="font-mono text-sm"
/>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<Label>Date</Label>