-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
admin financial aids requests page completed successfully.
- Loading branch information
1 parent
01e7e2d
commit ed4112f
Showing
9 changed files
with
288 additions
and
10 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
127 changes: 127 additions & 0 deletions
127
src/components/dashboard/FinancialAidRequestElement.jsx
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,127 @@ | ||
import { toast } from "react-toastify"; | ||
import { customFetch } from "../../utils/customFetch"; | ||
|
||
import TableBody from "./shard/TableBody"; | ||
import TableBodyCell from "./shard/TableBodyCell"; | ||
|
||
const FinancialAidRequestElement = ({ request, token, setIsChanged }) => { | ||
const { | ||
_id, | ||
age, | ||
education, | ||
employmentStatus, | ||
course, | ||
user, | ||
applicationStatus, | ||
createdAt, | ||
updatedAt, | ||
} = request; | ||
const formatCreatedAtDate = new Date(createdAt).toLocaleDateString(); | ||
|
||
const handleApprove = async () => { | ||
const confirm = window.confirm( | ||
"Are you sure you want to approve this financial aid request?" | ||
); | ||
if (!confirm) return; | ||
try { | ||
await customFetch.patch( | ||
`admin/approveFinancialAidRequest/${_id}`, | ||
{}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
} | ||
); | ||
setIsChanged(true); | ||
toast.success("Financial application approved successfully"); | ||
} catch (error) { | ||
toast.error(error.response.data.message); | ||
} | ||
}; | ||
|
||
const handleReject = async () => { | ||
const confirm = window.confirm( | ||
"Are you sure you want to reject this financial aid request?" | ||
); | ||
if (!confirm) return; | ||
try { | ||
await customFetch.patch( | ||
`admin/rejectFinancialAidRequest/${_id}`, | ||
{}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
} | ||
); | ||
setIsChanged(true); | ||
toast.success("Financial Aid application rejected successfully"); | ||
} catch (error) { | ||
toast.error(error.response.data.message); | ||
} | ||
}; | ||
|
||
const handleDelete = async () => { | ||
const confirm = window.confirm( | ||
"Are you sure you want to delete this financial aid Request?" | ||
); | ||
if (!confirm) return; | ||
try { | ||
await customFetch.delete(`admin/deleteFinancialAidRequest/${_id}`, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
|
||
setIsChanged(true); | ||
toast.success("Financial Aid application deleted successfully"); | ||
} catch (error) { | ||
toast.error(error.response.data.message); | ||
} | ||
}; | ||
|
||
return ( | ||
<TableBody> | ||
<TableBodyCell>{_id}</TableBodyCell> | ||
<TableBodyCell>{user.name}</TableBodyCell> | ||
<TableBodyCell>{user.email}</TableBodyCell> | ||
<TableBodyCell>{age}</TableBodyCell> | ||
<TableBodyCell>{education}</TableBodyCell> | ||
<TableBodyCell>{employmentStatus}</TableBodyCell> | ||
<TableBodyCell>{course.title}</TableBodyCell> | ||
<TableBodyCell>{formatCreatedAtDate}</TableBodyCell> | ||
<TableBodyCell>{applicationStatus}</TableBodyCell> | ||
|
||
<TableBodyCell> | ||
<div className="flex gap-5"> | ||
<button | ||
type="button" | ||
onClick={handleDelete} | ||
className="bg-red-500 text-white p-1.5 rounded hover:bg-red-800" | ||
> | ||
Delete | ||
</button> | ||
<button | ||
type="button" | ||
onClick={handleApprove} | ||
disabled={applicationStatus === "approved"} | ||
className="bg-green-500 text-white p-1.5 rounded hover:bg-green-800" | ||
> | ||
Approve | ||
</button> | ||
<button | ||
type="button" | ||
onClick={handleReject} | ||
disabled={applicationStatus === "rejected"} | ||
className="bg-blue-500 text-white p-1.5 rounded hover:bg-blue-800" | ||
> | ||
Reject | ||
</button> | ||
</div> | ||
</TableBodyCell> | ||
</TableBody> | ||
); | ||
}; | ||
|
||
export default FinancialAidRequestElement; |
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,21 @@ | ||
import TableHeader from "./shard/TableHeader"; | ||
import TableHeaderCell from "./shard/TableHeaderCell"; | ||
|
||
const FinancialAidRequestHeader = () => { | ||
return ( | ||
<TableHeader> | ||
<TableHeaderCell>Request-ID</TableHeaderCell> | ||
<TableHeaderCell>Name</TableHeaderCell> | ||
<TableHeaderCell>Email</TableHeaderCell> | ||
<TableHeaderCell>Age</TableHeaderCell> | ||
<TableHeaderCell>Education</TableHeaderCell> | ||
<TableHeaderCell>Employment-Status</TableHeaderCell> | ||
<TableHeaderCell>Course-Title</TableHeaderCell> | ||
<TableHeaderCell>Created At</TableHeaderCell> | ||
<TableHeaderCell>Application-Status</TableHeaderCell> | ||
<TableHeaderCell>Actions</TableHeaderCell> | ||
</TableHeader> | ||
); | ||
}; | ||
|
||
export default FinancialAidRequestHeader; |
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
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,107 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { customFetch } from "../../utils/customFetch"; | ||
|
||
import { | ||
PageIntro, | ||
PageContainer, | ||
FinancialAidRequestHeader, | ||
FinancialAidRequestElement, | ||
Pagination, | ||
} from "../../components"; | ||
|
||
const MangeFinancialAidRequests = () => { | ||
const { token } = useSelector((state) => state.userReducers); | ||
const [financialAidRequests, setFinancialAidRequests] = useState([]); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(null); | ||
const [isChanged, setIsChanged] = useState(false); | ||
const [currentPage, setCurrentPage] = useState(1); | ||
const [itemsPerPage, setItemsPerPage] = useState(15); | ||
const [isMorePages, setIsMorePages] = useState(false); | ||
|
||
useEffect(() => { | ||
const fetchFinancialAidRequests = async () => { | ||
setLoading(true); | ||
setError(null); | ||
try { | ||
const response = await customFetch.get( | ||
"admin/getAllFinancialAidRequests", | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
params: { | ||
page: currentPage, | ||
limit: itemsPerPage, | ||
}, | ||
} | ||
); | ||
|
||
const fetchedFinancialAidsApplications = | ||
response.data.data.financialAidRequests; | ||
|
||
if (fetchedFinancialAidsApplications.length < itemsPerPage) { | ||
setIsMorePages(false); | ||
} else { | ||
setIsMorePages(true); | ||
} | ||
|
||
setFinancialAidRequests(fetchedFinancialAidsApplications); | ||
} catch (error) { | ||
setError( | ||
error.message || "Failed to fetch Financial Aids Applications " | ||
); | ||
} finally { | ||
setLoading(false); | ||
setIsChanged(false); | ||
} | ||
}; | ||
|
||
fetchFinancialAidRequests(); | ||
}, [token, isChanged, currentPage, itemsPerPage]); | ||
|
||
return ( | ||
<div className="p-5"> | ||
<PageIntro pageName="Financial Aids requests" /> | ||
<PageContainer tableHeader="Financial Aids requests"> | ||
<FinancialAidRequestHeader /> | ||
{loading ? ( | ||
<tr> | ||
<td colSpan="10" className="text-center p-5 text-3xl"> | ||
Loading Financial Aids Requests...... | ||
</td> | ||
</tr> | ||
) : error ? ( | ||
<div className="flex justify-center items-center h-10"> | ||
<p className="text-2xl font-semibold text-red-500">{error}</p> | ||
</div> | ||
) : financialAidRequests.length > 0 ? ( | ||
financialAidRequests.map((request, index) => ( | ||
<FinancialAidRequestElement | ||
key={request._id} | ||
request={request} | ||
// index={index + 1 + (currentPage - 1) * itemsPerPage} | ||
token={token} | ||
setIsChanged={setIsChanged} | ||
/> | ||
)) | ||
) : ( | ||
<div className="flex justify-center items-center h-10"> | ||
<p className="text-2xl font-semibold"> | ||
No Financial Aid Requests were requested | ||
</p> | ||
</div> | ||
)} | ||
</PageContainer> | ||
<Pagination | ||
currentPage={currentPage} | ||
isMorePages={isMorePages} | ||
onPrevPage={() => setCurrentPage((prev) => prev - 1)} | ||
onNextPage={() => setCurrentPage((prev) => prev + 1)} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MangeFinancialAidRequests; |
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