|
@@ -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
|
|
|
}
|
|
|
}
|