index.js 1.4 KB

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