Leads: Kundenart ist beim Anlegen Pflicht

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-16 13:18:10 +00:00
1 parent 45b2b145b0
commit cbf4b265e0
2 files changed
+15 -3

No files matched your search

+6 -2
View File
@@ -1,5 +1,6 @@
import { databases, DATABASE_ID, COLLECTIONS, Query, ID } from './appwrite' import { databases, DATABASE_ID, COLLECTIONS, Query, ID } from './appwrite'
import { rejectionLine, notesWithRejection } from './leadDuplicates' import { rejectionLine, notesWithRejection } from './leadDuplicates'
import { kundenartPruefen } from './kundenFelder'
/** Pflichtfelder eines festen Kunden: Name, E-Mail und vollständige Anschrift (Voraussetzung für „Zum festen Kunden machen“). */ /** Pflichtfelder eines festen Kunden: Name, E-Mail und vollständige Anschrift (Voraussetzung für „Zum festen Kunden machen“). */
export function isInvoiceReady(c) { export function isInvoiceReady(c) {
@@ -55,13 +56,16 @@ export async function createAcquisitionTicket(customer, user) {
return databases.createDocument(DATABASE_ID, COLLECTIONS.WORKORDERS, ID.unique(), data) return databases.createDocument(DATABASE_ID, COLLECTIONS.WORKORDERS, ID.unique(), data)
} }
/** Legt einen Lead an (Unternehmen, E-Mail, Telefon) und erstellt das Akquise-Ticket. */ /** Legt einen Lead an (Unternehmen, E-Mail, Telefon, Kundenart) und erstellt das Akquise-Ticket. Ohne gültige Kundenart wird nichts geschrieben. */
export async function createLead({ company, email, phone }, user) { export async function createLead({ company, email, phone, kundenart }, user) {
const fehler = kundenartPruefen(kundenart)
if (fehler) throw new Error(fehler)
const customer = await databases.createDocument(DATABASE_ID, COLLECTIONS.CUSTOMERS, ID.unique(), { const customer = await databases.createDocument(DATABASE_ID, COLLECTIONS.CUSTOMERS, ID.unique(), {
name: company, name: company,
companyName: company, companyName: company,
email: email || '', email: email || '',
phone: phone || '', phone: phone || '',
kundenart,
customerStatus: 'lead', customerStatus: 'lead',
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
}) })
+9 -1
View File
@@ -7,6 +7,8 @@ import { CUSTOMER_TABS, customerBadges, customerTitle, filterCustomers, stageCou
import { isRowActivation } from '../lib/rowClick' import { isRowActivation } from '../lib/rowClick'
import { findDuplicates } from '../lib/leadDuplicates' import { findDuplicates } from '../lib/leadDuplicates'
import DuplicateWarning from '../components/customer/DuplicateWarning' import DuplicateWarning from '../components/customer/DuplicateWarning'
import KundenartAuswahl from '../components/KundenartAuswahl'
import { kundenartPruefen, KUNDENART_AUSWAHL_HINWEIS } from '../lib/kundenFelder'
import { PageHeader, Tabs, Button, Badge, EmptyState, Field, Dialog } from '../components/ui' import { PageHeader, Tabs, Button, Badge, EmptyState, Field, Dialog } from '../components/ui'
export default function CustomersPage() { export default function CustomersPage() {
@@ -138,6 +140,7 @@ function CreateLeadForm({ customers, onCancel, onDone }) {
const [company, setCompany] = useState('') const [company, setCompany] = useState('')
const [email, setEmail] = useState('') const [email, setEmail] = useState('')
const [phone, setPhone] = useState('') const [phone, setPhone] = useState('')
const [kundenart, setKundenart] = useState('')
const [busy, setBusy] = useState(false) const [busy, setBusy] = useState(false)
const [error, setError] = useState(null) const [error, setError] = useState(null)
// Abgleich mit allen Kunden (auch archivierten und abgesagten), damit niemand doppelt angerufen wird // Abgleich mit allen Kunden (auch archivierten und abgesagten), damit niemand doppelt angerufen wird
@@ -146,9 +149,11 @@ function CreateLeadForm({ customers, onCancel, onDone }) {
const submit = async (e) => { const submit = async (e) => {
e.preventDefault() e.preventDefault()
if (!company.trim()) { setError('Unternehmen erforderlich'); return } if (!company.trim()) { setError('Unternehmen erforderlich'); return }
const f = kundenartPruefen(kundenart)
if (f) { setError(f); return }
setBusy(true); setError(null) setBusy(true); setError(null)
try { try {
await onDone({ company: company.trim(), email: email.trim(), phone: phone.trim() }) await onDone({ company: company.trim(), email: email.trim(), phone: phone.trim(), kundenart })
} catch (err) { } catch (err) {
setError(err.message || 'Fehler') setError(err.message || 'Fehler')
setBusy(false) setBusy(false)
@@ -189,6 +194,9 @@ function CreateLeadForm({ customers, onCancel, onDone }) {
<input id="lead-phone" className="input" type="tel" value={phone} onChange={(e) => setPhone(e.target.value)} /> <input id="lead-phone" className="input" type="tel" value={phone} onChange={(e) => setPhone(e.target.value)} />
</Field> </Field>
</div> </div>
<Field label="Kundenart" hint={KUNDENART_AUSWAHL_HINWEIS}>
<KundenartAuswahl value={kundenart} onChange={setKundenart} disabled={busy} />
</Field>
</Dialog> </Dialog>
) )
} }