SavePageControls.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 config = this.props.crowi.getConfig();
  35. const aclEnable = config.isEnabledAcl;
  36. const label = this.state.pageId == null ? t('Create') : t('Update');
  37. return (
  38. <div className="d-flex align-items-center form-inline">
  39. <div className="mr-2">
  40. <SlackNotification
  41. ref='slackNotification'
  42. crowi={this.props.crowi}
  43. pageId={this.props.pageId}
  44. pagePath={this.props.pagePath}
  45. isSlackEnabled={false}
  46. slackChannels={this.props.slackChannels} />
  47. </div>
  48. {aclEnable &&
  49. <div className="mr-2">
  50. <GrantSelector crowi={this.props.crowi}
  51. ref={(elem) => {
  52. if (this.refs.grantSelector == null) {
  53. this.refs.grantSelector = elem.getWrappedInstance();
  54. }
  55. }}
  56. grant={this.props.grant}
  57. grantGroupId={this.props.grantGroupId}
  58. grantGroupName={this.props.grantGroupName} />
  59. </div>
  60. }
  61. <button className="btn btn-primary btn-submit" onClick={this.submit}>{label}</button>
  62. </div>
  63. );
  64. }
  65. }
  66. SavePageControls.propTypes = {
  67. t: PropTypes.func.isRequired, // i18next
  68. crowi: PropTypes.object.isRequired,
  69. onSubmit: PropTypes.func.isRequired,
  70. pageId: PropTypes.string,
  71. // for SlackNotification
  72. pagePath: PropTypes.string,
  73. slackChannels: PropTypes.string,
  74. // for GrantSelector
  75. grant: PropTypes.number,
  76. grantGroupId: PropTypes.string,
  77. grantGroupName: PropTypes.string,
  78. };
  79. export default translate()(SavePageControls);