-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update the code * fix code according to feedback * modify backend * edit Readme file to include how to upload the latest version * edit tenderlist.js file * edit tenderlist.js file * edit the code to fix the pagination requirement * fix some errors * revert changes to some files * edit Readme file * testing to revert changes * fix some errors * fix unwanted changes * fix some errors in README file
- Loading branch information
1 parent
bbf2562
commit bb1150a
Showing
8 changed files
with
183 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { useParams, useNavigate } from "react-router-dom"; | ||
|
||
const TendersList = () => { | ||
const { pageNumber } = useParams(); | ||
const currentPage = pageNumber ? parseInt(pageNumber, 10) : 1; | ||
const [tenders, setTenders] = useState([]); | ||
const [loading, setLoading] = useState(true); | ||
const [pagination, setPagination] = useState({ | ||
itemsPerPage: 25, | ||
currentPage: currentPage, | ||
totalPages: 1, | ||
}); | ||
const [error, setError] = useState(null); | ||
const navigate = useNavigate(); | ||
|
||
const fetchTenders = async (page) => { | ||
setLoading(true); | ||
try { | ||
const response = await fetch(`/api/tenders?page=${page}`); | ||
if (!response.ok) { | ||
throw new Error("Failed to fetch tenders. Please try again later."); | ||
} | ||
const data = await response.json(); | ||
|
||
if (data.results && data.pagination) { | ||
setTenders(data.results); | ||
setPagination(data.pagination); | ||
setError(null); | ||
} else { | ||
throw new Error("Server error"); | ||
} | ||
} catch (error) { | ||
setError("Error fetching tenders: " + error.message); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchTenders(currentPage); | ||
}, [currentPage]); | ||
|
||
const loadNextPage = () => { | ||
if (pagination.currentPage < pagination.totalPages && !loading) { | ||
navigate(`/list-tenders/page/${pagination.currentPage + 1}`); | ||
} | ||
}; | ||
|
||
const loadPreviousPage = () => { | ||
if (pagination.currentPage > 1 && !loading) { | ||
navigate(`/list-tenders/page/${pagination.currentPage - 1}`); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>Tenders List</h2> | ||
{error && <p style={{ color: "red" }}>{error}</p>} | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Tender ID</th> | ||
<th>Tender Title</th> | ||
<th>Tender Created Date</th> | ||
<th>Tender Announcement Date</th> | ||
<th>Tender Project Deadline Date</th> | ||
<th>Tender Status</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{tenders.map((tender) => ( | ||
<tr key={tender.id}> | ||
<td>{tender.id}</td> | ||
<td>{tender.title}</td> | ||
<td>{new Date(tender.creation_date).toLocaleDateString()}</td> | ||
<td>{new Date(tender.announcement_date).toLocaleDateString()}</td> | ||
<td>{new Date(tender.deadline).toLocaleDateString()}</td> | ||
<td>{tender.status}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
{loading && <p>Loading...</p>} | ||
<div> | ||
{pagination.currentPage > 1 && ( | ||
<button onClick={loadPreviousPage} disabled={loading}> | ||
Previous Page | ||
</button> | ||
)} | ||
{pagination.currentPage < pagination.totalPages && ( | ||
<button onClick={loadNextPage} disabled={loading}> | ||
Next Page | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TendersList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
const AdminDashboard = () => { | ||
return ( | ||
<div> | ||
<h1>Admin Dashboard</h1> | ||
<Link to="/list-tenders"> | ||
<button>View Tenders</button> | ||
</Link> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AdminDashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
export function BuyerDashboard() { | ||
return ( | ||
<main role="main"> | ||
<div> | ||
<h1>Buyer Dashboard</h1> | ||
<Link to="/publish-tender"> | ||
<button>Publish Tender</button> | ||
</Link> | ||
</div> | ||
</main> | ||
); | ||
} | ||
|
||
export default BuyerDashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters