Advertisement
vietanhlehuu

ListRecruitment

Nov 24th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import ListItem from '../share/ListItem';
  3. import request from 'superagent';
  4. import _ from 'lodash';
  5. import moment from 'moment';
  6. import Spinner from 'react-spinkit';
  7. import { SALARY_VALUES, EXPERIENCE_VALUES, SORT_TYPES } from '../recruitmentHolder/RecruitmentHolder';
  8. const FULL_SIZE = 10;
  9. const SHOW_SIZE = 1;
  10. class ListRecruitment extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. recruitments: [],
  15. show: false,
  16. }
  17. }
  18.  
  19. postFilterOptions(page = 0, pageSize = FULL_SIZE, sortMode = SORT_TYPES.NEWEST) {
  20. const data = {
  21. salary: [SALARY_VALUES.MIN, SALARY_VALUES.MAX],
  22. experience: EXPERIENCE_VALUES.MIN
  23. }
  24. this.setState({recruitments: []}, () => {
  25. request
  26. .post('/api/recruitment/filter')
  27. .query({page, PAGE_SIZE: pageSize, sortMode})
  28. .send(data)
  29. .end((err, res) => {
  30. if (err) {
  31. console.log(err);
  32. }
  33. else {
  34. const { recruitments } = res.body;
  35. this.setState({recruitments});
  36. }
  37. })
  38. })
  39. }
  40. renderList(propRecruitments, pageSize = SHOW_SIZE) {
  41. try {
  42. if (_.isEmpty(propRecruitments)) {
  43. return (
  44. <div className="row">
  45. <div className="col-sm-12 spinner-container">
  46. <Spinner name="three-bounce" color="#14b1bb" className="spinner-center"/>
  47. </div>
  48. </div>
  49. )
  50. }
  51. const recruitments = propRecruitments.map(
  52. (elem, index) => {
  53. if (index < pageSize) {
  54. var organizationName = '', organizationSlogan = '', organizationLogo = '', arr = [];
  55. if (!elem._organization) {}
  56. else if (!elem._organization.id) {
  57. organizationName = elem._organization.name;
  58. }
  59. else if (elem._organization.id) {
  60. organizationName = elem._organization.id.name;
  61. organizationSlogan = elem._organization.id.slogan;
  62. try {
  63. arr = elem._organization.id._logo.url.split('/');
  64. organizationLogo = '/' + [arr[arr.length-2], arr[arr.length-1]].join('/');
  65. } catch (error) {}
  66. }
  67. return (<ListItem
  68. key={elem._id}
  69. linkTo={`/recruitments/${elem._id}`}
  70. imageUrl={organizationLogo}
  71. name={elem.title}
  72. sub1={organizationName}
  73. sub2={organizationSlogan}
  74. col1_footer={`Cập nhật ${moment(new Date(elem.updatedDate), "YYYYMMDD").fromNow()}`}
  75. sub4={(elem.view)? elem.view.total: 0}
  76. col2_topleft="18/16 Tân bình Phường 14 Hồ Chí Minh"
  77. col2_topright=""
  78. col2_btmleft={elem.requirement.jobType}
  79. col2_btmright=""
  80. col2_footer={elem.requirement.positions}
  81. col3_top={`Lương: ${elem.requirement.minSalary} - ${elem.requirement.maxSalary} triệu`}
  82. tags={elem.requirement.skills}
  83. />)
  84. }
  85. else {
  86. return null;
  87. }
  88. }
  89. ).filter(elem => elem !== null);
  90. console.log(recruitments);
  91. return (
  92. <div className="row">
  93. <div className="col-sm-8">
  94. <div className="list-item">
  95. {recruitments}
  96. </div>
  97. </div>
  98. </div>
  99. )
  100. } catch (error) {
  101. console.log(error);
  102. return <div>404 Not Found.</div>
  103. }
  104. }
  105. handleClick(show) {
  106. this.setState({show: !show});
  107. }
  108. renderExpanseBtn(propRecruitments, show) {
  109. if (_.isEmpty(propRecruitments)) {
  110. return null;
  111. }
  112. return (
  113. <div className="row">
  114. <div className="col-sm-12">
  115. <button
  116. className="btn btn-primary"
  117. style={{backgroundColor: '#14b1bb', borderColor: '#14b1bb', color: 'black!important'}}
  118. onClick={(e) => this.handleClick(show)}>
  119. {(show)
  120. ? <span>Rút ngọn <i className="fa fa-arrow-up"></i></span>
  121. : <span>Xem thêm <i className="fa fa-arrow-down"></i></span>
  122. }
  123. </button>
  124. </div>
  125. </div>
  126. )
  127. }
  128. componentWillMount () {
  129. this.postFilterOptions();
  130. }
  131.  
  132. render () {
  133. const { recruitments, show } = this.state;
  134. return (
  135. <div style={{marginBottom: 10}}>
  136. <h2>Tin tuyển dụng</h2>
  137. {this.renderList(recruitments, (show)? FULL_SIZE: SHOW_SIZE)}
  138. {this.renderExpanseBtn(recruitments, show)}
  139.  
  140. </div>
  141. )
  142. }
  143. }
  144.  
  145. export default ListRecruitment
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement