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
| import React from "react";
import { Link, useNavigate } from "react-router-dom";
import { useState } from "react";
import axios from "axios";
function Add(){
const [home, setPatient ] = useState({
n_national: "",
ts: "",
sexe: "",
age: "",
date_pre: "",
date_ret_result: "",
val_cv: ""
});
const navigate = useNavigate();
const handleChange = (e) => {
setPatient((prev) => ({...prev, [e.target.n_national]: e.target.value}));
};
const handleClick = async (e) => {
e.preventDefault();
try {
await axios.post("http://localhost:8081/patient", home);
navigate("/home");
}catch (err) {
console.log(err);
}
};
return(
<div className="container">
<h2 className="W-100 d-flex justify-content-center p-3">ADD NEW Patient</h2>
<div className="row">
<div className="col-md-12">
<h3>Add Your Detail</h3>
<form>
<div className="mb-3 mt-3">
<label className="form-label">N_National</label>
<input type="text" placeholder="Enter Num National" id="n_national" name="n_national" className="form-control"onChange={handleChange} required ></input>
</div>
<div className="mb-3 mt-3">
<label className="form-label">Ts</label>
<input type="text" placeholder="Enter TS" id="ts" name="ts" className="form-control" onChange={handleChange} required></input>
</div>
<div className="mb-3 mt-3">
<label className="form-label">Sexe</label>
<input type="text" placeholder="Enter Sexe" id="sexe" name="sexe" className="form-control" onChange={handleChange} required></input>
</div>
<div className="mb-3 mt-3">
<label className="form-label">Age</label>
<input type="text" placeholder="Enter Age" id="age" name="age" className="form-control" onChange={handleChange} required ></input>
</div>
<div className="mb-3 mt-3">
<label className="form-label">Date De Prelevement</label>
<input type="date" placeholder="Enter Date of prelevement" id="date_pre" name="date_pre" className="form-control" onChange={handleChange} required></input>
</div>
<div className="mb-3 mt-3">
<label className="form-label">Date Retour Resultat</label>
<input type="date" placeholder="Enter " id="date_ret_result" name="date_ret_result" className="form-control" ></input>
</div>
<div className="mb-3 mt-3">
<label className="form-label">Val_Cv</label>
<input type="text" placeholder="Enter Val_Cv" id="val_cv" name="val_cv" className="form-control" ></input>
</div>
<button type="submit" className="btn btn-primary" onClick={handleClick}> Add Patient</button>
<Link to="/Home">see all Home</Link>
</form>
</div>
</div>
</div>
)
}
export default Add; |
Partager