vit9 5 năm trước cách đây
mục cha
commit
06839b36ab

+ 0 - 4
src/actions/getStaffByIdAction.js

@@ -33,7 +33,3 @@ export const getStaffsDataById = (payload) => {
 	};
 };
 
-export const deleteStaffById = (payload) => {
-	console.log(payload)
-	axios.delete(`http://127.0.0.1:2000/api/staffs?id=${payload}`,).then(res => console.log(res))
-}

+ 4 - 0
src/actions/getUserById.js

@@ -38,3 +38,7 @@ export const getParams = payload => ({
     payload
 })
 
+export const deleteStaffById = (payload) => ({
+	type:types.DELETE_STAFF,
+	payload
+})

+ 1 - 2
src/common/authRenderField.js

@@ -1,8 +1,7 @@
 import React from "react";
 
 export const authRenderField = ({input, meta: {touched, error}, label, type, placeholder }) => (
-    <div className={touched && error ? "form__input-box":"error"}> 
-        {console.log(error)} 
+    <div className={touched && error ? "form__input-box":"error"}>  
         <label className="form__input-label" htmlFor="origin">
             {label}
             <input  className="input" type = {type} placeholder = {placeholder} {...input} />

+ 3 - 7
src/components/AllStaffs/FullInfoAboutStaff.js

@@ -1,7 +1,7 @@
-import React, { Component, Fragment } from 'react';
+import React, { Component } from 'react';
 
 import Loader from 'react-loader-spinner';
-import { Menu, Icon, Carousel } from 'antd';
+import { Carousel } from 'antd';
 
 class FullInfoAboutStaff extends Component {
     constructor(props) {
@@ -16,11 +16,8 @@ class FullInfoAboutStaff extends Component {
 
         const { InfoStaff, isFetching } = this.props
         let arr = [];
-        let str;
-
-        str = InfoStaff.map(el => {
-            console.log(el.state)
 
+        InfoStaff.map(el => {
             if (el.state) {
                 let str1 = el.img.substr(29)
 
@@ -53,7 +50,6 @@ class FullInfoAboutStaff extends Component {
                     <p><b>Контактное лицо: </b>{el.user.name}</p> 
                     <p><b>Номер телефона: </b>{el.user.phone}</p>
                 </div>
-                {console.log(el.user)}
             </div>
             )
             data1 = <div className="carusel">

+ 1 - 1
src/components/Btn/linkHome.js

@@ -1,4 +1,4 @@
-import React, { Component, Fragment } from 'react';
+import React, { Component } from 'react';
 
 import { Icon } from 'antd';
 import { Link } from "react-router-dom";

+ 1 - 1
src/components/FormsAdd/FormAddNewCategory/SendingCategoryForm.js

@@ -2,7 +2,7 @@ import React from 'react'
 import { Field, reduxForm } from 'redux-form'
 
 const SendingForm = props => {
-    const { handleSubmit, pristine, reset, submitting, AddNewCategory, allCategory, podcategory } = props
+    const { handleSubmit, pristine, reset, submitting, AddNewCategory, podcategory } = props
 
     const submit = values => {
         AddNewCategory(values)

+ 6 - 7
src/components/FormsAdd/FormAddNewStaff/SendingStaffForm.js

@@ -53,7 +53,7 @@ class SendingForm extends Component {
         const { pushPhoto, base643 } = this.props
         this.setState({ trig: true })
         let data = new FormData();
-        if (e.target.files[0] == undefined) {
+        if (e.target.files[0] === undefined) {
             return
         }
         data.append('image', e.target.files[0], e.target.files[0].name);
@@ -81,7 +81,6 @@ class SendingForm extends Component {
         values.staff = "Машина"
 
         values.userId = getUser.id
-        console.log(values)
         AddNewStaffAction(values)
 
     };
@@ -120,28 +119,28 @@ class SendingForm extends Component {
                         className="input"
                     >
                         <option >Выберите рубрику</option>
-                        {allCategory.map(el => <option value={el.id}> {el.title}</option>)}
+                        {allCategory.map((el,key) => <option value={el.id} key={key}> {el.title}</option>)}
                     </Field>
 
 
                     <div className="file">
                         <label className='upload-zone zone1'>
-                            {addOrnot ? <img src={base64Photo} style={{ "width": "80px", "height": "80px" }}></img> : <i>&nbsp;</i>}
+                            {addOrnot ? <img src={base64Photo} style={{ "width": "80px", "height": "80px" }} alt=""></img> : <i>&nbsp;</i>}
                             <input type='file' className='files' onChange={this.onChange} />
 
                         </label>
                         <label className='upload-zone zone2'>
-                            {addOrnot1 ? <img src={base64Photo1} style={{ "width": "80px", "height": "80px" }}></img> : <i>&nbsp;</i>}
+                            {addOrnot1 ? <img src={base64Photo1} style={{ "width": "80px", "height": "80px" }} alt=""></img> : <i>&nbsp;</i>}
                             <input type='file' className='files' onChange={this.onChange1} />
 
                         </label>
                         <label className='upload-zone zone3'>
-                            {addOrnot2 ? <img src={base64Photo2} style={{ "width": "80px", "height": "80px" }}></img> : <i>&nbsp;</i>}
+                            {addOrnot2 ? <img src={base64Photo2} style={{ "width": "80px", "height": "80px" }} alt=""></img> : <i>&nbsp;</i>}
                             <input type='file' className='files' onChange={this.onChange2} />
 
                         </label>
                         <label className='upload-zone zone4'>
-                            {addOrnot3 ? <img src={base64Photo3} style={{ "width": "80px", "height": "80px" }}></img> : <i>&nbsp;</i>}
+                            {addOrnot3 ? <img src={base64Photo3} style={{ "width": "80px", "height": "80px" }} alt=""></img> : <i>&nbsp;</i>}
                             <input type='file' className='files' onChange={this.onChange3} />
 
                         </label>

+ 1 - 1
src/components/FormsAdd/FormAddNewStaff/index.js

@@ -15,7 +15,7 @@ class FormAddNewStaff extends Component {
     }
     render() {
         
-        const { isFetching, AddNewStaffAction, allCategory, getUser, photo, pushPhoto, base64Photo, base64, addOrnot } = this.props
+        const { isFetching, allCategory } = this.props
         let data;
         if (allCategory.data===undefined){
             data = []

+ 12 - 19
src/components/FormsAdd/redForm/index.js

@@ -1,6 +1,6 @@
 import React, { Component } from 'react';
-import { Field, reduxForm } from 'redux-form';
-import { Link, Redirect } from "react-router-dom";
+import { reduxForm } from 'redux-form';
+
 import FormData from 'form-data'
 
 
@@ -10,16 +10,8 @@ class FormRedactorStaff extends  Component  {
         super(props)
        this.state = { trig:false }
     }
-    // componentDidUpdate(prevProps){
-    //     const {  match } = this.props
-    //     if(prevProps.InfoStaff[0].id !==this.props.InfoStaff[0].id ){
-    //         this.props.getStaffsDataById(this.props.InfoStaff[0].id)
-    //     }
-    //     console.log("prevProps.InfoStaff", prevProps.InfoStaff, "this.props.InfoStaff", this.props.InfoStaff)
-    // }
     onChange = e =>{
-        const { pushPhoto,photo } = this.props
-        //this.setState({image: e.target.files[0]})
+        const { pushPhoto } = this.props
         this.setState({trig:true})
         let data = new FormData();
         data.append('image',e.target.files[0], e.target.files[0].name);
@@ -46,7 +38,7 @@ class FormRedactorStaff extends  Component  {
         
     }
     send = () =>{
-        const { inputData, inputData1, inputData2, inputData3, match, photo, EditStaffAction, InfoStaff, getUser } = this.props  
+        const { inputData, inputData1, inputData2, inputData3, photo, EditStaffAction, InfoStaff, getUser } = this.props  
         let values = {}
         if(!this.state.trig){
             values.img = "http://rs.img.com.ua/crop?v2=1&w=600&h=0&url=%2F%2Fbm.img.com.ua%2Fberlin%2Fstorage%2Forig%2Fd224d3bd9bfe8bcb6b561da523d87364.jpg";
@@ -77,26 +69,27 @@ class FormRedactorStaff extends  Component  {
         }
           EditStaffAction(values)
         
-          //console.log(values)
+         
     }
     render(){
         
         
-         const { handleSubmit, pristine, reset, submitting, InfoStaff, photo, allCategory } = this.props
+         const { pristine, reset, submitting, InfoStaff, allCategory } = this.props
          
          const category = allCategory.data.filter(el => el.parentId !== 0)
          let data;
          
          
-            data = InfoStaff.map(el => <form  className="form">
+            data = InfoStaff.map((el,key) => <form  className="form" key={key}>
             <input type="text"  name="title" defaultValue ={el.title} className="input" onChange={this.changeHandler}/>
-            <textarea type="text"  name="description" defaultValue ={el.description} className="input" onChange={this.changeHandler1}/>
+            <textarea type="text"  name="description" defaultValue ={el.description} className="textarea" onChange={this.changeHandler1}/>
             <input type="number"  name="price" defaultValue ={el.price} className="input" onChange={this.changeHandler2}/>
             <select type="number"  name="categoryId"  className="input" defaultValue ={el.categoryId} onChange={this.changeHandler3}>
 
               <option >Выберите рубрику</option>
                     {category.map(el => <option value={el.id}> {el.title}</option>)}
                 </select>         
+                        <div className="file">
                             <label className='upload-zone'>
                                <i>&nbsp;</i>
                                 <input type='file' className='files'  onChange={this.onChange}/>
@@ -117,15 +110,15 @@ class FormRedactorStaff extends  Component  {
                                 <input type='file' className='files'  onChange={this.onChange}/>
                                 
                             </label>
-                            
+                        </div>   
                         
                
                 <div className="buttonConteiner">
                 <button type="button" className="button" onClick={this.send}>
-                        Submit
+                Добавить
                     </button>
                    <button type="button" disabled={pristine || submitting} onClick={reset} className="button" >
-                        Clear Values
+                        Очистить
                     </button>
                    
                 </div>

+ 1 - 1
src/components/Header/Myprofile.js

@@ -10,7 +10,7 @@ class Myprofile extends Component {
         let localS = JSON.parse(localStorage.getItem("login"));
         let data;
 
-        if(!name && !getUser.name || localS===null){
+        if((!name && !getUser.name) || localS===null){
 
             data = <Link to="/auth" className="link">
                 <div className="header__auth__container">

+ 48 - 13
src/components/SearchStaffsPage/SearchFullInfoStaff.js

@@ -1,28 +1,63 @@
 import React, { Component } from 'react';
 import Loader from 'react-loader-spinner'
+import { Carousel } from 'antd';
+
 class SearchFullInfoStaff extends Component {
     render() {
         
         const { fullInfoSearchData, isFetching } = this.props
+        let arr = [];
+        
+
+        fullInfoSearchData.map(el => {
+            if (el.state) {
+                let str1 = el.img.substr(29)
 
+                for (var i = 0, b = 24; i < str1.length; i = i + 25) {
+                    arr.push({ newStr: str1.substr(i, b), state: el.state, defaultStr: el.img })
+                }
+            } else {
+                arr.push({ state: el.state, defaultStr: el.img })
+            }
+
+        })
+        let data1
         let data;
-            if(isFetching===true){
-                data = <div className="loader"> 
+        if (isFetching === true) {
+            data = <div className="loader">
                 <Loader type="Triangle"
                     color="#FD7F71"
-                    height="100"	
+                    height="100"
                     width="100"
-                /> 
-            </div> 
-            }
-            else {
-                data = fullInfoSearchData.map((el,key)=>(<div key={key}> {el.title} {el.price} {el.description} </div>)
-                    )
-            } 
+                />
+            </div>
+        } else {
+            data = fullInfoSearchData.map((el, key) => <div className="divCenter">
+                <div className="flex-around">
+                    <p><b>Название: </b>{el.title} </p>
+                    <p><b>Цена: </b>{el.price}</p>
+                    <p><b>Описание: </b>{el.description}</p>
+                    <p><b>Контактное лицо: </b>{el.user.name}</p> 
+                    <p><b>Номер телефона: </b>{el.user.phone}</p>
+                </div>
+            </div>
+            )
+            data1 = <div className="carusel">
+                <Carousel effect="fade">
+                    {arr.map(el => <div>
+                        {el.state ? <img src={`http://127.0.0.1:2000/static/${el.newStr}`} className="fullImgStaff" alt="lorem" /> :
+                            <img src={`${el.defaultStr}`} width="325" height="190" className="imgStaff" alt="lorem" />}
+                    </div>)}
+                </Carousel>
+            </div>
+        }
+
+
         return (
-            <div>
-                 {data}  
-                    
+
+            <div className="staffinfo" >
+                {data1}
+                {data}
             </div>
         );
     }

+ 10 - 4
src/components/SearchStaffsPage/index.js

@@ -20,9 +20,15 @@ class searchStaffs extends Component {
             else{
                 data = <div className="staffs">
                       {searchData.map((el,key)=>(
-                      <Link to = {`/search/Staff/${el.id}`}  key={key}  >
-                        <div className="staff" > {el.title} {el.price}  <img src={el.img} width="325" height="190" className="imgStaff"  alt="lorem" /></div>
-                      </Link> 
+                      <Link to={`/search/Staff/${el.id}`}  key={key}>
+                      <div className="staff">
+                      {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" />}
+                          <div className="titlleAndPrice">
+                              <h4>{el.title}</h4>
+                              <h4>Цена: {el.price}</h4>
+                          </div>
+                      </div>
+                      </Link>
                                                 )
                                     )}
                       </div>
@@ -38,4 +44,4 @@ class searchStaffs extends Component {
 }
 
 
-export default searchStaffs;
+export default searchStaffs;

+ 4 - 1
src/constants/actionTypes.js

@@ -78,4 +78,7 @@
     export const USER_AUTH_REQUEST_BY_ID = "USER_AUTH_REQUEST_BY_ID";
     export const USER_AUTH_REQUEST_SUCCESS_BY_ID = "USER_AUTH_REQUEST_SUCCESS_BY_ID";
     export const USER_AUTH_REQUEST_FAIL_BY_ID = "USER_AUTH_REQUEST_FAIL_BY_ID";
-    export const GET_PARAMS = "GET_PARAMS";
+    export const GET_PARAMS = "GET_PARAMS";
+
+
+    export const DELETE_STAFF = "DELETE_STAFF"

+ 3 - 2
src/container/AddNewCategory.js

@@ -6,7 +6,7 @@ import * as actions from '../actions/addNewCategoryAction';
 import { bindActionCreators } from 'redux';
 
 import FormAddNewCategory from '../components/FormsAdd/FormAddNewCategory';
-import EditModal from '../components/Modal';
+import EditModal from '../components/Modal/addNewStaffModal';
 
 
 class AddNewCategory extends Component {
@@ -18,7 +18,7 @@ class AddNewCategory extends Component {
 
     render() {
         const { AddNewCategory, isFetching, showModal, error } = this.props
-        
+        const str = "Не все поля были заполнены или заполнены не верно"
         return(
             <div>
                 <div>
@@ -30,6 +30,7 @@ class AddNewCategory extends Component {
                     onOk={this.closeEditModal}
                     onCancel={this.closeEditModal}
                     error={error}
+                    str={ str }
                 />
             </div>      
         )

+ 0 - 1
src/container/UserProfile.js

@@ -38,7 +38,6 @@ class UserProfile extends Component {
     render() {
 
         const { getUser } = this.props
-        const { staffs } = this.props.getUser
 
         return (
 

+ 54 - 9
src/container/activeStaffs.js

@@ -1,19 +1,32 @@
 import React, { Component } from 'react';
 
-import { getUsersDataById } from "../actions/getUserById"
-import { deleteStaffById } from "../actions/getStaffByIdAction"
+import { getUsersDataById, deleteStaffById } from "../actions/getUserById"
+
 import { Link } from "react-router-dom";
-import { Menu, Icon, Carousel } from 'antd';
+import { Icon } from 'antd';
 import { connect } from 'react-redux';
 
 import { bindActionCreators } from "redux";
 
 import Header from '../container/Header'
+import { stat } from 'fs';
+
 
-const axios = require('axios')
 
 class activeStaffs extends Component {
- 
+    componentDidUpdate(prevProps){   
+        if(prevProps.del !== this.props.del){
+            const { getUsersDataById } = this.props
+
+        let localS = JSON.parse(localStorage.getItem("login"));
+        if (localS === null) {
+
+        }
+        else {
+            getUsersDataById(localS)
+        }
+        }
+    }
     componentDidMount() {
         const { getUsersDataById } = this.props
 
@@ -26,14 +39,45 @@ class activeStaffs extends Component {
         }
     }
     deleteStaff = (id) => {
-        axios.delete(`http://127.0.0.1:2000/api/staffs`, id).then(res => console.log(res))
+        const { deleteStaffById } = this.props
+        var qs = require("querystring");
+var http = require("http");
+
+var options = {
+  "method": "DELETE",
+  "hostname": [
+   "127.0.0.1:2000/api/staffs"
+  ],
+  "headers": {
+    "Content-Type": "application/x-www-form-urlencoded",
+    "cache-control": "no-cache",
+    "mode":'cors'
+  }
+};
+
+var req = http.request(options, function (res) {
+  var chunks = [];
+
+  res.on("data", function (chunk) {
+    chunks.push(chunk);
+  });
+
+  res.on("end", function () {
+    var body = Buffer.concat(chunks);
+    deleteStaffById(body.toString());
+  });
+});
+
+req.write(qs.stringify({ id: `${id}`, undefined: undefined }));
+req.end();
     }
     render() {
 
-        const { getUser, deleteStaffById } = this.props
-        const { name, isAdmin, id } = this.props
+        const { getUser } = this.props
+        const { name, id, del } = this.props
         const { staffs } = getUser
-
+        
+        
         return (
             <div >
                 <Header name={name} getUser={getUser} id={id} />
@@ -69,6 +113,7 @@ class activeStaffs extends Component {
 const mapStateToProps = state => ({
     getUser: state.getUserById.getUser,
     params: state.getUserById.params,
+    del: state.getUserById.del
 
 });
 

+ 2 - 5
src/container/redactorForm.js

@@ -11,10 +11,8 @@ import { bindActionCreators } from "redux";
 class redactorForm extends Component {
     // componentDidUpdate(prevProps){
     //     const {getStaffsDataById, match } = this.props
-    //     console.log(prevProps.match.params.id, match.params.id)
-    //     if(prevProps.match.params.id !==match.params.id ){
-    //         getStaffsDataById(match.params.id)
-    //     }
+    //     console.log(prevProps, this.props)
+        
     // }
     componentDidMount(){
         const { getStaffsDataById, match, getUsersDataById } = this.props
@@ -40,7 +38,6 @@ class redactorForm extends Component {
             data = []
         }
         else{ 
-            const category = allCategory.data.filter(el => el.parentId !== 0)
             data = <Fragment>
             <FormRedactorStaff {...this.props}/>  
             <EditModal visible={this.props.showModal}

+ 1 - 1
src/container/renderRegistration.js

@@ -1,4 +1,4 @@
-import React, { Component, Fragment } from "react";
+import React, { Component } from "react";
 import { bindActionCreators } from "redux";
 import { connect } from 'react-redux';
 

+ 12 - 3
src/reducer/getUserById.js

@@ -4,7 +4,8 @@ const initState = {
     getUser: [],
     isFetching: false,
     error: null,
-    params: null
+    params: null,
+    del: ""
     
   };
 
@@ -22,7 +23,8 @@ export default (state = initState, {type, payload} ) => {
             return {
                 ...state,
                 getUser: payload.data,
-                isFetching: false
+                isFetching: false,
+                del: ""
             }
         }
         case types.USER_AUTH_REQUEST_FAIL_BY_ID: {
@@ -38,7 +40,14 @@ export default (state = initState, {type, payload} ) => {
                 params: payload
             }
         }
-        
+        case types.DELETE_STAFF: {
+            return {
+            ...state,
+            isFetching: false,
+            error: "ERROR",
+            del: payload
+            }
+          }
         default: return state;
 
     }

+ 10 - 1
src/reducer/staffsById.js

@@ -5,7 +5,8 @@ import * as types from "../constants/actionTypes";
 const initState = {
     infoStaffs: [],
     isFetching: false,
-    error: null
+    error: null,
+    
   };
 
   export default (state = initState, { type, payload }) => {
@@ -32,6 +33,14 @@ const initState = {
           error: "ERROR"
           }
         }
+        case types.DELETE_STAFF: {
+          return {
+          ...state,
+          isFetching: false,
+          error: "ERROR",
+          del: payload
+          }
+        }
         default: return state;    
     }
   };

+ 1 - 1
src/reducer/usersRegistration.js

@@ -8,7 +8,7 @@ const initState = {
   };
 
   export default (state = initState, { type, payload }) => {
-    console.log(payload)
+    
       switch (type) {
         case types.USER_REG_REQUEST: {
           return {

+ 2 - 4
src/router.js

@@ -27,19 +27,18 @@ import { getUsersDataById } from "./actions/getUserById"
 
 import { getUsersData } from './actions/usersAuthActions'
 
-import addCategory from './components/privateRouterComponents/addCategoryIfAdmin'
+
 
 class Router extends Component {
 
    render() {
        
-       const { inputData, trig, params} = this.props
+       const { inputData, params} = this.props
       
        return (
     <Fragment>
 	    <Switch>
             <PrivateRoute path="/"   data= { inputData } params = {params} exact component={MainPage} />
-            {/* <Route path="/" exact component={MainPage} /> */}
             <Route path="/user/:id" exact component={userProfile} />
             <Route path="/authorisation" exact component={RenderAuthorisation} />
             <Route path="/auth" exact component= {RenderAuthorisation}/>
@@ -61,7 +60,6 @@ class Router extends Component {
 
 const mapStateToProps = state => ({
     inputData: state.usersAuth.inputData,
-    trig: state.usersAuth.trig,
     params: state.getUserById.params,
 })
 const mapDispatchToProps = dispatch => bindActionCreators({ getUsersData, getUsersDataById }, dispatch);

+ 4 - 4
src/style/components/_form.scss

@@ -124,7 +124,7 @@ input[type=number]::-webkit-outer-spin-button {
   cursor: pointer;
   position: absolute;
   left: 38%;
-  top: 70%;
+  top: 66%;
     -webkit-transform: translate(-50%, -50%);
     -ms-transform: translate(-50%, -50%);
     -moz-transform: translate(-50%, -50%);
@@ -258,17 +258,17 @@ input[type=number]::-webkit-outer-spin-button {
   
 .zone2{
   left: 46%;
-  top: 70%;
+  top: 66%;
 }
   
 .zone3{
   left: 54%;
-  top: 70%;
+  top: 66%;
 }
 
 .zone4{
   left: 62%;
-  top: 70%;
+  top: 66%;
 }
    
 //Page auth