-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement user autocomplete fields
- Loading branch information
Showing
17 changed files
with
304 additions
and
58 deletions.
There are no files selected for viewing
8 changes: 6 additions & 2 deletions
8
libs/api/user/data-access/src/lib/helpers/get-user-user-where.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { SimpleGrid, Text } from '@mantine/core' | ||
import type { User } from '@pubkey-stack/sdk' | ||
import { AdminUserUiSearch, UserUiAvatar, UserUiSearch, UserUiTitle } from '@pubkey-stack/web-user-ui' | ||
import { UiCard, UiDebug, UiInfo, UiStack } from '@pubkey-ui/core' | ||
import { useState } from 'react' | ||
|
||
export function DevUserAutocomplete() { | ||
const [adminResult, setAdminResult] = useState<User | undefined>(undefined) | ||
const [userResult, setUserResult] = useState<User | undefined>(undefined) | ||
|
||
return ( | ||
<UiStack> | ||
<UiCard> | ||
<UiStack> | ||
<UiInfo title="AdminUserUiSearch" message="Search for a user as an admin (all users will be shown)" /> | ||
<AdminUserUiSearch select={setAdminResult} /> | ||
{adminResult ? <ShowUserItems user={adminResult} /> : null} | ||
</UiStack> | ||
</UiCard> | ||
<UiCard> | ||
<UiStack> | ||
<UiInfo title="UserUiSearch" message="Search for a user as a normal user. Only active users are shown" /> | ||
<UserUiSearch select={setUserResult} /> | ||
{userResult ? <ShowUserItems user={userResult} /> : null} | ||
</UiStack> | ||
</UiCard> | ||
</UiStack> | ||
) | ||
} | ||
|
||
function ShowUserItems({ user }: { user: User }) { | ||
return ( | ||
<UiStack> | ||
<SimpleGrid cols={3}> | ||
<UiCard | ||
title={ | ||
<Text size="sm" c="dimmed"> | ||
UserUiTitle with link | ||
</Text> | ||
} | ||
> | ||
<UserUiTitle user={user} to={user.profileUrl} /> | ||
</UiCard> | ||
<UiCard | ||
title={ | ||
<Text size="sm" c="dimmed"> | ||
UserUiTitle | ||
</Text> | ||
} | ||
> | ||
<UserUiTitle user={user} /> | ||
</UiCard> | ||
<UiCard | ||
title={ | ||
<Text size="sm" c="dimmed"> | ||
UserUiAvatar | ||
</Text> | ||
} | ||
> | ||
<UserUiAvatar user={user} /> | ||
</UiCard> | ||
</SimpleGrid> | ||
<UiDebug data={user} /> | ||
</UiStack> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Select } from '@mantine/core' | ||
|
||
export function UiSelectEnumOption<T>({ | ||
value, | ||
onChange, | ||
options, | ||
}: { | ||
value: T | undefined | ||
onChange: (value: T | undefined) => void | ||
options: { value: string; label: string }[] | ||
}) { | ||
return ( | ||
<Select | ||
value={value?.toString() ?? ''} | ||
onChange={(value) => onChange(value === '' ? undefined : (value as T))} | ||
data={options} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 18 additions & 3 deletions
21
libs/web/user/data-access/src/lib/use-user-find-many-user.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
import { UserFindManyUserInput } from '@pubkey-stack/sdk' | ||
import { useSdk } from '@pubkey-stack/web-core-data-access' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { useState } from 'react' | ||
|
||
export function useUserFindManyUser(input: UserFindManyUserInput) { | ||
export function useUserFindManyUser(props?: UserFindManyUserInput) { | ||
const sdk = useSdk() | ||
const [limit, setLimit] = useState(props?.limit ?? 10) | ||
const [page, setPage] = useState(props?.page ?? 1) | ||
const [search, setSearch] = useState<string>('') | ||
|
||
const input: UserFindManyUserInput = { limit, page, search } | ||
const query = useQuery({ | ||
queryKey: ['user', 'find-many-user', input], | ||
queryFn: () => sdk.userFindManyUser({ input }).then((res) => res.data), | ||
retry: 0, | ||
}) | ||
const total = query.data?.paging.meta?.totalCount ?? 0 | ||
const items = query.data?.paging.data ?? [] | ||
|
||
return { | ||
data: query.data?.paging.data ?? [], | ||
meta: query.data?.paging.meta, | ||
items, | ||
query, | ||
pagination: { | ||
limit, | ||
page, | ||
total, | ||
setLimit, | ||
setPage, | ||
}, | ||
setSearch, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
libs/web/user/feature/src/lib/admin-user-ui-select-role.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getEnumOptions, UserRole } from '@pubkey-stack/sdk' | ||
import { UiSelectEnumOption } from '@pubkey-stack/web-ui-core' | ||
|
||
export function AdminUserUiSelectRole({ | ||
value, | ||
onChange, | ||
}: { | ||
value: UserRole | undefined | ||
onChange: (role: UserRole | undefined) => void | ||
}) { | ||
return ( | ||
<UiSelectEnumOption<UserRole> | ||
value={value} | ||
onChange={onChange} | ||
options={[{ value: '', label: 'Filter by role' }, ...getEnumOptions(UserRole)]} | ||
/> | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
libs/web/user/feature/src/lib/admin-user-ui-select-status.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getEnumOptions, UserStatus } from '@pubkey-stack/sdk' | ||
import { UiSelectEnumOption } from '@pubkey-stack/web-ui-core' | ||
|
||
export function AdminUserUiSelectStatus({ | ||
value, | ||
onChange, | ||
}: { | ||
value: UserStatus | undefined | ||
onChange: (value: UserStatus | undefined) => void | ||
}) { | ||
return ( | ||
<UiSelectEnumOption<UserStatus> | ||
value={value} | ||
onChange={onChange} | ||
options={[{ value: '', label: 'Filter by status' }, ...getEnumOptions(UserStatus)]} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
export * from './lib/admin-user-ui-create-form' | ||
export * from './lib/admin-user-ui-search' | ||
export * from './lib/admin-user-ui-table' | ||
export * from './lib/admin-user-ui-update-form' | ||
export * from './lib/user-ui-autocomplete' | ||
export * from './lib/user-ui-avatar' | ||
export * from './lib/user-ui-profile' | ||
export * from './lib/user-ui-role-badge' | ||
export * from './lib/user-ui-search' | ||
export * from './lib/user-ui-status-badge' | ||
export * from './lib/user-ui-title' | ||
export * from './lib/user-ui-update-form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useAdminFindManyUser } from '@pubkey-stack/web-user-data-access' | ||
import { UserUiAutocomplete, type UserUiAutocompleteProps } from './user-ui-autocomplete' | ||
|
||
export type AdminUserUiSearchProps = Omit<UserUiAutocompleteProps, 'items' | 'isLoading' | 'setSearch'> | ||
|
||
export function AdminUserUiSearch({ select, ...props }: AdminUserUiSearchProps) { | ||
const { items, query, setSearch } = useAdminFindManyUser({ limit: 5 }) | ||
|
||
return ( | ||
<UserUiAutocomplete isLoading={query.isLoading} select={select} items={items} setSearch={setSearch} {...props} /> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.