From 7f754f91fd67fbd70c6e9199bd0755bd910adcbf Mon Sep 17 00:00:00 2001 From: Bram Borggreve Date: Wed, 17 Jan 2024 21:54:51 +0000 Subject: [PATCH] feat: implement user autocomplete fields --- .../lib/helpers/get-user-user-where.input.ts | 8 ++- .../dev/feature/src/lib/dev-admin-routes.tsx | 2 + .../feature/src/lib/dev-user-autocomplete.tsx | 66 +++++++++++++++++++ libs/web/ui/core/src/index.ts | 1 + .../ui/core/src/lib/ui-select-enum-option.tsx | 19 ++++++ .../src/lib/use-admin-find-many-user.ts | 21 ++++-- .../src/lib/use-user-find-many-user.ts | 21 +++++- .../src/lib/admin-user-list-feature.tsx | 23 ++----- .../src/lib/admin-user-ui-select-role.tsx | 18 +++++ .../src/lib/admin-user-ui-select-status.tsx | 18 +++++ libs/web/user/ui/src/index.ts | 4 ++ .../user/ui/src/lib/admin-user-ui-search.tsx | 12 ++++ .../user/ui/src/lib/admin-user-ui-table.tsx | 26 +------- .../user/ui/src/lib/user-ui-autocomplete.tsx | 60 +++++++++++++++++ libs/web/user/ui/src/lib/user-ui-avatar.tsx | 10 ++- libs/web/user/ui/src/lib/user-ui-search.tsx | 12 ++++ libs/web/user/ui/src/lib/user-ui-title.tsx | 41 ++++++++++++ 17 files changed, 304 insertions(+), 58 deletions(-) create mode 100644 libs/web/dev/feature/src/lib/dev-user-autocomplete.tsx create mode 100644 libs/web/ui/core/src/lib/ui-select-enum-option.tsx create mode 100644 libs/web/user/feature/src/lib/admin-user-ui-select-role.tsx create mode 100644 libs/web/user/feature/src/lib/admin-user-ui-select-status.tsx create mode 100644 libs/web/user/ui/src/lib/admin-user-ui-search.tsx create mode 100644 libs/web/user/ui/src/lib/user-ui-autocomplete.tsx create mode 100644 libs/web/user/ui/src/lib/user-ui-search.tsx create mode 100644 libs/web/user/ui/src/lib/user-ui-title.tsx diff --git a/libs/api/user/data-access/src/lib/helpers/get-user-user-where.input.ts b/libs/api/user/data-access/src/lib/helpers/get-user-user-where.input.ts index 7ff9900..5778e5c 100644 --- a/libs/api/user/data-access/src/lib/helpers/get-user-user-where.input.ts +++ b/libs/api/user/data-access/src/lib/helpers/get-user-user-where.input.ts @@ -1,8 +1,12 @@ -import { Prisma } from '@prisma/client' +import { Prisma, UserStatus } from '@prisma/client' import { UserFindManyUserInput } from '../dto/user-find-many-user.input' export function getUserUserWhereInput(input: UserFindManyUserInput): Prisma.UserWhereInput { - const where: Prisma.UserWhereInput = {} + const where: Prisma.UserWhereInput = { + status: { + in: [UserStatus.Active], + }, + } if (input.search) { where.OR = [ diff --git a/libs/web/dev/feature/src/lib/dev-admin-routes.tsx b/libs/web/dev/feature/src/lib/dev-admin-routes.tsx index 94fba96..d02c521 100644 --- a/libs/web/dev/feature/src/lib/dev-admin-routes.tsx +++ b/libs/web/dev/feature/src/lib/dev-admin-routes.tsx @@ -1,6 +1,7 @@ import { UiContainer, UiTabRoutes } from '@pubkey-ui/core' import { DevIdentityWizard } from './dev-identity-wizard' import { DevNew } from './dev-new' +import { DevUserAutocomplete } from './dev-user-autocomplete' export default function DevAdminRoutes() { return ( @@ -10,6 +11,7 @@ export default function DevAdminRoutes() { tabs={[ { path: 'new', label: 'New', element: }, { path: 'identity-wizard', label: 'Identity Wizard', element: }, + { path: 'user-autocomplete', label: 'User Autocomplete', element: }, ]} /> diff --git a/libs/web/dev/feature/src/lib/dev-user-autocomplete.tsx b/libs/web/dev/feature/src/lib/dev-user-autocomplete.tsx new file mode 100644 index 0000000..c75aac3 --- /dev/null +++ b/libs/web/dev/feature/src/lib/dev-user-autocomplete.tsx @@ -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(undefined) + const [userResult, setUserResult] = useState(undefined) + + return ( + + + + + + {adminResult ? : null} + + + + + + + {userResult ? : null} + + + + ) +} + +function ShowUserItems({ user }: { user: User }) { + return ( + + + + UserUiTitle with link + + } + > + + + + UserUiTitle + + } + > + + + + UserUiAvatar + + } + > + + + + + + ) +} diff --git a/libs/web/ui/core/src/index.ts b/libs/web/ui/core/src/index.ts index b1f3704..7abeeab 100644 --- a/libs/web/ui/core/src/index.ts +++ b/libs/web/ui/core/src/index.ts @@ -3,3 +3,4 @@ export * from './lib/ui-header-profile' export * from './lib/ui-modal-button' export * from './lib/ui-page-limit' export * from './lib/ui-search-field' +export * from './lib/ui-select-enum-option' diff --git a/libs/web/ui/core/src/lib/ui-select-enum-option.tsx b/libs/web/ui/core/src/lib/ui-select-enum-option.tsx new file mode 100644 index 0000000..3d660a9 --- /dev/null +++ b/libs/web/ui/core/src/lib/ui-select-enum-option.tsx @@ -0,0 +1,19 @@ +import { Select } from '@mantine/core' + +export function UiSelectEnumOption({ + value, + onChange, + options, +}: { + value: T | undefined + onChange: (value: T | undefined) => void + options: { value: string; label: string }[] +}) { + return ( + { - pagination.setPage(1) - setRole(role === '' ? undefined : (role as UserRole)) - }} - data={[{ value: '', label: 'Filter by role' }, ...getEnumOptions(UserRole)]} - /> -