fix(admin-ui): add destination_email field to account form
The API requires destination_email for BizDocs SMTP forwarding; the UI still sent legacy bizdocs_api_key fields. Default [email protected].
This commit is contained in:
1 parent
0c63ae7fbd
commit
eb4a95dfc2
2 files changed
+36
-15
No files matched your search
@@ -21,6 +21,8 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
return res.json()
|
||||
}
|
||||
|
||||
export const DEFAULT_DESTINATION_EMAIL = '[email protected]'
|
||||
|
||||
export interface Account {
|
||||
id: number
|
||||
name: string
|
||||
@@ -31,8 +33,8 @@ export interface Account {
|
||||
smtp_host: string
|
||||
smtp_port: number
|
||||
smtp_user: string
|
||||
bizdocs_api_key: string
|
||||
bizdocs_entity_id: string
|
||||
destination_email: string
|
||||
sync_interval_minutes: number
|
||||
active: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState } from 'react'
|
||||
import { api, Account, AccountCreate } from '../lib/api'
|
||||
import { api, Account, AccountCreate, DEFAULT_DESTINATION_EMAIL } from '../lib/api'
|
||||
import { useAsync } from '../hooks/useApi'
|
||||
import Spinner from '../components/Spinner'
|
||||
import StatusBadge from '../components/StatusBadge'
|
||||
@@ -16,8 +16,8 @@ const EMPTY_FORM: AccountCreate = {
|
||||
smtp_port: 587,
|
||||
smtp_user: '',
|
||||
smtp_password: '',
|
||||
bizdocs_api_key: '',
|
||||
bizdocs_entity_id: '',
|
||||
destination_email: DEFAULT_DESTINATION_EMAIL,
|
||||
sync_interval_minutes: 15,
|
||||
active: true,
|
||||
}
|
||||
|
||||
@@ -41,8 +41,21 @@ function AccountModal({
|
||||
e.preventDefault()
|
||||
setSaving(true)
|
||||
setError(null)
|
||||
const imapUser = form.imap_user.trim() || form.email.trim()
|
||||
const smtpUser = form.smtp_user.trim() || form.email.trim()
|
||||
if (!imapUser) {
|
||||
setError('Indica o email de origem ou o utilizador IMAP.')
|
||||
setSaving(false)
|
||||
return
|
||||
}
|
||||
const payload: AccountCreate = {
|
||||
...form,
|
||||
imap_user: imapUser,
|
||||
smtp_user: smtpUser,
|
||||
destination_email: form.destination_email.trim() || DEFAULT_DESTINATION_EMAIL,
|
||||
}
|
||||
try {
|
||||
await onSave(form)
|
||||
await onSave(payload)
|
||||
onClose()
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : String(e))
|
||||
@@ -109,11 +122,16 @@ function AccountModal({
|
||||
</fieldset>
|
||||
|
||||
<fieldset className="border border-gray-200 rounded-md p-3">
|
||||
<legend className="text-xs font-semibold text-gray-500 px-1">BizDocs</legend>
|
||||
<div className="grid grid-cols-2 gap-3 mt-1">
|
||||
{field('API Key', 'bizdocs_api_key', 'password')}
|
||||
{field('Entity ID', 'bizdocs_entity_id')}
|
||||
</div>
|
||||
<legend className="text-xs font-semibold text-gray-500 px-1">BizDocs (destino)</legend>
|
||||
<p className="text-xs text-gray-500 mb-2">
|
||||
Email para onde as facturas são reencaminhadas via SMTP (.eml).
|
||||
</p>
|
||||
{field(
|
||||
'Email destino',
|
||||
'destination_email',
|
||||
'email',
|
||||
DEFAULT_DESTINATION_EMAIL,
|
||||
)}
|
||||
</fieldset>
|
||||
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
@@ -248,7 +266,7 @@ export default function Accounts() {
|
||||
<tr>
|
||||
<th className="text-left px-4 py-3 text-xs font-medium text-gray-500 uppercase tracking-wide">Nome</th>
|
||||
<th className="text-left px-4 py-3 text-xs font-medium text-gray-500 uppercase tracking-wide">Email</th>
|
||||
<th className="text-left px-4 py-3 text-xs font-medium text-gray-500 uppercase tracking-wide">IMAP</th>
|
||||
<th className="text-left px-4 py-3 text-xs font-medium text-gray-500 uppercase tracking-wide">Destino BizDocs</th>
|
||||
<th className="text-left px-4 py-3 text-xs font-medium text-gray-500 uppercase tracking-wide">Estado</th>
|
||||
<th className="text-right px-4 py-3 text-xs font-medium text-gray-500 uppercase tracking-wide">Ações</th>
|
||||
</tr>
|
||||
@@ -258,8 +276,8 @@ export default function Accounts() {
|
||||
<tr key={a.id} className="hover:bg-gray-50">
|
||||
<td className="px-4 py-3 font-medium">{a.name}</td>
|
||||
<td className="px-4 py-3 text-gray-600">{a.email}</td>
|
||||
<td className="px-4 py-3 text-gray-500 text-xs">
|
||||
{a.imap_host}:{a.imap_port}
|
||||
<td className="px-4 py-3 text-gray-500 text-xs truncate max-w-[200px]" title={a.destination_email}>
|
||||
{a.destination_email}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -319,7 +337,8 @@ export default function Accounts() {
|
||||
smtp_host: modal.account.smtp_host,
|
||||
smtp_port: modal.account.smtp_port,
|
||||
smtp_user: modal.account.smtp_user,
|
||||
bizdocs_entity_id: modal.account.bizdocs_entity_id,
|
||||
destination_email: modal.account.destination_email,
|
||||
sync_interval_minutes: modal.account.sync_interval_minutes,
|
||||
active: modal.account.active,
|
||||
}
|
||||
: null
|
||||
|
||||
Reference in new issue
Block a user