From a86c9dc3f5f6944dbe4e8788587686351e626e37 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Tue, 16 Feb 2021 23:26:30 +0100 Subject: [PATCH] always consider empty strings as no value given --- components/App.tsx | 21 +++++++++++++--- interfaces/IDocProps.ts | 28 ++++++++++++--------- lib/templates.ts | 56 ++++++++++++++++++++--------------------- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/components/App.tsx b/components/App.tsx index b1fb3b6..e48cf0e 100644 --- a/components/App.tsx +++ b/components/App.tsx @@ -11,10 +11,23 @@ import { IDocProps } from '../interfaces/IDocProps' export default function App() { const [options, setOptions] = useState({ + address: 'Max Mustermann\\\\Musterstrasse\\\\12345 Musterstadt', + body: 'Inhalt des Briefs', + closing: 'Mit freundlichen Grüßen', + customer: '', + date: new Date().toLocaleDateString('de-DE'), + enclosing: '', + invoice: '', + myRef: '', + opening: 'Sehr geehrte Damen und Herren', + ps: '', + signature: '', + specialMail: '', + subject: 'Betreffzeile', template: 'brief-fam', - subject: '', - body: '', - address: '', + yourMail: '', + yourRef: '', + yourRefName: '', }) const [latest, setLatest] = useState([]) const [pdfUrl, setPdfUrl] = useState(null) @@ -32,7 +45,7 @@ export default function App() { return } const value = event && event.target && event.target.value - setOptions({ ...options, [name]: value || undefined }) + setOptions({ ...options, [name]: value }) } const _onSelectLatest = (selectedOption: ILatest) => { diff --git a/interfaces/IDocProps.ts b/interfaces/IDocProps.ts index fe784b5..3592766 100644 --- a/interfaces/IDocProps.ts +++ b/interfaces/IDocProps.ts @@ -1,15 +1,19 @@ export interface IDocProps { - template: string - subject: string - body: string address: string - date?: string - opening?: string - closing?: string - yourRef?: string - yourMail?: string - myRef?: string - customer?: string - invoice?: string - specialMail?: string + body: string + closing: string + customer: string + date: string + enclosing: string + invoice: string + myRef: string + opening: string + ps: string + signature: string + specialMail: string + subject: string + template: string + yourMail: string + yourRef: string + yourRefName: string } diff --git a/lib/templates.ts b/lib/templates.ts index 47458d6..b13f765 100644 --- a/lib/templates.ts +++ b/lib/templates.ts @@ -6,23 +6,23 @@ function convertLineBreaks(lines: string) { export function brief(options: IDocProps) { const { - template = 'brief-fam', - subject = '', - yourRef = '', - yourRefName = 'Ihr Zeichen', - yourMail = '', - myRef = '', - customer = '', - invoice = '', - date = '\\today', - signature = '', - specialMail = '', - address = 'Max Mustermann\\\\Musterstrasse\\\\12345 Musterstadt', - opening = 'Sehr geehrte Damen und Herren', - body = '', - closing = 'Mit freundlichen Grüßen', - ps = '', - enclosing = '', + template, + subject, + yourRef, + yourRefName, + yourMail, + myRef, + customer, + invoice, + date, + signature, + specialMail, + address, + opening, + body, + closing, + ps, + enclosing, } = { ...options } return `% brief document @@ -31,17 +31,15 @@ export function brief(options: IDocProps) { \\setkomavar{subject}{${subject}} -\\setkomavar{yourref}[${yourRefName}]{${yourRef}} -\\setkomavar{yourmail}{${yourMail}} -\\setkomavar{myref}{${myRef}} -\\setkomavar{customer}{${customer}} -\\setkomavar{invoice}{${invoice}} +${yourRef ? `\\setkomavar{yourref}[${yourRefName}]{${yourRef}}` : ''} +${yourMail ? `\\setkomavar{yourmail}{${yourMail}}` : ''} +${myRef ? `\\setkomavar{myref}{${myRef}}` : ''} +${customer ? `\\setkomavar{customer}{${customer}}` : ''} +${invoice ? `\\setkomavar{invoice}{${invoice}}` : ''} +${signature ? `\\setkomavar{signature}{${signature}}` : ''} +${specialMail ? `\\setkomavar{specialmail}{${specialMail}}` : ''} -\\setkomavar{date}{${date}} - -%\\setkomavar{signature}{${signature}} - -\\setkomavar{specialmail}{${specialMail}} +${date ? `\\setkomavar{date}{${date}}` : ''} \\begin{document} \\begin{letter}{${convertLineBreaks(address)}} @@ -52,9 +50,9 @@ export function brief(options: IDocProps) { \\closing{${closing}} - \\ps{${ps}} + ${ps ? `\\ps{${ps}}` : ''} - %\\encl{${enclosing}} + ${enclosing ? `\\encl{${enclosing}}` : ''} \\end{letter} \\end{document}`