Files
freeCodeCamp/common/app/routes/Jobs/components/ShowJob.jsx

144 lines
3.4 KiB
JavaScript
Raw Normal View History

2015-09-26 22:23:56 -07:00
import React, { PropTypes } from 'react';
2015-10-30 15:43:50 -07:00
import { Well, Row, Col, Thumbnail, Panel } from 'react-bootstrap';
2015-10-30 16:58:49 -07:00
import urlRegexFactory from 'url-regex';
2015-09-26 22:23:56 -07:00
2015-10-30 16:58:49 -07:00
const urlRegex = urlRegexFactory();
2015-10-11 20:25:09 -07:00
const defaultImage =
'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png';
2015-10-11 20:25:09 -07:00
2015-09-26 22:23:56 -07:00
const thumbnailStyle = {
backgroundColor: 'white',
maxHeight: '100px',
maxWidth: '100px'
};
2015-10-30 16:58:49 -07:00
function addATags(text) {
return text.replace(urlRegex, function(match) {
return `<a href=${match} target='_blank'>${match}</a>`;
2015-10-30 16:58:49 -07:00
});
}
2015-09-26 22:23:56 -07:00
export default React.createClass({
displayName: 'ShowJob',
propTypes: {
job: PropTypes.object,
2015-11-05 12:36:02 -08:00
params: PropTypes.object,
showApply: PropTypes.bool,
preview: PropTypes.bool,
2015-11-05 12:36:02 -08:00
message: PropTypes.string
2015-09-26 22:23:56 -07:00
},
renderHeader({ company, position }) {
return (
<div>
<h4 style={{ display: 'inline-block' }}>{ company }</h4>
<h5
className='pull-right hidden-xs hidden-md'
style={{ display: 'inline-block' }}>
{ position }
</h5>
</div>
);
},
renderHowToApply(showApply, preview, message, howToApply) {
2015-11-05 12:36:02 -08:00
if (!showApply) {
return (
<Row>
<Col
md={ 6 }
mdOffset={ 3 }>
<h4 className='bg-info text-center'>{ message }</h4>
2015-11-05 12:36:02 -08:00
</Col>
</Row>
);
}
return (
<Row>
2015-11-05 12:36:02 -08:00
<Col
md={ 6 }
mdOffset={ 3 }>
<Well>
<bold>{ preview ? 'How do I apply?' : message }</bold>
2015-11-05 12:36:02 -08:00
<br />
<br />
<span dangerouslySetInnerHTML={{
__html: addATags(howToApply)
}} />
</Well>
2015-11-05 12:36:02 -08:00
</Col>
</Row>
2015-11-05 12:36:02 -08:00
);
},
2015-09-26 22:23:56 -07:00
render() {
2015-11-05 12:36:02 -08:00
const {
showApply = true,
2015-11-05 12:36:02 -08:00
message,
preview = true,
2015-11-05 12:36:02 -08:00
job = {}
} = this.props;
2015-09-26 22:23:56 -07:00
const {
logo,
position,
city,
company,
state,
2015-10-11 21:11:27 -07:00
locale,
description,
howToApply
2015-09-26 22:23:56 -07:00
} = job;
return (
<div>
<Row>
2015-10-15 22:09:12 -07:00
<Col
md={ 10 }
mdOffset={ 1 }
xs={ 12 }>
2015-09-26 22:23:56 -07:00
<Panel>
2015-10-15 22:09:12 -07:00
<Row>
<h2 className='text-center'>
{ company }
</h2>
</Row>
<div className='spacer' />
<Row>
<Col
2015-10-19 14:46:17 -07:00
md={ 2 }
mdOffset={ 3 }>
2015-10-15 22:09:12 -07:00
<Thumbnail
alt={ logo ? company + 'company logo' : 'stock image' }
src={ logo || defaultImage }
style={ thumbnailStyle } />
</Col>
<Col
md={ 4 }>
2015-10-19 14:46:17 -07:00
<bold>Position: </bold> { position || 'N/A' }
2015-10-15 22:09:12 -07:00
<br />
2015-10-19 14:46:17 -07:00
<bold>Location: </bold>
{ locale ? locale : `${city}, ${state}` }
2015-10-15 22:09:12 -07:00
</Col>
</Row>
<div className='spacer' />
<Row>
<Col
md={ 6 }
mdOffset={ 3 }
2015-10-30 15:27:29 -07:00
style={{ whiteSpace: 'pre-line' }}
2015-10-15 22:09:12 -07:00
xs={ 12 }>
<p>{ description }</p>
</Col>
</Row>
{ this.renderHowToApply(showApply, preview, message, howToApply) }
2015-09-26 22:23:56 -07:00
</Panel>
2015-10-15 22:09:12 -07:00
</Col>
2015-09-26 22:23:56 -07:00
</Row>
</div>
);
}
});