Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AddMeetingUrlButton.web.tsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React, { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { createCalendarClickedEvent } from '../../analytics/AnalyticsEvents';
  5. import { sendAnalytics } from '../../analytics/functions';
  6. import { IStore } from '../../app/types';
  7. import { translate } from '../../base/i18n/functions';
  8. import Icon from '../../base/icons/components/Icon';
  9. import { IconPlus } from '../../base/icons/svg';
  10. import Tooltip from '../../base/tooltip/components/Tooltip';
  11. import { updateCalendarEvent } from '../actions.web';
  12. /**
  13. * The type of the React {@code Component} props of {@link AddMeetingUrlButton}.
  14. */
  15. interface IProps extends WithTranslation {
  16. /**
  17. * The calendar ID associated with the calendar event.
  18. */
  19. calendarId: string;
  20. /**
  21. * Invoked to add a meeting URL to a calendar event.
  22. */
  23. dispatch: IStore['dispatch'];
  24. /**
  25. * The ID of the calendar event that will have a meeting URL added on click.
  26. */
  27. eventId: string;
  28. }
  29. /**
  30. * A React Component for adding a meeting URL to an existing calendar event.
  31. *
  32. * @augments Component
  33. */
  34. class AddMeetingUrlButton extends Component<IProps> {
  35. /**
  36. * Initializes a new {@code AddMeetingUrlButton} instance.
  37. *
  38. * @inheritdoc
  39. */
  40. constructor(props: IProps) {
  41. super(props);
  42. // Bind event handler so it is only bound once for every instance.
  43. this._onClick = this._onClick.bind(this);
  44. this._onKeyPress = this._onKeyPress.bind(this);
  45. }
  46. /**
  47. * Implements React's {@link Component#render}.
  48. *
  49. * @inheritdoc
  50. */
  51. render() {
  52. return (
  53. <Tooltip content = { this.props.t('calendarSync.addMeetingURL') }>
  54. <div
  55. className = 'button add-button'
  56. onClick = { this._onClick }
  57. onKeyPress = { this._onKeyPress }
  58. role = 'button'>
  59. <Icon src = { IconPlus } />
  60. </div>
  61. </Tooltip>
  62. );
  63. }
  64. /**
  65. * Dispatches an action to adding a meeting URL to a calendar event.
  66. *
  67. * @returns {void}
  68. */
  69. _onClick() {
  70. const { calendarId, dispatch, eventId } = this.props;
  71. sendAnalytics(createCalendarClickedEvent('add.url'));
  72. dispatch(updateCalendarEvent(eventId, calendarId));
  73. }
  74. /**
  75. * KeyPress handler for accessibility.
  76. *
  77. * @param {Object} e - The key event to handle.
  78. *
  79. * @returns {void}
  80. */
  81. _onKeyPress(e: React.KeyboardEvent) {
  82. if (e.key === ' ' || e.key === 'Enter') {
  83. e.preventDefault();
  84. this._onClick();
  85. }
  86. }
  87. }
  88. export default translate(connect()(AddMeetingUrlButton));