DoctorMenuContainer.tsx
5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React, { useState, useEffect } from 'react';
import { RouteComponentProps} from 'react-router-dom';
import DoctorMenuPresenter from './DoctorMenuPresenter';
import { useRecoilState, useRecoilValue } from 'recoil';
import * as recoilUtil from '../../../util/recoilUtil';
import { doctorApi, authApi } from '../../../api';
type DoctorMenuProps = RouteComponentProps
const DoctorMenuContainer = (props : DoctorMenuProps) => {
const token = useRecoilValue(recoilUtil.token);
const [doctorInfo, setDoctorInfo] = useState<any>({
doctorNm : '',
doctorType : '',
hospitalNm : '',
hospitalAddr : '',
contact : '',
});
const [patientList, setPatientList] = useState<any>([]);
const [info, setInfo] = useState<any>({
infoType : 'DOCTOR',
userNm : '',
userAge : 0,
contact : '',
doctorType : '',
patientInfo : '',
});
const [searchPatientKeyword, setSearchPatientKeyword] = useState<string>('');
const [filteringPatientList, setFilteringPatientList] = useState<any>([]);
const [patientDetail, setPatientDetail] = useState<any>();
const [editModal, setEditModal] = useState<boolean>(false);
const [newPatientRegisterModal, setNewPatientRegisterModal] = useState<boolean>(false);
const [newPatientSearchId, setNewPatientSearchId] = useState<string>('');
const fetchData = async() => {
try {
const res = await doctorApi.getDoctorsInfo(token);
if(res.statusText === 'OK') {
const { doctorInfo } = res.data;
setDoctorInfo(doctorInfo);
setInfo({
infoType : 'DOCTOR',
userNm : doctorInfo.doctorNm,
doctorType : doctorInfo.doctorType,
contact : doctorInfo.contact,
userAge : null,
patientInfo : '',
});
//로그인한 환자의 리스트를 가져옴 : 프론트에서 필터로 검색
await doctorApi.getPatientList(token).then(res => {
setPatientList(res.data.patientList);
}).catch(error => console.log(error));
}
} catch(e) {
console.log(e);
}
};
const onSetKeyword = (e : React.ChangeEvent<HTMLInputElement>) => {
setSearchPatientKeyword(e.target.value);
};
const onFetchPatientDetail = async (patientId : string) => {
try {
await doctorApi.getPatientDetail(token, patientId).then(res => {
setPatientDetail(res.data);
setInfo({
infoType : 'PATIENT',
userNm : res.data.profile.userNm,
userAge : res.data.profile.userAge,
contact : res.data.profile.contact,
doctorType : null,
patientInfo : res.data.info,
});
}).catch(err => console.log(err));
} catch(e) {
console.log(e);
}
};
const onInitialize = () => {
setInfo({
infoType : 'DOCTOR',
userNm : doctorInfo.doctorNm,
doctorType : doctorInfo.doctorType,
contact : doctorInfo.contact,
userAge : null,
patientInfo : '',
});
setFilteringPatientList([]);
setSearchPatientKeyword('');
setPatientDetail(null);
};
const onSetNewPatientSearchId = (e : React.ChangeEvent<HTMLInputElement>) => {
setNewPatientSearchId(e.target.value);
};
const onSearchNewPatientByEmail = async () => {
try {
await doctorApi.searchPatientById(token, newPatientSearchId).then(res => {
console.log(res.data);
}).catch(err => console.log(err));
} catch(e) {
console.log(e);
}
};
const onGoBottleDetail = (bottleId : number) => {
console.log(bottleId);
};
useEffect(() => {
if(!token || !token.length) {
props.history.push('/login');
} else fetchData();
}, []);
useEffect(() => {
setFilteringPatientList(searchPatientKeyword === '' ? [] :
patientList.filter((patient : any) =>
patient.contact.includes(searchPatientKeyword)
|| patient.userNm.includes(searchPatientKeyword)
|| patient.userId.includes(searchPatientKeyword)
)
);
}, [searchPatientKeyword]);
return (
<DoctorMenuPresenter
info = {info}
searchPatientKeyword = {searchPatientKeyword}
onSetKeyword = {onSetKeyword}
filteringPatientList = {filteringPatientList}
patientDetail = {patientDetail}
onFetchPatientDetail = {onFetchPatientDetail}
onInitialize = {onInitialize}
onGoBottleDetail = {onGoBottleDetail}
editModal = {editModal}
setEditModal = {setEditModal}
newPatientRegisterModal = {newPatientRegisterModal}
setNewPatientRegisterModal = {setNewPatientRegisterModal}
newPatientSearchId = {newPatientSearchId}
onSetNewPatientSearchId = {onSetNewPatientSearchId}
onSearchNewPatientByEmail = {onSearchNewPatientByEmail}
/>
);
};
export default DoctorMenuContainer;