2020-06-04 14:01:31 +02:00
import React , { useState } from 'react' ;
import Dialog from './Dialog' ;
2020-06-04 18:56:55 +02:00
import { Room , Access } from './Api' ;
2020-06-04 14:01:31 +02:00
import { SubmitInput } from './SubmitInput' ;
const descriptions : { [ key : string ] : string } = {
name : t ( 'bbb' , 'Descriptive name of this room.' ) ,
welcome : t ( 'bbb' , 'This message is shown to all users in the chat area after they joined.' ) ,
maxParticipants : t ( 'bbb' , 'Sets a limit on the number of participants for this room. Zero means there is no limit.' ) ,
recording : t ( 'bbb' , 'If enabled, the moderator is able to start the recording.' ) ,
2020-06-04 18:56:55 +02:00
access : t ( 'bbb' , 'Public: Everyone knowing the link is able to join. Password: Guests have to provide a password. Waiting room: A moderator has to accept every guest before they can join. Internal: Only Nextcloud users can join.' ) ,
2020-06-04 14:01:31 +02:00
} ;
type Props = {
room : Room ;
updateProperty : ( key : string , value : string | boolean | number ) = > Promise < void > ;
}
const EditRoomDialog : React.FC < Props > = ( { room , updateProperty } ) = > {
const [ open , setOpen ] = useState < boolean > ( false ) ;
2020-06-04 18:56:55 +02:00
function inputElement ( label : string , field : string , type : 'text' | 'number' = 'text' ) {
2020-06-04 14:01:31 +02:00
return (
< div className = "bbb-form-element" >
< label htmlFor = { ` bbb- ${ field } ` } >
2020-06-04 18:56:55 +02:00
< h3 > { label } < / h3 >
2020-06-04 14:01:31 +02:00
< / label >
< SubmitInput initialValue = { room [ field ] } type = { type } name = { field } onSubmitValue = { value = > updateProperty ( field , value ) } / >
{ descriptions [ field ] && < em > { descriptions [ field ] } < / em > }
< / div >
) ;
}
2020-06-04 18:56:55 +02:00
function selectElement ( label : string , field : string , value : string , options : { [ key : string ] : string } , onChange : ( value : string ) = > void ) {
return (
< div className = "bbb-form-element" >
< label htmlFor = { ` bbb- ${ field } ` } >
< h3 > { label } < / h3 >
< / label >
< select name = { field } value = { value } onChange = { ( event ) = > onChange ( event . target . value ) } >
{ Object . keys ( options ) . map ( key = > {
const label = options [ key ] ;
return < option key = { key } value = { key } > { label } < / option > ;
} ) }
< / select >
{ ( value === Access . Password && room . password ) && < input type = "text" readOnly = { true } value = { room . password } / > }
{ descriptions [ field ] && < em > { descriptions [ field ] } < / em > }
< / div >
) ;
}
2020-06-04 14:01:31 +02:00
return (
< >
< a className = "icon icon-edit icon-visible"
onClick = { ev = > { ev . preventDefault ( ) , setOpen ( true ) ; } }
title = { t ( 'bbb' , 'Edit' ) } / >
< Dialog open = { open } onClose = { ( ) = > setOpen ( false ) } title = { t ( 'bbb' , 'Edit "{room}"' , { room : room.name } ) } >
2020-06-04 18:56:55 +02:00
{ inputElement ( t ( 'bbb' , 'Name' ) , 'name' ) }
{ inputElement ( t ( 'bbb' , 'Welcome' ) , 'welcome' ) }
{ inputElement ( t ( 'bbb' , 'Participant limit' ) , 'maxParticipants' , 'number' ) }
{ selectElement ( t ( 'bbb' , 'Access' ) , 'access' , room . access , {
[ Access . Public ] : t ( 'bbb' , 'Public' ) ,
[ Access . Password ] : t ( 'bbb' , 'Internal + Password protection for guests' ) ,
[ Access . WaitingRoom ] : t ( 'bbb' , 'Internal + Waiting room for guests' ) ,
[ Access . Internal ] : t ( 'bbb' , 'Internal' ) ,
// [Access.InternalRestricted]: t('bbb', 'Restricted'),
} , ( value ) = > {
console . log ( 'access' , value ) ;
updateProperty ( 'access' , value ) ;
} ) }
2020-06-04 14:01:31 +02:00
< div >
< div >
< input id = { ` bbb-record- ${ room . id } ` }
type = "checkbox"
className = "checkbox"
checked = { room . record }
onChange = { ( event ) = > updateProperty ( 'record' , event . target . checked ) } / >
< label htmlFor = { ` bbb-record- ${ room . id } ` } > { t ( 'bbb' , 'Recording' ) } < / label >
< / div >
< em > { descriptions . recording } < / em >
< / div >
< / Dialog >
< / >
) ;
} ;
export default EditRoomDialog ;