2020-04-26 11:36:41 +02:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import {CopyToClipboard} from 'react-copy-to-clipboard';
|
|
|
|
import { SubmitInput } from './SubmitInput';
|
|
|
|
import { Room, api } from './Api';
|
|
|
|
|
|
|
|
type Props = {
|
2020-04-26 22:41:06 +02:00
|
|
|
room: Room;
|
|
|
|
updateRoom: (room: Room) => void;
|
|
|
|
deleteRoom: (id: number) => void;
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type EditableValueProps = {
|
2020-04-26 22:41:06 +02:00
|
|
|
setValue: (key: string, value: string|number) => void;
|
|
|
|
setActive: (key: string) => void;
|
|
|
|
active: string;
|
|
|
|
field: string;
|
|
|
|
value: string;
|
|
|
|
type: 'text' | 'number';
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const EditableValue: React.FC<EditableValueProps> = ({ setValue, setActive, active, field, value, type }) => {
|
|
|
|
if (active === field) {
|
|
|
|
return <SubmitInput
|
|
|
|
autoFocus={true}
|
|
|
|
onSubmitValue={(value) => setValue(field, type === 'number' ? parseInt(value):value)}
|
|
|
|
onClick={event => event.stopPropagation()}
|
|
|
|
initialValue={value}
|
|
|
|
type={type}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
|
|
|
|
function onClick(ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
|
|
setActive(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <a className="action-rename" onClick={onClick}>{value}</a>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RoomRow: React.FC<Props> = (props) => {
|
|
|
|
const [activeEdit, setActiveEdit] = useState('');
|
|
|
|
const room = props.room;
|
|
|
|
|
|
|
|
function updateRoom(key: string, value: string|boolean|number) {
|
|
|
|
props.updateRoom({
|
|
|
|
...props.room,
|
|
|
|
[key]: value,
|
|
|
|
});
|
|
|
|
|
|
|
|
setActiveEdit('');
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteRow(ev: MouseEvent) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
OC.dialogs.confirm(
|
2020-04-26 13:26:34 +02:00
|
|
|
t('bbb', 'Are you sure you want to delete "{name}"? This operation can not be undone', { name: room.name }),
|
|
|
|
t('bbb', 'Delete "{name}"?', { name: room.name }),
|
2020-04-26 11:36:41 +02:00
|
|
|
confirmed => {
|
|
|
|
if (confirmed) {
|
|
|
|
props.deleteRoom(room.id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function edit(field: string, type: 'text' | 'number' = 'text'){
|
|
|
|
return <EditableValue field={field} value={room[field]} active={activeEdit} setActive={setActiveEdit} setValue={updateRoom} type={type} />
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tr key={room.id}>
|
|
|
|
<td className="share icon-col">
|
2020-04-26 13:43:16 +02:00
|
|
|
<CopyToClipboard text={window.location.origin + api.getUrl(`b/${room.uid}`)}>
|
2020-04-26 11:36:41 +02:00
|
|
|
<span className="icon icon-clippy icon-visible copy-to-clipboard" ></span>
|
|
|
|
</CopyToClipboard>
|
|
|
|
</td>
|
|
|
|
<td className="start icon-col">
|
2020-04-26 13:43:16 +02:00
|
|
|
<a href={api.getUrl(`b/${room.uid}`)} className="icon icon-play icon-visible" target="_blank" rel="noopener noreferrer"></a>
|
2020-04-26 11:36:41 +02:00
|
|
|
</td>
|
|
|
|
<td className="name">
|
|
|
|
{edit('name')}
|
|
|
|
</td>
|
|
|
|
<td className="welcome">
|
|
|
|
{edit('welcome')}
|
|
|
|
</td>
|
|
|
|
<td className="max-participants">
|
|
|
|
{edit('maxParticipants', 'number')}
|
|
|
|
</td>
|
|
|
|
<td className="record">
|
|
|
|
<input id={`bbb-record-${room.id}`} type="checkbox" className="checkbox" checked={room.record} onChange={(event) => updateRoom('record', event.target.checked)} />
|
|
|
|
<label htmlFor={`bbb-record-${room.id}`}></label>
|
|
|
|
</td>
|
|
|
|
<td className="remove icon-col">
|
|
|
|
<a className="icon icon-delete icon-visible"
|
|
|
|
onClick={deleteRow as any}
|
|
|
|
title="Delete" />
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RoomRow;
|