SavePageControls.jsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.submit = this.submit.bind(this);
  13. }
  14. componentWillMount() {
  15. }
  16. /**
  17. * update pageId of state
  18. * @param {string} pageId
  19. */
  20. setPageId(pageId) {
  21. this.setState({pageId});
  22. }
  23. submit() {
  24. const slackNotificationState = this.refs.slackNotification.state;
  25. const grantSelectorState = this.refs.grantSelector.state;
  26. const options = Object.assign(slackNotificationState, grantSelectorState);
  27. this.props.onSubmit(options);
  28. }
  29. render() {
  30. const { t } = this.props;
  31. const label = this.state.pageId == null ? t('Create') : t('Update');
  32. return (
  33. <div className="d-flex align-items-center form-inline">
  34. <div className="mr-2">
  35. <SlackNotification
  36. ref='slackNotification'
  37. crowi={this.props.crowi}
  38. pageId={this.props.pageId}
  39. pagePath={this.props.pagePath}
  40. isSlackEnabled={false}
  41. slackChannels={this.props.slackChannels}
  42. formName='pageForm' />
  43. </div>
  44. <div className="mr-2">
  45. <GrantSelector crowi={this.props.crowi}
  46. ref={(elem) => { this.refs.grantSelector = elem.getWrappedInstance()} }
  47. pageGrant={this.props.pageGrant}
  48. pageGrantGroupId={this.props.pageGrantGroupId}
  49. pageGrantGroupName={this.props.pageGrantGroupName} />
  50. </div>
  51. <button className="btn btn-primary btn-submit" onClick={this.submit}>{label}</button>
  52. </div>
  53. );
  54. }
  55. }
  56. SavePageControls.propTypes = {
  57. t: PropTypes.func.isRequired, // i18next
  58. crowi: PropTypes.object.isRequired,
  59. onSubmit: PropTypes.func.isRequired,
  60. pageId: PropTypes.string,
  61. // for SlackNotification
  62. pagePath: PropTypes.string,
  63. slackChannels: PropTypes.string,
  64. // for GrantSelector
  65. pageGrant: PropTypes.number,
  66. pageGrantGroupId: PropTypes.string,
  67. pageGrantGroupName: PropTypes.string,
  68. };
  69. export default translate()(SavePageControls);