AllenYuan

Untitled

May 31st, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 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. if (loading) return null;
  20. return (
  21. <div style={style}>
  22. {error && <Error />}
  23. {!error && !loading && user
  24. ? <LoggedIn style={style} playerId={user.account_id} />
  25. :
  26. <Button href={`${process.env.REACT_APP_API_HOST}/login`}>
  27. <IconSteam />
  28. <ButtonLabel>{strings.app_login}</ButtonLabel>
  29. </Button>
  30. }
  31. </div>
  32. );
  33. };
  34.  
  35. AccountWidget.propTypes = {
  36. loading: PropTypes.bool,
  37. error: PropTypes.string,
  38. user: PropTypes.shape({}),
  39. style: PropTypes.string,
  40. strings: PropTypes.shape({}),
  41. };
  42.  
  43. const mapStateToProps = (state) => {
  44. const { error, loading, data } = state.app.metadata;
  45. return {
  46. loading,
  47. error,
  48. user: data.user,
  49. strings: data.app.strings,
  50. };
  51. };
  52.  
  53. export default connect(mapStateToProps, null)(AccountWidget);
Add Comment
Please, Sign In to add comment