FullTextSearchPage.jsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React, { Fragment } from 'react';
  2. import PropTypes from 'prop-types';
  3. import AppContainer from '../../../services/AppContainer';
  4. import { createSubscribedElement } from '../../UnstatedUtils';
  5. import { toastSuccess, toastError } from '../../../util/apiNotification';
  6. class FullTextSearchManagement extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.buildIndex = this.buildIndex.bind(this);
  10. }
  11. async buildIndex() {
  12. const { appContainer } = this.props;
  13. const pageId = this.pageId;
  14. try {
  15. const res = await appContainer.apiPost('/admin/search/build', { page_id: pageId });
  16. if (!res.ok) {
  17. throw new Error();
  18. }
  19. else {
  20. toastSuccess('Building request is successfully posted.');
  21. }
  22. }
  23. catch (e) {
  24. toastError(new Error('エラーが発生しました'));
  25. }
  26. }
  27. render() {
  28. return (
  29. <Fragment>
  30. <div>
  31. <button type="submit" className="btn btn-inverse" onClick={this.buildIndex}>Build Now</button>
  32. </div>
  33. </Fragment>
  34. );
  35. }
  36. }
  37. const FullTextSearchManagementWrapper = (props) => {
  38. return createSubscribedElement(FullTextSearchManagement, props, [AppContainer]);
  39. };
  40. FullTextSearchManagement.propTypes = {
  41. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  42. };
  43. export default FullTextSearchManagementWrapper;