SavePageControls.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. formName='pageForm' />
  46. </div>
  47. <div className="mr-2">
  48. <GrantSelector crowi={this.props.crowi}
  49. ref={(elem) => { this.refs.grantSelector = elem.getWrappedInstance()} }
  50. grant={this.props.grant}
  51. grantGroupId={this.props.grantGroupId}
  52. grantGroupName={this.props.grantGroupName} />
  53. </div>
  54. <button className="btn btn-primary btn-submit" onClick={this.submit}>{label}</button>
  55. </div>
  56. );
  57. }
  58. }
  59. SavePageControls.propTypes = {
  60. t: PropTypes.func.isRequired, // i18next
  61. crowi: PropTypes.object.isRequired,
  62. onSubmit: PropTypes.func.isRequired,
  63. pageId: PropTypes.string,
  64. // for SlackNotification
  65. pagePath: PropTypes.string,
  66. slackChannels: PropTypes.string,
  67. // for GrantSelector
  68. grant: PropTypes.number,
  69. grantGroupId: PropTypes.string,
  70. grantGroupName: PropTypes.string,
  71. };
  72. export default translate()(SavePageControls);