Bladeren bron

some minor changes

Boris K 5 jaren geleden
bovenliggende
commit
04bc4a4646

+ 2 - 2
src/components/Admin/Admin.js

@@ -26,7 +26,7 @@ import {
 } from "../../actions/user"
 
 import Shedule from './Shedule'
-import Tempp from './tempp'
+import ChangeUser from './ChangeUser'
 import ChangeServicesDoctors from './ChangeServices-Doctors'
 
 
@@ -106,7 +106,7 @@ export class Admin extends React.Component {
                             deleteItem={deleteServices}
                             changeInputValues={changeInputValueServiceForm}
                         />} />
-                        <Route path='/admin/change-user' render={() => <Tempp
+                        <Route path='/admin/change-user' render={() => <ChangeUser
                             user={user}
                             findUserInput={findUserInput}
                             changeFindUserInput={changeFindUserInput}

+ 94 - 0
src/components/Admin/ChangeUser.js

@@ -0,0 +1,94 @@
+import React from 'react';
+
+
+import Input from "./Input"
+
+export default class ChangeUser extends React.Component {
+
+    changeUserInput = (e) => {
+        this.props.changeFindUserInput(e.target.value)
+    };
+
+    findUser = () => {
+        this.props.findUser(this.props.findUserInput.includes('@') ? '?email=' + this.props.findUserInput : this.props.findUserInput)
+    };
+
+    enterPressed = (e) => {
+        if (e.key === 'Enter') {
+            this.findUser();
+        }
+    };
+
+    changeUser = (e) => {
+        e.preventDefault();
+        const obj = {};
+        // eslint-disable-next-line array-callback-return
+        this.props.changeUserForm.map(el => {
+            obj[el.name] = el.type === 'radio' ? el.checked ? el.value : !el.value : el.value
+        });
+        console.log(obj) //заменить на putUsers
+    };
+
+    deleteUser = () => {
+        console.log(this.props.user._id) // заменить на deleteUser
+    };
+
+    render() {
+        const {
+            user,
+            findUserInput,
+            changeInputValueUserForm,
+            changeUserForm,
+            error
+        } = this.props;
+        return (
+            <div
+                style={{
+                    display:'flex'
+                }}
+            >
+                <div>
+                    <input type='text' name='find_user' onKeyDown={this.enterPressed} onChange={this.changeUserInput}/>
+                    {findUserInput &&
+                    <button id='enter' onClick={this.findUser}>Find User</button>
+                    }
+                    {user &&
+                    <div>
+                        <form
+                            style={{
+                                display: 'flex',
+                                flexDirection: 'column',
+                                width: '400px'
+                            }}
+                        >
+                            {changeUserForm.map(el =>
+                                <label
+                                    key={el.id}>{el.name === 'role' || el.name === 'doctor' ? `${el.name} ${el.value}` : el.name}
+                                    {el.name !== 'role' && el.name !== 'doctor' && <br/>}
+                                    <Input
+                                        el={el}
+                                        changeInputValues={changeInputValueUserForm}
+                                        className={el.className}
+                                    />
+                                </label>
+                            )}
+                        </form>
+                        <button onClick={this.changeUser}>Change</button>
+                        <button onClick={this.deleteUser}>DELETE</button>
+                    </div>
+                    }
+
+                    {error &&
+                    <div>
+                        <p>User not found</p>
+                    </div>
+                    }
+                </div>
+                <div>
+                    <p>User List will be here</p>
+                </div>
+            </div>
+        );
+    }
+};
+

+ 0 - 74
src/components/Admin/tempp.js

@@ -1,74 +0,0 @@
-import React from 'react';
-
-
-import Input from "./Input"
-
-export default class Tempp extends React.Component {
-
-    changeUserInput = (e) => {
-    this.props.changeFindUserInput(e.target.value)
-    };
-
-    findUser = () => {
-        this.props.findUser(this.props.findUserInput.includes('@') ? '?email='+this.props.findUserInput : this.props.findUserInput)
-    };
-
-    enterPressed = (e) => {
-        if (e.key === 'Enter') {
-            this.findUser();
-        }
-    };
-
-    changeUser = (e) => {
-        const obj = {}
-        e.preventDefault()
-        this.props.changeUserForm.map(el => {
-            obj[el.name] = el.type === 'radio' ? el.checked ? el.value : !el.value : el.value
-        });
-        console.log(obj)
-    };
-
-    render(){
-        const {
-            user,
-            findUserInput,
-            changeFindUserInput,
-            findUser,
-            deleteUser,
-            changeInputValueUserForm,
-            changeUserForm,
-            error
-        } = this.props;
-        console.log(this.props)
-        return (
-           <div>
-                <input type='text' name='find_user' onKeyDown={this.enterPressed} onChange={this.changeUserInput} />
-                {findUserInput && 
-                    <button id='enter' onClick={this.findUser}>Find User</button>
-                }
-                {user &&
-                    <div>
-                        <form onSubmit={this.changeUser} className="form-doctors">
-                            {changeUserForm.map(el =>
-                                <Input
-                                    key={el.id}
-                                    el={el}
-                                    changeInputValues={changeInputValueUserForm}
-                                    className={el.className}
-                                />
-                            )}
-                            <button type='submit'>Change</button>
-                        </form>
-                    </div>
-                }
-
-                {error &&
-                    <div>
-                        <p>User not found</p>
-                    </div>
-               }
-           </div>
-        );
-    }
-};
-

+ 1 - 2
src/components/appointment/Appointment.js

@@ -53,14 +53,13 @@ export class Appoint extends React.Component {
     };
 
     postOrder = () => {
-        console.log(this.props.appointment)
         this.props.postOrders({
             shedule: this.props.appointment.sheduleId,
             time: this.props.appointment.time,
             doctor: this.props.appointment.doctorId,
             spec: this.props.appointment.specId,
             comment: this.props.appointment.comment,
-            user: this.props.user
+            user: this.props.user._id
         })
     };
 

+ 4 - 4
src/reducers/appointment.js

@@ -15,10 +15,10 @@ 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;
+            const timeArray =[];
+            const doctor = action.payload.doctors.find(el => el._id === state.appointment.doctorId);
+            const shedule = doctor.shedule.find(el => el.data === action.payload.data);
+            const 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++){

+ 28 - 36
src/reducers/calendar.js

@@ -2,52 +2,44 @@ import * as types from '../actionsTypes/actionsTypes'
 import moment from "moment";
 
 const defaultState = {
-    monthArray:[],
-    current:moment()
+    monthArray: [],
+    current: moment()
 };
 
 export const calendarReducer = (state = defaultState, action) => {
-    switch(action.type){
+    switch (action.type) {
 
         case types.CREATE_CALENDAR_MONTH_ARRAY: {
             const daysArray = [];
-            for (let x=1; x <= state.current.daysInMonth();x++){
-                let day = {
-                    day:"",
-                    disabled:false,
-                    backgroundColor:"",
-                    border:"", 
+            for (let x = 1; x <= state.current.daysInMonth(); x++) {
+                const el = state.current.date(x).format('YYYY-MM-DD');
+                const day = {
+                    day: el,
+                    disabled: moment(el).format('YYYY-MM-DD') < moment().format('YYYY-MM-DD')
+                        || (moment(el).day() === 6)
+                        || (moment(el).day() === 0)
+                        || moment(el).month() !== state.current.month()
+                        || !action.payload.shedule.find(item => item.data === el),
+                    backgroundColor: moment(el).month() === state.current.month() ? action.payload.shedule.find(item => item.data === el) ? "#b1e8ca" : "#ff9774" : "lightgrey",
+                    border: moment().format('YYYY-MM-DD') === moment(el).format('YYYY-MM-DD') ? "2px solid rgba(17,17,17,0.8)" : null
                 };
-                let el = state.current.date(x).format('YYYY-MM-DD');
-                day.day = el;
-                day.disabled =  moment(el).format('YYYY-MM-DD') < moment().format('YYYY-MM-DD')
-                    || (moment(el).day()===6)
-                    || (moment(el).day()===0)
-                    || moment(el).month() !== state.current.month()
-                    || !action.payload.shedule.find(item => item.data === el);
-                day.backgroundColor = moment(el).month() === state.current.month() ? action.payload.shedule.find(item => item.data === el) ? "#b1e8ca" : "#ff9774" : "lightgrey";
-                day.border = moment().format('YYYY-MM-DD') ===  moment(el).format('YYYY-MM-DD') ? "2px solid rgba(17,17,17,0.8)" : null;
                 daysArray.push(day)
             }
 
-            const prevMonth = moment(state.current).subtract(1,'months');
-            const startDay = state.current.startOf ('month').day ( ) === 0 ? 7 : state.current.startOf('month').day( );
-            for (let x=1; x < startDay; x++){
-                let day = {
-                    day: "",
-                    disabled: false,
-                    backgroundColor: "",
-                    border: "",
+            const prevMonth = moment(state.current).subtract(1, 'months');
+            const startDay = state.current.startOf('month').day() === 0 ? 7 : state.current.startOf('month').day();
+            for (let x = 1; x < startDay; x++) {
+                const el = prevMonth.endOf('month').subtract(x - 1, 'days').format('YYYY-MM-DD');
+                const day = {
+                    day: el,
+                    disabled: moment(el).format('YYYY-MM-DD') < moment().format('YYYY-MM-DD')
+                        || (moment(el).day() === 6)
+                        || (moment(el).day() === 0)
+                        || moment(el).month() !== state.current.month()
+                        || !action.payload.shedule.find(item => item.data === el),
+                    backgroundColor: moment(el).month() === state.current.month() ? action.payload.shedule.find(item => item.data === el) ? "#b1e8ca" : "#ff9774" : "lightgrey",
+                    border: moment().format('YYYY-MM-DD') === moment(el).format('YYYY-MM-DD') ? "2px solid rgba(17,17,17,0.8)" : null
                 };
-                let el = prevMonth.endOf('month').subtract(x-1,'days').format('YYYY-MM-DD');
-                day.day = el;
-                day.disabled =  moment(el).format('YYYY-MM-DD') < moment().format('YYYY-MM-DD')
-                    || (moment(el).day()===6)
-                    || (moment(el).day()===0)
-                    || moment(el).month() !== state.current.month()
-                    || !action.payload.shedule.find(item => item.data === el);
-                day.backgroundColor = moment(el).month() === state.current.month() ? action.payload.shedule.find(item => item.data === el) ? "#b1e8ca" : "#ff9774" : "lightgrey";
-                day.border = moment().format('YYYY-MM-DD') ===  moment(el).format('YYYY-MM-DD') ? "2px solid rgba(17,17,17,0.8)" : null;
                 daysArray.unshift(day)
             }
             return {
@@ -59,7 +51,7 @@ export const calendarReducer = (state = defaultState, action) => {
         case types.CHANGE_CALENDAR_MONTH: {
             return {
                 ...state,
-                current: state.current.add(action.payload,"month")
+                current: state.current.add(action.payload, "month")
             };
         }
 

+ 0 - 2
src/reducers/user.js

@@ -22,7 +22,6 @@ export const userReducer = (state = defaultState, action) => {
 
         case types.FIND_USER_REQUEST_SUCCESS : {
             const data = state.findUserInput.includes('@') ? action.payload.users[0] : action.payload.user;
-            state.changeUserForm.map(el => console.log(Object.keys(data).find(item => item === el.name)));
             return {
                 ...state,
                 user: data,
@@ -58,7 +57,6 @@ export const userReducer = (state = defaultState, action) => {
         }
 
         case types.CHANGE_INPUT_VALUE_USER_FORM : {
-            console.log(action.payload.target);
             const data = action.payload.target;
             return {
                 ...state,