Skip to content

Commit ab291e9

Browse files
committed
Finished with applicants job list and application.
1 parent 4402495 commit ab291e9

File tree

5 files changed

+166
-5
lines changed

5 files changed

+166
-5
lines changed

frontend/src/components/CreateJobModal.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ function CreateJobModal(props) {
116116
)}
117117
</div>
118118
<div className="row right-align button-container">
119-
<Button variant="outlined" onClick={cancelModal}>
119+
<Button variant="outlined" /*onClick={cancelModal}*/>
120120
Cancel
121121
</Button>
122122
<Button type="submit" variant="contained">
123-
{isEditing ? `Update Job` : `Post Job`}
123+
{/*isEditing ? `Update Job` : `Post Job`*/}
124124
</Button>
125125
</div>
126126
</form>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, { useState } from 'react'
2+
import { useEffect } from 'react';
3+
import { Typography } from "@mui/material";
4+
import JobPost from './JobPost';
5+
6+
const JobApply = () => {
7+
8+
const [appliedJobs, setAppliedJobs] = useState([]);
9+
10+
const getAplliedJobs = async () => {
11+
await fetch("https://chapi.techstartucalgary.com/applications/me", {
12+
mode: "cors",
13+
headers: {
14+
Authorization: `Bearer ${localStorage.getItem("access_token")}`,
15+
},
16+
})
17+
.then((response) => response.json())
18+
.then((data) => setAppliedJobs(data))
19+
.catch((error) => console.error(error))
20+
}
21+
22+
useEffect(() => {
23+
getAplliedJobs()
24+
},[])
25+
26+
27+
28+
29+
return (
30+
<div>
31+
{appliedJobs.length > 0 ? (
32+
<div>
33+
<Typography>Applied Jobs</Typography>
34+
{appliedJobs.map((appliedJob) => (
35+
<JobPost
36+
key = {appliedJob.id}
37+
job = {appliedJob.job}
38+
disabled = {true}
39+
40+
41+
/>
42+
)) }
43+
44+
</div>
45+
):(
46+
47+
<Typography>No found Job</Typography>
48+
)}
49+
50+
</div>
51+
)
52+
}
53+
54+
export default JobApply

frontend/src/components/JobPost.jsx

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import React from "react";
2+
import { useState } from "react";
23
import { Button, Typography } from "@mui/material";
34

45
import "../styles/JobPost.css";
56

7+
68
function JobPost(props) {
9+
10+
const [apply, setApply] = useState(false)
11+
12+
13+
14+
15+
716
const formatCurrency = (num) => {
817
return num.toLocaleString("en-US", {
918
style: "currency",
@@ -12,6 +21,40 @@ function JobPost(props) {
1221
});
1322
};
1423

24+
const applyHandler = async () => {
25+
setApply(true)
26+
try{
27+
28+
29+
const response = await fetch(`https://chapi.techstartucalgary.com/applications/${props.job.id}`, {
30+
method:"POST",
31+
mode:"cors",
32+
headers: {
33+
"Content-Type": "application/json",
34+
Authorization: `Bearer ${localStorage.getItem("access_token")}`,
35+
},
36+
37+
})
38+
if (response.ok) {
39+
alert("Job was succesful")
40+
setApply(false)
41+
window.location.reload();
42+
}else {
43+
throw new Error("Job application failed. Please try again later")
44+
}
45+
}catch(error){
46+
console.error(error)
47+
alert(error.message)
48+
setApply(false)
49+
}
50+
51+
52+
53+
}
54+
55+
56+
57+
1558
return (
1659
<div className="jobContainer">
1760
<Typography className="jobTitle">{props.job.title}</Typography>
@@ -37,8 +80,15 @@ function JobPost(props) {
3780
</Typography>
3881
);
3982
})}
40-
<Button variant="contained" className="applyButton">
41-
<Typography>Apply</Typography>
83+
<Button
84+
variant="contained"
85+
href="" className="applyButton"
86+
disabled = {apply}
87+
onClick = {applyHandler}
88+
89+
>
90+
{apply ? <Typography>Applying...</Typography> : <Typography>Apply</Typography>}
91+
4292
</Button>
4393
</div>
4494
);

frontend/src/pages/ApplicantHome.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import "../styles/ApplicantHome.css";
44
import JobList from "../components/JobList";
55
import { Button, Container, IconButton, Typography, Box } from "@mui/material";
66
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
7+
import JobApply from "../components/JobApply";
78

89
function ApplicantHome() {
910
const [showJobs, setShowJobs] = useState(false);
11+
const [appliedList, setAppliedList] = useState(false)
1012

1113
const toggleJobs = () => {
1214
setShowJobs(!showJobs);
1315
};
16+
const toggleAppliedJobs = () => {
17+
setAppliedList(!appliedList)
18+
}
1419

1520
return (
1621
<Box className="appHome">
@@ -22,15 +27,27 @@ function ApplicantHome() {
2227
<Typography align="center" variant="h5">
2328
Job List
2429
</Typography>
30+
2531
<IconButton className="toggleJobs" onClick={toggleJobs}>
2632
<ArrowDropDownIcon
2733
fontSize="large"
2834
className={showJobs ? "rotate" : ""}
2935
/>
3036
</IconButton>
37+
38+
<Typography align = "left" variant="h5">
39+
Applied Jobs
40+
</Typography>
41+
<IconButton className="toggleJobs" onClick={toggleAppliedJobs}>
42+
<ArrowDropDownIcon
43+
fontSize="large"
44+
className={showJobs ? "rotate" : ""}
45+
/>
46+
</IconButton>
3147
</Container>
3248

3349
{showJobs && <JobList />}
50+
{appliedList && <JobApply />}
3451
</Box>
3552
);
3653
}

frontend/src/styles/JobPost.css

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
border-radius: 15px;
44
margin-bottom: 10px;
55
padding: 20px;
6-
width: 100%;
6+
width: 50% !important;
7+
flex-direction: column;
8+
9+
10+
711
}
812

913
.jobContainer * {
1014
margin-bottom: 10px;
15+
16+
1117
}
1218

1319
.jobTitle {
@@ -37,3 +43,37 @@
3743
border-radius: 15px;
3844
padding: 20px;
3945
}
46+
47+
@media only screen and (max-width: 600px) {
48+
.jobContainer {
49+
display: flex;
50+
flex-direction: column;
51+
align-items: center;
52+
justify-content: space-between;
53+
width: 10% !important;
54+
55+
}
56+
57+
.descContainer {
58+
padding: 5px !important;
59+
display: flex;
60+
align-items: center;
61+
box-sizing: border-box;
62+
63+
}
64+
65+
.jobDescription {
66+
font-size: 10px !important;
67+
width: 100% !important;
68+
text-align: center !important;
69+
}
70+
.jobContainer * {
71+
margin-bottom: 15px;
72+
width: 50% !important ;
73+
74+
75+
}
76+
77+
78+
79+
}

0 commit comments

Comments
 (0)