AllenYuan

Untitled

Jun 1st, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import { Button } from '@material-ui/core';
  2. import { PropTypes } from 'prop-types';
  3. import React from 'react';
  4. import { connect } from 'react-redux';
  5. import styled from 'styled-components';
  6.  
  7. import Error from '../Error';
  8. import { IconSteam } from '../Icons';
  9. import LoggedIn from './LoggedIn';
  10.  
  11. const ButtonLabel = styled.span`
  12. margin-left: 4px;
  13. `;
  14.  
  15. // login/profile button
  16. const AccountWidget = ({
  17. loading, error, user, style, strings,
  18. }) => {
  19. console.log('accountwidget props', {
  20. loading,
  21. error,
  22. user,
  23. style,
  24. strings,
  25. });
  26. if (loading) return null;
  27. return (
  28. <div style={style}>
  29. {error && <Error />}
  30. {!error && !loading && user
  31. ? <LoggedIn style={style} playerId={user.account_id} />
  32. :
  33. <Button href={`${process.env.REACT_APP_API_HOST}/login`}>
  34. <IconSteam />
  35. <ButtonLabel>{strings.app_login}</ButtonLabel>
  36. </Button>
  37. }
  38. </div>
  39. );
  40. };
  41.  
  42. AccountWidget.propTypes = {
  43. loading: PropTypes.bool,
  44. error: PropTypes.string,
  45. user: PropTypes.shape({}),
  46. style: PropTypes.string,
  47. strings: PropTypes.shape({}),
  48. };
  49.  
  50. const mapStateToProps = (state) => {
  51. const { error, loading, data } = state.app.metadata;
  52. return {
  53. loading,
  54. error,
  55. user: data.user,
  56. strings: state.app.strings,
  57. };
  58. };
  59.  
  60. export default connect(mapStateToProps, null)(AccountWidget);
Add Comment
Please, Sign In to add comment