-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollegeSelect.js
117 lines (106 loc) · 3.15 KB
/
CollegeSelect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import React from "react";
import nameList from "./names.json";
import Grid from "@material-ui/core/Grid";
import Introductions from "./Introduction";
import Paper from "@material-ui/core/Paper";
import Button from "@material-ui/core/Button";
import { Typography } from "@material-ui/core";
import { makeStyles } from "@material-ui/core/styles";
import AutocompleteTextField from "./AutocompleteTextField.js";
const useStyles = makeStyles((theme) => ({
paper: {
padding: theme.spacing(2),
textAlign: "center",
backgroundColor: "#fff",
},
paperOn: {
color: "#fff",
padding: theme.spacing(2),
textAlign: "center",
backgroundColor: theme.palette.primary.main,
},
button: {
width: '50vw'
}
}));
function CollegeSelect({ setResults }) {
const names = Object.values(nameList);
const classes = useStyles();
const [reach, setReach] = React.useState(names[2001]);
const [target, setTarget] = React.useState(names[2001]);
const [safety, setSafety] = React.useState(names[2001]);
const isSelected = (college) =>
college === "Select a University" || college === null;
const canSubmit = () => {
return isSelected(reach) || isSelected(safety) || isSelected(target);
};
const handleClick = () => {
setResults("");
const selectResults = [
{
dream:reach,
target,
safety,
},
];
const configObj = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(selectResults),
};
getResults(configObj);
};
const getResults = async (configObj) => {
try {
const response = await fetch(
"https://college-rec-system.herokuapp.com/model/",
configObj
);
const data = await response.json();
setResults(data);
} catch (error) {
console.log(error);
}
};
return (
<Grid container spacing={3}>
<Grid item xs={12}>
<Introductions />
</Grid>
<Grid item xs={12} sm={4}>
<Paper className={isSelected(reach) ? classes.paper : classes.paperOn}>
<Typography variant='h6'>Reach</Typography>
<AutocompleteTextField college={reach} callback={setReach} />
</Paper>
</Grid>
<Grid item xs={12} sm={4}>
<Paper className={isSelected(target) ? classes.paper : classes.paperOn}>
<Typography variant='h6'>Target</Typography>
<AutocompleteTextField college={target} callback={setTarget} />
</Paper>
</Grid>
<Grid item xs={12} sm={4}>
<Paper className={isSelected(safety) ? classes.paper : classes.paperOn}>
<Typography variant='h6'>Safety</Typography>
<AutocompleteTextField college={safety} callback={setSafety} />
</Paper>
</Grid>
<Grid item xs={12} container justify='center'>
<Button
disabled={canSubmit()}
onClick={() => handleClick()}
variant='contained'
color='primary'
size='large'
className={classes.button}
>
Submit
</Button>
</Grid>
</Grid>
);
}
export default CollegeSelect;