Skip to content

Commit

Permalink
Merge pull request #582 from MeetDOD/issue-576
Browse files Browse the repository at this point in the history
Feat: Added delete users feedback feature for admin successfully issue 576
  • Loading branch information
VaibhavArora314 authored Aug 8, 2024
2 parents fbbde94 + bf4a817 commit 9fdc366
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
27 changes: 24 additions & 3 deletions admin/src/pages/UsersFeedbacks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ const GetFeedbacks = () => {
}
};

const handleDeleteFeedback = async (feedbackId: string) => {
try {
await axios.delete(`/api/v1/admin/deletefeedback/${feedbackId}`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
toast.success("Feedback deleted successfully");
setFeedbacks(feedbacks.filter(feedback => feedback.id !== feedbackId));
} catch (error) {
console.error("Error deleting feedback:", error);
toast.error("Error deleting feedback");
}
};

return (
<div>
<div className="flex-1 flex flex-col lg:ml-80">
Expand Down Expand Up @@ -95,12 +110,18 @@ const GetFeedbacks = () => {
<td className="px-8 py-4 font-semibold">{feedback.comment}</td>
<td className="px-8 py-4 font-semibold">{feedback.rating}</td>
<td className="px-8 py-4 font-semibold">{new Date(feedback.createdAt).toLocaleDateString()}</td>
<td className="px-2 py-4 grid justify-center text-center">
<button
<td className="px-2 py-4 grid grid-cols-1 gap-3 justify-center md:grid-cols-2">
<button
className={`font-semibold rounded-md p-2 text-white border-2 ${feedback.visible ? 'bg-red-500 hover:bg-red-600' : 'bg-sky-500 hover:bg-sky-600'}`}
onClick={() => handleToggleVisibility(feedback.id)}
>
{feedback.visible ? 'Hide from Testimonials' : 'Show on Testimonials'}
{feedback.visible ? 'Hide' : 'Show'}
</button>
<button
className='font-semibold rounded-md p-2 text-white border-2 bg-red-500 hover:bg-red-600'
onClick={() => handleDeleteFeedback(feedback.id)}
>
Delete
</button>
</td>
</tr>
Expand Down
15 changes: 15 additions & 0 deletions backend/src/routes/admin/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,4 +1107,19 @@ export const deleteContactMessage = async (req: Request, res: Response) => {
error: "An error occurred while deleting the contact message!",
});
}
};

export const deleteFeedback = async (req: Request, res: Response) => {
const { id } = req.params;

try {
const feedback = await prisma.feedback.delete({
where: { id },
});

res.status(200).json({ message: 'Feedback deleted successfully', feedback });
} catch (error) {
console.error('Error deleting feedback:', error);
res.status(500).json({ error: 'An unexpected error occurred!' });
}
};
4 changes: 3 additions & 1 deletion backend/src/routes/admin/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Router} from 'express';
import { getPostReactionsController,getFavoritesController,adminLoginController, adminProfileController, allUserForAdmin, blockUserController, unblockUserController, getAdminPostsController, getAdminTrendingPostsController, getAdminStatsController, getGraphsStatsController, updatePostController, deletePostController, getPostByIdController, getAllContactMessages, deleteCommentController, downloadReportController, getFeedbacks, toggleFeedbackVisibility, downloadCommentsReportController, downloadFavoritesReportController, downloadReactionsReportController, downloadUsersReportController, downloadContactMessagesReportController, downloadPostsReportController, deleteContactMessage } from './controller';
import { getPostReactionsController,getFavoritesController,adminLoginController, adminProfileController, allUserForAdmin, blockUserController, unblockUserController, getAdminPostsController, getAdminTrendingPostsController, getAdminStatsController, getGraphsStatsController, updatePostController, deletePostController, getPostByIdController, getAllContactMessages, deleteCommentController, downloadReportController, getFeedbacks, toggleFeedbackVisibility, downloadCommentsReportController, downloadFavoritesReportController, downloadReactionsReportController, downloadUsersReportController, downloadContactMessagesReportController, downloadPostsReportController, deleteContactMessage, deleteFeedback } from './controller';
import { isAdmin } from '../../middleware/adminAuth';

const adminRouter = Router();
Expand Down Expand Up @@ -56,4 +56,6 @@ adminRouter.get("/downloadusersreactionreport", downloadReactionsReportControlle

adminRouter.delete("/deletecontactmessage/:id", isAdmin, deleteContactMessage);

adminRouter.delete('/deletefeedback/:id', isAdmin, deleteFeedback);

export default adminRouter;

0 comments on commit 9fdc366

Please sign in to comment.