Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): gate Enter in the session name field like Create
Yudhi Armyndharis32c1c824b647
diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.tsindex 698a7e804..e0fad1d64 100644--- a/dashboard/src/pages/Sessions.test.ts+++ b/dashboard/src/pages/Sessions.test.ts@@ -391,6 +391,32 @@ test('creating a session issues POST /api/sessions with the entered name', asyncawait screen.findByText('backup-bot');});+test('Enter in the name field follows the same gate as the Create button', async () => {+ const { screen, fireEvent, waitFor, within } = rtl;+ resetFetchCalls();+ renderSessions();++ await screen.findByText('new-device');+ fireEvent.click(screen.getByRole('button', { name: 'New Session' }));+ const dialog = await screen.findByRole('dialog');+ const input = within(dialog).getByPlaceholderText('e.g., marketing-bot');+ const posted = () => fetchCalls.filter(c => c.method === 'POST' && c.path === '/api/sessions').map(c => c.body);++ // A name the form flags as invalid is not posted on Enter either.+ fireEvent.change(input, { target: { value: 'ab' } });+ fireEvent.keyDown(input, { key: 'Enter' });+ assert.deepEqual(posted(), [], 'Enter posted a name the Create button refuses');++ // A second Enter while the first create is in flight does not post the same name again.+ fireEvent.change(input, { target: { value: 'enter-bot' } });+ fireEvent.keyDown(input, { key: 'Enter' });+ fireEvent.keyDown(input, { key: 'Enter' });++ await screen.findByText('enter-bot');+ await waitFor(() => assert.ok(!screen.queryByRole('dialog')));+ assert.deepEqual(posted(), [{ name: 'enter-bot' }]);+});+test('opening the proxy modal fetches GET /api/sessions/:id/proxy', async () => {const { screen, fireEvent, within, waitFor } = rtl;resetFetchCalls();diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsxindex 4918dbe0f..3ddacd8e8 100644--- a/dashboard/src/pages/Sessions.tsx+++ b/dashboard/src/pages/Sessions.tsx@@ -568,6 +568,9 @@ export function Sessions() {// One term: isValidProxyUrl rejects '' too, so the emptiness check was redundant, and its// `string && boolean` shape widened this to `boolean | ""`, which the disabled prop rejects.const createProxyInvalid = useProxy && !isValidProxyUrl(createProxyUrl.trim());+ // Shared by the Create button and the name field's Enter key, which would otherwise post a name+ // the button refuses, or post the same name twice while the first create is in flight.+ const createDisabled = creating || !canCreateSession(newSessionName, existingSessionNames) || createProxyInvalid;if (loading) {return (@@ -659,11 +662,7 @@ export function Sessions() {<button className="btn-secondary" onClick={() => setShowCreateModal(false)}>{t('common.cancel')}</button>- <button- className="btn-primary"- onClick={handleCreate}- disabled={creating || !canCreateSession(newSessionName, existingSessionNames) || createProxyInvalid}- >+ <button className="btn-primary" onClick={handleCreate} disabled={createDisabled}>{creating ? <Loader2 className="animate-spin" size={16} /> : t('common.create')}</button></>@@ -679,7 +678,7 @@ export function Sessions() {const value = e.target.value.toLowerCase().replace(/\s+/g, '-');setNewSessionName(value);}}- onKeyDown={e => e.key === 'Enter' && handleCreate()}+ onKeyDown={e => e.key === 'Enter' && !createDisabled && handleCreate()}/><p className="input-hint"><Trans i18nKey="sessions.create.hint" components={{ code: <code /> }} />