Skip to content

Commit

Permalink
[TCES-68] Create Job Posts Page: Replace mock data with backend endpo…
Browse files Browse the repository at this point in the history
…ints (#137)

* Task completed

- Save as Draft and Publish buttons now call backend and not mockresponse
- Buttons now redirect to job posts page and not dashboard
- Made route names more consistent

* Updated Job Posting

- description field is now properly updated when publish button is pushed

* Published job posts now marked as active, and not drafts

* Job post creations accurately reflect draft or active

* Removed unnecessary log

* fix job_type and close_date field updates

Signed-off-by: Kashish Mittal <[email protected]>

---------

Signed-off-by: Kashish Mittal <[email protected]>
Co-authored-by: Kashish Mittal <[email protected]>
  • Loading branch information
penguinc00kies and 04kash authored Jan 20, 2025
1 parent 308229e commit 11b20a8
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function App() {
}
/>
<Route
path="/job-posts/add"
path="/job-postings/add"
element={
<AuthGuard
isAuthenticated={isAuthenticated}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ function AddJobPostParent({ currUser }) {
creation_date: dayjs(),
close_date: dayjs().add(1, "month"),
job_type: [],
description: "",
job_description: "",
state: ""
},
applicationFields: {
custom_questions: [],
Expand Down
16 changes: 8 additions & 8 deletions client/src/components/add-job-post-component/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import AddJobDetails from "./job-info-form";
import AddApplicationFields from "./application-form-fields";
import { Container, ButtonContainer } from "./index.styles";
import UserType from "../../prop-types/UserType";
import createJobPost from "./mockResponse";
import { createJobPost } from "../../utils/job_posts_api";
// import createJobPost from "./mockResponse";
import PostingResultDialog from "./posting-result-dialog";

function AddJobPost({ jobPostData, updateJobPostData, currUser }) {
Expand All @@ -33,7 +34,7 @@ function AddJobPost({ jobPostData, updateJobPostData, currUser }) {
const SUCCESS_DRAFT = {
isSuccess: true,
message: "Your job posting was saved",
handleClose: () => navigate("/dashboard"),
handleClose: () => navigate("/job-postings"),
buttonMessage: "CLOSE",
};
const ERROR_DRAFT = {
Expand All @@ -45,7 +46,7 @@ function AddJobPost({ jobPostData, updateJobPostData, currUser }) {
const SUCCESS_PUBLISH = {
isSuccess: true,
message: "Your job posting was published",
handleClose: () => navigate("/dashboard"),
handleClose: () => navigate("/job-postings"),
buttonMessage: "CLOSE",
};
const ERROR_PUBLISH = {
Expand Down Expand Up @@ -76,18 +77,17 @@ function AddJobPost({ jobPostData, updateJobPostData, currUser }) {

const handleSubmit = async (e, postState) => {
const DRAFT = "Draft";
jobPostData.jobInfo.state = postState // eslint-disable-line no-param-reassign
const updatedJobPost = { ...jobPostData, state: postState };
updateJobPostData("state", postState);

setIsLoading(true);
try {
const response = await createJobPost(
updatedJobPost,
updatedJobPost.jobInfo,
currUser.userID,
currUser.userID,
);

if (response.ok) {
if (response.status === "success") {
setResultModalValues(
postState === DRAFT ? SUCCESS_DRAFT : SUCCESS_PUBLISH,
);
Expand Down Expand Up @@ -231,7 +231,7 @@ function AddJobPost({ jobPostData, updateJobPostData, currUser }) {
variant="contained"
disabled={isLoading}
disableElevation
onClick={() => handleSubmit(null, "Publish")}
onClick={() => handleSubmit(null, "Active")}
>
PUBLISH
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ function AddJobDetails({ jobPostData, setJobPostData }) {
sx={{ m: 1, width: "47%" }}
value={jobPostData.close_date}
minDate={dayjs()}
onChange={(newValue) =>
handleInputChange(newValue, jobPostData, "close_date")
}
onChange={(newValue) => handleInputChange(newValue, "close_date")}
renderInput={(params) => (
// eslint-disable-next-line
<TextField {...params} error={false} helperText="" required />
Expand All @@ -243,14 +241,14 @@ function AddJobDetails({ jobPostData, setJobPostData }) {
<TextField
fullWidth
sx={{ m: 1, width: "96%" }}
id="description"
id="job_description"
label="Description"
multiline
rows={4}
value={jobPostData.description}
value={jobPostData.job_description}
InputLabelProps={{ shrink: true, required: false }}
helperText="*Required"
onChange={(e) => handleInputChange(e.target.value, "description")}
onChange={(e) => handleInputChange(e.target.value, "job_description")}
required
/>
</Container>
Expand Down
12 changes: 6 additions & 6 deletions client/src/components/add-job-post-component/mockResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ function mockFetch(jobPostData, currUserId) {
return new Promise((resolve, reject) => {
console.log(reject);
// Simulate error
setTimeout(() => {
reject(new Error("Failure"));
}, timeout);

// Simulate success
// setTimeout(() => {
// resolve({ ok: 200, jobPostData, currUserId });
// reject(new Error("Failure"));
// }, timeout);

// Simulate success
setTimeout(() => {
resolve({ ok: 200, jobPostData, currUserId });
}, timeout);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function DashboardHeaderComponent({ currUser }) {
Add New Client
</MenuItem>
<MenuItem
onClick={() => handleClose("/job-posts/add")}
onClick={() => handleClose("/job-postings/add")}
sx={{ justifyContent: "center" }}
>
Add New Job Posting
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const COMPENSATION_RATES_FOR_JOB_POSTS = [
"Hourly",
"Weekly",
"Annually",
"Commision",
"Commission",
"Base and Commission",
];

Expand Down
4 changes: 2 additions & 2 deletions server/src/controllers/job_posts/addJobPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const addJobPostRequestHandler = async (req, res) => {
close_date: closeDate,
job_description: jobDescription,
custom_questions: customQuestions,
state = "Draft",
state,
// The creator field is excluded because the backend can retrieve the current user's ID from req.user.id.
} = req.body;

Expand Down Expand Up @@ -85,7 +85,7 @@ const addJobPostRequestHandler = async (req, res) => {
job_description: jobDescription,
custom_questions: customQuestions,
creator: req.user.id,
state: state === "Draft" ? "Draft" : "Active",
state,
});

// ! Return a response stating that the object is successfully created.
Expand Down

0 comments on commit 11b20a8

Please sign in to comment.