Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(admin): replace live search with explicit search button
- Split searchInput (controlled input) from searchQuery (committed value)
  so the hook only fires on Search click or Enter, not every keystroke
- Gate table render on searchQuery.length > 0 to prevent stale results
  showing after input is cleared

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
  • Loading branch information
waleedlatif1 and claude committed Mar 18, 2026
commit 8eb5e23532618c86aabc106b25dfc1882ab3fad3
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function Admin() {

const [workflowId, setWorkflowId] = useState('')
const [usersOffset, setUsersOffset] = useState(0)
const [searchInput, setSearchInput] = useState('')
const [searchQuery, setSearchQuery] = useState('')
const [banUserId, setBanUserId] = useState<string | null>(null)
const [banReason, setBanReason] = useState('')
Expand All @@ -41,6 +42,11 @@ export function Admin() {
error: usersError,
} = useAdminUsers(usersOffset, PAGE_SIZE, searchQuery)

const handleSearch = () => {
setUsersOffset(0)
setSearchQuery(searchInput.trim())
}

const totalPages = useMemo(
() => Math.ceil((usersData?.total ?? 0) / PAGE_SIZE),
[usersData?.total]
Expand Down Expand Up @@ -128,14 +134,17 @@ export function Admin() {

<div className='flex flex-col gap-[12px]'>
<p className='font-medium text-[14px] text-[var(--text-primary)]'>User Management</p>
<EmcnInput
value={searchQuery}
onChange={(e) => {
setSearchQuery(e.target.value)
setUsersOffset(0)
}}
placeholder='Search by email or paste a user ID...'
/>
<div className='flex gap-[8px]'>
<EmcnInput
value={searchInput}
onChange={(e) => setSearchInput(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Enter key fires on empty input

The onKeyDown handler fires handleSearch when Enter is pressed regardless of whether searchInput has content. This has the same side-effect as the empty button click: it resets usersOffset to 0 and sets searchQuery to '', making any previously visible results disappear. Adding a searchInput.trim() guard before calling handleSearch keeps keyboard and click behaviour consistent.

placeholder='Search by email or paste a user ID...'
/>
<Button variant='primary' onClick={handleSearch} disabled={usersLoading}>
{usersLoading ? 'Searching...' : 'Search'}
</Button>
Comment on lines +144 to 146
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Search button enabled on empty input

The Search button is currently enabled whenever usersLoading is false, even when searchInput is empty. Clicking Search with an empty (or whitespace-only) input will call handleSearch, reset usersOffset to 0, and set searchQuery to '' — causing any previously displayed results to immediately disappear (since the table is gated on searchQuery.length > 0). Adding || !searchInput.trim() to the disabled condition would prevent this accidental result-clearing and avoid unnecessary state updates.

Suggested change
<Button variant='primary' onClick={handleSearch} disabled={usersLoading}>
{usersLoading ? 'Searching...' : 'Search'}
</Button>
<Button variant='primary' onClick={handleSearch} disabled={usersLoading || !searchInput.trim()}>
{usersLoading ? 'Searching...' : 'Search'}

</div>

{usersError && (
<p className='text-[13px] text-[var(--text-error)]'>
Expand All @@ -158,7 +167,7 @@ export function Admin() {
</div>
)}

{usersData && (
{searchQuery.length > 0 && usersData && (
<>
<div className='flex flex-col gap-[2px]'>
<div className='flex items-center gap-[12px] border-[var(--border-secondary)] border-b px-[12px] py-[8px] text-[12px] text-[var(--text-tertiary)]'>
Expand Down
Loading