Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Added delete users feedback feature for admin successfully issue 576 #582

Merged
merged 2 commits into from
Aug 8, 2024
Merged
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
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;
Loading