2015-11-05 14:52:04 -08:00
|
|
|
|
import React, { PropTypes } from 'react';
|
2015-10-19 22:51:30 -07:00
|
|
|
|
import { History } from 'react-router';
|
2015-08-29 01:00:52 -07:00
|
|
|
|
import { contain } from 'thundercats-react';
|
2015-10-19 22:51:30 -07:00
|
|
|
|
|
2015-09-26 22:23:56 -07:00
|
|
|
|
import ShowJob from './ShowJob.jsx';
|
2015-10-19 22:51:30 -07:00
|
|
|
|
import JobNotFound from './JobNotFound.jsx';
|
|
|
|
|
import { isJobValid } from '../utils';
|
2015-08-25 14:36:07 -07:00
|
|
|
|
|
2015-11-05 14:52:04 -08:00
|
|
|
|
function shouldShowApply(
|
2015-11-05 12:36:02 -08:00
|
|
|
|
{
|
|
|
|
|
isFrontEndCert: isFrontEndCertReq = false,
|
|
|
|
|
isFullStackCert: isFullStackCertReq = false
|
|
|
|
|
}, {
|
|
|
|
|
isFrontEndCert = false,
|
|
|
|
|
isFullStackCert = false
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
return (!isFrontEndCertReq && !isFullStackCertReq) ||
|
|
|
|
|
(isFullStackCertReq && isFullStackCert) ||
|
|
|
|
|
(isFrontEndCertReq && isFrontEndCert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateMessage(
|
|
|
|
|
{
|
2015-11-05 14:52:04 -08:00
|
|
|
|
isFrontEndCert: isFrontEndCertReq = false,
|
|
|
|
|
isFullStackCert: isFullStackCertReq = false
|
|
|
|
|
},
|
|
|
|
|
{
|
2015-11-05 12:36:02 -08:00
|
|
|
|
isFrontEndCert = false,
|
2015-11-05 14:52:04 -08:00
|
|
|
|
isFullStackCert = false,
|
2015-11-05 12:36:02 -08:00
|
|
|
|
isSignedIn = false
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
if (!isSignedIn) {
|
2015-11-05 13:06:27 -08:00
|
|
|
|
return 'Must be signed in to apply';
|
2015-11-05 12:36:02 -08:00
|
|
|
|
}
|
|
|
|
|
if (isFrontEndCertReq && !isFrontEndCert) {
|
2015-11-05 14:52:04 -08:00
|
|
|
|
return 'This employer requires Free Code Camp’s Front ' +
|
|
|
|
|
'End Development Certification in order to apply';
|
2015-11-05 12:36:02 -08:00
|
|
|
|
}
|
2015-11-05 14:52:04 -08:00
|
|
|
|
if (isFullStackCertReq && !isFullStackCert) {
|
|
|
|
|
return 'This employer requires Free Code Camp’s Full ' +
|
|
|
|
|
'Stack Development Certification in order to apply';
|
|
|
|
|
}
|
|
|
|
|
if (isFrontEndCertReq && isFrontEndCertReq) {
|
|
|
|
|
return 'This employer requires the Front End Development Certification. ' +
|
|
|
|
|
"You've earned it, so feel free to apply.";
|
|
|
|
|
}
|
|
|
|
|
return 'This employer requires the Full Stack Development Certification. ' +
|
|
|
|
|
"You've earned it, so feel free to apply.";
|
2015-11-05 12:36:02 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-29 01:00:52 -07:00
|
|
|
|
export default contain(
|
|
|
|
|
{
|
2015-11-05 12:36:02 -08:00
|
|
|
|
stores: ['appStore', 'jobsStore'],
|
|
|
|
|
fetchWaitFor: 'jobsStore',
|
2015-08-29 01:00:52 -07:00
|
|
|
|
fetchAction: 'jobActions.getJob',
|
2015-11-05 13:06:27 -08:00
|
|
|
|
combineLatest(
|
|
|
|
|
{ username, isFrontEndCert, isFullStackCert },
|
|
|
|
|
{ currentJob }
|
|
|
|
|
) {
|
2015-11-05 12:36:02 -08:00
|
|
|
|
return {
|
2015-11-05 13:06:27 -08:00
|
|
|
|
username,
|
2015-11-05 12:36:02 -08:00
|
|
|
|
job: currentJob,
|
|
|
|
|
isFrontEndCert,
|
|
|
|
|
isFullStackCert
|
|
|
|
|
};
|
2015-09-10 16:26:41 -07:00
|
|
|
|
},
|
|
|
|
|
getPayload({ params: { id }, job = {} }) {
|
2015-08-31 14:32:31 -07:00
|
|
|
|
return {
|
2015-09-10 16:26:41 -07:00
|
|
|
|
id,
|
|
|
|
|
isPrimed: job.id === id
|
2015-08-31 14:32:31 -07:00
|
|
|
|
};
|
|
|
|
|
},
|
2015-09-10 16:26:41 -07:00
|
|
|
|
// using es6 destructuring
|
|
|
|
|
shouldContainerFetch({ job = {} }, { params: { id } }
|
|
|
|
|
) {
|
|
|
|
|
return job.id !== id;
|
2015-08-29 01:00:52 -07:00
|
|
|
|
}
|
2015-08-25 14:36:07 -07:00
|
|
|
|
},
|
2015-11-05 14:52:04 -08:00
|
|
|
|
React.createClass({
|
2015-10-19 22:51:30 -07:00
|
|
|
|
displayName: 'Show',
|
|
|
|
|
|
2015-11-05 14:52:04 -08:00
|
|
|
|
propTypes: {
|
|
|
|
|
job: PropTypes.object,
|
|
|
|
|
isFullStackCert: PropTypes.bool,
|
|
|
|
|
isFrontEndCert: PropTypes.bool,
|
|
|
|
|
username: PropTypes.string
|
|
|
|
|
},
|
|
|
|
|
|
2015-10-19 22:51:30 -07:00
|
|
|
|
mixins: [History],
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const { job } = this.props;
|
|
|
|
|
// redirect user in client
|
|
|
|
|
if (!isJobValid(job)) {
|
|
|
|
|
this.history.pushState(null, '/jobs');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
render() {
|
2015-11-05 12:36:02 -08:00
|
|
|
|
const {
|
|
|
|
|
isFullStackCert,
|
|
|
|
|
isFrontEndCert,
|
|
|
|
|
job,
|
|
|
|
|
username
|
|
|
|
|
} = this.props;
|
2015-10-19 22:51:30 -07:00
|
|
|
|
|
|
|
|
|
if (!isJobValid(job)) {
|
|
|
|
|
return <JobNotFound />;
|
|
|
|
|
}
|
2015-11-05 14:52:04 -08:00
|
|
|
|
|
|
|
|
|
const isSignedIn = !!username;
|
|
|
|
|
|
|
|
|
|
const showApply = shouldShowApply(
|
|
|
|
|
job,
|
|
|
|
|
{ isFrontEndCert, isFullStackCert }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const message = generateMessage(
|
|
|
|
|
job,
|
|
|
|
|
{ isFrontEndCert, isFullStackCert, isSignedIn }
|
|
|
|
|
);
|
|
|
|
|
|
2015-11-05 12:36:02 -08:00
|
|
|
|
return (
|
|
|
|
|
<ShowJob
|
2015-11-05 14:52:04 -08:00
|
|
|
|
message={ message }
|
|
|
|
|
preview={ false }
|
|
|
|
|
showApply={ showApply }
|
2015-11-05 12:36:02 -08:00
|
|
|
|
{ ...this.props }/>
|
|
|
|
|
);
|
2015-10-19 22:51:30 -07:00
|
|
|
|
}
|
|
|
|
|
})
|
2015-08-29 01:00:52 -07:00
|
|
|
|
);
|