SavePageControls.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { translate } from 'react-i18next';
  4. import SlackNotification from './SlackNotification';
  5. import GrantSelector from './SavePageControls/GrantSelector';
  6. class SavePageControls extends React.PureComponent {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. pageId: this.props.pageId,
  11. };
  12. this.getCurrentOptionsToSave = this.getCurrentOptionsToSave.bind(this);
  13. this.submit = this.submit.bind(this);
  14. }
  15. componentWillMount() {
  16. }
  17. getCurrentOptionsToSave() {
  18. const slackNotificationOptions = this.refs.slackNotification.getCurrentOptionsToSave();
  19. const grantSelectorOptions = this.refs.grantSelector.getCurrentOptionsToSave();
  20. return Object.assign(slackNotificationOptions, grantSelectorOptions);
  21. }
  22. /**
  23. * update pageId of state
  24. * @param {string} pageId
  25. */
  26. setPageId(pageId) {
  27. this.setState({pageId});
  28. }
  29. submit() {
  30. this.props.onSubmit();
  31. }
  32. render() {
  33. const { t } = this.props;
  34. const label = this.state.pageId == null ? t('Create') : t('Update');
  35. return (
  36. <div className="d-flex align-items-center form-inline">
  37. <div className="mr-2">
  38. <SlackNotification
  39. ref='slackNotification'
  40. crowi={this.props.crowi}
  41. pageId={this.props.pageId}
  42. pagePath={this.props.pagePath}
  43. isSlackEnabled={false}
  44. slackChannels={this.props.slackChannels} />
  45. </div>
  46. <div className="mr-2">
  47. <GrantSelector crowi={this.props.crowi}
  48. ref={(elem) => {
  49. if (this.refs.grantSelector == null) {
  50. this.refs.grantSelector = elem.getWrappedInstance();
  51. }
  52. }}
  53. grant={this.props.grant}
  54. grantGroupId={this.props.grantGroupId}
  55. grantGroupName={this.props.grantGroupName} />
  56. </div>
  57. <button className="btn btn-primary btn-submit" onClick={this.submit}>{label}</button>
  58. </div>
  59. );
  60. }
  61. }
  62. SavePageControls.propTypes = {
  63. t: PropTypes.func.isRequired, // i18next
  64. crowi: PropTypes.object.isRequired,
  65. onSubmit: PropTypes.func.isRequired,
  66. pageId: PropTypes.string,
  67. // for SlackNotification
  68. pagePath: PropTypes.string,
  69. slackChannels: PropTypes.string,
  70. // for GrantSelector
  71. grant: PropTypes.number,
  72. grantGroupId: PropTypes.string,
  73. grantGroupName: PropTypes.string,
  74. };
  75. export default translate()(SavePageControls);