-
Notifications
You must be signed in to change notification settings - Fork 0
/
File.txt
216 lines (175 loc) · 6.24 KB
/
File.txt
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import React, { Component, useEffect, useState} from 'react';
import axios from 'axios';
import { useParams } from 'react-router-dom';
import patientService from '../service/patientService';
import './FormStyle.css';
function EditDetails(){
const {id}= useParams();
const URL=`http://localhost:8080/api/v1/patients/${id}`;
var patientsInfo;
useEffect(()=>{
getPatientById();
},[])
const getPatientById= async e =>{
patientsInfo = await axios.get(URL);
//const patientsInfo = await patientService.getPatientById({id});
console.log("info: ",patientsInfo.data);
patient.name=patientsInfo.data.name;
patient.gen=patientsInfo.data.gen;
patient.address=patientsInfo.data.address;
patient.email=patientsInfo.data.email;
patient.phone=patientsInfo.data.phone;
//setPatient(patientsInfo.data);
}
const [patient, setPatient] = useState({
name:"",
phone:"",
gen:"select",
address:"",
email:"",
});
const { name ,phone, gen, address, email} = patient;
const onInputChange = e =>{
//console.log("oninput:"+name+" "+phone+" "+gender+" "+address+" "+email);
setPatient({...patient,[e.target.name]:e.target.value})
}
const FormHandle = e =>{
//console.log("patients data in the form func:"+JSON.stringify(patientsInfo.data));
/*
console.log(e);
updateDataToServer(patient)
"http://localhost:8080/api/v1/patients"
if(patient)
{
fetch(URL,{
method:"PUT",
headers:{"Content-type":"application/json"},
body:JSON.stringify(patient)
}).then(()=>{})
window.alert("Patient Data modified!");
}
patientService.updatePatient(patient,id);
e.preventDefault();
try {
const { data } = axios({
method: 'PUT',
url: URL,
data: {
body : patient
},
});
console.log(JSON.stringify(data));
*/
/*
setPatient({name:patientsInfo.data.name,
address:patientsInfo.data.address,
phone:patientsInfo.data.phone,
gen:patientsInfo.data.gen,
email:patientsInfo.data.email
});
*/
//patientsInfo = axios.get(URL);
//const patientsInfo = await patientService.getPatientById({id});
console.log("info: ",patientsInfo.data);
/*
this.name=patientsInfo.name;
this.gen=patientsInfo.gen;
this.address=patientsInfo.address;
this.email=patientsInfo.email;
this.phone=patientsInfo.phone;
*/
console.log("set data: " +patient.name+" "+patient.gen+" "+patient.address+" "+patient.email+" "+patient.phone);
console.log("Patient: "+JSON.stringify(patient));
try{
//const res = axios.put(URL, patient);
const res = axios.put(URL,patient);
//res.data.headers['Content-Type'];
console.log("res: ",res);
} catch (err) {
if (err.response.status === 404) {
console.log('Resource could not be found!');
} else {
console.log(err.message);
}
}
}
const updateDataToServer=(data) =>{
/*
console.log("Data: "+data);
axios.put(URL).then(
(response)=>{
alert("Patient Updated Successfully");
console.log(response.json());
},(error)=>{
alert("Operation failed");
console.log("error:"+error);
}
);
/*
axios.put(URL,+'/'+{id},data,{
foo: "bar"
})
.then(function (response) {
alert("Book Updated Successfully");
console.log(response.json());
}.bind(this))
.catch(function (error) {
console.log("Error: "+error)
});
*/
/*
patientService.updatePatient(data,{id}).then(
(response)=>{
console.log(response);
alert("Patient Updated Successfully");
},(error)=>{
console.log(error);
alert("Operation failed");
}
);
*/
};
const onCancel=(e)=>{
setPatient("");
}
return (
<div>
<div className="container">
<h1 className="">Update Patients!</h1>
<div>
<form onSubmit={e => FormHandle(e)}>
<div className=''>
<label>Name</label>
<input type="text" className="form-control" name="name" placeholder="Enter Here" value={name} onChange={(e) =>onInputChange(e)} />
</div>
<div className="form-group">
<label>Phone</label>
<input type="number" className="form-control" name="phone" placeholder="Enter Here" value={phone} onChange={(e) =>onInputChange(e)} />
</div>
<div className="form-group">
<label>Gender</label>
<select value={patient.gen} name="gen" placeholder="Enter Here" onChange={(e) =>onInputChange(e)} className='element-control'>
<option value="select">select</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div className="form-group">
<label>Address</label>
<input type="textarea" className="form-control" name="address" placeholder="Enter Here" value={address} onChange={(e) =>onInputChange(e)} />
</div>
<div className="form-group">
<label>Email</label>
<input type="email" className="form-control" name="email" placeholder="Enter Here" value={email} onChange={(e) =>onInputChange(e)} />
</div>
<div className="container text-center">
<button type="button" id="btn-update" onClick={e => FormHandle(e)}>Update Patient</button>
<button type="reset" id="btn-clear" onClick={(e) =>onCancel(e)}>Clear</button>
</div>
</form>
</div>
</div>
</div>
)
}
export default EditDetails