Commit 3ae60f45 authored by NilanDMeegoda's avatar NilanDMeegoda

modifications to candidate registration

parent 7463ea5a
...@@ -100,7 +100,12 @@ def data(): ...@@ -100,7 +100,12 @@ def data():
age = body['age'] age = body['age']
residence = body['residence'] residence = body['residence']
disorders = body['disorders'] disorders = body['disorders']
# db.users.insert_one({ email = body['email']
contactNo = body['contactNo']
institute = body['institute']
status = body['status']
parent = body['parent']
db.db['users'].insert_one({ db.db['users'].insert_one({
"firstName": firstName, "firstName": firstName,
"lastName": lastName, "lastName": lastName,
...@@ -109,6 +114,11 @@ def data(): ...@@ -109,6 +114,11 @@ def data():
"age": age, "age": age,
"residence": residence, "residence": residence,
"disorders": disorders, "disorders": disorders,
"email": email,
"contactNo": contactNo,
"institute": institute,
"status": status,
"parent": parent,
}) })
return jsonify({ return jsonify({
'status': 'Candidate details are added to the system successfully!', 'status': 'Candidate details are added to the system successfully!',
...@@ -140,6 +150,23 @@ def data(): ...@@ -140,6 +150,23 @@ def data():
dataJson.append(dataDict) dataJson.append(dataDict)
return jsonify(dataJson) return jsonify(dataJson)
@app.route('/institutes/', methods=['GET'])
@cross_origin()
def data3():
# GET all data from database
if request.method == 'GET':
allData = db.db['institutes'].find()
dataJson = []
for data in allData:
id = data['_id']
name = data['name']
dataDict = {
'id': str(id),
'name': name,
}
dataJson.append(dataDict)
return jsonify(dataJson)
@app.route('/users/<string:id>', methods=['GET', 'DELETE', 'PUT']) @app.route('/users/<string:id>', methods=['GET', 'DELETE', 'PUT'])
def onedata(id): def onedata(id):
......
import React, { useState } from "react"; import React, { useState, useEffect } from "react";
import { ContainerCard } from "../../components/index"; import { ContainerCard } from "../../components/index";
import toast, { Toaster } from "react-hot-toast"; import toast, { Toaster } from "react-hot-toast";
import "./student_reg.css"; import "./student_reg.css";
...@@ -12,8 +12,31 @@ const StdReg_screen = () => { ...@@ -12,8 +12,31 @@ const StdReg_screen = () => {
const [nationality, setNationality] = useState(""); const [nationality, setNationality] = useState("");
const [school, setSchool] = useState(""); const [school, setSchool] = useState("");
const [age, setAge] = useState(""); const [age, setAge] = useState("");
const [email, setEmail] = useState("");
const [contactNo, setContactNo] = useState("");
const [parent, setParent] = useState("");
const [institute, setInstitute] = useState("");
const [residence, setResidence] = useState(""); const [residence, setResidence] = useState("");
const [disorders, setDisorders] = useState(""); const [disorders, setDisorders] = useState("");
const [instituteData, setInstituteData] = useState([{}]);
const headerConfig = {
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
},
};
useEffect(() => {
const fetchData = async () => {
const response = await API.get("institutes/", headerConfig)
.then((response) => setInstituteData(response.data))
.catch((err) => {
console.log(err.message);
});
};
fetchData();
}, []);
let handleSubmit = async (e) => { let handleSubmit = async (e) => {
e.preventDefault(); e.preventDefault();
...@@ -26,6 +49,11 @@ const StdReg_screen = () => { ...@@ -26,6 +49,11 @@ const StdReg_screen = () => {
age: age, age: age,
residence: residence, residence: residence,
disorders: disorders, disorders: disorders,
parent: parent,
status: false,
institute: institute,
email: email,
contactNo: contactNo,
}; };
await API.post("users/", JSON.stringify(payload), { await API.post("users/", JSON.stringify(payload), {
headers: { headers: {
...@@ -44,6 +72,9 @@ const StdReg_screen = () => { ...@@ -44,6 +72,9 @@ const StdReg_screen = () => {
setAge(""); setAge("");
setResidence(""); setResidence("");
setDisorders(""); setDisorders("");
setContactNo("");
setEmail("");
setParent("");
toast.success("Candidate has been added successfully"); toast.success("Candidate has been added successfully");
} else { } else {
toast.error("Some error occured"); toast.error("Some error occured");
...@@ -119,7 +150,82 @@ const StdReg_screen = () => { ...@@ -119,7 +150,82 @@ const StdReg_screen = () => {
onChange={(e) => setLastName(e.target.value)} onChange={(e) => setLastName(e.target.value)}
/> />
</div> </div>
<div className="col-span-6 sm:col-span-3">
<label
htmlFor="parent-name"
className="block text-sm font-medium text-gray-700"
>
Parent name
</label>
<input
type="text"
name="parent-name"
id="parent-name"
value={parent}
className="mt-1 text-black focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-2 rounded-md"
onChange={(e) => setParent(e.target.value)}
/>
</div>
<div className="col-span-6 sm:col-span-3">
<label
htmlFor="contactNo"
className="block text-sm font-medium text-gray-700"
>
Contact number
</label>
<input
type="text"
name="contactNo"
id="contactNo"
value={contactNo}
className="mt-1 text-black focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-2 rounded-md"
onChange={(e) => setContactNo(e.target.value)}
/>
</div>
<div className="col-span-6 sm:col-span-3">
<label
htmlFor="email"
className="block text-sm font-medium text-gray-700"
>
Email
</label>
<input
type="email"
name="email"
id="email"
value={email}
className="mt-1 text-black focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-2 rounded-md"
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div className="col-span-6 sm:col-span-3">
<label
htmlFor="institute"
className="block text-sm font-medium text-gray-700"
>
Please select the medical center
</label>
<select
id="institute"
name="institute"
defaultValue={"DEFAULT"}
className="mt-1 block text-black w-40 py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
onChange={(e) =>
setInstitute(e.target.value)
}
>
<option value="DEFAULT" disabled>
Select ...
</option>
{instituteData.map((e, key) => {
return (
<option key={key} value={e.id}>
{e.name}
</option>
);
})}
</select>
</div>
<div className="col-span-6 sm:col-span-3"> <div className="col-span-6 sm:col-span-3">
<label <label
htmlFor="country" htmlFor="country"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment