Mila-Zagrevskaya 5 lat temu
rodzic
commit
bc3fa53959

+ 4 - 4
db.json

@@ -380,7 +380,7 @@
                 "id": 6
             }
   ],
-  
+
   "services": [
     {
       "name": "Первичное эндодонтическое лечение зуба",
@@ -503,7 +503,7 @@
       "price": 19800
     },
   
-  
+
     {
       "name": "Удаление зуба",
       "duration": 1,
@@ -522,8 +522,8 @@
       "description": "Хирургия",
       "price": 2350
     },
-  
-  
+
+
     {
       "name": "Пластика десны (в области 1-3 зубов)",
       "duration": 2,

+ 7 - 1
src/App.js

@@ -2,7 +2,8 @@ import React from 'react';
 import {connect} from 'react-redux';
 import {Switch} from "react-router-dom";
 
-import {getDoctors, getServices} from "./actions/actions";
+import {getDoctors} from "./actions/actions";
+import {getServices, getCategories} from "./actions/services";
 import {getUser} from "./actions/auth"
 
 import Loader from "./components/hooks/loader";
@@ -18,7 +19,11 @@ export class App extends React.Component {
     componentDidMount() {
         this.props.getDoctors();
         this.props.getServices();
+<<<<<<< HEAD
         console.log(this.props.app)
+=======
+        this.props.getCategories();
+>>>>>>> ffc22fefa05d985c41e67b265e33a56a26cd6bfe
 
        if(localStorage.getItem('userId')) this.props.getUser()
 
@@ -67,6 +72,7 @@ const mapStateToProps = state => {
 const mapDispatchToProps = {
     getDoctors,
     getServices,
+    getCategories,
     getUser
 };
 

+ 26 - 93
src/actions/actions.js

@@ -33,43 +33,8 @@ export const changeSelectedServiceId = payload => ({
 
 // -----------------------------------------------------------------------------------------------------------------
 
-export const setAppointmentShedule = payload => ({
-    type: types.CHANGE_APPOINTMENT_SHEDULE,
-    payload
-});
-
-// -----------------------------------------------------------------------------------------------------------------
-
-export const setAppointmentDoctor = payload => ({
-    type: types.CHANGE_APPOINTMENT_DOCTOR,
-    payload
-});
-
-// -----------------------------------------------------------------------------------------------------------------
-
-export const setAppointmentTime = payload => ({
-    type: types.CHANGE_APPOINTMENT_TIME,
-    payload
-});
-
-// -----------------------------------------------------------------------------------------------------------------
-
-export const setAppointmentSpec = payload => ({
-    type: types.CHANGE_APPOINTMENT_SPEC,
-    payload
-});
-
-// -----------------------------------------------------------------------------------------------------------------
-
-export const setAppointmentComment = payload => ({
-    type: types.CHANGE_APPOINTMENT_COMMENT,
-    payload
-});
-
-// -----------------------------------------------------------------------------------------------------------------
-
-export const clearAppointment = payload => ({
-    type: types.CLEAR_APPOINTMENT,
+export const changeSpecialityArray = payload => ({
+    type: types.CHANGE_SPECIALITY_ARRAY,
     payload
 });
 
@@ -111,30 +76,30 @@ export const getDoctors = () => dispatch => {
 
 // -----------------------------------------------------------------------------------------------------------------
 
-const getServicesRequest = payload => ({
-    type: types.GET_SERVICES_REQUEST,
-    payload
-});
-
-const getServicesRequestSuccess = payload => ({
-    type: types.GET_SERVICES_REQUEST_SUCCESS,
-    payload
-});
-
-const getServicesRequestFail = payload => ({
-    type: types.GET_SERVICES_REQUEST_FAIL,
-    payload
-});
-
-export const getServices = () => dispatch => {
-    dispatch(getServicesRequest());
-    return fetch(`${URL}services`,{
-        credentials:"include"
-    })
-        .then(res => res.json())
-        .then(res => dispatch(getServicesRequestSuccess(res)))
-        .catch(err => dispatch(getServicesRequestFail(err)));
-};
+// const getServicesRequest = payload => ({
+//     type: types.GET_SERVICES_REQUEST,
+//     payload
+// });
+//
+// const getServicesRequestSuccess = payload => ({
+//     type: types.GET_SERVICES_REQUEST_SUCCESS,
+//     payload
+// });
+//
+// const getServicesRequestFail = payload => ({
+//     type: types.GET_SERVICES_REQUEST_FAIL,
+//     payload
+// });
+//
+// export const getServices = () => dispatch => {
+//     dispatch(getServicesRequest());
+//     return fetch(`${URL}services`,{
+//         credentials:"include"
+//     })
+//         .then(res => res.json())
+//         .then(res => dispatch(getServicesRequestSuccess(res)))
+//         .catch(err => dispatch(getServicesRequestFail(err)));
+// };
 
 // -----------------------------------------------------------------------------------------------------------------
 // -----------------------------------------------------------------------------------------------------------------
@@ -233,38 +198,6 @@ export const postShedule = (payload) => dispatch => {
         .catch(err => dispatch(postSheduleFail(err)));
 };
 
-// -----------------------------------------------------------------------------------------------------------------
-
-const postOrdersRequest = payload => ({
-    type: types.POST_ORDERS_REQUEST,
-    payload
-});
-
-const postOrdersSuccess = payload => ({
-    type: types.POST_ORDERS_REQUEST_SUCCESS,
-    payload
-});
-
-const postOrdersFail = payload => ({
-    type: types.POST_ORDERS_REQUEST_FAIL,
-    payload
-});
-
-export const postOrders = (payload) => dispatch => {
-    dispatch(postOrdersRequest());
-    return fetch(`${URL}orders`, {
-        method: "POST",
-        credentials:"include",
-        headers: {
-            'Content-Type': 'application/json'
-        },
-        body: JSON.stringify(payload)
-    })
-        .then(res => res.json())
-        .then(res => dispatch(postOrdersSuccess(res)))
-        .catch(err => dispatch(postOrdersFail(err)));
-};
-
 // -----------------------------------------------------------------------------------------------------------------
 // -----------------------------------------------------------------------------------------------------------------
 

+ 86 - 0
src/actions/appointment.js

@@ -0,0 +1,86 @@
+import * as types from "../actionsTypes/actionsTypes";
+
+const URL = "https://api-clinics.herokuapp.com/api/v1/";
+
+export const setAppointmentShedule = payload => ({
+    type: types.CHANGE_APPOINTMENT_SHEDULE,
+    payload
+});
+
+// -----------------------------------------------------------------------------------------------------------------
+
+export const setAppointmentDoctor = payload => ({
+    type: types.CHANGE_APPOINTMENT_DOCTOR,
+    payload
+});
+
+// -----------------------------------------------------------------------------------------------------------------
+
+export const setAppointmentTime = payload => ({
+    type: types.CHANGE_APPOINTMENT_TIME,
+    payload
+});
+
+// -----------------------------------------------------------------------------------------------------------------
+
+export const setAppointmentSpec = payload => ({
+    type: types.CHANGE_APPOINTMENT_SPEC,
+    payload
+});
+
+// -----------------------------------------------------------------------------------------------------------------
+
+export const setAppointmentComment = payload => ({
+    type: types.CHANGE_APPOINTMENT_COMMENT,
+    payload
+});
+
+// -----------------------------------------------------------------------------------------------------------------
+
+export const clearAppointment = payload => {
+    localStorage.removeItem('appointment');
+     return  {
+         type: types.CLEAR_APPOINTMENT,
+         payload
+     }
+};
+
+// -----------------------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------------------------------------------
+
+const postOrdersRequest = payload => ({
+    type: types.POST_ORDERS_REQUEST,
+    payload
+});
+
+// -----------------------------------------------------------------------------------------------------------------
+
+const postOrdersSuccess = payload => ({
+    type: types.POST_ORDERS_REQUEST_SUCCESS,
+    payload
+});
+
+// -----------------------------------------------------------------------------------------------------------------
+
+const postOrdersFail = payload => ({
+    type: types.POST_ORDERS_REQUEST_FAIL,
+    payload
+});
+
+// -----------------------------------------------------------------------------------------------------------------
+
+export const postOrders = (payload) => dispatch => {
+    dispatch(postOrdersRequest());
+    return fetch(`${URL}orders`, {
+        method: "POST",
+        credentials:"include",
+        headers: {
+            'Content-Type': 'application/json'
+        },
+        body: JSON.stringify(payload)
+    })
+        .then(res => res.json())
+        .then(res => dispatch(postOrdersSuccess(res)))
+        .then(dispatch(clearAppointment()))
+        .catch(err => dispatch(postOrdersFail(err)));
+};

+ 55 - 0
src/actions/services.js

@@ -0,0 +1,55 @@
+import * as types from "../actionsTypes/actionsTypes";
+
+const URL = "https://api-clinics.herokuapp.com/api/v1/";
+
+const getServicesRequest = payload => ({
+    type: types.GET_SERVICES_REQUEST,
+    payload
+});
+
+const getServicesRequestSuccess = payload => ({
+    type: types.GET_SERVICES_REQUEST_SUCCESS,
+    payload
+});
+
+const getServicesRequestFail = payload => ({
+    type: types.GET_SERVICES_REQUEST_FAIL,
+    payload
+});
+
+export const getServices = () => dispatch => {
+    dispatch(getServicesRequest());
+    return fetch(`${URL}services`,{
+        credentials:"include"
+    })
+        .then(res => res.json())
+        .then(res => dispatch(getServicesRequestSuccess(res)))
+        .catch(err => dispatch(getServicesRequestFail(err)));
+};
+
+
+
+const getCategoriesRequest = payload => ({
+    type: types.GET_CATEGORIES_REQUEST,
+    payload
+});
+
+const getCategoriesRequestSuccess = payload => ({
+    type: types.GET_CATEGORIES_REQUEST_SUCCESS,
+    payload
+});
+
+const getCategoriesRequestFail = payload => ({
+    type: types.GET_CATEGORIES_REQUEST_FAIL,
+    payload
+});
+
+export const getCategories = () => dispatch => {
+    dispatch(getCategoriesRequest());
+    return fetch(`${URL}category`,{
+        credentials:"include"
+    })
+        .then(res => res.json())
+        .then(res => dispatch(getCategoriesRequestSuccess(res)))
+        .catch(err => dispatch(getCategoriesRequestFail(err)));
+};

+ 5 - 1
src/actionsTypes/actionsTypes.js

@@ -6,6 +6,10 @@ export const GET_SERVICES_REQUEST = "GET_SERVICES_REQUEST";
 export const GET_SERVICES_REQUEST_SUCCESS = "GET_SERVICES_REQUEST_SUCCESS";
 export const GET_SERVICES_REQUEST_FAIL = "GET_SERVICES_REQUEST_FAIL";
 
+export const GET_CATEGORIES_REQUEST = "GET_CATEGORIES_REQUEST";
+export const GET_CATEGORIES_REQUEST_SUCCESS = "GET_CATEGORIES_REQUEST_SUCCESS";
+export const GET_CATEGORIES_REQUEST_FAIL = "GET_CATEGORIES_REQUEST_FAIL";
+
 export const CHANGE_APPOINTMENT_SHEDULE= "CHANGE_APPOINTMENT_SHEDULE";
 export const CHANGE_APPOINTMENT_DOCTOR= "CHANGE_APPOINTMENT_DOCTOR";
 export const CHANGE_APPOINTMENT_TIME= "CHANGE_APPOINTMENT_TIME";
@@ -63,9 +67,9 @@ export const CHANGE_SHEDULE_DOCTOR= "CHANGE_SHEDULE_DOCTOR";
 
 export const CHANGE_INPUT_VALUE_DOCTOR_FORM= "CHANGE_INPUT_VALUE_DOCTOR_FORM";
 export const CHANGE_INPUT_VALUE_SERVICE_FORM= "CHANGE_INPUT_VALUE_SERVICE_FORM";
-
 export const CHANGE_SELECTED_DOCTOR_ID= "CHANGE_SELECTED_DOCTOR_ID";
 export const CHANGE_SELECTED_SERVICE_ID= "CHANGE_SELECTED_SERVICE_ID";
+export const CHANGE_SPECIALITY_ARRAY= "CHANGE_SPECIALITY_ARRAY";
 
 export const CREATE_CALENDAR_MONTH_ARRAY= "CREATE_CALENDAR_MONTH_ARRAY";
 export const CHANGE_CALENDAR_MONTH= "CHANGE_CALENDAR_MONTH";

+ 22 - 8
src/components/Admin/Admin.js

@@ -14,7 +14,8 @@ import {
     deleteDoctors,
     postServices,
     putServices,
-    deleteServices
+    deleteServices,
+    changeSpecialityArray
 } from "../../actions/actions";
 
 import Shedule from './Shedule'
@@ -27,14 +28,13 @@ export class Admin extends React.Component {
     render() {
         const {
             doctors,
-            services,
             postNewShedule,
             postNewDoctor,
             postNewService,
             changeDoctorId,
-            changeServiceId
-        } = this.props.app;
-        const {
+            changeServiceId,
+            services,
+            categories,
             setSheduleDoctor,
             postShedule,
             changeInputValueDoctorForm,
@@ -46,7 +46,9 @@ export class Admin extends React.Component {
             deleteDoctors,
             putServices,
             deleteServices,
-            postServices
+            postServices,
+            changeSpecialityArray,
+            specialityArray
         } = this.props;
 
         return (
@@ -65,7 +67,9 @@ export class Admin extends React.Component {
                             postShedule={postShedule}
                         />} />
                         <Route path='/admin/change-doctors' render={() => <ChangeServicesDoctors
+                            categories={categories}
                             data={doctors}
+                            specialityArray={specialityArray}
                             itemId={changeDoctorId}
                             changeId={changeSelectedDoctorId}
                             form={postNewDoctor}
@@ -73,6 +77,7 @@ export class Admin extends React.Component {
                             putItem={putDoctors}
                             deleteItem={deleteDoctors}
                             changeInputValues={changeInputValueDoctorForm}
+                            changeSpecialityArray={changeSpecialityArray}
                         />} />
                         <Route path='/admin/change-services' render={() => <ChangeServicesDoctors
                             data={services}
@@ -93,7 +98,15 @@ export class Admin extends React.Component {
 
 const mapStateToProps = state => {
     return {
-        app:state.app,
+        doctors:state.app.doctors,
+        postNewShedule:state.app.postNewShedule,
+        postNewDoctor:state.app.postNewDoctor,
+        postNewService:state.app.postNewService,
+        changeDoctorId:state.app.changeDoctorId,
+        changeServiceId:state.app.changeServiceId,
+        specialityArray:state.app.specialityArray,
+        services: state.services.services,
+        categories: state.services.categories
     }
 };
 
@@ -109,7 +122,8 @@ const mapDispatchToProps = {
     deleteDoctors,
     postServices,
     putServices,
-    deleteServices
+    deleteServices,
+    changeSpecialityArray
 };
 
 export default connect (mapStateToProps,mapDispatchToProps)(Admin)

+ 62 - 42
src/components/Admin/ChangeServices-Doctors.js

@@ -1,25 +1,48 @@
 import React from 'react';
 import Input from './Input'
+import CheckBoxWindow from "./CheckBoxWindow";
 
 export default class ChangeServicesDoctors extends React.Component {
+    state = {
+        flag: false,
+    };
+
+    componentDidUpdate(prevProps) {
+        if (this.props.data !== prevProps.data) this.setState({flag: false})
+    };
+
+    changeFlag = (e) => {
+        e.preventDefault();
+        this.setState({flag: !this.state.flag})
+    };
 
     postNewItem = (e) => {
         const obj = {};
         e.preventDefault();
+        // eslint-disable-next-line array-callback-return
         this.props.form.map(el => {
             obj[el.name] = el.value
         });
-        this.props.postItem(obj)
+        this.props.postItem(this.props.categories? {
+            ...obj,
+            speciality:this.props.specialityArray
+        } : obj)
     };
 
     changeItem = (e) => {
         const obj = {};
         e.preventDefault();
+        // eslint-disable-next-line array-callback-return
         this.props.form.map(el => {
-            if (el.value !== '')
-                obj[el.name] = el.value
+            if (el.value !== '') obj[el.name] = el.value
         });
-        this.props.putItem({data:obj,id:this.props.itemId})
+        this.props.putItem({
+            data: this.props.categories? {
+                ...obj,
+                speciality:this.props.specialityArray
+            } : obj,
+            id: this.props.itemId
+        })
 
     };
 
@@ -28,71 +51,68 @@ export default class ChangeServicesDoctors extends React.Component {
     };
 
     changeId = (e) => {
-        this.props.changeId(e.target.value)
+        this.props.changeId({
+            item: e.target.value,
+            data: this.props.data
+        })
     };
 
     render() {
         const {
+            categories,
             data,
             itemId,
             form,
             changeInputValues,
+            changeSpecialityArray,
+            specialityArray
         } = this.props;
+        let doctor = data.find(el => el._id === itemId);
+        if (doctor) doctor = doctor.speciality;
+        console.log(data,specialityArray)
         return (
-            <div className = "change-services-doctors">
+            <div className="change-services-doctors">
+                {this.state.flag &&
+                <CheckBoxWindow categories={categories} specialityArray={specialityArray} changeFlag={this.changeFlag} changeSpecialityArray={changeSpecialityArray}/>}
                 <div className="admin-item">
-                    <form className ="form-doctors" onSubmit={this.postNewItem}>
+                    <form className="form-doctors" onSubmit={itemId ? this.changeItem : this.postNewItem}>
                         {
-                            form.map(el => (
-                                <Input
-                                    key={el.id}
-                                    id={el.id}
-                                    el={el}
-                                    changeInputValues={changeInputValues}
-                                />
-                            ))
+                            form.map(el => {
+                                el.required = !itemId;
+                                    return (
+                                        <Input
+                                            key={el.id}
+                                            id={el.id}
+                                            el={el}
+                                            changeInputValues={changeInputValues}
+                                        />
+                                    )
+                            })
                         }
-                        <input className = "btn link"
+                        {categories && <button onClick={this.changeFlag}>Choose Services</button>}
+                        <input className="btn link"
                                type='submit'
-                               value='Добавить '
+                               value={itemId ? 'Изменить'  : 'Добавить'}
                         />
                     </form>
                 </div>
                 <div className="admin-item">
-                    <select  className = "appointment admin-form"  onChange={this.changeId} defaultValue='Выбрать'>
-                        <option disabled >Выбрать</option>
+                    <select className="appointment admin-form" onChange={this.changeId} defaultValue='Выбрать'>
+                        <option >Выбрать</option>
                         {
-                            data.map(el=> (
+                            data.map(el => (
                                 <option key={el._id}>{el.name}</option>
                             ))
                         }
                     </select>
 
-                    <form  onSubmit={this.props.changeItem}>
-                        {itemId &&
-                            form.map(el => {
-                                el.required = false;
-                                return (
-                                    <Input
-                                        key={el.id}
-                                        id={el.id}
-                                        el={el}
-                                        changeInputValues={changeInputValues}
-                                    />
-                                )
-                            })
-                        }
-                        <input
-                            className = "btn link"
-                            type='submit'
-                            value='Изменить выбранный элемент'
-                        />
-                    </form>
+
                     {itemId &&
-                    <button className = "btn link" onClick={this.deleteItem} style={{backgroundColor:"#ff9774"}}>Удалить выбранный элемент</button>
+                    <button className="btn link" onClick={this.deleteItem} style={{backgroundColor: "#ff9774"}}>Удалить
+                        выбранный элемент</button>
                     }
                 </div>
             </div>
         );
     }
-}
+}

+ 67 - 0
src/components/Admin/CheckBoxWindow.js

@@ -0,0 +1,67 @@
+import React from 'react';
+
+
+class CheckBoxWindow extends React.Component {
+    changeSpecialityArray = (e) => {
+        this.props.changeSpecialityArray(e.target)
+    };
+
+    render() {
+        const {categories, changeFlag,specialityArray} = this.props;
+        return (
+            <>
+                <div style={{
+                    position: 'fixed',
+                    right: '0',
+                    left: '0',
+                    display: 'flex',
+                    justifyContent:'center',
+                    backgroundColor: 'black',
+                    margin: '5% auto',
+                    width: '80%',
+                    fontSize: '12px',
+                    zIndex: '2'
+                }}>
+                    {categories.map(el => (
+                        <div key={el._id} style={{
+                            display: 'flex',
+                            flexDirection: 'column',
+                            wrap: 'nowrap',
+                            textAlign:'start',
+                            width:'20%'
+                        }}>
+                            <p>{el.name}</p>
+                            {
+                                el.services.map(item => (
+                                    <div key={item._id} >
+                                        <label>
+                                            <input
+                                                type="checkbox"
+                                                value={item._id}
+                                                defaultChecked={specialityArray.find(el => el === item._id)}
+                                                onChange={this.changeSpecialityArray}
+                                            />
+                                            {item.name}
+                                        </label>
+                                    </div>
+                                ))
+                            }
+                        </div>
+                    ))
+                    }
+                </div>
+                <div style={{
+                    position: 'fixed',
+                    top: '0',
+                    left: "0",
+                    width: '100%',
+                    height: '100%',
+                    backgroundColor: 'black',
+                    opacity: '0.5'
+                }} onClick={changeFlag}></div>
+            </>
+        )
+    }
+}
+
+export default CheckBoxWindow;

+ 12 - 63
src/components/Reviews.js

@@ -1,75 +1,24 @@
 import React from 'react';
 // import {Link} from 'react-router-dom';
 // import Button from "../buttons/button";
-// import { postServices} from "../../store/app/actions";
-import {connect} from 'react-redux'
-import {
-    changeInputValueDoctorForm,
-} from "../actions/actions";
-
-
 
 export class Reviews extends React.Component {
-    render( ) {
-        const {postNewDoctor,doctors,servicesArray} = this.props.app
-        const servArray =  Object.keys(servicesArray).map(key => {
-            return [key, servicesArray[key]];
-        })
-        let doctor
-        if (doctors[0]) {
-            doctor = doctors[2].speciality
-        }
-        console.log(doctor)
-        console.log(servArray)
 
+    render() {
         return (
-           <div style={{display:'flex',margin:'100px 5px'}}>
-               {doctor &&
-                   servArray.map(el => (
-                       <div key={[el[0]]}>
-                           <p>{el[0]}</p>
-
-                            {
-                                el[1].map(item => (
-                                    <div key={item._id} style={{display:'flex',margin:'5px 5px',flexDirection:'column',width:'200px'}}>
-                                        <label >
-                                            <input
-                                                type="checkbox"
-                                                value={item._id}
-                                                defaultChecked={doctor.find(spec => spec._id === item._id)}
-                                            />
-                                            {item.name}
-                                        </label>
-                                    </div>
-                                ))
-                            }
-
-                       </div>
-                   ))
-               }
-           </div>
-        ) 
+            <div className = "main">
+                <div className="info-wrap">
+                    <h2>Отзывы</h2>
+                    <div classdescription = "reviews-container">
+                        ЗДЕСЬ БУДУТ ОТЗЫВЫ ПОСЕТИТЕЛЕЙ
+                    </div>
+                </div>
+
+            </div>
+        )
     }
 }
 
-const mapStateToProps = state => {
-    return {
-        app:state.app,
-    }
-};
-
-const mapDispatchToProps = {
-    changeInputValueDoctorForm,
-};
 
-export default connect (mapStateToProps,mapDispatchToProps)(Reviews)
+export default Reviews
 
-// <div className = "main">
-//     <div className="info-wrap">
-//     <h2>Отзывы</h2>
-// <div classdescription = "reviews-container">
-//     ЗДЕСЬ БУДУТ ОТЗЫВЫ ПОСЕТИТЕЛЕЙ
-// </div>
-// </div>
-//
-// </div>

+ 144 - 139
src/components/appointment/Appointment.js

@@ -1,164 +1,169 @@
 import React from "react";
-import { connect } from "react-redux";
+import {connect} from "react-redux";
 import moment from "moment";
 import { CustomSelect } from "../hooks/select";
 
 import {
-  setAppointmentSpec,
-  setAppointmentShedule,
-  setAppointmentDoctor,
-  clearAppointment,
-  setAppointmentTime,
-  setAppointmentComment,
-  postOrders
-} from "../../actions/actions";
+    setAppointmentSpec,
+    setAppointmentShedule,
+    setAppointmentDoctor,
+    clearAppointment,
+    setAppointmentTime,
+    setAppointmentComment,
+    postOrders
+} from "../../actions/appointment";
 
 import Calendar from "../Calendar";
 
 export class Appoint extends React.Component {
-  state = {
-    pickedDate: null
-  };
+    state = {
+        pickedDate: null
+    };
 
-  componentDidMount() {
-    this.props.setAppointmentDoctor(this.props.match.params.doctorId);
-  }
-
-  componentWillUnmount() {
-    this.props.clearAppointment();
-  }
-
-  setSpec = e => {
-    this.props.setAppointmentSpec(e);
-  };
-
-  setShedule = e => {
-    this.setState({ pickedDate: e.target.id });
-    this.props.setAppointmentShedule(e.target.id);
-  };
-
-  setShedule = e => {
-    this.setState({ pickedDate: e.target.id });
-    this.props.setAppointmentShedule(e.target.id);
-  };
-
-  setTime = e => {
-    this.props.setAppointmentTime(e.target.value);
-  };
-
-  setComment = e => {
-    this.props.setAppointmentComment(e.target.value);
-  };
-
-  postOrder = () => {
-    this.props.postOrders(this.props.app.appointment);
-  };
+    componentDidMount() {
+        this.props.setAppointmentDoctor(this.props.match.params.doctorId)
+    }
 
-  render() {
-    const { doctors, appointment, timeArray, services } = this.props.app;
-    const { match } = this.props;
-    const doctor = doctors.find(el => el._id === match.params.doctorId);
-    let spec;
-    if (appointment.spec) {
-      spec = services.find(el => el._id === appointment.spec);
+    componentWillUnmount() {
+        this.props.clearAppointment()
     }
-    return (
-      <>
-        <div className="main">
-          {doctor && (
-            <div className="info-wrap">
-              <div className="card">
-                <div className="card-item present">
-                  <div className="photo">
-                    <img src={`.${doctor.photo}`} alt={doctor.name} />
-                  </div>
-                  <div className="order">
-                      <h3>{doctor.name}</h3>
-                  <p className="highlights">{doctor.profession}</p>
 
-                  <CustomSelect
-                    label="Выбор услуги"
-                    options={doctor.speciality}
-                    clickOptionEvent={this.setSpec}
-                  />
-                  </div>
-                </div>
-                <div className="card-item desc">
-                    <div className="date-container">
-                        {appointment.spec && (
-                            <Calendar doctor={doctor} action={this.setShedule} />
-                        )}
-                        {appointment.shedule && (
-                        <div className="appointment-time">
-                            <div className="btn-box">
-                            {timeArray.map((el, index) => (
-                                <div className="radio-btn" key={Object.keys(el)}>
-                                    <input
-                                        type="radio"
-                                        className="radio"
-                                        name="choise-time"
-                                        id={index}
-                                        onChange={this.setTime}
-                                        value={Object.keys(el)}
-                                    />
-                                    <label htmlFor={index}>{Object.keys(el)}</label>
+    setSpec = (e) => {
+        this.props.setAppointmentSpec({
+            data: e,
+            services: this.props.services
+        })
+    };
+
+    setShedule = (e) => {
+        this.setState({pickedDate: e.target.id});
+        this.props.setAppointmentShedule({
+            data: e.target.id,
+            services: this.props.services,
+            doctors: this.props.doctors
+        })
+    };
+
+    setTime = (e) => {
+        this.props.setAppointmentTime(e.target.value)
+    };
+
+    setComment = (e) => {
+        this.props.setAppointmentComment(e.target.value)
+    };
+
+    postOrder = () => {
+        this.props.postOrders(this.props.appointment.appointment)
+    };
+
+
+    render() {
+        const {appointment, timeArray, doctors, services, match} = this.props;
+        const doctor = doctors.find(el => el._id === match.params.doctorId);
+        let spec;
+        if (appointment.specId) {
+            spec = services.find(el => el._id === appointment.specId)
+        }
+        return (
+            <>
+                <div className="main">
+                    {doctor &&
+                        <div className="info-wrap">
+                            <div className="card">
+                                <div className="card-item present">
+                                    <div className="photo">
+                                        <img src={`.${doctor.photo}`} alt={doctor.name}/>
+                                    </div>
+                                    <div className="order">
+                                        <h3>{doctor.name}</h3>
+                                        <p className="highlights">{doctor.profession}</p>
+                                        <CustomSelect
+                                            label="Выбор услуги"
+                                            options={doctor.speciality}
+                                            clickOptionEvent={this.setSpec}
+                                        />
+                                    </div>
+                                </div>
+                                <div className="card-item desc">
+                                    <div className="date-container">
+                                        {appointment.specId &&
+                                            <Calendar
+                                                doctor={doctor}
+                                                action={this.setShedule}
+                                            />
+                                        }
+                                        {appointment.sheduleId && (
+                                            <div className="appointment-time">
+                                                <div className="btn-box">
+                                                    {timeArray.map((el, index) => (
+                                                        <div className="radio-btn" key={Object.keys(el)}>
+                                                            <input
+                                                                type="radio"
+                                                                className="radio"
+                                                                name="choise-time"
+                                                                id={index}
+                                                                onChange={this.setTime}
+                                                                value={Object.keys(el)}
+                                                            />
+                                                            <label htmlFor={index}>{Object.keys(el)}</label>
+                                                        </div>
+                                                    ))}
+                                                </div>
+                                                {appointment.time && (
+                                                    <textarea
+                                                        className="appointment comment"
+                                                        rows="2"
+                                                        placeholder="Добавить комментарий "
+                                                        onChange={this.setComment}
+                                                    />
+                                                )}
+                                            </div>
+                                        )}
+                                    </div>
+                                    {appointment.specId &&
+                                        <div className="order-information">
+                                            <p>{spec.name}</p>
+                                            <p>Длительность: {spec.duration} ч.</p>
+                                            <p>Цена от {spec.price} грн.</p>
+                                            {this.state.pickedDate &&
+                                                <p> {moment(this.state.pickedDate).format("DD-MMMM-YYYY")} </p>
+                                            }
+                                            {appointment.time &&
+                                            <>
+                                                <p>{appointment.time}</p>
+                                                <button className="btn link" onClick={this.postOrder}>Подтвердите запись
+                                                </button>
+                                            </>
+                                            }
+                                        </div>
+                                    }
                                 </div>
-                            ))}
                             </div>
-                            {appointment.time && (
-                            <textarea
-                                className="appointment comment"
-                                rows="2"
-                                placeholder="Добавить комментарий "
-                                onChange={this.setComment}
-                            />
-                        )}
                         </div>
-                        )}
-                    </div>
-                        
-                        {appointment.spec && (
-                            <div className="order-information">
-                                <p>{spec.name}</p>
-                                <p>Длительность: {spec.duration} ч.</p>
-                                <p>Цена от {spec.price} грн.</p>
-                                {this.state.pickedDate && (
-                                <p> {moment(this.state.pickedDate).format("DD-MMMM-YYYY")} </p>
-                                )}
-                                {appointment.time && <p>{appointment.time}</p>}
-                                {appointment.time && (
-                                    <button className="btn link" onClick={this.postOrder}>Подтвердите запись </button>
-                                )}
-                            </div>
-                         )}
+                    }
                 </div>
-              </div>
-            </div>
-          )}
-        </div>
-      </>
-    );
-  }
+            </>
+        );
+    }
 }
 
 const mapStateToProps = state => {
-  return {
-    app: state.app
-  };
+    return {
+        appointment: state.appointment.appointment,
+        timeArray: state.appointment.timeArray,
+        doctors: state.app.doctors,
+        services: state.services.services
+    };
 };
 
 const mapDispatchToProps = {
-  setAppointmentSpec,
-  setAppointmentShedule,
-  setAppointmentDoctor,
-  clearAppointment,
-  setAppointmentTime,
-  setAppointmentComment,
-  postOrders
+    setAppointmentSpec,
+    setAppointmentShedule,
+    setAppointmentDoctor,
+    clearAppointment,
+    setAppointmentTime,
+    setAppointmentComment,
+    postOrders
 };
 
-export default connect(
-  mapStateToProps,
-  mapDispatchToProps
-)(Appoint);
-
+export default connect(mapStateToProps,mapDispatchToProps)(Appoint);

+ 39 - 12
src/components/services/Services.js

@@ -1,9 +1,10 @@
 import React from "react";
 
 import {Link} from 'react-router-dom';
-import { connect } from "react-redux";
+import {connect} from "react-redux";
 
 export class Services extends React.Component {
+<<<<<<< HEAD
   render() {
     const { categories } = this.props;
     const servArray = Object.keys(categories).map(key => {
@@ -34,31 +35,57 @@ export class Services extends React.Component {
                       <div>
                         <Link to = {`/appointment/${el._id}`}  className="btn service-btn">  Записаться  </Link>
                       </div>
+=======
+    render() {
+        const {categories} = this.props;
+        return (
+            <div className="main">
+                <div className="wrapper">
+                    <div className="doctors-wrap  services">
+                        <div className="categories" id="accordion">
+                            {categories.map(el => (
+                                <div className="service-type" key={el._id} id={`item${el._id}`}>
+                                    <a href={`#item${el._id}`} className="categories-link icon-angle-down" key={el._id}>
+                                        {el.name}
+                                    </a>
+                                    {el.services.map(item => (
+                                        <div className="servise-name" key={item._id}>
+                                            <p>{item.name}</p>
+                                            {/* <p>Длительность: {item.duration} ч.</p>  */}
+                                            <p>Стоимость: {item.price} грн.</p>
+                                            <div>
+                                                <Link to={`/appointment/${item._id}`}
+                                                      className="btn service-btn"> Записаться </Link>
+                                            </div>
+                                        </div>
+                                    ))}
+                                </div>
+                            ))}
+                        </div>
+>>>>>>> ffc22fefa05d985c41e67b265e33a56a26cd6bfe
                     </div>
-                  ))}
                 </div>
-              ))}
             </div>
-          </div>
-        </div>
-      </div>
-    );
-  }
+        );
+    }
 }
 
 const mapStateToProps = state => {
+<<<<<<< HEAD
   return {
         app:state.app,
         // data:state.app.services.category,
         categories:state.app.servicesArray
   };
+=======
+    return {
+        categories: state.services.categories
+    };
+>>>>>>> ffc22fefa05d985c41e67b265e33a56a26cd6bfe
 };
 
 const mapDispatchToProps = {
   
 };
 
-export default connect(
-  mapStateToProps,
-  mapDispatchToProps
-)(Services);
+export default connect(mapStateToProps, mapDispatchToProps)(Services);

+ 1 - 1
src/components/specialists/MoreInfo.js

@@ -47,7 +47,7 @@ export class MoreInfo extends React.Component {
 const mapStateToProps = state => {
     return {
         doctors:state.app.doctors,
-        services:state.app.services
+        services:state.services.services
     }
 };
 

+ 0 - 1
src/privateRouter.js

@@ -8,7 +8,6 @@ export const PrivateRoute = ({ component: Component, protectedRoute, ...rest })
 		render={props => {
 			if (protectedRoute) {
 				const token = localStorage.getItem("userId");
-				console.log('token', token)
 				if (!token) {
 					return <Redirect to="/auth" />;
 				}

+ 101 - 0
src/reducers/appointment.js

@@ -0,0 +1,101 @@
+import * as types from '../actionsTypes/actionsTypes'
+
+const defaultState = {
+    appointment: {
+        sheduleId: null,
+        time: null,
+        doctorId: null,
+        specId: null,
+        comment: ''
+    },
+    timeArray:[]
+};
+
+export const appointmentReducer = (state = defaultState, action) => {
+    switch(action.type){
+
+        case types.CHANGE_APPOINTMENT_SHEDULE : {
+            let timeArray =[];
+            let doctor = action.payload.doctors.find(el => el._id === state.appointment.doctorId);
+            let shedule = doctor.shedule.find(el => el.data === action.payload.data);
+            let duration = action.payload.services.find(el => el._id === state.appointment.specId).duration;
+            for (let index in shedule) {
+                let check = true;
+                for (let x=0;x < duration; x++){
+                    if (shedule[`${+index.split(':')[0]+x < 10 ? '0' +(+index.split(':')[0] + x) + ':00' : +index.split(':')[0]+ x + ':00'}`] !== true){
+                        check = false
+                    }
+                }
+                if (check) timeArray.push({[`${index}`]:shedule[`${index}`]});
+            }
+            return {
+                ...state,
+                appointment:{
+                    ...state.appointment,
+                    sheduleId:shedule._id,
+                    time:null
+                },
+                timeArray:timeArray
+            };
+        }
+
+        case types.CHANGE_APPOINTMENT_DOCTOR : {
+            return {
+                ...state,
+                appointment:{
+                    ...state.appointment,
+                    doctorId:action.payload
+                }
+            };
+        }
+
+        case types.CHANGE_APPOINTMENT_TIME : {
+            return {
+                ...state,
+                appointment:{
+                    ...state.appointment,
+                    time:action.payload
+                }
+            };
+        }
+
+        case types.CHANGE_APPOINTMENT_SPEC : {
+            return {
+                ...state,
+                appointment:{
+                    ...state.appointment,
+                    specId:action.payload.services.find(el => el.name === action.payload.data)._id,
+                    sheduleId:null,
+                    time:null
+                }
+            };
+        }
+
+        case types.CHANGE_APPOINTMENT_COMMENT : {
+            return {
+                ...state,
+                appointment:{
+                    ...state.appointment,
+                    comment:action.payload
+                }
+            };
+        }
+
+        case types.CLEAR_APPOINTMENT : {
+            return {
+                appointment: {
+                    sheduleId: null,
+                    time: null,
+                    doctorId: null,
+                    specId: null,
+                    comment: ''
+                },
+                timeArray:[]
+            };
+        }
+
+
+        default:
+            return state
+    }
+};

+ 5 - 1
src/reducers/index.js

@@ -3,11 +3,15 @@ import {combineReducers} from "redux";
 import {appReducer} from "./reducers";
 import {calendarReducer} from "./calendar"
 import auth from './auth';
+import {appointmentReducer} from "./appointment";
+import {servicesReducer} from "./services";
 
 
 
 export default combineReducers({
     app:appReducer,
     auth,
-    calendar:calendarReducer
+    calendar:calendarReducer,
+    appointment:appointmentReducer,
+    services:servicesReducer
 })

+ 39 - 200
src/reducers/reducers.js

@@ -3,17 +3,7 @@ import * as types from '../actionsTypes/actionsTypes'
 import {postNewDoctorForm,postNewServiceForm} from '../utils/formFields'
 
 const defaultState = {
-    user:localStorage.getItem('id') ? localStorage.getItem('id') : null,
     doctors:[],
-    services:[],
-    servicesArray:{
-        'Хирургия':[],
-        'Детская стоматология':[],
-        'Ортодонтия':[],
-        'Терапия':[],
-        'Имплантология': [],
-        'Эндодонтия':[]
-    },
 
     orders:[],
     users:[],
@@ -26,10 +16,11 @@ const defaultState = {
 
     postNewDoctor:postNewDoctorForm,
     postNewService:postNewServiceForm,
-
     changeDoctorId:null,
     changeServiceId:null,
+    specialityArray:[],
 
+<<<<<<< HEAD
     appointment:{
         shedule:null,
         time:null,
@@ -39,6 +30,8 @@ const defaultState = {
       },
 
     timeArray:[ ],
+=======
+>>>>>>> ffc22fefa05d985c41e67b265e33a56a26cd6bfe
     isFetching:false,
     error: null,
 
@@ -52,6 +45,18 @@ export const appReducer = (state = defaultState,action) => {
 
 // -----------------------------------------------------------------------------------------------------------------
 
+        case types.CHANGE_SPECIALITY_ARRAY : {
+            const arr = state.specialityArray.slice();
+            action.payload.checked ? arr.push(action.payload.value) : arr.splice(arr.indexOf(action.payload.value),1);
+            return {
+                ...state,
+                specialityArray: arr
+            };
+        }
+
+// -----------------------------------------------------------------------------------------------------------------
+
+
         case types.CHANGE_INPUT_VALUE_DOCTOR_FORM : {
             return {
                 ...state,
@@ -77,110 +82,43 @@ export const appReducer = (state = defaultState,action) => {
 // -----------------------------------------------------------------------------------------------------------------
 
         case types.CHANGE_SELECTED_DOCTOR_ID : {
-            let doctor = state.doctors.find(el => el.name === action.payload)
-            let result = Object.keys(doctor).map(key => {
-                return [key, doctor[key]];
-            });
+            let doctor = action.payload.data.find(el => el.name === action.payload.item);
+            let result;
+            let specArray=[];
+            if (doctor){
+                result = Object.keys(doctor).map(key => {
+                    return [key, doctor[key]];
+                });
+                doctor.speciality.map(el => specArray.push(el._id))
+            }
             return {
                 ...state,
-                changeDoctorId: state.doctors.find(el => el.name === action.payload)._id,
-                postNewDoctor:state.postNewDoctor.map(el => result.find(item => item[0] === el.name) ? {
+                specialityArray:specArray,
+                changeDoctorId: doctor ? doctor._id : null,
+                postNewDoctor:doctor ? state.postNewDoctor.map(el => result.find(item => item[0] === el.name) ? {
                     ...el,
                     value:result.find(item => item[0] === el.name)[1]
-                } : el)
+                } : el) : postNewDoctorForm
             };
         }
 
 // -----------------------------------------------------------------------------------------------------------------
 
         case types.CHANGE_SELECTED_SERVICE_ID : {
-            let service = state.services.find(el => el.name === action.payload)
-            let result = Object.keys(service).map(key => {
-                return [key, service[key]];
-            });
+            let service = action.payload.data.find(el => el.name === action.payload.item);
+            let result;
+                if (service){
+                    result = Object.keys(service).map(key => {
+                        return [key, service[key]];
+                    });
+                }
             return {
                 ...state,
-                changeServiceId: service._id,
-                postNewService: state.postNewService.map(el => result.find(item => item[0] === el.name) ? {
+                changeServiceId: service ? service._id : null,
+                postNewService: service ? state.postNewService.map(el => result.find(item => item[0] === el.name) ? {
                     ...el,
                     value:result.find(item => item[0] === el.name)[1]
-                } : el)
-            };
-        }
-
-// -----------------------------------------------------------------------------------------------------------------
-
-        case types.CHANGE_APPOINTMENT_SHEDULE : {
-            let timeArray =[];
-            let doctor = state.doctors.find(el => el._id === state.appointment.doctor);
-            let shedule = doctor.shedule.find(el => el.data === action.payload);
-            let duration = state.services.find(el => el._id === state.appointment.spec).duration;
-            console.log(shedule,  action.payload)
-            for (let index in shedule) {
-                let check = true;
-                for (let x=0;x < duration; x++){
-                    if (shedule[`${+index.split(':')[0]+x < 10 ? '0' +(+index.split(':')[0] + x) + ':00' : +index.split(':')[0]+ x + ':00'}`] !== true){
-                        check = false
-                    }
-                }
-                if (check) timeArray.push({[`${index}`]:shedule[`${index}`]});
-            }
-            return {
-                ...state,
-                appointment:{
-                    ...state.appointment,
-                    shedule:shedule._id
-                },
-                timeArray:timeArray
-            };
-        }
-
-        case types.CHANGE_APPOINTMENT_DOCTOR : {
-            return {
-                ...state,
-                appointment:{
-                    ...state.appointment,
-                    doctor:action.payload
-                }
-            };
-        }
-
-        case types.CHANGE_APPOINTMENT_TIME : {
-            return {
-                ...state,
-                appointment:{
-                    ...state.appointment,
-                    time:action.payload
-                }
-            };
-        }
-
-        case types.CHANGE_APPOINTMENT_SPEC : {
-            return {
-                ...state,
-                appointment:{
-                    ...state.appointment,
-                    spec:state.services.find(el => el.name === action.payload)._id,
-                    shedule:null,
-                    time:null
-                }
-            };
-        }
-
-        case types.CHANGE_APPOINTMENT_COMMENT : {
-            return {
-                ...state,
-                appointment:{
-                    ...state.appointment,
-                    comment:action.payload
-                }
-            };
-        }
-
-        case types.CLEAR_APPOINTMENT : {
-            return {
-                ...state,
-                appointment: defaultState.appointment
+                } : el) : postNewServiceForm
             };
         }
 
@@ -229,104 +167,7 @@ export const appReducer = (state = defaultState,action) => {
             }
         }
 
-// -----------------------------------------------------------------------------------------------------------------
 
-        case types.GET_SERVICES_REQUEST : {
-            return {
-                ...state,
-                isFetching: true
-            };
-        }
-
-        case types.GET_SERVICES_REQUEST_SUCCESS : {
-            action.payload.services.sort((a,b) => {
-                if (a.name.slice(0,1) < b.name.slice(0,1)) {return -1;}
-                if(a.name.slice(0,1) > b.name.slice(0,1)) {return 1;}
-                return 0
-            });
-                action.payload.services.map(el => {
-                    switch (el.description){
-                        case "Ортодонтия" : {
-                            return {
-                                ...state,
-                                servicesArray:{
-                                    ...state.servicesArray,
-                                    'Ортодонтия':state.servicesArray['Ортодонтия'].push(el)
-                                }
-                            }
-                        }
-                        case "Детская стоматология" : {
-                            return {
-                                ...state,
-                                servicesArray:{
-                                    ...state.servicesArray,
-                                    'Детская стоматология':state.servicesArray['Детская стоматология'].push(el)
-                                }
-                            }
-                        }
-                        case "Протезирование" : {
-                            return {
-                                ...state,
-                                servicesArray:{
-                                    ...state.servicesArray,
-                                    'Имплантология':state.servicesArray['Имплантология'].push(el)
-                                }
-                            }
-                        }
-                        case "Имплантация" : {
-                            return {
-                                ...state,
-                                servicesArray:{
-                                    ...state.servicesArray,
-                                    'Имплантология':state.servicesArray['Имплантология'].push(el)
-                                }
-                            }
-                        }
-                        case "Хирургия" : {
-                            return {
-                                ...state,
-                                servicesArray:{
-                                    ...state.servicesArray,
-                                    'Хирургия':state.servicesArray['Хирургия'].push(el)
-                                }
-                            }
-                        }
-                        case "Эндодонтическое лечение с помощью микроскопа" : {
-                            return {
-                                ...state,
-                                servicesArray:{
-                                    ...state.servicesArray,
-                                    'Эндодонтия':state.servicesArray['Эндодонтия'].push(el)
-                                }
-                            }
-                        }
-                        case "Лечение пародонтита" : {
-                            return {
-                                ...state,
-                                servicesArray:{
-                                    ...state.servicesArray,
-                                    'Терапия':state.servicesArray['Терапия'].push(el)
-                                }
-                            }
-                        }
-                        default: return el
-                    }
-                });
-
-            return {
-                ...state,
-                services:action.payload.services,
-                isFetching: false
-            }
-        }
-
-        case types.GET_SERVICES_REQUEST_FAIL : {
-            return {
-                ...state,
-                error:action.payload,
-                isFetching: false
-            }
-        }
 
 // -----------------------------------------------------------------------------------------------------------------
 // -----------------------------------------------------------------------------------------------------------------
@@ -418,8 +259,6 @@ export const appReducer = (state = defaultState,action) => {
         case types.POST_ORDERS_REQUEST_SUCCESS : {
             return {
                 ...state,
-                appointment: defaultState.appointment,
-                orders:action.payload,
                 isFetching: false
             }
         }

+ 62 - 0
src/reducers/services.js

@@ -0,0 +1,62 @@
+import * as types from '../actionsTypes/actionsTypes'
+
+const defaultState = {
+    services:[],
+    categories:[],
+    isFetching: false,
+    error:null
+};
+
+export const servicesReducer = (state = defaultState, action) => {
+    switch(action.type){
+
+        case types.GET_SERVICES_REQUEST : {
+            return {
+                ...state,
+                isFetching: true
+            };
+        }
+
+        case types.GET_SERVICES_REQUEST_SUCCESS : {
+            return {
+                ...state,
+                services:action.payload.services,
+                isFetching: false
+            };
+        }
+
+        case types.GET_SERVICES_REQUEST_FAIL : {
+            return {
+                ...state,
+                error:action.payload,
+                isFetching: false
+            }
+        }
+
+        case types.GET_CATEGORIES_REQUEST : {
+            return {
+                ...state,
+                isFetching: true
+            };
+        }
+
+        case types.GET_CATEGORIES_REQUEST_SUCCESS : {
+            return {
+                ...state,
+                categories:action.payload.categories,
+                isFetching: false
+            };
+        }
+
+        case types.GET_CATEGORIES_REQUEST_FAIL : {
+            return {
+                ...state,
+                error:action.payload,
+                isFetching: false
+            }
+        }
+
+        default:
+            return state
+    }
+};

+ 3 - 0
src/utils/formFields.js

@@ -193,6 +193,7 @@ export const postNewDoctorForm =[
 		name:'skillsDescription',
 		placeholder:'Введите описание навыков здесь',
 		required:true
+<<<<<<< HEAD
 	},
 	{
 		id:6,
@@ -201,6 +202,8 @@ export const postNewDoctorForm =[
 		name:'speciality',
 		placeholder:'Выберите предоставляемые услуги',
 		required:true
+=======
+>>>>>>> ffc22fefa05d985c41e67b265e33a56a26cd6bfe
 	}
 ];