Skip to content

Commit

Permalink
feat(ui):My recent jobs page completed
Browse files Browse the repository at this point in the history
  • Loading branch information
soham4abc committed Jun 21, 2022
1 parent 3003944 commit f6c4ae2
Show file tree
Hide file tree
Showing 4 changed files with 881 additions and 26 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"array-to-tree": "^3.3.2",
"bootstrap": "4.6.0",
"js-cookie": "^2.2.1",
"mdbreact": "^5.2.0",
"prop-types": "^15.8.1",
"query-string": "^7.1.1",
"react": "^17.0.2",
Expand Down
10 changes: 10 additions & 0 deletions src/api/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import { getToken } from "shared/authHelper";
// Function for calling the fetch function for the APIs
import sendRequest from "./sendRequest";

export const getAllJobApi = () => {
const url = endpoints.jobs.scheduleAnalysis();
return sendRequest({
url,
method: "GET",
headers: {
Authorization: getToken(),
},
});
};
// Fetching the jobs
export const getJobApi = ({ jobId }) => {
const url = endpoints.jobs.details(jobId);
Expand Down
107 changes: 101 additions & 6 deletions src/pages/Jobs/MyRecentJobs/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (C) 2021 Shruti Agarwal ([email protected])
Copyright (C) 2021 Shruti Agarwal ([email protected]),
Copyright (C) 2022 Soham Banerjee ([email protected])
SPDX-License-Identifier: GPL-2.0
Expand All @@ -16,20 +17,114 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

import React from "react";
import React, { useEffect, useState } from "react";

// Title
import Title from "components/Title";

// Required functions for API and Error handling
import { getAllJobApi } from "api/jobs";
import { handleError } from "shared/helper";
import { initialMessage } from "constants/constants";
import messages from "constants/messages";
import { Alert } from "components/Widgets";
import { MDBDataTable } from "mdbreact";
import { getUserSelf } from "services/users";

const MyRecentJobs = () => {
// Setting the browse data to the table
const [jobsDataList, setJobsDataList] = useState();

// State Variables for handling Error Boundaries
const [message, setMessage] = useState(initialMessage);
const [showMessage, setShowMessage] = useState(false);

function Dateformatter(date) {
const options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
const d = new Date(date);
return d.toLocaleDateString("en-US", options);
}

useEffect(() => {
const arr = [];
setMessage({
type: "success",
text: messages.loading,
});
setShowMessage(true);

getAllJobApi()
.then((res) => {
// Checking the id of user with the userId from the jobs list
const uid = getUserSelf();
uid.then(function getUid(result) {
const usrId = result.id;
let k = 0;
for (let i = 0; i < res.length; i++) {
// Formatting the date from time stamp to readable date
res[i].queueDate = Dateformatter(res[i].queueDate);
if (res[i].userId === `${usrId}`) {
arr[k] = res[i];
k += 1;
}
}
setJobsDataList(arr);
});

setShowMessage(false);
})
.catch((error) => {
handleError(error, setMessage);
});
}, []);

// Data formatted for the data-table with respective coloumns
const data = {
columns: [
{
label: "Job Name ",
field: "name",
sort: "asc",
width: 150,
},
{
label: "Queue Date",
field: `queueDate`,
sort: "asc",
width: 270,
},
{
label: "Status",
field: "status",
sort: "asc",
width: 200,
},
],
rows: jobsDataList,
};

return (
<>
<Title title="My Recent Jobs" />
<div className="main-container my-3">
<div className="main-container my-3 text-center">
{showMessage && (
<Alert
type={message.type}
setShow={setShowMessage}
message={message.text}
/>
)}
<div className="row">
<div className="col-lg-8 col-md-12 col-sm-12 col-12">
<h1 className="font-size-main-heading">My Recent Jobs</h1>
<br />
<div className="col-md-3 col-lg-2">
<h2 className="font-size-sub-heading">My Jobs</h2>
</div>
<div className="col-md-9 col-lg-10">
<MDBDataTable striped bordered data={data} />
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit f6c4ae2

Please sign in to comment.