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 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { IReduxState, IStore } from '../../app/types';
  6. import { getParticipantById } from '../../base/participants/functions';
  7. import Dialog from '../../base/ui/components/web/Dialog';
  8. import { participantVerified } from '../actions';
  9. import { ISas } from '../reducer';
  10. interface IProps {
  11. decimal: string;
  12. dispatch: IStore['dispatch'];
  13. emoji: string;
  14. pId: string;
  15. participantName?: string;
  16. sas: ISas;
  17. }
  18. const useStyles = makeStyles()(() => {
  19. return {
  20. container: {
  21. display: 'flex',
  22. flexDirection: 'column',
  23. margin: '16px'
  24. },
  25. row: {
  26. alignSelf: 'center',
  27. display: 'flex'
  28. },
  29. item: {
  30. textAlign: 'center',
  31. margin: '16px'
  32. },
  33. emoji: {
  34. fontSize: '40px',
  35. margin: '12px'
  36. }
  37. };
  38. });
  39. const ParticipantVerificationDialog = ({
  40. dispatch,
  41. participantName,
  42. pId,
  43. sas
  44. }: IProps) => {
  45. const { classes } = useStyles();
  46. const { t } = useTranslation();
  47. const _onDismissed = useCallback(() => {
  48. dispatch(participantVerified(pId, false));
  49. return true;
  50. }, [ pId ]);
  51. const _onConfirmed = useCallback(() => {
  52. dispatch(participantVerified(pId, true));
  53. return true;
  54. }, [ pId ]);
  55. const { emoji } = sas;
  56. return (
  57. <Dialog
  58. cancel = {{ translationKey: 'dialog.verifyParticipantDismiss' }}
  59. ok = {{ translationKey: 'dialog.verifyParticipantConfirm' }}
  60. onCancel = { _onDismissed }
  61. onSubmit = { _onConfirmed }
  62. titleKey = 'dialog.verifyParticipantTitle'>
  63. <div>
  64. {t('dialog.verifyParticipantQuestion', { participantName })}
  65. </div>
  66. <div className = { classes.container }>
  67. <div className = { classes.row }>
  68. {/* @ts-ignore */}
  69. {emoji.slice(0, 4).map((e: Array<string>) =>
  70. (<div
  71. className = { classes.item }
  72. key = { e.toString() }>
  73. <div className = { classes.emoji }>{e[0]}</div>
  74. <div>{e[1].charAt(0).toUpperCase() + e[1].slice(1)}</div>
  75. </div>))}
  76. </div>
  77. <div className = { classes.row }>
  78. {/* @ts-ignore */}
  79. {emoji.slice(4, 7).map((e: Array<string>) =>
  80. (<div
  81. className = { classes.item }
  82. key = { e.toString() }>
  83. <div className = { classes.emoji }>{e[0]} </div>
  84. <div>{e[1].charAt(0).toUpperCase() + e[1].slice(1)}</div>
  85. </div>))}
  86. </div>
  87. </div>
  88. </Dialog>
  89. );
  90. };
  91. /**
  92. * Maps part of the Redux store to the props of this component.
  93. *
  94. * @param {IReduxState} state - The Redux state.
  95. * @param {IProps} ownProps - The own props of the component.
  96. * @returns {IProps}
  97. */
  98. export function _mapStateToProps(state: IReduxState, ownProps: IProps) {
  99. const participant = getParticipantById(state, ownProps.pId);
  100. return {
  101. sas: ownProps.sas,
  102. pId: ownProps.pId,
  103. participantName: participant?.name
  104. };
  105. }
  106. export default connect(_mapStateToProps)(ParticipantVerificationDialog);