diff --git a/package-lock.json b/package-lock.json index 511d160..8b6c4e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,9 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1" + }, + "devDependencies": { + "web-vitals": "^3.0.4" } }, "node_modules/@ampproject/remapping": { @@ -15346,6 +15349,12 @@ "minimalistic-assert": "^1.0.0" } }, + "node_modules/web-vitals": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-3.0.4.tgz", + "integrity": "sha512-Yau8qf1AJ/dm6MY180Bi0qpCIuWmAfKAnOqmxLecGfIHn0+ND3H4JOhXeY73Pyi9zjSF5J4SNUewHLNUzU7mmA==", + "dev": true + }, "node_modules/webidl-conversions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz", @@ -27020,6 +27029,12 @@ "minimalistic-assert": "^1.0.0" } }, + "web-vitals": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-3.0.4.tgz", + "integrity": "sha512-Yau8qf1AJ/dm6MY180Bi0qpCIuWmAfKAnOqmxLecGfIHn0+ND3H4JOhXeY73Pyi9zjSF5J4SNUewHLNUzU7mmA==", + "dev": true + }, "webidl-conversions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz", diff --git a/package.json b/package.json index 7ad0538..e8d9676 100644 --- a/package.json +++ b/package.json @@ -31,5 +31,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "devDependencies": { + "web-vitals": "^3.0.4" } } diff --git a/src/App.css b/src/App.css index 74b5e05..1d268dc 100644 --- a/src/App.css +++ b/src/App.css @@ -36,3 +36,85 @@ transform: rotate(360deg); } } + +.card-bg{ + background-color: aqua; + margin: 5px; + padding: 5px; +} + +table { + border-collapse: collapse; + width: 80%; + margin-left: auto; + margin-right: auto; +} + +th, td { + text-align: left; + padding: 8px; +} + +tr:nth-child(even){background-color: #f2f2f2} + +th { + background-color: #3995FF; + color: white; +} + +.add { + background-color: #3995FF; + border: none; + color: white; + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin: 4px 2px; + cursor: pointer; + border-radius: 10%; +} + +.delete { + background-color: #FF5353; + border: none; + color: white; + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin: 4px 2px; + cursor: pointer; + border-radius: 10%; +} + +.input_text { + /* background-color:; */ + /* border: none; */ + /* color: white; */ + padding: 10px 15px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin: 40px 10px; + cursor: pointer; + /* border-radius: 10%; */ +} + +.input_search{ + /* background-color:; */ + /* border: none; */ + /* color: white; */ + padding: 10px 15px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin: 10px 10px; + cursor: pointer; + width: 30%; + /* border-radius: 10%; */ +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 4d333f8..30f2159 100644 --- a/src/App.js +++ b/src/App.js @@ -1,14 +1,157 @@ +import { useState } from 'react'; import './App.css'; - -const App = ()=>{ + const PATIENTS = [ + { + id:1, + full_name:"Ali Ahmed", + birth_date:"1990-11-14", + gender:"Male", + phone:"+9647803016985" + }, + { + id:2, + full_name:"Ameer Saad", + birth_date:"2014-1-18", + gender:"Male", + phone:"+9647803019924" + }, + { + id:3, + full_name:"Muna Ali", + birth_date:"2019-4-15", + gender:"Female", + phone:"+9647804017802" + } + ]; +const App = (props)=>{ // State here - return ( -
- {/* Add new patient FORM */} - {/* Search input */} - {/* Table */} -
- ); + const [patients, setPatients] = useState(PATIENTS) + const [filterPatients, setFilterPatient] = useState(PATIENTS) + const [full_name, setFullName] = useState() + const [phone, setPhone] = useState() + const [birth_date, setBirthDate] = useState() + const [gender, setGender] = useState() + const [search, setSearch] = useState() + + const addNew = () =>{ + if(!full_name){ + alert('Please fill your name') + return; + } + let pTemp = !patients?[]:patients + pTemp.push({ + id:pTemp.length>0?pTemp[pTemp.length - 1].id + 1:1, + full_name:full_name, + birth_date:birth_date, + gender:gender, + phone:phone + }) + setPatients([...pTemp]) + setFilterPatient([...pTemp]) + } + + + const FullNamOnChange = (e)=>{ + setFullName(e.target.value) + } + + const genderOnChange = (e)=>{ + setGender(e.target.value) + } + + const birthDateOnChange = (e)=>{ + setBirthDate(e.target.value) + } + + const phoneOnChange = (e)=>{ + setPhone(e.target.value) + } + + const submit = (e)=>{ + e.preventDefault() + addNew() + } + + const SearchOnChange = (e) => { + setSearch(e.target.value) + let pTemp = !patients?[]:patients + let new_pTemp = [...pTemp]; + new_pTemp = (e.target.value)==="" + ?pTemp + :new_pTemp.filter((person) => { + return person.full_name.toLowerCase().includes(e.target.value.toLowerCase()) || + person.phone.includes(e.target.value) || + person.gender.includes(e.target.value) || + person.birth_date.includes(e.target.value) || person.id.toString().includes(e.target.value) ;}); + setFilterPatient([...new_pTemp]) + }; + + const removeHandler = (event)=>{ + let event_id = event.target.value; + let pTemp = !filterPatients?[]:filterPatients + pTemp = pTemp.filter((item) => item.id !== parseInt(event_id)); + setFilterPatient([...pTemp]); + setPatients([...pTemp]) + } + + return ( +
+ {/* Add new patient FORM */} + {/* Search input */} + {/* Table */} + +
+ + + + + +
+ +
+ + +
+

Solved By Karar Haider

+ + + + + + + + + + + + + { + filterPatients?filterPatients.map((item, onRemove )=>{ + const patient = item + return ( + + + + + + + + + ) + }) + : +

No Data

+ } + +
#Full NamePhoneGenderBirth DateEvent
{patient.id}{patient.full_name}{patient.phone}{patient.gender}{patient.birth_date}
+
+ +
+ ); } export default App;