mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-07-01 04:29:18 +00:00
NORY-15: add identity search
This commit is contained in:
parent
0ac5c67dfe
commit
59ed13b2cc
2 changed files with 61 additions and 6 deletions
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
Add a link
Reference in a new issue