1
0
Fork 0
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:
Markus Thielker 2024-12-05 18:28:15 +01:00
parent 0ac5c67dfe
commit 59ed13b2cc
No known key found for this signature in database
2 changed files with 61 additions and 6 deletions

View 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}/>
);
}