Files
Compass/web/components/select-users.tsx
Okechi Jones-Williams 549eba0bbe [User functionality] Messages UI page and messaging helpers added for end-to-end scenarios (#53)
* Added Database checks to the onboarding flow

* Added compatibility page setup
Added more compatibility questions

* Finished up the onboarding flow suite
Added compatibility question tests and verifications
Updated tests to cover Keywords and Headline changes recently made
Updated tests to cover all of the big5 personality traits

* .

* Fix: Merge conflict

* .

* Fix: Added fix for None discriptive error issue #36
Updated signUp.spec.ts to use new fixture
Updated Account information variable names
Deleted "deleteUserFixture.ts" as it was incorporated into the "base.ts" file

* Linting and Prettier

* Minor cleaning

* Added Google account to the Onboarding flow

* Added account cleanup for google accounts

* Started work on Sign-in tests
Updated seedDatabase.ts to throw an error if the user already exists, to also add display names and usernames so they seedUser func acts like a normal basic user
Some organising of the google auth code

* Linting and Prettier

* Added checks to the deleteUser func to check if the accout exists
Added account deletion checks

* Linting and Prettier

* Formatting update, fixed homePage locator for signin

* .

* .

* .

* Coderabbitai fix's

* Fix

* Improve test utilities and stabilize onboarding flow tests

* Changes requested

* Changed POM/Fixture structure to use an app class to instantiate the page objects

* Apply suggestion from @MartinBraquet

* Delete .vscode/settings.json

* Apply suggestion from @MartinBraquet

* Apply suggestion from @MartinBraquet

* Apply suggestion from @MartinBraquet

* Linting and Prettier

* Updated People page

* Fix app.ts

* Updated peoplePage.ts: continued adding functions to use filters
Updated filters.tsx: added data testid

* Coderabbitai fix's

* .

* Updated People page
Added data test attributes to search.tsx and profile-grid.tsx

* Lint and Prettier

* .

* Continued work on filter tests
Added testid attributes to people page so the info from the results can be accessed

* Added more filter tests

* Added tests for hiding profiles

* Added a context manager to test with multiple accounts interacting with each other
Added an option to verify the users email when creating an account

* Added Tests for sending/recieving messages
Added tests for staring/favoriting profiles
Added testIds where necessary
Added messagesPage.ts
Updated peoplePage.ts

* Linting and Prettier

* Coderabbit suggestions

* CodeRabbit suggestion #2

* Fix #1

* Minor fixes

* TC fix

---------

Co-authored-by: MartinBraquet <martin.braquet@gmail.com>
2026-05-29 01:00:57 +02:00

175 lines
6.1 KiB
TypeScript

import {Menu, Transition} from '@headlessui/react'
import {XMarkIcon} from '@heroicons/react/24/outline'
import clsx from 'clsx'
import {Fragment, useEffect, useRef, useState} from 'react'
import {Button} from 'web/components/buttons/button'
import {Col} from 'web/components/layout/col'
import {Row} from 'web/components/layout/row'
import {Avatar} from 'web/components/widgets/avatar'
import {UserLink} from 'web/components/widgets/user-link'
import {DisplayUser, searchUsers} from 'web/lib/supabase/users'
import {Input} from './widgets/input'
export function SelectUsers(props: {
setSelectedUsers: (users: DisplayUser[]) => void
selectedUsers: DisplayUser[]
ignoreUserIds: string[]
showSelectedUsersTitle?: boolean
selectedUsersClassName?: string
showUserUsername?: boolean
maxUsers?: number
searchLimit?: number
className?: string
}) {
const {
ignoreUserIds,
selectedUsers,
setSelectedUsers,
showSelectedUsersTitle,
selectedUsersClassName,
showUserUsername,
maxUsers,
className,
searchLimit,
} = props
const [query, setQuery] = useState('')
const [filteredUsers, setFilteredUsers] = useState<DisplayUser[]>([])
const requestId = useRef(0)
const queryReady = query.length > 1
const inputRef = useRef<HTMLInputElement>(null)
useEffect(() => {
// Wait for the modal (and transition) to finish
const timeout = setTimeout(() => {
inputRef.current?.focus()
}, 100)
return () => clearTimeout(timeout)
}, [])
useEffect(() => {
const id = ++requestId.current
if (queryReady) {
searchUsers(query, searchLimit ?? 5).then((results) => {
// if there's a more recent request, forget about this one
if (id === requestId.current) {
setFilteredUsers(
results.filter((user) => {
return (
!selectedUsers.some(({name}) => name === user.name) &&
!ignoreUserIds.includes(user.id)
)
}),
)
}
})
} else {
setFilteredUsers([])
}
}, [query, selectedUsers, ignoreUserIds])
const shouldShow = maxUsers ? selectedUsers.length < maxUsers : true
return (
<Col className={className}>
{shouldShow && (
<>
<Col className="relative mt-1 w-full rounded-md">
<Input
ref={inputRef}
type="text"
name="user name"
id="user name"
value={query}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setQuery(e.target.value)}
placeholder="Search users..."
searchIcon
/>
</Col>
{queryReady && (
<Menu
as="div"
className={clsx(
'relative inline-block w-full overflow-y-scroll text-right',
queryReady && 'h-56',
)}
data-testid="search-results"
>
{() => (
<Transition
show={queryReady}
as={Fragment}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Menu.Items
static={true}
className="divide-ink-100 bg-canvas-50 ring-ink-1000 absolute right-0 mt-2 w-full origin-top-right cursor-pointer divide-y rounded-md shadow-lg ring-1 ring-opacity-5 focus:outline-none"
>
<div className="py-1">
{filteredUsers.map((user) => (
<Menu.Item key={user.id} data-testid="search-results-username">
{({active}) => (
<button
className={clsx(
active ? 'bg-ink-100 text-ink-900' : 'text-ink-700',
'group flex w-full items-center px-4 py-2 text-sm',
)}
onClick={() => {
setQuery('')
setSelectedUsers([...selectedUsers, user])
}}
>
<Avatar
username={user.username}
avatarUrl={user.avatarUrl}
size={'xs'}
className={'mr-2'}
/>
{user.name}
{showUserUsername && (
<span className={'text-ink-500 ml-1'}>@{user.username}</span>
)}
</button>
)}
</Menu.Item>
))}
</div>
</Menu.Items>
</Transition>
)}
</Menu>
)}
</>
)}
{selectedUsers.length > 0 && (
<>
{showSelectedUsersTitle && <div className={'mb-2'}>'Added members:'</div>}
<Row className={clsx('mt-2 flex-wrap gap-2', selectedUsersClassName)}>
{selectedUsers.map((user) => (
<Row key={user.id} className={'items-center gap-1'}>
<Avatar username={user.username} avatarUrl={user.avatarUrl} size={'sm'} />
<UserLink user={user} className="ml-1" />
<Button
onClick={() =>
setSelectedUsers([...selectedUsers.filter(({id}) => id != user.id)])
}
color={'gray-white'}
size={'xs'}
>
<XMarkIcon className="h-5 w-5" aria-hidden="true" />
</Button>
</Row>
))}
</Row>
</>
)}
</Col>
)
}