You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PasswordForm.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, { useCallback, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import Input from '../../../../base/ui/components/web/Input';
  4. import { LOCKED_LOCALLY } from '../../../../room-lock/constants';
  5. /**
  6. * The type of the React {@code Component} props of {@link PasswordForm}.
  7. */
  8. interface IProps {
  9. /**
  10. * Whether or not to show the password editing field.
  11. */
  12. editEnabled: boolean;
  13. /**
  14. * The value for how the conference is locked (or undefined if not locked)
  15. * as defined by room-lock constants.
  16. */
  17. locked?: string;
  18. /**
  19. * Callback to invoke when the local participant is submitting a password
  20. * set request.
  21. */
  22. onSubmit: Function;
  23. /**
  24. * The current known password for the JitsiConference.
  25. */
  26. password?: string;
  27. /**
  28. * The number of digits to be used in the password.
  29. */
  30. passwordNumberOfDigits?: number;
  31. /**
  32. * Whether or not the password should be visible.
  33. */
  34. visible: boolean;
  35. }
  36. /**
  37. * React {@code Component} for displaying and editing the conference password.
  38. *
  39. * @returns {ReactElement}
  40. */
  41. export default function PasswordForm({
  42. editEnabled,
  43. locked,
  44. onSubmit,
  45. password,
  46. passwordNumberOfDigits,
  47. visible
  48. }: IProps) {
  49. const { t } = useTranslation();
  50. const [ enteredPassword, setEnteredPassword ] = useState('');
  51. const onKeyPress = useCallback(event => {
  52. if (event.key === 'Enter') {
  53. event.preventDefault();
  54. event.stopPropagation();
  55. onSubmit(enteredPassword);
  56. }
  57. }, [ onSubmit, enteredPassword ]);
  58. if (!editEnabled && enteredPassword && enteredPassword !== '') {
  59. setEnteredPassword('');
  60. }
  61. const placeHolderText
  62. = passwordNumberOfDigits ? t('passwordDigitsOnly', { number: passwordNumberOfDigits }) : t('dialog.password');
  63. return (
  64. <div className = 'info-password'>
  65. { locked && <>
  66. <span className = 'info-label'>
  67. {t('info.password')}
  68. </span>
  69. <span className = 'spacer'>&nbsp;</span>
  70. <span className = 'info-password-field info-value'>
  71. {locked === LOCKED_LOCALLY ? (
  72. <div className = 'info-password-local'>
  73. { visible ? password : '******' }
  74. </div>
  75. ) : (
  76. <div className = 'info-password-remote'>
  77. { t('passwordSetRemotely') }
  78. </div>
  79. ) }
  80. </span>
  81. </>
  82. }
  83. {
  84. editEnabled && <div
  85. className = 'info-password-form'>
  86. <Input
  87. accessibilityLabel = { t('info.addPassword') }
  88. autoFocus = { true }
  89. id = 'info-password-input'
  90. maxLength = { passwordNumberOfDigits }
  91. mode = { passwordNumberOfDigits ? 'numeric' : undefined }
  92. onChange = { setEnteredPassword }
  93. onKeyPress = { onKeyPress }
  94. placeholder = { placeHolderText }
  95. type = 'password'
  96. value = { enteredPassword } />
  97. </div>
  98. }
  99. </div>
  100. );
  101. }