auth-message.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React from "react"
  2. export default class extends React.Component {
  3. refresh() {
  4. window.location.reload()
  5. }
  6. getMessage() {
  7. if (this.props.signedIn) {
  8. return interpolate(
  9. gettext(
  10. "You have signed in as %(username)s. Please refresh the page before continuing."
  11. ),
  12. { username: this.props.signedIn.username },
  13. true
  14. )
  15. } else if (this.props.signedOut) {
  16. return interpolate(
  17. gettext(
  18. "%(username)s, you have been signed out. Please refresh the page before continuing."
  19. ),
  20. { username: this.props.user.username },
  21. true
  22. )
  23. }
  24. }
  25. render() {
  26. let className = "auth-message"
  27. if (this.props.signedIn || this.props.signedOut) {
  28. className += " show"
  29. }
  30. return (
  31. <div className={className}>
  32. <div className="container">
  33. <p className="lead">{this.getMessage()}</p>
  34. <p>
  35. <button
  36. className="btn btn-default"
  37. type="button"
  38. onClick={this.refresh}
  39. >
  40. {gettext("Reload page")}
  41. </button>
  42. <span className="hidden-xs hidden-sm">
  43. {" " + gettext("or press F5 key.")}
  44. </span>
  45. </p>
  46. </div>
  47. </div>
  48. )
  49. }
  50. }
  51. export function select(state) {
  52. return {
  53. user: state.auth.user,
  54. signedIn: state.auth.signedIn,
  55. signedOut: state.auth.signedOut,
  56. }
  57. }