diff --git a/webapp/components/common/EditableItem/index.tsx b/webapp/components/common/EditableItem/index.tsx index 28718ab8..2b986143 100644 --- a/webapp/components/common/EditableItem/index.tsx +++ b/webapp/components/common/EditableItem/index.tsx @@ -12,7 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { useState } from 'react'; import { Input } from '@/components/ui/input'; +import useDebounceFunc from '@/hooks/useDebounceFunc'; + +export type EditableItemProps = { + id: string; + title: string; + className?: string; + editable?: boolean; + onChange?: (value: string, id: string) => void; +}; export default function EditableItem({ id, @@ -20,22 +30,23 @@ export default function EditableItem({ className, editable = false, onChange, -}: { - id: string; - title: string; - className?: string; - editable?: boolean; - onChange?: (value: string, id: string) => void; -}) { +}: EditableItemProps) { + const [changedValue, setChangedValue] = useState(undefined); + + const onDebouncedChange = (value: string) => { + onChange?.(value, id); + }; + + useDebounceFunc(onDebouncedChange, changedValue, 500); if (editable) { return ( { e.preventDefault(); - onChange?.(e.target.value, id); + setChangedValue(e.target.value); }} /> );