Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): show the live row in the session detail modal
Yudhi Armyndharis84711957c638
diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.tsindex 05368723e..9e097ae68 100644--- a/dashboard/src/pages/Sessions.test.ts+++ b/dashboard/src/pages/Sessions.test.ts@@ -1171,6 +1171,30 @@ test('a list read in flight does not undo a create, a stop or a delete', async (}});+// The detail modal shows the row as it is now, not as it was when View was clicked.+test('an open detail modal follows its session status and phone', async () => {+ const { screen, fireEvent, within, waitFor } = rtl;+ resetFetchCalls();+ window.sessionStorage.setItem('openwa_api_key', 'test-key');+ const row: Session = { ...SESSION_QR, id: 'sess-viewed-1', name: 'viewed', status: 'authenticating' };+ SESSIONS.push(row);+ try {+ renderSessions();+ const card = (await screen.findByText('viewed')).closest('.session-card') as HTMLElement;+ fireEvent.click(within(card).getByRole('button', { name: 'View' }));+ const dialog = await screen.findByRole('dialog');+ await within(dialog).findByText('Not connected');++ Object.assign(row, { status: 'ready', phone: '15550005555' });+ pushSessionStatus(row.id, 'ready');++ await waitFor(() => within(dialog).getByText('15550005555'));+ assert.ok(within(dialog).queryByText('Connected'), 'the detail modal kept the status it was opened with');+ } finally {+ SESSIONS.pop();+ }+});+test('a restricted session shows the restriction on its card, even while it is ready', async () => {const { screen, within } = rtl;resetFetchCalls();diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsxindex 37474f3d2..31dd66051 100644--- a/dashboard/src/pages/Sessions.tsx+++ b/dashboard/src/pages/Sessions.tsx@@ -79,7 +79,10 @@ export function Sessions() {const [error, setError] = useState<string | null>(null);const [searchQuery, setSearchQuery] = useState('');const [statusFilter, setStatusFilter] = useState('all');- const [selectedSession, setSelectedSession] = useState<Session | null>(null);+ // Only the id: the detail modal renders the row as it is in `sessions` now, so a status push or a+ // list read shows there too, and a row that is gone closes it.+ const [selectedSessionId, setSelectedSessionId] = useState<string | null>(null);+ const selectedSession = selectedSessionId ? (sessions.find(s => s.id === selectedSessionId) ?? null) : null;const [deleteConfirmId, setDeleteConfirmId] = useState<string | null>(null);const [killConfirmId, setKillConfirmId] = useState<string | null>(null);const [unlinkConfirmId, setUnlinkConfirmId] = useState<string | null>(null);@@ -225,7 +228,6 @@ export function Sessions() {rowWrites.current += 1;sessionsRef.current = replaceSession(sessionsRef.current, updated);setSessions(sessionsRef.current);- setSelectedSession(current => (current?.id === updated.id ? updated : current));dismissQrForSession(updated.id);await reconcileSessionCache(queryClient, queryKeys.sessions, updated);},@@ -419,7 +421,6 @@ export function Sessions() {// Load the config when the detail modal opens and drop it when it closes, so a value fetched for// one session can never render against another.- const selectedSessionId = selectedSession?.id ?? null;useEffect(() => {setSessionConfig(null);if (!selectedSessionId) return;@@ -901,11 +902,11 @@ export function Sessions() {{selectedSession && (<Modalopen- onClose={() => setSelectedSession(null)}+ onClose={() => setSelectedSessionId(null)}title={t('sessions.details.title')}closeLabel={t('common.close')}footer={- <button className="btn-secondary" onClick={() => setSelectedSession(null)}>+ <button className="btn-secondary" onClick={() => setSelectedSessionId(null)}>{t('common.close')}</button>}@@ -1224,7 +1225,7 @@ export function Sessions() {)}<div className="card-actions">- <button className="btn-action" onClick={() => setSelectedSession(session)}>+ <button className="btn-action" onClick={() => setSelectedSessionId(session.id)}><Eye size={16} />{t('sessions.actions.view')}</button>