2023-05-29 06:37:34 +02:00
|
|
|
import { useState } from 'react';
|
|
|
|
import { useMessages } from 'hooks';
|
|
|
|
import { Button, Form, FormButtons, FormRow, TextField } from 'react-basics';
|
2023-06-03 08:10:59 +02:00
|
|
|
import styles from './UrlAddForm.module.css';
|
2023-05-29 06:37:34 +02:00
|
|
|
|
2023-06-03 08:10:59 +02:00
|
|
|
export function UrlAddForm({ defaultValue = '', onSave, onClose }) {
|
2023-05-29 06:37:34 +02:00
|
|
|
const [url, setUrl] = useState(defaultValue);
|
|
|
|
const { formatMessage, labels } = useMessages();
|
|
|
|
|
|
|
|
const handleSave = () => {
|
|
|
|
onSave?.(url);
|
|
|
|
setUrl('');
|
|
|
|
onClose();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleChange = e => {
|
|
|
|
setUrl(e.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-06-05 12:08:43 +02:00
|
|
|
<Form className={styles.form} onSubmit={handleSave}>
|
2023-05-29 06:37:34 +02:00
|
|
|
<FormRow label={formatMessage(labels.url)}>
|
|
|
|
<TextField
|
|
|
|
name="url"
|
|
|
|
value={url}
|
|
|
|
onChange={handleChange}
|
|
|
|
autoFocus={true}
|
|
|
|
autoComplete="off"
|
|
|
|
/>
|
|
|
|
</FormRow>
|
|
|
|
<FormButtons align="center" flex>
|
|
|
|
<Button variant="primary" onClick={handleSave}>
|
|
|
|
{formatMessage(labels.save)}
|
|
|
|
</Button>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-03 08:10:59 +02:00
|
|
|
export default UrlAddForm;
|