forum-options.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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_url.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 <form onSubmit={this.handleSubmit} className="form-horizontal">
  91. <div className="panel panel-default panel-form">
  92. <div className="panel-heading">
  93. <h3 className="panel-title">{gettext("Change forum options")}</h3>
  94. </div>
  95. <div className="panel-body">
  96. <fieldset>
  97. <legend>{gettext("Privacy settings")}</legend>
  98. <FormGroup
  99. label={gettext("Hide my presence")}
  100. helpText={gettext("If you hide your presence, only members with permission to see hidden users will see when you are online.")}
  101. for="id_is_hiding_presence"
  102. labelClass="col-sm-4"
  103. controlClass="col-sm-8"
  104. >
  105. <YesNoSwitch
  106. id="id_is_hiding_presence"
  107. disabled={this.state.isLoading}
  108. iconOn="visibility_off"
  109. iconOff="visibility"
  110. labelOn={gettext("Hide my presence from other users")}
  111. labelOff={gettext("Show my presence to other users")}
  112. onChange={this.bindInput('is_hiding_presence')}
  113. value={this.state.is_hiding_presence}
  114. />
  115. </FormGroup>
  116. <FormGroup
  117. label={gettext("Private thread invitations")}
  118. for="id_limits_private_thread_invites_to"
  119. labelClass="col-sm-4"
  120. controlClass="col-sm-8"
  121. >
  122. <Select
  123. id="id_limits_private_thread_invites_to"
  124. disabled={this.state.isLoading}
  125. onChange={this.bindInput('limits_private_thread_invites_to')}
  126. value={this.state.limits_private_thread_invites_to}
  127. choices={this.privateThreadInvitesChoices}
  128. />
  129. </FormGroup>
  130. </fieldset>
  131. <fieldset>
  132. <legend>{gettext("Automatic subscriptions")}</legend>
  133. <FormGroup
  134. label={gettext("Threads I start")}
  135. for="id_subscribe_to_started_threads"
  136. labelClass="col-sm-4"
  137. controlClass="col-sm-8"
  138. >
  139. <Select
  140. id="id_subscribe_to_started_threads"
  141. disabled={this.state.isLoading}
  142. onChange={this.bindInput('subscribe_to_started_threads')}
  143. value={this.state.subscribe_to_started_threads}
  144. choices={this.subscribeToChoices}
  145. />
  146. </FormGroup>
  147. <FormGroup
  148. label={gettext("Threads I reply to")}
  149. for="id_subscribe_to_replied_threads"
  150. labelClass="col-sm-4"
  151. controlClass="col-sm-8"
  152. >
  153. <Select
  154. id="id_subscribe_to_replied_threads"
  155. disabled={this.state.isLoading}
  156. onChange={this.bindInput('subscribe_to_replied_threads')}
  157. value={this.state.subscribe_to_replied_threads}
  158. choices={this.subscribeToChoices}
  159. />
  160. </FormGroup>
  161. </fieldset>
  162. </div>
  163. <div className="panel-footer">
  164. <div className="row">
  165. <div className="col-sm-8 col-sm-offset-4">
  166. <Button className="btn-primary" loading={this.state.isLoading}>
  167. {gettext("Save changes")}
  168. </Button>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. </form>
  174. /* jshint ignore:end */
  175. }
  176. }