activeStaffs.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React, { Component } from 'react';
  2. import { getUsersDataById, deleteStaffById } from "../actions/getUserById"
  3. import { Link } from "react-router-dom";
  4. import { Icon } from 'antd';
  5. import { connect } from 'react-redux';
  6. import { bindActionCreators } from "redux";
  7. import Header from '../container/Header'
  8. import { stat } from 'fs';
  9. class activeStaffs extends Component {
  10. componentDidUpdate(prevProps){
  11. if(prevProps.del !== this.props.del){
  12. const { getUsersDataById } = this.props
  13. let localS = JSON.parse(localStorage.getItem("login"));
  14. if (localS === null) {
  15. }
  16. else {
  17. getUsersDataById(localS)
  18. }
  19. }
  20. }
  21. componentDidMount() {
  22. const { getUsersDataById } = this.props
  23. let localS = JSON.parse(localStorage.getItem("login"));
  24. if (localS === null) {
  25. }
  26. else {
  27. getUsersDataById(localS)
  28. }
  29. }
  30. deleteStaff = (id) => {
  31. const { deleteStaffById } = this.props
  32. var qs = require("querystring");
  33. var http = require("http");
  34. var options = {
  35. "method": "DELETE",
  36. "hostname": [
  37. "127.0.0.1:2000/api/staffs"
  38. ],
  39. "headers": {
  40. "Content-Type": "application/x-www-form-urlencoded",
  41. "cache-control": "no-cache",
  42. "mode":'cors'
  43. }
  44. };
  45. var req = http.request(options, function (res) {
  46. var chunks = [];
  47. res.on("data", function (chunk) {
  48. chunks.push(chunk);
  49. });
  50. res.on("end", function () {
  51. var body = Buffer.concat(chunks);
  52. deleteStaffById(body.toString());
  53. });
  54. });
  55. req.write(qs.stringify({ id: `${id}`, undefined: undefined }));
  56. req.end();
  57. }
  58. render() {
  59. const { getUser } = this.props
  60. const { name, id, del } = this.props
  61. const { staffs } = getUser
  62. return (
  63. <div >
  64. <Header name={name} getUser={getUser} id={id} />
  65. <div className="menuAndContent">
  66. <div className="contentStaffs">
  67. <div className="staffs">
  68. {staffs !== undefined && staffs.reverse().map((el, key) => <div className="staff" key={key}>
  69. {el.state ? <img src={el.img.substr(0, 53)} width="325" height="190" className="imgStaff" alt="lorem" /> : <img src={el.img} width="325" height="190" className="imgStaff" alt="lorem" />}
  70. <div className="titlleAndPrice">
  71. <h4>{el.title}</h4>
  72. <h4>Цена: {el.price}</h4>
  73. </div>
  74. <div className="titlleAndPrice">
  75. <Link to={`/activeStaffs/${el.id}`} className="allMyStaff">
  76. <Icon type="edit" style={{ fontSize: '30px' }} />
  77. </Link>
  78. <button className="Exit" onClick={() => this.deleteStaff(el.id)} >
  79. <Icon type="delete" style={{ fontSize: '30px' }} />
  80. </button>
  81. </div>
  82. </div>
  83. )}
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. );
  89. }
  90. }
  91. const mapStateToProps = state => ({
  92. getUser: state.getUserById.getUser,
  93. params: state.getUserById.params,
  94. del: state.getUserById.del
  95. });
  96. const mapDispatchToProps = dispatch => bindActionCreators({ getUsersDataById, deleteStaffById }, dispatch);
  97. export default activeStaffs = connect(
  98. mapStateToProps,
  99. mapDispatchToProps
  100. )(activeStaffs);