Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AddMeetingUrlButton.web.js 2.7KB

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