Commit 3ae60f45 authored by NilanDMeegoda's avatar NilanDMeegoda

modifications to candidate registration

parent 7463ea5a
......@@ -100,7 +100,12 @@ def data():
age = body['age']
residence = body['residence']
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({
"firstName": firstName,
"lastName": lastName,
......@@ -109,6 +114,11 @@ def data():
"age": age,
"residence": residence,
"disorders": disorders,
"email": email,
"contactNo": contactNo,
"institute": institute,
"status": status,
"parent": parent,
})
return jsonify({
'status': 'Candidate details are added to the system successfully!',
......@@ -140,6 +150,23 @@ def data():
dataJson.append(dataDict)
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'])
def onedata(id):
......
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { ContainerCard } from "../../components/index";
import toast, { Toaster } from "react-hot-toast";
import "./student_reg.css";
......@@ -12,8 +12,31 @@ const StdReg_screen = () => {
const [nationality, setNationality] = useState("");
const [school, setSchool] = 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 [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) => {
e.preventDefault();
......@@ -26,6 +49,11 @@ const StdReg_screen = () => {
age: age,
residence: residence,
disorders: disorders,
parent: parent,
status: false,
institute: institute,
email: email,
contactNo: contactNo,
};
await API.post("users/", JSON.stringify(payload), {
headers: {
......@@ -44,6 +72,9 @@ const StdReg_screen = () => {
setAge("");
setResidence("");
setDisorders("");
setContactNo("");
setEmail("");
setParent("");
toast.success("Candidate has been added successfully");
} else {
toast.error("Some error occured");
......@@ -119,7 +150,82 @@ const StdReg_screen = () => {
onChange={(e) => setLastName(e.target.value)}
/>
</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">
<label
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