accept-agreement.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from "react"
  2. import ajax from "misago/services/ajax"
  3. export default class AcceptAgreement extends React.Component {
  4. constructor(props) {
  5. super(props)
  6. this.state = { submiting: false }
  7. }
  8. handleDecline = () => {
  9. if (this.state.submiting) return
  10. const confirmation = window.confirm(
  11. gettext(
  12. "Declining will result in immediate deactivation and deletion of your account. This action is not reversible."
  13. )
  14. )
  15. if (!confirmation) return
  16. this.setState({ submiting: true })
  17. ajax.post(this.props.api, { accept: false }).then(() => {
  18. window.location.reload(true)
  19. })
  20. }
  21. handleAccept = () => {
  22. if (this.state.submiting) return
  23. this.setState({ submiting: true })
  24. ajax.post(this.props.api, { accept: true }).then(() => {
  25. window.location.reload(true)
  26. })
  27. }
  28. render() {
  29. return (
  30. <div>
  31. <button
  32. className="btn btn-default"
  33. disabled={this.state.submiting}
  34. type="buton"
  35. onClick={this.handleDecline}
  36. >
  37. {gettext("Decline")}
  38. </button>
  39. <button
  40. className="btn btn-primary"
  41. disabled={this.state.submiting}
  42. type="buton"
  43. onClick={this.handleAccept}
  44. >
  45. {gettext("Accept and continue")}
  46. </button>
  47. </div>
  48. )
  49. }
  50. }