NORY-15: add identity search
This commit is contained in:
parent
0ac5c67dfe
commit
59ed13b2cc
2 changed files with 61 additions and 6 deletions
|
@ -2,12 +2,25 @@ import React, { Suspense } from 'react';
|
|||
import { DataTableFallback } from '@/components/ui/data-table-fallback';
|
||||
import { IdentityDataTable } from '@/app/user/data-table';
|
||||
import { getIdentityApi } from '@/ory/sdk/server';
|
||||
import { SearchInput } from '@/components/search-input';
|
||||
|
||||
export default async function UserPage() {
|
||||
export default async function UserPage(
|
||||
{
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||
},
|
||||
) {
|
||||
|
||||
const identityApi = await getIdentityApi();
|
||||
|
||||
const { data } = await identityApi.listIdentities();
|
||||
const params = await searchParams;
|
||||
const query = params.query ? params.query as string : '';
|
||||
|
||||
const data = await identityApi.listIdentities({
|
||||
pageSize: 100,
|
||||
previewCredentialsIdentifierSimilar: query,
|
||||
}).then(response => response.data);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-4">
|
||||
|
@ -16,10 +29,12 @@ export default async function UserPage() {
|
|||
<p className="text-lg font-light">See and manage all identities registered with your Ory Kratos
|
||||
instance</p>
|
||||
</div>
|
||||
|
||||
<Suspense fallback={<DataTableFallback columnCount={5} rowCount={20}/>}>
|
||||
<IdentityDataTable data={data}/>
|
||||
</Suspense>
|
||||
<div className="flex flex-col space-y-2">
|
||||
<SearchInput queryParamKey="query" placeholder="Search"/>
|
||||
<Suspense fallback={<DataTableFallback columnCount={5} rowCount={20}/>}>
|
||||
<IdentityDataTable data={data}/>
|
||||
</Suspense>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
40
dashboard/src/components/search-input.tsx
Normal file
40
dashboard/src/components/search-input.tsx
Normal file
|
@ -0,0 +1,40 @@
|
|||
'use client';
|
||||
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { ChangeEvent, HTMLInputTypeAttribute } from 'react';
|
||||
|
||||
interface SearchInputProps {
|
||||
placeholder: string;
|
||||
queryParamKey: string;
|
||||
type?: HTMLInputTypeAttribute;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function SearchInput({ placeholder, queryParamKey, type, className }: SearchInputProps) {
|
||||
|
||||
const router = useRouter();
|
||||
const params = useSearchParams();
|
||||
|
||||
const onSearchChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
|
||||
const value = event.target.value;
|
||||
const newParams = new URLSearchParams(params.toString());
|
||||
|
||||
if (value.length < 1) {
|
||||
newParams.delete(queryParamKey);
|
||||
} else {
|
||||
newParams.set(queryParamKey, value);
|
||||
}
|
||||
|
||||
router.replace('?' + newParams.toString());
|
||||
};
|
||||
|
||||
return (
|
||||
<Input
|
||||
type={type ?? 'text'}
|
||||
placeholder={placeholder}
|
||||
className={className}
|
||||
onChange={onSearchChange}/>
|
||||
);
|
||||
}
|
Loading…
Add table
Reference in a new issue