diff --git a/package.json b/package.json index 7ad0538..86dfb1a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "cra-template": "1.2.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-scripts": "5.0.1" + "react-scripts": "5.0.1", + "uuidv4": "^6.2.13", + "web-vitals": "^2.1.4" }, "scripts": { "start": "react-scripts start", diff --git a/src/App.css b/src/App.css index 74b5e05..5b2b874 100644 --- a/src/App.css +++ b/src/App.css @@ -2,37 +2,34 @@ text-align: center; } -.App-logo { - height: 40vmin; - pointer-events: none; +table { + border: 2px solid rgb(34, 124, 177); + width: 800px; + height: 200px; + position: relative; + left: 20px; + top: 100px; } - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } + +th { + border-bottom: 1px solid black; } - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; + +td { + text-align: center; } - -.App-link { - color: #61dafb; +form{ + position: relative; + top: 82px; + left: -137px; } +.search{ + position: relative; + top: 87px; + left: -216px; + width: 465px; -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } } +input{ + margin:5px ; +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 4d333f8..ebfb065 100644 --- a/src/App.js +++ b/src/App.js @@ -1,14 +1,104 @@ +import logo from './logo.svg'; import './App.css'; +import { useState } from 'react'; +import PatientForm from './components/PatientForm'; +import PatientDet from './components/PatientDet'; + + + +function App() { + const [patients, setPatients] = useState([ + { + id:1, + full_name:"Ali Ahmed", + birth_date:"10/10/1999", + gender:"m", + phone:"+96477889654" + }, + { + id:2, + full_name:"Ameer Saad", + birth_date:"10/10/2000", + gender:"m", + phone:"+96477809654" + }, + { + id:3, + full_name:"Muna Ali", + birth_date:"10/10/1998", + gender:"f", + phone:"+964777809654" + } + ]) + +const [filteredList, setFilteredList] = useState(patients); + +const addPatient=(patient)=>{ + setPatients([...patients, patient]) + setFilteredList([...patients, patient]) + console.log(patients) +} + +const onDelete =(id)=>{ + const delP = patients.filter(p=> p.id !== id) + const delF = filteredList.filter(p=> p.id !== id) + setFilteredList(delF) + setPatients(delP) +} + + + + const filterBySearch = (event) => { + + const pcopy = patients + console.log(pcopy) + const query = event.target.value; + + var updatedList = [...patients]; + updatedList = updatedList.filter((item) => { + return item.full_name.toLowerCase().indexOf(query.toLowerCase()) !== -1; + }); + + if(query){ + setPatients(updatedList); + } + else{ + setPatients(filteredList) + } + + }; -const App = ()=>{ - // State here return (
- {/* Add new patient FORM */} - {/* Search input */} - {/* Table */} + +
+ +
+ + {/* {patients.map(p=>
  • {p.full_name}
  • )} */} + {/* + */} +
    ); } export default App; + + + +// const [arr, setArr] = useState(['Ahmed', 'Fadi', 'Ammar', 'Aws', 'Zaid']) +// const [person, setPerson] = useState('Ahmed') +// let [filterArr, setFilterArr] = useState([]) +// let [name, setName] = useState('') + +// const myFun =(e)=>{ +// // console.log(name) +// setName(e.target.value) +// // const upp = arr.filter((item)=> item==name) +// console.log(arr) +// setFilterArr(arr.filter((item)=> item==name)) +// console.log(filterArr) + + +// } \ No newline at end of file diff --git a/src/components/PatientDet.jsx b/src/components/PatientDet.jsx new file mode 100644 index 0000000..2a98e32 --- /dev/null +++ b/src/components/PatientDet.jsx @@ -0,0 +1,27 @@ +import '../App.css' +import PatientRec from './PatientRec'; + +function PatientDet(props) { + return ( +
    + + + + + + + + + + + { + + props.patients.map(p=> ) + + } +
    Full NameBirth-DateGenderPhone 
    +
    + ); +} + +export default PatientDet; \ No newline at end of file diff --git a/src/components/PatientForm.jsx b/src/components/PatientForm.jsx new file mode 100644 index 0000000..ae14c4c --- /dev/null +++ b/src/components/PatientForm.jsx @@ -0,0 +1,67 @@ +import { useState } from "react"; +// import { uuid } from 'uuidv4' +import { v4 as uuidv4 } from 'uuid'; +import '../App.css' + +function PatientForm(props) { + const [name, setName]=useState('') + const [birth, setBirth]= useState('') + const [gender, setGender]= useState('m') + const [phone, setPhone]= useState('') + + + const handleName =(e)=>{ + setName(e.target.value) + } + + const handleBirth =(e)=>{ + setBirth(e.target.value) + } + + const handleGender =(e)=>{ + setGender(e.target.value) + } + + const handlePhone =(e)=>{ + setPhone(e.target.value) + } + + // const handleName =(e)=>{ + // setName(e.target.value) + // } + const handleSubmit =(e)=>{ + e.preventDefault() + const patient ={ + id: uuidv4(), + full_name: name, + birth_date:birth, + gender:gender, + phone:phone + + } + props.addPatient(patient) + setBirth('') + setName('') + setPhone('') + } + + + + + + return ( +
    + + + {/* */} + + + +
    + ); +} + +export default PatientForm; \ No newline at end of file diff --git a/src/components/PatientRec.jsx b/src/components/PatientRec.jsx new file mode 100644 index 0000000..2156445 --- /dev/null +++ b/src/components/PatientRec.jsx @@ -0,0 +1,12 @@ +function PatientRec(props) { + return ( + + {props.patient.full_name} + {props.patient.birth_date} + {props.patient.gender} + {props.patient.phone} + + ); +} + +export default PatientRec; \ No newline at end of file