PageStatusAlert.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { translate } from 'react-i18next';
  4. /**
  5. *
  6. * @author Yuki Takei <yuki@weseek.co.jp>
  7. *
  8. * @export
  9. * @class PageStatusAlert
  10. * @extends {React.Component}
  11. */
  12. class PageStatusAlert extends React.Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. revisionId: this.props.revisionId,
  17. latestRevisionId: this.props.revisionId,
  18. lastUpdateUsername: undefined,
  19. };
  20. }
  21. initRevisionId(revisionId) {
  22. this.setState({
  23. revisionId,
  24. latestRevisionId: revisionId,
  25. });
  26. }
  27. setLatestRevisionId(revisionId) {
  28. this.setState({latestRevisionId: revisionId});
  29. }
  30. setLastUpdateUsername(lastUpdateUsername) {
  31. this.setState({lastUpdateUsername});
  32. }
  33. render() {
  34. const { t } = this.props;
  35. const label1 = t('edited this page');
  36. const label2 = t('Load latest');
  37. const isShown = this.state.revisionId !== this.state.latestRevisionId;
  38. const style = {
  39. display: isShown ? 'block' : 'none'
  40. };
  41. return (
  42. <div className="myadmin-alert alert-warning myadmin-alert-bottom alertbottom2" style={style}>
  43. <i className="icon-fw icon-bulb"></i>
  44. <span>{this.state.lastUpdateUsername}</span> {label1}&nbsp;
  45. <a href="javascript:location.reload();">
  46. <i className="fa fa-angle-double-right"></i> {label2}
  47. </a>
  48. </div>
  49. );
  50. }
  51. }
  52. PageStatusAlert.propTypes = {
  53. t: PropTypes.func.isRequired, // i18next
  54. crowi: PropTypes.object.isRequired,
  55. revisionId: PropTypes.string,
  56. latestRevisionId: PropTypes.string,
  57. };
  58. PageStatusAlert.defaultProps = {
  59. };
  60. export default translate()(PageStatusAlert);