123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- /* eslint-disable react/no-multi-comp */
- // @flow
-
- import React, { useRef } from 'react';
-
- import { translate } from '../../../base/i18n';
- import { copyText } from '../../../invite';
-
- import PasswordForm from './PasswordForm';
-
- type Props = {
-
- /**
- * Whether or not the current user can modify the current password.
- */
- canEditPassword: boolean,
-
- /**
- * The JitsiConference for which to display a lock state and change the
- * password.
- */
- conference: Object,
-
- /**
- * The value for how the conference is locked (or undefined if not locked)
- * as defined by room-lock constants.
- */
- locked: string,
-
- /**
- * The current known password for the JitsiConference.
- */
- password: string,
-
- /**
- * Whether or not to show the password in editing mode.
- */
- passwordEditEnabled: boolean,
-
- /**
- * The number of digits to be used in the password.
- */
- passwordNumberOfDigits: ?number,
-
- /**
- * Action that sets the conference password.
- */
- setPassword: Function,
-
- /**
- * Method that sets whether the password editing is enabled or not.
- */
- setPasswordEditEnabled: Function,
-
- /**
- * Invoked to obtain translated strings.
- */
- t: Function
- };
-
- /**
- * Component that handles the password manipulation from the invite dialog.
- *
- * @returns {React$Element<any>}
- */
- function PasswordSection({
- canEditPassword,
- conference,
- locked,
- password,
- passwordEditEnabled,
- passwordNumberOfDigits,
- setPassword,
- setPasswordEditEnabled,
- t }: Props) {
-
- const formRef: Object = useRef(null);
-
- /**
- * Callback invoked to set a password on the current JitsiConference.
- *
- * @param {string} enteredPassword - The new password to be used to lock the
- * current JitsiConference.
- * @private
- * @returns {void}
- */
- function onPasswordSubmit(enteredPassword) {
- setPassword(conference, conference.lock, enteredPassword);
- }
-
- /**
- * Toggles whether or not the password should currently be shown as being
- * edited locally.
- *
- * @private
- * @returns {void}
- */
- function onTogglePasswordEditState() {
- setPasswordEditEnabled(!passwordEditEnabled);
- }
-
- /**
- * Method to remotely submit the password from outside of the password form.
- *
- * @returns {void}
- */
- function onPasswordSave() {
- if (formRef.current) {
- formRef.current.querySelector('form').requestSubmit();
- }
- }
-
- /**
- * Callback invoked to unlock the current JitsiConference.
- *
- * @returns {void}
- */
- function onPasswordRemove() {
- onPasswordSubmit('');
- }
-
- /**
- * Copies the password to the clipboard.
- *
- * @returns {void}
- */
- function onPasswordCopy() {
- copyText(password);
- }
-
- /**
- * Method that renders the password action(s) based on the current
- * locked-status of the conference.
- *
- * @returns {React$Element<any>}
- */
- function renderPasswordActions() {
- if (!canEditPassword) {
- return null;
- }
-
- if (passwordEditEnabled) {
- return (
- <>
- <a onClick = { onTogglePasswordEditState }>{ t('dialog.Cancel') }</a>
- <a onClick = { onPasswordSave }>{ t('dialog.add') }</a>
- </>
- );
- }
-
- if (locked) {
- return (
- <>
- <a
- className = 'remove-password'
- onClick = { onPasswordRemove }>{ t('dialog.Remove') }</a>
- <a
- className = 'copy-password'
- onClick = { onPasswordCopy }>{ t('dialog.copy') }</a>
- </>
- );
- }
-
- return (
- <a
- className = 'add-password'
- onClick = { onTogglePasswordEditState }>{ t('info.addPassword') }</a>
- );
- }
-
- return (
- <div className = 'security-dialog password-section'>
- <p className = 'description'>
- { t('security.about') }
- </p>
- <div className = 'security-dialog password'>
- <div
- className = 'info-dialog info-dialog-column info-dialog-password'
- ref = { formRef }>
- <PasswordForm
- editEnabled = { passwordEditEnabled }
- locked = { locked }
- onSubmit = { onPasswordSubmit }
- password = { password }
- passwordNumberOfDigits = { passwordNumberOfDigits } />
- </div>
- <div className = 'security-dialog password-actions'>
- { renderPasswordActions() }
- </div>
- </div>
- </div>
- );
- }
-
- export default translate(PasswordSection);
|