auth-message.js 1.4 KB

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