Files
freeCodeCamp/common/app/routes/settings/components/Settings.jsx

321 lines
8.3 KiB
JavaScript
Raw Normal View History

2016-07-15 14:32:42 -07:00
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
2016-10-28 22:14:39 -07:00
import { createSelector } from 'reselect';
2016-07-15 14:32:42 -07:00
import { Button, Row, Col } from 'react-bootstrap';
import FA from 'react-fontawesome';
2016-07-15 14:32:42 -07:00
import LockedSettings from './Locked-Settings.jsx';
2017-06-17 18:09:43 -04:00
import JobSettings from './Job-Settings.jsx';
2016-07-15 14:32:42 -07:00
import SocialSettings from './Social-Settings.jsx';
import EmailSettings from './Email-Setting.jsx';
2016-10-06 13:12:22 -05:00
import LanguageSettings from './Language-Settings.jsx';
2017-05-03 00:18:14 +01:00
import SettingsSkeleton from './SettingsSkeleton.jsx';
2016-10-28 22:14:39 -07:00
2016-07-15 14:32:42 -07:00
2016-10-28 22:14:39 -07:00
import { toggleUserFlag } from '../redux/actions.js';
import { userSelector } from '../../../redux/selectors.js';
import { toggleNightMode, updateTitle } from '../../../redux/actions.js';
2016-10-28 22:14:39 -07:00
const mapDispatchToProps = {
updateTitle,
toggleNightMode,
2017-06-17 18:09:43 -04:00
toggleIsAvailableForHire: () => toggleUserFlag('isAvailableForHire'),
toggleIsLocked: () => toggleUserFlag('isLocked'),
toggleQuincyEmail: () => toggleUserFlag('sendQuincyEmail'),
toggleNotificationEmail: () => toggleUserFlag('sendNotificationEmail'),
toggleMonthlyEmail: () => toggleUserFlag('sendMonthlyEmail')
};
2016-10-28 22:14:39 -07:00
const mapStateToProps = createSelector(
userSelector,
state => state.app.isSignInAttempted,
(
{
user: {
username,
email,
2017-06-17 18:09:43 -04:00
isAvailableForHire,
2016-10-28 22:14:39 -07:00
isLocked,
isGithubCool,
isTwitter,
isLinkedIn,
sendMonthlyEmail,
sendNotificationEmail,
sendQuincyEmail
}
},
isSignInAttempted
) => ({
showLoading: isSignInAttempted,
username,
email,
2017-06-17 18:09:43 -04:00
isAvailableForHire,
isLocked,
isGithubCool,
isTwitter,
isLinkedIn,
sendMonthlyEmail,
sendNotificationEmail,
sendQuincyEmail
2016-10-28 22:14:39 -07:00
})
);
const propTypes = {
children: PropTypes.element,
2017-01-12 06:54:43 +00:00
email: PropTypes.string,
initialLang: PropTypes.string,
2017-06-17 18:09:43 -04:00
isAvailableForHire: PropTypes.bool,
2016-10-28 22:14:39 -07:00
isGithubCool: PropTypes.bool,
isLinkedIn: PropTypes.bool,
2017-01-12 06:54:43 +00:00
isLocked: PropTypes.bool,
isTwitter: PropTypes.bool,
lang: PropTypes.string,
2016-10-28 22:14:39 -07:00
sendMonthlyEmail: PropTypes.bool,
sendNotificationEmail: PropTypes.bool,
sendQuincyEmail: PropTypes.bool,
2017-01-12 06:54:43 +00:00
showLoading: PropTypes.bool,
2017-06-17 18:09:43 -04:00
toggleIsAvailableForHire: PropTypes.func.isRequired,
2016-10-28 22:14:39 -07:00
toggleIsLocked: PropTypes.func.isRequired,
toggleMonthlyEmail: PropTypes.func.isRequired,
2017-01-12 06:54:43 +00:00
toggleNightMode: PropTypes.func.isRequired,
2016-10-28 22:14:39 -07:00
toggleNotificationEmail: PropTypes.func.isRequired,
2017-01-12 06:54:43 +00:00
toggleQuincyEmail: PropTypes.func.isRequired,
updateMyLang: PropTypes.func,
updateTitle: PropTypes.func.isRequired,
username: PropTypes.string
};
export class Settings extends React.Component {
constructor(...props) {
super(...props);
this.updateMyLang = this.updateMyLang.bind(this);
}
2016-07-15 14:32:42 -07:00
updateMyLang(e) {
e.preventDefault();
const lang = e.target.value;
this.props.updateMyLang(lang);
}
componentWillMount() {
this.props.updateTitle('Settings');
}
2016-07-15 14:32:42 -07:00
render() {
const {
children,
username,
2017-06-17 18:09:43 -04:00
isAvailableForHire,
2016-07-15 14:32:42 -07:00
isLocked,
isGithubCool,
isTwitter,
isLinkedIn,
2016-10-28 22:14:39 -07:00
showLoading,
2016-07-15 14:32:42 -07:00
email,
sendMonthlyEmail,
sendNotificationEmail,
sendQuincyEmail,
2017-06-17 18:09:43 -04:00
toggleIsAvailableForHire,
toggleNightMode,
toggleIsLocked,
toggleQuincyEmail,
toggleMonthlyEmail,
toggleNotificationEmail
2016-07-15 14:32:42 -07:00
} = this.props;
2016-10-28 22:14:39 -07:00
if (!username && !showLoading) {
2017-05-03 00:18:14 +01:00
return <SettingsSkeleton />;
2016-10-28 22:14:39 -07:00
}
if (children) {
return (
<Row>
<Col
sm={ 4 }
smOffset={ 4 }
>
{ children }
</Col>
</Row>
);
}
2016-07-15 14:32:42 -07:00
return (
<div>
<Row>
<Col xs={ 12 }>
<Button
block={ true }
bsSize='lg'
bsStyle='primary'
className='btn-link-social'
href={ `/${username}` }
>
<FA name='user' />
Show me my public profile
</Button>
<Button
block={ true }
bsSize='lg'
bsStyle='primary'
className='btn-link-social'
href={ '/signout' }
>
Sign me out of freeCodeCamp
</Button>
<Button
block={ true }
bsSize='lg'
bsStyle='primary'
className='btn-link-social'
href={ 'mail:team@freecodecamp.com' }
>
Email us at team@freecodecamp.com
</Button>
</Col>
</Row>
2016-07-15 14:32:42 -07:00
<h1 className='text-center'>Settings for your Account</h1>
<h2 className='text-center'>Actions</h2>
<Row>
<Col xs={ 12 }>
<Button
block={ true }
bsSize='lg'
bsStyle='primary'
className='btn-link-social'
onClick={ toggleNightMode }
2016-07-15 14:32:42 -07:00
>
NightMode
</Button>
</Col>
</Row>
<Row>
<Col xs={ 12 }>
<SocialSettings
isGithubCool={ isGithubCool }
isLinkedIn={ isLinkedIn }
isTwitter={ isTwitter }
/>
</Col>
</Row>
<div className='spacer' />
<h2 className='text-center'>Account Settings</h2>
<Row>
<Col xs={ 12 }>
<Button
block={ true }
bsSize='lg'
bsStyle='primary'
className='btn-link-social'
href='/commit'
>
Edit my pledge
</Button>
</Col>
</Row>
<div className='spacer' />
<h2 className='text-center'>Privacy Settings</h2>
<Row>
<Col
md={ 6 }
mdOffset={ 3 }
sm={ 8 }
smOffset={ 2 }
xs={ 12 }
>
<LockedSettings
isLocked={ isLocked }
toggle={ toggleIsLocked }
/>
2016-07-15 14:32:42 -07:00
</Col>
2017-06-17 18:09:43 -04:00
</Row>
<div className='spacer' />
<h2 className='text-center'>Job Search Settings</h2>
<Row>
<Col
md={ 6 }
mdOffset={ 3 }
sm={ 8 }
smOffset={ 2 }
xs={ 12 }
>
<JobSettings
isAvailableForHire={ isAvailableForHire }
toggle={ toggleIsAvailableForHire }
/>
</Col>
2016-07-15 14:32:42 -07:00
</Row>
<div className='spacer' />
<h2 className='text-center'>Email Settings</h2>
<Row>
<Col
md={ 6 }
mdOffset={ 3 }
sm={ 8 }
smOffset={ 2 }
xs={ 12 }
>
<EmailSettings
email={ email }
sendMonthlyEmail={ sendMonthlyEmail }
sendNotificationEmail={ sendNotificationEmail }
sendQuincyEmail={ sendQuincyEmail }
toggleMonthlyEmail={ toggleMonthlyEmail }
toggleNotificationEmail={ toggleNotificationEmail }
toggleQuincyEmail={ toggleQuincyEmail }
2016-07-15 14:32:42 -07:00
/>
</Col>
</Row>
<div className='spacer' />
<h2 className='text-center'>Display challenges in:</h2>
2016-07-15 14:32:42 -07:00
<Row>
<Col
md={ 6 }
mdOffset={ 3 }
sm={ 8 }
smOffset={ 2 }
xs={ 12 }
>
2016-10-06 13:12:22 -05:00
<LanguageSettings />
2016-07-15 14:32:42 -07:00
</Col>
</Row>
<div className='spacer' />
<h2 className='text-center'>Danger Zone</h2>
<Row>
<Col
md={ 6 }
mdOffset={ 3 }
sm={ 8 }
smOffset={ 2 }
xs={ 12 }
>
<Button
block={ true }
bsSize='lg'
bsStyle='danger'
className='btn-link-social'
href='/delete-my-account'
>
Delete my freeCodeCamp account
</Button>
<Button
block={ true }
bsSize='lg'
bsStyle='danger'
className='btn-link-social'
href='/reset-my-progress'
>
Reset all of my progress and brownie points
</Button>
2016-07-15 14:32:42 -07:00
</Col>
</Row>
</div>
);
}
}
2016-10-28 22:14:39 -07:00
Settings.displayName = 'Settings';
Settings.propTypes = propTypes;
export default connect(
mapStateToProps,
mapDispatchToProps
)(Settings);