2020-06-04 10:16:09 +02:00
|
|
|
import React, { useState } from 'react';
|
2020-04-26 11:36:41 +02:00
|
|
|
|
|
|
|
type Props = {
|
2020-06-04 10:16:09 +02:00
|
|
|
addRoom: (name: string) => Promise<void>;
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const NewRoomForm: React.FC<Props> = (props) => {
|
2020-06-04 10:16:09 +02:00
|
|
|
const [name, setName] = useState<string>('');
|
|
|
|
const [processing, setProcessing] = useState<boolean>(false);
|
|
|
|
const [error, setError] = useState<string>('');
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-04-27 16:47:32 +02:00
|
|
|
function addRoom(ev: React.FormEvent) {
|
|
|
|
ev.preventDefault();
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-06-04 10:16:09 +02:00
|
|
|
setProcessing(true);
|
|
|
|
setError('');
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-06-04 10:16:09 +02:00
|
|
|
props.addRoom(name).then(() => {
|
|
|
|
setName('');
|
|
|
|
}).catch(err => {
|
|
|
|
setError(err.toString());
|
|
|
|
}).then(() => {
|
|
|
|
setProcessing(false);
|
|
|
|
});
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
2020-04-27 16:47:32 +02:00
|
|
|
return (
|
|
|
|
<form action="#" onSubmit={addRoom}>
|
|
|
|
<input
|
|
|
|
className="newgroup-name"
|
2020-06-04 10:16:09 +02:00
|
|
|
disabled={processing}
|
2020-04-27 16:47:32 +02:00
|
|
|
value={name}
|
2020-05-16 14:44:21 +02:00
|
|
|
placeholder={t('bbb', 'Room name')}
|
2020-06-04 10:16:09 +02:00
|
|
|
onChange={(event) => { setName(event.target.value); }} />
|
2020-04-27 16:47:32 +02:00
|
|
|
|
2020-06-04 10:16:09 +02:00
|
|
|
<input type="submit" disabled={processing} value={t('bbb', 'Create')} />
|
|
|
|
|
|
|
|
{error && <p>{error}</p>}
|
2020-04-27 16:47:32 +02:00
|
|
|
</form>
|
2020-04-27 16:50:45 +02:00
|
|
|
);
|
|
|
|
};
|
2020-04-26 11:36:41 +02:00
|
|
|
|
|
|
|
export default NewRoomForm;
|