Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

populate professor and applicant with real data #63

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Checkbox({ onCheckBoxChange, name, checked, disabled }) {
onChange={onCheckBoxChange}
type="checkbox"
id={name}
checked={checked}
name={name}
disabled={disabled}
//checked={!onCheckBoxChange && checked}
Expand Down
64 changes: 43 additions & 21 deletions frontend/grad-admissions-hub-app/src/Pages/Applicant.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@ import Input from '../Components/Input/Input';
import Checkbox from '../Components/Checkbox/Checkbox';

import { UserContext } from '../App';
import { useQuery, gql } from '@apollo/client';


function getApplicantQuery(id){

const APPLICANT_QUERY = gql`
{
applicantById(id: "${id}") {
id
name
graduationDate
majors
}
}
`;

return APPLICANT_QUERY;
}
const majors = [
'Engineering',
'Arts',
Expand All @@ -29,17 +46,26 @@ function Applicant() {
const { userState, setUserState } = useContext(UserContext);
const [applicant, setApplicant] = useState(applicant1);

useEffect(() => {
async function getApplicantById() {
try {
// TODO: Call backend with apollo client here
// setApplicant(res)
} catch (e) {
console.log(e);
}
}
getApplicantById();
}, [])
const { loading, error, data } = useQuery(getApplicantQuery(userState.id));

if (loading) return 'Loading...';
if (error) return `Error! ${error.message}`;
console.log(data && data.applicantById.name);
console.log(data && data.applicantById.id);
console.log(data && data.applicantById.graduationDate);


// useEffect(() => {
// async function getApplicantById() {
// try {
// // TODO: Call backend with apollo client here
// // setApplicant(res)
// } catch (e) {
// console.log(e);
// }
// }
// getApplicantById();
// }, [])

const handleLogOut = async (event) => {
console.log("logout is clicked!");
Expand Down Expand Up @@ -67,32 +93,28 @@ function Applicant() {
placeholder="Full name"
type="text"
label="name"
value={applicant.name}
value={data && data.applicantById.name}
readOnly={true}
/>
<Input
placeholder="Email"
type="text"
label="email"
value={applicant.email}
value={data && data.applicantById.id}
readOnly={true}
/>
<h2>Graduation Date</h2>
<input
type="Date"
name="graduationdate"
readOnly={true}
value={applicant.graduationDate}
/>
<p style={{'color':'white'}}>{new Date(data && data.applicantById.graduationDate).toDateString()}</p>
<h2>Majors</h2>
<ul className="checkbox-list">
{majors.map((elem, idx) => (
{data && data.applicantById.majors.map((elem, idx) => (
<li key= {elem} className="checkbox-item">
<Checkbox
key={idx}
name={elem}
disabled={true}
checked={true}
readOnly = {true}
// disabled={true}
/>
</li>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const ApplicantSignup = () => {

const requestBody = `{
"Applicant": {
"id": "${email}"
"id": "${email}",
"name": "${fullname}",
"graduationDate": "${state.graduationDate}",
"majors": [${state.majors}]
Expand Down
30 changes: 16 additions & 14 deletions frontend/grad-admissions-hub-app/src/Pages/ProfLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ProfLogin = () => {

const requestProf = `{
"Professor": {
"id": "${state.email}"
"id": "${state.email}",
"name": "${state.name}",
"areasOfResearch": [${state.areasOfResearch}]
}
Expand All @@ -61,19 +61,21 @@ const ProfLogin = () => {
profile: 'professor'
// other custom attributes
}
})
if (user) {
const newState = { ...state, verifying: true }
setState(newState);
console.log(user);
console.log("Successfully signed up!");

fetch("https://j2ofh2owcb.execute-api.us-east-1.amazonaws.com/main/graphql",
{
method: 'POST',
body: requestProf
})
}
}).then((res) => {
if (res) {
const newState = { ...state, verifying: true }
setState(newState);
console.log(res);
console.log("Successfully signed up!");

fetch("https://j2ofh2owcb.execute-api.us-east-1.amazonaws.com/main/graphql",
{
method: 'POST',
body: requestProf
})
}
}
);
} catch (error) {
console.log('error signing up:', error);
}
Expand Down
10 changes: 6 additions & 4 deletions frontend/grad-admissions-hub-app/src/Pages/Professor.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ const checkboxes = [
function Professor() {
const { userState, setUserState } = useContext(UserContext);
const [professor, setProfessor] = useState(professor1);
const { loading, error, data } = useQuery(getProfessorQuery("9cc14e72-eca7-4528-b2b8-1ab6f16ce02a"));
console.log("HEEERREE");
console.log(userState.id);
const { loading, error, data } = useQuery(getProfessorQuery(userState.id));

if (loading) return 'Loading...';
if (error) return `Error! ${error.message}`;
console.log(data.professorById.name);
console.log(data && data.professorById.name);

/*
useEffect(() => {
Expand Down Expand Up @@ -90,7 +92,7 @@ function Professor() {
placeholder="Full name"
type="text"
label="name"
value={data.professorById.name}
value={ data && data.professorById.name}
//value={data.professorById.name}
readOnly={true}
/>
Expand All @@ -99,7 +101,7 @@ function Professor() {
type="text"
label="email"

value={id}
value={userState.id}
readOnly={true}
/>
<h2>Areas of Research</h2>
Expand Down