feat(opportunities): Neue Opportunity auf den angemeldeten Benutzer

Beim Anlegen stand als Zustaendiger bisher der erste Benutzer der Liste
(in der Praxis "Administrator"). Jetzt ist es - wie im Kontaktformular -
der angemeldete Benutzer, mit users[0] als Rueckfallebene. Beim
Bearbeiten bleibt die gespeicherte Zustaendigkeit unangetastet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sascha Wolf
2026-09-21 11:34:59 +02:00
co-authored by Claude Opus 5
parent c8eaaa1947
commit 86aa7468af
3 changed files with 15 additions and 1 deletions
@@ -6,6 +6,7 @@ import { Avatar, inputClass, labelClass, labelRowClass, labelTextClass } from '.
import { STAGE_COLORS, STAGE_HINTS, STAGE_LABELS } from './opportunityUi';
import { useToast } from '../Toast';
import { acquisitionOptionsApi, opportunitiesApi } from '../../lib/api';
import { useAuth } from '../../lib/auth';
import {
OPPORTUNITY_STAGES,
contactFullName,
@@ -90,7 +91,15 @@ export const OpportunityModal: React.FC<OpportunityModalProps> = ({
onCopy,
}) => {
const { addToast } = useToast();
const [form, setForm] = useState<FormState>(() => toFormState(opportunity, users[0]?.id ?? null));
const { user: currentUser } = useAuth();
/*
* Beim Neuanlegen ist der angemeldete Benutzer zustaendig - das trifft fast
* immer zu und laesst sich im Feld "Zustaendig" aendern. Beim Bearbeiten
* bleibt die gespeicherte Zustaendigkeit unangetastet.
*/
const [form, setForm] = useState<FormState>(() =>
toFormState(opportunity, currentUser?.id ?? users[0]?.id ?? null)
);
const [contacts, setContacts] = useState<ContactEntry[]>(
() => opportunity?.contacts.map((c) => ({ lead_id: c.lead_id, role: c.role ?? '' })) ?? []
);