umami/src/app/(main)/reports/funnel/UrlAddForm.tsx

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-02-04 08:44:20 +00:00
'use client';
import { useState } from 'react';
import { useMessages } from 'components/hooks';
2023-06-23 08:19:08 +00:00
import { Button, Form, FormRow, TextField, Flexbox } from 'react-basics';
2023-06-03 06:10:59 +00:00
import styles from './UrlAddForm.module.css';
2023-12-03 11:07:03 +00:00
export interface UrlAddFormProps {
defaultValue?: string;
onAdd?: (url: string) => void;
}
export function UrlAddForm({ defaultValue = '', onAdd }: UrlAddFormProps) {
const [url, setUrl] = useState(defaultValue);
const { formatMessage, labels } = useMessages();
2023-07-02 05:02:49 +00:00
const handleSave = () => {
onAdd(url);
setUrl('');
};
const handleChange = e => {
setUrl(e.target.value);
};
2023-07-02 05:02:49 +00:00
const handleKeyDown = e => {
if (e.key === 'Enter') {
e.stopPropagation();
handleSave();
}
2023-06-23 08:19:08 +00:00
};
2023-07-02 05:02:49 +00:00
return (
2023-08-04 07:51:52 +00:00
<Form>
<FormRow label={formatMessage(labels.url)}>
<Flexbox gap={10}>
<TextField
className={styles.input}
value={url}
onChange={handleChange}
autoFocus={true}
autoComplete="off"
onKeyDown={handleKeyDown}
/>
<Button variant="primary" onClick={handleSave}>
{formatMessage(labels.add)}
</Button>
</Flexbox>
</FormRow>
</Form>
);
}
2023-06-03 06:10:59 +00:00
export default UrlAddForm;