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.

ParticipantVerificationDialog.tsx 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { withStyles } from '@mui/styles';
  2. import React, { Component } from 'react';
  3. import { WithTranslation } from 'react-i18next';
  4. import { IReduxState, IStore } from '../../app/types';
  5. import { translate } from '../../base/i18n/functions';
  6. import { getParticipantById } from '../../base/participants/functions';
  7. import { connect } from '../../base/redux/functions';
  8. import Dialog from '../../base/ui/components/web/Dialog';
  9. import { participantVerified } from '../actions';
  10. import { ISas } from '../reducer';
  11. interface IProps extends WithTranslation {
  12. classes: any;
  13. decimal: string;
  14. dispatch: IStore['dispatch'];
  15. emoji: string;
  16. pId: string;
  17. participantName: string;
  18. sas: ISas;
  19. }
  20. /**
  21. * Creates the styles for the component.
  22. *
  23. * @param {Object} theme - The current UI theme.
  24. *
  25. * @returns {Object}
  26. */
  27. const styles = () => {
  28. return {
  29. container: {
  30. display: 'flex',
  31. flexDirection: 'column',
  32. margin: '16px'
  33. },
  34. row: {
  35. alignSelf: 'center',
  36. display: 'flex'
  37. },
  38. item: {
  39. textAlign: 'center',
  40. margin: '16px'
  41. },
  42. emoji: {
  43. fontSize: '40px',
  44. margin: '12px'
  45. }
  46. };
  47. };
  48. /**
  49. * Class for the dialog displayed for E2EE sas verification.
  50. */
  51. export class ParticipantVerificationDialog extends Component<IProps> {
  52. /**
  53. * Instantiates a new instance.
  54. *
  55. * @inheritdoc
  56. */
  57. constructor(props: IProps) {
  58. super(props);
  59. this._onConfirmed = this._onConfirmed.bind(this);
  60. this._onDismissed = this._onDismissed.bind(this);
  61. }
  62. /**
  63. * Implements React's {@link Component#render()}.
  64. *
  65. * @inheritdoc
  66. * @returns {ReactElement}
  67. */
  68. render() {
  69. const { emoji } = this.props.sas;
  70. const { participantName } = this.props;
  71. const { classes, t } = this.props;
  72. return (
  73. <Dialog
  74. cancel = {{ translationKey: 'dialog.verifyParticipantDismiss' }}
  75. ok = {{ translationKey: 'dialog.verifyParticipantConfirm' }}
  76. onCancel = { this._onDismissed }
  77. onSubmit = { this._onConfirmed }
  78. titleKey = 'dialog.verifyParticipantTitle'>
  79. <div>
  80. { t('dialog.verifyParticipantQuestion', { participantName }) }
  81. </div>
  82. <div className = { classes.container }>
  83. <div className = { classes.row }>
  84. {/* @ts-ignore */}
  85. {emoji.slice(0, 4).map((e: Array<string>) =>
  86. (<div
  87. className = { classes.item }
  88. key = { e.toString() }>
  89. <div className = { classes.emoji }>{ e[0] }</div>
  90. <div>{ e[1].charAt(0).toUpperCase() + e[1].slice(1) }</div>
  91. </div>))}
  92. </div>
  93. <div className = { classes.row }>
  94. {/* @ts-ignore */}
  95. {emoji.slice(4, 7).map((e: Array<string>) =>
  96. (<div
  97. className = { classes.item }
  98. key = { e.toString() }>
  99. <div className = { classes.emoji }>{ e[0] } </div>
  100. <div>{ e[1].charAt(0).toUpperCase() + e[1].slice(1) }</div>
  101. </div>))}
  102. </div>
  103. </div>
  104. </Dialog>
  105. );
  106. }
  107. /**
  108. * Notifies this ParticipantVerificationDialog that it has been dismissed by cancel.
  109. *
  110. * @private
  111. * @returns {void}
  112. */
  113. _onDismissed() {
  114. this.props.dispatch(participantVerified(this.props.pId, false));
  115. return true;
  116. }
  117. /**
  118. * Notifies this ParticipantVerificationDialog that it has been dismissed with confirmation.
  119. *
  120. * @private
  121. * @returns {void}
  122. */
  123. _onConfirmed() {
  124. this.props.dispatch(participantVerified(this.props.pId, true));
  125. return true;
  126. }
  127. }
  128. /**
  129. * Maps part of the Redux store to the props of this component.
  130. *
  131. * @param {IReduxState} state - The Redux state.
  132. * @param {IProps} ownProps - The own props of the component.
  133. * @returns {IProps}
  134. */
  135. export function _mapStateToProps(state: IReduxState, ownProps: IProps) {
  136. const participant = getParticipantById(state, ownProps.pId);
  137. return {
  138. sas: ownProps.sas,
  139. pId: ownProps.pId,
  140. participantName: participant?.name
  141. };
  142. }
  143. export default translate(connect(_mapStateToProps)(
  144. // @ts-ignore
  145. withStyles(styles)(ParticipantVerificationDialog)));