import { Button } from '@documenso/ui/primitives/button'; import { Input } from '@documenso/ui/primitives/input'; import { Trans } from '@lingui/react/macro'; import { PlusIcon, Trash2Icon } from 'lucide-react'; type RateLimitEntryValue = { window: string; max: number }; type RateLimitArrayInputProps = { value: RateLimitEntryValue[]; onChange: (value: RateLimitEntryValue[]) => void; disabled?: boolean; }; export const RateLimitArrayInput = ({ value, onChange, disabled }: RateLimitArrayInputProps) => { const entries = value ?? []; const updateEntry = (index: number, patch: Partial) => { const next = entries.map((entry, i) => (i === index ? { ...entry, ...patch } : entry)); onChange(next); }; const removeEntry = (index: number) => { onChange(entries.filter((_, i) => i !== index)); }; const addEntry = () => { onChange([...entries, { window: '5m', max: 100 }]); }; return (
{entries.map((entry, index) => (
updateEntry(index, { window: e.target.value })} /> updateEntry(index, { max: parseInt(e.target.value, 10) || 0 })} />
))}
); };