-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplyJob.js
97 lines (77 loc) · 2.89 KB
/
ApplyJob.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
import React, {useState, useEffect} from 'react';
//import Button from '@material-ui/core/Button';
import { Formik, Form, Field} from "formik";
import { useLocation, useHistory } from "react-router-dom";
import { Button, MenuItem, Grid} from "@material-ui/core";
import FileUploader from "../../Components/FileUpload";
import req from "../../api/index"
const ApplyJob = () => {
const [selectedFile, setSelectedFile] = useState(""); //Contains information about currently uploaded file
const [selectedPitch, setSelectedPitch] = useState(""); //Contains information about currently uploaded file
let history = useHistory();
let route = useLocation();
useEffect(() => {
req.get("/jobs/checkApplicant").then((resp) => {
if(resp.status != 200) {
history.push("/#")
}
}).catch((err) => {
history.push("/#")
});
}, [])
const initialValuesApplicant = {};
function apply(selectedFile, selectedPitch, history) {
var form_data = new FormData();
form_data.append("resume", selectedFile);
form_data.append("pitch", selectedPitch);
form_data.append("jobID", route.pathname.split('/')[2]);
// console.log(route.pathname.split('/')[2]);
req.put("/jobs/applyjob", form_data).then((resp) => {
console.log(resp);
if(resp.status == 200) {
history.push("/JobBoard");
}
}).catch(error => {
console.log(error);
if(error.response.status == 418) {
alert("Error");
}
})
}
// const changeHandler = (event) => {
// setSelectedFile(event.target.files[0]); //Sets selected file to the file uploaded using button below
// };
return (
<Formik initialValues={initialValuesApplicant} onSubmit={( nextValues ) => { apply(selectedFile, selectedPitch, history) }}>
{({ submitForm, isSubmitting, touched, errors }) => (
<Form>
<div style={{
display: 'flex',
margin: 'auto',
width: 400,
flexWrap: 'wrap',
}}>
<Grid item container spacing={2}>
<Grid item xs={6}>
<FileUploader text="Upload Resume" setSelectedFile={setSelectedFile} page="ApplyJob"/>
<FileUploader text="Upload Pitch" setSelectedFile={setSelectedPitch} page="ApplyJob"/>
</Grid>
</Grid>
<Grid item container justify="center">
<Button
variant="contained"
color="primary"
onClick={submitForm}
size="small"
fullWidth
>
Submit
</Button>
</Grid>
</div>
</Form>
)}
</Formik>
);
}
export default ApplyJob;