Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions admin/src/apis/br.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,26 @@ export const uploadBRs = async (file) => {
throw error;
}
};
// Delete BR
export const deleteBR = async(email) =>{
try {
const response = await
fetch(`${API_BASE_URL}api/br/delete`,{
method: "DELETE",
credentials: "include",
headers:{
"Content-Type":"application/json",
Authorization:"Bearer admin-coursehub-cc23-golang"},
body: JSON.stringify({email:email}),
});
const result = await response.json();
if(!response.ok){
throw new Error(result.error || result.message || "Failed to delete BR");
}
return result ;
}
catch (error){
console.error("Error deleting single BR:" , error);
throw error;
}
};
12 changes: 11 additions & 1 deletion admin/src/components/brTable.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

const BrTable = ({ brs }) => {
const BrTable = ({ brs , onDelete }) => {
return (
<div className="p-6 bg-white rounded-lg shadow-md">
<div className="flex items-center mb-6">
Expand All @@ -25,6 +25,9 @@ const BrTable = ({ brs }) => {
<th className="py-3 px-4 text-left text-sm font-semibold text-gray-700">
Semester
</th>
<th className="py-3 px-4 text-left text-sm font-semibold text-gray-700">
Actions
</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-100">
Expand All @@ -41,6 +44,13 @@ const BrTable = ({ brs }) => {
<td className="py-4 px-4 text-sm text-gray-600">
{person.semester}
</td>
<td className="py-4 px-4 text-sm text-gray-600">
<button onClick={() => onDelete(person.email)}
className="text-red-500 hover:text-red-900 font-medium transition" >
Remove
</button>
</td>

</tr>
))}
</tbody>
Expand Down
25 changes: 22 additions & 3 deletions admin/src/pages/BranchRepresentatives.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from "react";
import BrTable from "../components/brTable";
import UploadBRs from "../components/UploadBRs";
import { fetchBRs, createBR } from "@/apis/br";
import { fetchBRs, createBR ,deleteBR } from "@/apis/br";
import { FaPlus, FaUpload } from "react-icons/fa";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
Expand Down Expand Up @@ -69,7 +69,26 @@ export default function BranchRepresentatives() {
setTimeout(() => setAddSuccess(null), 3000);
}
}
};
}

const handleDeleteBR = async(email) => {
const isConfirmed = window.confirm(`Are you sure you want to remove ${email} as a Branch Representative ?`);
if(!isConfirmed){
return ;
}
// error == er ;
try {
setLoading(true);
await deleteBR(email);
await loadBRs();
}
catch(er){
console.error("Failed to delete BR :" , er);
setError(er.message || "An error occurred while trying to remove the BR" );
setLoading(false);
}

}

return (
<div className="p-6 space-y-6">
Expand Down Expand Up @@ -126,7 +145,7 @@ export default function BranchRepresentatives() {
<div className="bg-white/80 backdrop-blur-sm rounded-2xl shadow-lg border border-gray-200/60 p-6">
{loading && <p>Loading...</p>}
{error && <p className="text-red-500">{error}</p>}
{!loading && !error && <BrTable brs={brs} />}
{!loading && !error && <BrTable brs={brs} onDelete={handleDeleteBR} />}
</div>

{showUploadModal && (
Expand Down
Loading