index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* jshint ignore:start */
  2. import React from 'react';
  3. import Blankslate from './blankslate';
  4. import Loader from './loader';
  5. import Form from './form';
  6. import ajax from 'misago/services/ajax';
  7. import snackbar from 'misago/services/snackbar';
  8. export default class extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. loading: true,
  13. groups: null
  14. };
  15. }
  16. componentDidMount() {
  17. ajax.get(this.props.api).then(
  18. (groups) => {
  19. this.setState({
  20. loading: false,
  21. groups
  22. });
  23. },
  24. (rejection) => {
  25. snackbar.apiError(rejection);
  26. if (this.props.cancel) {
  27. this.props.cancel();
  28. }
  29. }
  30. );
  31. }
  32. render() {
  33. const { groups, loading } = this.state;
  34. return (
  35. <div className="panel panel-default panel-form">
  36. <div className="panel-heading">
  37. <h3 className="panel-title">
  38. {gettext("Edit details")}
  39. </h3>
  40. </div>
  41. <Loader display={loading} />
  42. <Blankslate display={!loading && !groups.length} />
  43. <FormDisplay
  44. api={this.props.api}
  45. display={!loading && groups.length}
  46. groups={groups}
  47. onCancel={this.props.onCancel}
  48. onSuccess={this.props.onSuccess}
  49. />
  50. </div>
  51. );
  52. }
  53. }
  54. export function FormDisplay({ api, display, groups, onCancel, onSuccess }) {
  55. if (!display) return null;
  56. return (
  57. <Form
  58. api={api}
  59. groups={groups}
  60. onCancel={onCancel}
  61. onSuccess={onSuccess}
  62. />
  63. );
  64. }