template
This commit is contained in:
parent
84544e1153
commit
a109df2deb
7 changed files with 51 additions and 11 deletions
|
|
@ -137,7 +137,9 @@ export function CustomerWhatsAppInbox({ account, onBack }: { account: WhatsAppAc
|
|||
useEffect(() => {
|
||||
Promise.all([
|
||||
whatsappApi.messages(account.id),
|
||||
whatsappApi.templates(account.id).catch(() => ({ available: false, templates: [] as WhatsAppTemplateRow[] })),
|
||||
account.status === 'disconnected'
|
||||
? Promise.resolve({ available: false, templates: [] as WhatsAppTemplateRow[] })
|
||||
: whatsappApi.templates(account.id).catch(() => ({ available: false, templates: [] as WhatsAppTemplateRow[] })),
|
||||
])
|
||||
.then(([items, templatePayload]) => {
|
||||
setMessages(items)
|
||||
|
|
|
|||
|
|
@ -193,6 +193,11 @@ export function WhatsAppSetupPage() {
|
|||
useEffect(() => {
|
||||
if (phase !== 'detail' || !selected) return
|
||||
if (tab === 'templates') {
|
||||
if (selected.status === 'disconnected') {
|
||||
setTemplates([])
|
||||
setTemplatesAvailable(false)
|
||||
return
|
||||
}
|
||||
setTemplates(null)
|
||||
whatsappApi.templates(selected.id)
|
||||
.then((payload) => {
|
||||
|
|
@ -213,7 +218,7 @@ export function WhatsAppSetupPage() {
|
|||
.then(setLogs)
|
||||
.catch((reason) => setError(reason instanceof Error ? reason.message : 'Unable to load logs'))
|
||||
}
|
||||
}, [phase, tab, selected?.id])
|
||||
}, [phase, tab, selected?.id, selected?.status])
|
||||
|
||||
function replaceAccount(next: WhatsAppAccount) {
|
||||
setAccounts((current) => current.map((account) => (account.id === next.id ? next : account)))
|
||||
|
|
@ -563,9 +568,11 @@ export function WhatsAppSetupPage() {
|
|||
<MessageCircle size={15} /> Chat
|
||||
</button>
|
||||
)}
|
||||
<button className="secondary-button" onClick={() => void refreshSelected()} disabled={busy}>
|
||||
<RefreshCw size={14} /> Refresh
|
||||
</button>
|
||||
{selected.status !== 'disconnected' && (
|
||||
<button className="secondary-button" onClick={() => void refreshSelected()} disabled={busy}>
|
||||
<RefreshCw size={14} /> Refresh
|
||||
</button>
|
||||
)}
|
||||
<button className="secondary-button" onClick={() => void startEmbeddedSignup()} disabled={busy}>Reconnect</button>
|
||||
<button className="secondary-button wa-biz-danger" onClick={() => setDisconnecting(selected)}>Disconnect</button>
|
||||
</div>
|
||||
|
|
@ -620,7 +627,7 @@ export function WhatsAppSetupPage() {
|
|||
</div>
|
||||
<StatusDot status={phone.status} />
|
||||
<span>Quality: {phone.quality || '—'}</span>
|
||||
{phone.needs_registration && !phone.needs_otp && (
|
||||
{selected.status !== 'disconnected' && phone.needs_registration && !phone.needs_otp && (
|
||||
<div className="wa-biz-register">
|
||||
<input
|
||||
inputMode="numeric"
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ export function WhatsAppTemplateWizard() {
|
|||
if (!editing && !duplicateId) window.localStorage.setItem(DRAFT_KEY, JSON.stringify(draft))
|
||||
}, [draft, editing, duplicateId])
|
||||
|
||||
const numbers = useMemo(() => accounts.flatMap((account) => (
|
||||
const numbers = useMemo(() => accounts.filter((account) => account.status !== 'disconnected').flatMap((account) => (
|
||||
account.phones.length
|
||||
? account.phones.map((phone) => ({ account, phone: phone as WhatsAppAccount['phones'][number] | null }))
|
||||
: [{ account, phone: null as WhatsAppAccount['phones'][number] | null }]
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ export function WhatsAppTemplatesPage() {
|
|||
<input value={search} onChange={(event) => setSearch(event.target.value)} placeholder="Search by name or ID" aria-label="Search templates" />
|
||||
<select value={accountId} onChange={(event) => { setAccountId(event.target.value); load(event.target.value) }} aria-label="WhatsApp account">
|
||||
<option value="">All accounts</option>
|
||||
{accounts.map((account) => {
|
||||
{accounts.filter((account) => account.status !== 'disconnected').map((account) => {
|
||||
const numbers = account.phones.map((phone) => phone.display_phone).filter(Boolean).join(', ')
|
||||
return <option key={account.id} value={account.id}>{numbers ? `${account.name} · ${numbers}` : account.name}</option>
|
||||
})}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue