Files
freeCodeCamp/client/src/client-only-routes/ShowSettings.js

239 lines
6.6 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { Grid, Button } from '@freecodecamp/react-bootstrap';
2018-09-14 16:14:35 +01:00
import Helmet from 'react-helmet';
import { signInLoadingSelector, userSelector } from '../redux';
import { submitNewAbout, updateUserFlag } from '../redux/settings';
import Layout from '../components/Layout';
import Spacer from '../components/helpers/Spacer';
import Loader from '../components/helpers/Loader';
import FullWidthRow from '../components/helpers/FullWidthRow';
import About from '../components/settings/About';
2018-09-18 09:36:20 +01:00
import Privacy from '../components/settings/Privacy';
import Email from '../components/settings/Email';
2018-09-20 12:29:31 +01:00
import Internet from '../components/settings/Internet';
import Portfolio from '../components/settings/Portfolio';
2018-09-21 14:49:13 +01:00
import Honesty from '../components/settings/Honesty';
2018-09-24 18:45:11 +01:00
import Certification from '../components/settings/Certification';
const propTypes = {
showLoading: PropTypes.bool,
submitNewAbout: PropTypes.func.isRequired,
toggleNightMode: PropTypes.func.isRequired,
2018-09-20 12:29:31 +01:00
updateInternetSettings: PropTypes.func.isRequired,
2018-09-21 14:49:13 +01:00
updateIsHonest: PropTypes.func.isRequired,
updatePortfolio: PropTypes.func.isRequired,
updateQuincyEmail: PropTypes.func.isRequired,
2018-09-24 18:45:11 +01:00
user: PropTypes.shape({
about: PropTypes.string,
completedChallenges: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string,
solution: PropTypes.string,
githubLink: PropTypes.string,
challengeType: PropTypes.number,
completedDate: PropTypes.number,
files: PropTypes.array
})
),
email: PropTypes.string,
githubProfile: PropTypes.string,
is2018DataVisCert: PropTypes.bool,
isApisMicroservicesCert: PropTypes.bool,
isBackEndCert: PropTypes.bool,
isDataVisCert: PropTypes.bool,
isEmailVerified: PropTypes.bool,
isFrontEndCert: PropTypes.bool,
isFrontEndLibsCert: PropTypes.bool,
isFullStackCert: PropTypes.bool,
isHonest: PropTypes.bool,
isInfosecQaCert: PropTypes.bool,
isJsAlgoDataStructCert: PropTypes.bool,
isRespWebDesignCert: PropTypes.bool,
linkedin: PropTypes.string,
location: PropTypes.string,
name: PropTypes.string,
picture: PropTypes.string,
points: PropTypes.number,
portfolio: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
title: PropTypes.string,
url: PropTypes.string,
image: PropTypes.string,
description: PropTypes.string
})
),
sendQuincyEmail: PropTypes.bool,
theme: PropTypes.string,
twitter: PropTypes.string,
username: PropTypes.string,
website: PropTypes.string
})
};
const mapStateToProps = createSelector(
signInLoadingSelector,
userSelector,
2018-09-24 18:45:11 +01:00
(showLoading, user) => ({
showLoading,
2018-09-24 18:45:11 +01:00
user
})
);
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
submitNewAbout,
toggleNightMode: theme => updateUserFlag({ theme }),
2018-09-20 12:29:31 +01:00
updateInternetSettings: updateUserFlag,
2018-09-21 14:49:13 +01:00
updateIsHonest: updateUserFlag,
updatePortfolio: updateUserFlag,
updateQuincyEmail: sendQuincyEmail => updateUserFlag({ sendQuincyEmail })
},
dispatch
);
function ShowSettings(props) {
const {
submitNewAbout,
toggleNightMode,
2018-09-24 18:45:11 +01:00
user: {
completedChallenges,
email,
is2018DataVisCert,
isApisMicroservicesCert,
isJsAlgoDataStructCert,
isBackEndCert,
isDataVisCert,
isFrontEndCert,
isInfosecQaCert,
isFrontEndLibsCert,
isFullStackCert,
isEmailVerified,
isHonest,
sendQuincyEmail,
username,
about,
picture,
points,
theme,
location,
name,
githubProfile,
linkedin,
twitter,
website,
portfolio
},
showLoading,
2018-09-20 12:29:31 +01:00
updateQuincyEmail,
updateInternetSettings,
2018-09-21 14:49:13 +01:00
updatePortfolio,
updateIsHonest
} = props;
if (showLoading) {
return (
<Layout>
<div className='loader-wrapper'>
<Loader />
</div>
</Layout>
);
}
return (
<Layout>
2018-09-14 16:14:35 +01:00
<Helmet>
<title>Settings | freeCodeCamp.org</title>
</Helmet>
<Grid>
<Spacer size={2} />
<FullWidthRow>
<Button
block={true}
bsSize='lg'
bsStyle='primary'
className='btn-invert'
href={`/${username}`}
>
Show me my public portfolio
</Button>
<Button
block={true}
bsSize='lg'
bsStyle='primary'
className='btn-invert'
href={'/signout'}
>
Sign me out of freeCodeCamp
</Button>
</FullWidthRow>
<Spacer />
<h1 className='text-center'>{`Account Settings for ${username}`}</h1>
2018-09-13 18:28:23 +01:00
<About
about={about}
currentTheme={theme}
location={location}
name={name}
picture={picture}
points={points}
submitNewAbout={submitNewAbout}
toggleNightMode={toggleNightMode}
username={username}
/>
<Spacer />
2018-09-18 09:36:20 +01:00
<Privacy />
<Spacer />
<Email
email={email}
isEmailVerified={isEmailVerified}
sendQuincyEmail={sendQuincyEmail}
updateQuincyEmail={updateQuincyEmail}
/>
<Spacer />
2018-09-20 12:29:31 +01:00
<Internet
githubProfile={githubProfile}
linkedin={linkedin}
twitter={twitter}
updateInternetSettings={updateInternetSettings}
website={website}
/>
<Spacer />
<Portfolio portfolio={portfolio} updatePortfolio={updatePortfolio} />
<Spacer />
2018-09-24 18:45:11 +01:00
<Honesty isHonest={isHonest} updateIsHonest={updateIsHonest} />
<Spacer />
2018-09-24 18:45:11 +01:00
<Certification
completedChallenges={completedChallenges}
is2018DataVisCert={is2018DataVisCert}
isApisMicroservicesCert={isApisMicroservicesCert}
isBackEndCert={isBackEndCert}
isDataVisCert={isDataVisCert}
isFrontEndCert={isFrontEndCert}
isFrontEndLibsCert={isFrontEndLibsCert}
isFullStackCert={isFullStackCert}
isInfosecQaCert={isInfosecQaCert}
isJsAlgoDataStructCert={isJsAlgoDataStructCert}
/>
<Spacer />
2018-09-24 18:45:11 +01:00
{/* <DangerZone /> */}
</Grid>
</Layout>
);
}
ShowSettings.displayName = 'ShowSettings';
ShowSettings.propTypes = propTypes;
export default connect(
mapStateToProps,
mapDispatchToProps
)(ShowSettings);