Skip to content

Commit b3dfaa7

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ab291e9 commit b3dfaa7

File tree

5 files changed

+100
-136
lines changed

5 files changed

+100
-136
lines changed

frontend/src/components/CreateJobModal.jsx

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function CreateJobModal(props) {
2929
const title = formData.get("title");
3030
const description = formData.get("description");
3131
const location = formData.get("location");
32-
const company_name = formData.get("company_name")
32+
const company_name = formData.get("company_name");
3333
const data = {
3434
title,
3535
description,
@@ -39,28 +39,28 @@ function CreateJobModal(props) {
3939
max_salary,
4040
};
4141

42-
await fetch("https://chapi.techstartucalgary.com/jobs", {
43-
method: "POST",
44-
headers: {
45-
"Content-Type": "application/json",
46-
Authorization: `Bearer ${localStorage.getItem("access_token")}`,
47-
},
48-
body: JSON.stringify(data),
49-
})
42+
await fetch("https://chapi.techstartucalgary.com/jobs", {
43+
method: "POST",
44+
headers: {
45+
"Content-Type": "application/json",
46+
Authorization: `Bearer ${localStorage.getItem("access_token")}`,
47+
},
48+
body: JSON.stringify(data),
49+
})
5050
.then((response) => {
51-
if (!response.ok) {
52-
if (response.status === 401) {
53-
window.location.href = "#/signin";
54-
} else {
55-
setShowGenericError(true);
56-
}
57-
throw new Error("Job creation failed");
51+
if (!response.ok) {
52+
if (response.status === 401) {
53+
window.location.href = "#/signin";
54+
} else {
55+
setShowGenericError(true);
5856
}
59-
props.closeModal();
60-
})
61-
.catch((error) => {
62-
console.error(error);
63-
});
57+
throw new Error("Job creation failed");
58+
}
59+
props.closeModal();
60+
})
61+
.catch((error) => {
62+
console.error(error);
63+
});
6464
};
6565

6666
const formatCurrency = (num) => {
@@ -76,7 +76,7 @@ function CreateJobModal(props) {
7676
<DialogTitle>Create New Job</DialogTitle>
7777
<form className="form" onSubmit={submitNewJob}>
7878
<TextField name="title" label="Job Title" required />
79-
<TextField name="company_name" label = "Company Name" required />
79+
<TextField name="company_name" label="Company Name" required />
8080
<TextField
8181
name="description"
8282
label="Job Description"
@@ -116,9 +116,7 @@ function CreateJobModal(props) {
116116
)}
117117
</div>
118118
<div className="row right-align button-container">
119-
<Button variant="outlined" /*onClick={cancelModal}*/>
120-
Cancel
121-
</Button>
119+
<Button variant="outlined" /*onClick={cancelModal}*/>Cancel</Button>
122120
<Button type="submit" variant="contained">
123121
{/*isEditing ? `Update Job` : `Post Job`*/}
124122
</Button>
Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,41 @@
1-
import React, { useState } from 'react'
2-
import { useEffect } from 'react';
3-
import { Typography } from "@mui/material";
4-
import JobPost from './JobPost';
1+
import React, { useState } from "react";
2+
import { useEffect } from "react";
3+
import { Typography } from "@mui/material";
4+
import JobPost from "./JobPost";
55

66
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-
7+
const [appliedJobs, setAppliedJobs] = useState([]);
8+
9+
const getAplliedJobs = async () => {
10+
await fetch("https://chapi.techstartucalgary.com/applications/me", {
11+
mode: "cors",
12+
headers: {
13+
Authorization: `Bearer ${localStorage.getItem("access_token")}`,
14+
},
15+
})
16+
.then((response) => response.json())
17+
.then((data) => setAppliedJobs(data))
18+
.catch((error) => console.error(error));
19+
};
20+
21+
useEffect(() => {
22+
getAplliedJobs();
23+
}, []);
2824

2925
return (
3026
<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-
27+
{appliedJobs.length > 0 ? (
28+
<div>
29+
<Typography>Applied Jobs</Typography>
30+
{appliedJobs.map((appliedJob) => (
31+
<JobPost key={appliedJob.id} job={appliedJob.job} disabled={true} />
32+
))}
33+
</div>
34+
) : (
35+
<Typography>No found Job</Typography>
36+
)}
5037
</div>
51-
)
52-
}
38+
);
39+
};
5340

54-
export default JobApply
41+
export default JobApply;

frontend/src/components/JobPost.jsx

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ import { Button, Typography } from "@mui/material";
44

55
import "../styles/JobPost.css";
66

7-
87
function JobPost(props) {
9-
10-
const [apply, setApply] = useState(false)
11-
12-
13-
14-
8+
const [apply, setApply] = useState(false);
159

1610
const formatCurrency = (num) => {
1711
return num.toLocaleString("en-US", {
@@ -22,38 +16,32 @@ function JobPost(props) {
2216
};
2317

2418
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")
19+
setApply(true);
20+
try {
21+
const response = await fetch(
22+
`https://chapi.techstartucalgary.com/applications/${props.job.id}`,
23+
{
24+
method: "POST",
25+
mode: "cors",
26+
headers: {
27+
"Content-Type": "application/json",
28+
Authorization: `Bearer ${localStorage.getItem("access_token")}`,
29+
},
30+
},
31+
);
32+
if (response.ok) {
33+
alert("Job was succesful");
34+
setApply(false);
35+
window.location.reload();
36+
} else {
37+
throw new Error("Job application failed. Please try again later");
38+
}
39+
} catch (error) {
40+
console.error(error);
41+
alert(error.message);
42+
setApply(false);
4443
}
45-
}catch(error){
46-
console.error(error)
47-
alert(error.message)
48-
setApply(false)
49-
}
50-
51-
52-
53-
}
54-
55-
56-
44+
};
5745

5846
return (
5947
<div className="jobContainer">
@@ -81,14 +69,17 @@ function JobPost(props) {
8169
);
8270
})}
8371
<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-
72+
variant="contained"
73+
href=""
74+
className="applyButton"
75+
disabled={apply}
76+
onClick={applyHandler}
77+
>
78+
{apply ? (
79+
<Typography>Applying...</Typography>
80+
) : (
81+
<Typography>Apply</Typography>
82+
)}
9283
</Button>
9384
</div>
9485
);

frontend/src/pages/ApplicantHome.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import JobApply from "../components/JobApply";
88

99
function ApplicantHome() {
1010
const [showJobs, setShowJobs] = useState(false);
11-
const [appliedList, setAppliedList] = useState(false)
11+
const [appliedList, setAppliedList] = useState(false);
1212

1313
const toggleJobs = () => {
1414
setShowJobs(!showJobs);
1515
};
1616
const toggleAppliedJobs = () => {
17-
setAppliedList(!appliedList)
18-
}
17+
setAppliedList(!appliedList);
18+
};
1919

2020
return (
2121
<Box className="appHome">
@@ -27,15 +27,15 @@ function ApplicantHome() {
2727
<Typography align="center" variant="h5">
2828
Job List
2929
</Typography>
30-
30+
3131
<IconButton className="toggleJobs" onClick={toggleJobs}>
3232
<ArrowDropDownIcon
3333
fontSize="large"
3434
className={showJobs ? "rotate" : ""}
3535
/>
3636
</IconButton>
3737

38-
<Typography align = "left" variant="h5">
38+
<Typography align="left" variant="h5">
3939
Applied Jobs
4040
</Typography>
4141
<IconButton className="toggleJobs" onClick={toggleAppliedJobs}>

frontend/src/styles/JobPost.css

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@
55
padding: 20px;
66
width: 50% !important;
77
flex-direction: column;
8-
9-
10-
118
}
129

1310
.jobContainer * {
1411
margin-bottom: 10px;
15-
16-
1712
}
1813

1914
.jobTitle {
@@ -51,15 +46,13 @@
5146
align-items: center;
5247
justify-content: space-between;
5348
width: 10% !important;
54-
5549
}
5650

5751
.descContainer {
5852
padding: 5px !important;
5953
display: flex;
6054
align-items: center;
6155
box-sizing: border-box;
62-
6356
}
6457

6558
.jobDescription {
@@ -70,10 +63,5 @@
7063
.jobContainer * {
7164
margin-bottom: 15px;
7265
width: 50% !important ;
73-
74-
7566
}
76-
77-
78-
79-
}
67+
}

0 commit comments

Comments
 (0)