diff --git a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PreparePanel.tsx b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PreparePanel.tsx index 6504734..bd50233 100644 --- a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PreparePanel.tsx +++ b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PreparePanel.tsx @@ -40,15 +40,15 @@ export function PreparePanel({ }: PreparePanelProps) { const router = useRouter(); - // If the document already has an explicit assigned client, lock to that client. - // Otherwise default to the document owner (defaultClientId) but allow changing. - const isLocked = assignedClientId !== null; - // selectedClientId: id from the dropdown (empty string = "pick manually by email") const [selectedClientId, setSelectedClientId] = useState( assignedClientId ?? defaultClientId, ); + // primaryEmail: editable email for the assigned client (pre-filled, can be overridden) + const assignedClient = clients.find(c => c.id === assignedClientId); + const [primaryEmail, setPrimaryEmail] = useState(assignedClient?.email ?? ''); + // emailInput: raw text for manual email entry (used when selectedClientId is '' or // as additional CC addresses) const [emailInput, setEmailInput] = useState(''); @@ -61,12 +61,15 @@ export function PreparePanel({ const canPrepare = currentStatus === 'Draft'; // The email addresses that will be sent with the prepare request. - // If a known client is selected, start with that client's email. + // When an assigned client exists, use the (editable) primaryEmail. + // Otherwise use the dropdown-selected client's email. // Any manually-entered addresses are appended. function buildEmailAddresses(): string[] { const addresses: string[] = []; - if (selectedClientId) { + if (assignedClientId && primaryEmail.trim()) { + addresses.push(primaryEmail.trim()); + } else if (selectedClientId) { const client = clients.find((c) => c.id === selectedClientId); if (client?.email) addresses.push(client.email); } @@ -136,22 +139,25 @@ export function PreparePanel({

Prepare Document

- {/* Client / recipient selection */} + {/* Primary recipient */}
- - {isLocked ? ( - // Document already has an assigned client — show read-only info -
- {(() => { - const c = clients.find((c) => c.id === assignedClientId); - return c ? `${c.name} (${c.email})` : assignedClientId; - })()} -
+ {assignedClientId ? ( + <> + setPrimaryEmail(e.target.value)} + className="w-full border rounded px-2 py-1.5 text-sm" + placeholder="recipient@example.com" + /> +

+ Assigned client: {clients.find(c => c.id === assignedClientId)?.name ?? assignedClientId} +

+ ) : ( - // No explicit assignment yet — allow choosing from list or entering email manually