forum-options.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import React from 'react'; // jshint ignore:line
  2. import Button from 'misago/components/button'; // jshint ignore:line
  3. import Form from 'misago/components/form';
  4. import FormGroup from 'misago/components/form-group'; // jshint ignore:line
  5. import Select from 'misago/components/select'; // jshint ignore:line
  6. import YesNoSwitch from 'misago/components/yes-no-switch'; // jshint ignore:line
  7. import { patch } from 'misago/reducers/auth';
  8. import ajax from 'misago/services/ajax';
  9. import title from 'misago/services/page-title';
  10. import snackbar from 'misago/services/snackbar';
  11. import store from 'misago/services/store';
  12. export default class extends Form {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. 'isLoading': false,
  17. 'is_hiding_presence': props.user.is_hiding_presence,
  18. 'limits_private_thread_invites_to': props.user.limits_private_thread_invites_to,
  19. 'subscribe_to_started_threads': props.user.subscribe_to_started_threads,
  20. 'subscribe_to_replied_threads': props.user.subscribe_to_replied_threads,
  21. 'errors': {}
  22. };
  23. this.privateThreadInvitesChoices = [
  24. {
  25. 'value': 0,
  26. 'icon': 'help_outline',
  27. 'label': gettext("Everybody")
  28. },
  29. {
  30. 'value': 1,
  31. 'icon': 'done_all',
  32. 'label': gettext("Users I follow")
  33. },
  34. {
  35. 'value': 2,
  36. 'icon': 'highlight_off',
  37. 'label': gettext("Nobody")
  38. }
  39. ];
  40. this.subscribeToChoices = [
  41. {
  42. 'value': 0,
  43. 'icon': 'star_border',
  44. 'label': gettext("No")
  45. },
  46. {
  47. 'value': 1,
  48. 'icon': 'star_half',
  49. 'label': gettext("Notify")
  50. },
  51. {
  52. 'value': 2,
  53. 'icon': 'star',
  54. 'label': gettext("Notify with e-mail")
  55. }
  56. ];
  57. }
  58. send() {
  59. return ajax.post(this.props.user.api.options, {
  60. is_hiding_presence: this.state.is_hiding_presence,
  61. limits_private_thread_invites_to: this.state.limits_private_thread_invites_to,
  62. subscribe_to_started_threads: this.state.subscribe_to_started_threads,
  63. subscribe_to_replied_threads: this.state.subscribe_to_replied_threads
  64. });
  65. }
  66. handleSuccess() {
  67. store.dispatch(patch({
  68. is_hiding_presence: this.state.is_hiding_presence,
  69. limits_private_thread_invites_to: this.state.limits_private_thread_invites_to,
  70. subscribe_to_started_threads: this.state.subscribe_to_started_threads,
  71. subscribe_to_replied_threads: this.state.subscribe_to_replied_threads
  72. }));
  73. snackbar.success(gettext("Your forum options have been changed."));
  74. }
  75. handleError(rejection) {
  76. if (rejection.status === 400) {
  77. snackbar.error(gettext("Please reload page and try again."));
  78. } else {
  79. snackbar.apiError(rejection);
  80. }
  81. }
  82. componentDidMount() {
  83. title.set({
  84. title: gettext("Forum options"),
  85. parent: gettext("Change your options")
  86. });
  87. }
  88. render() {
  89. /* jshint ignore:start */
  90. return (
  91. <form onSubmit={this.handleSubmit}>
  92. <div className="panel panel-default panel-form">
  93. <div className="panel-heading">
  94. <h3 className="panel-title">{gettext("Change forum options")}</h3>
  95. </div>
  96. <div className="panel-body">
  97. <fieldset>
  98. <legend>{gettext("Privacy settings")}</legend>
  99. <FormGroup
  100. label={gettext("Hide my presence")}
  101. helpText={gettext("If you hide your presence, only members with permission to see hidden users will see when you are online.")}
  102. for="id_is_hiding_presence"
  103. >
  104. <YesNoSwitch
  105. id="id_is_hiding_presence"
  106. disabled={this.state.isLoading}
  107. iconOn="visibility_off"
  108. iconOff="visibility"
  109. labelOn={gettext("Hide my presence from other users")}
  110. labelOff={gettext("Show my presence to other users")}
  111. onChange={this.bindInput('is_hiding_presence')}
  112. value={this.state.is_hiding_presence}
  113. />
  114. </FormGroup>
  115. <FormGroup
  116. label={gettext("Private thread invitations")}
  117. for="id_limits_private_thread_invites_to"
  118. >
  119. <Select
  120. id="id_limits_private_thread_invites_to"
  121. disabled={this.state.isLoading}
  122. onChange={this.bindInput('limits_private_thread_invites_to')}
  123. value={this.state.limits_private_thread_invites_to}
  124. choices={this.privateThreadInvitesChoices}
  125. />
  126. </FormGroup>
  127. </fieldset>
  128. <fieldset>
  129. <legend>{gettext("Automatic subscriptions")}</legend>
  130. <FormGroup
  131. label={gettext("Threads I start")}
  132. for="id_subscribe_to_started_threads"
  133. >
  134. <Select
  135. id="id_subscribe_to_started_threads"
  136. disabled={this.state.isLoading}
  137. onChange={this.bindInput('subscribe_to_started_threads')}
  138. value={this.state.subscribe_to_started_threads}
  139. choices={this.subscribeToChoices}
  140. />
  141. </FormGroup>
  142. <FormGroup
  143. label={gettext("Threads I reply to")}
  144. for="id_subscribe_to_replied_threads"
  145. >
  146. <Select
  147. id="id_subscribe_to_replied_threads"
  148. disabled={this.state.isLoading}
  149. onChange={this.bindInput('subscribe_to_replied_threads')}
  150. value={this.state.subscribe_to_replied_threads}
  151. choices={this.subscribeToChoices}
  152. />
  153. </FormGroup>
  154. </fieldset>
  155. </div>
  156. <div className="panel-footer">
  157. <Button className="btn-primary" loading={this.state.isLoading}>
  158. {gettext("Save changes")}
  159. </Button>
  160. </div>
  161. </div>
  162. </form>
  163. );
  164. /* jshint ignore:end */
  165. }
  166. }