Commit 3e8708c9 authored by Daniel Puchala's avatar Daniel Puchala
Browse files

feat: review deletion finished on fe

parent c3dfa2f0
......@@ -90,6 +90,7 @@ export const Movie = () => {
{reviews.map((review: any) =>
<Review averageRating={
getAverageRating(review)}
id={review.id}
userId={+review.user.id}
text={review.text}
userName={review.user.name}
......
......@@ -2,23 +2,24 @@ import { getToken, getUser } from '../services/auth';
import instance from '../models/axios';
export interface ReviewProps {
id: number,
userId: number,
text: string,
averageRating: number,
userName: string,
}
export const Review = ({userId, text, averageRating, userName}: ReviewProps) => {
export const Review = ({id, userId, text, averageRating, userName}: ReviewProps) => {
const user = getUser();
// const deleteReview = async () => {
// const headers = {
// 'Content-Type': 'application/json',
// 'Authorization': getToken()
// };
// await instance.delete('reviews/delete', { headers });
// alert('Review deleted');
// };
const deleteReview = async () => {
const headers = {
'Content-Type': 'application/json',
'Authorization': getToken()
};
await instance.delete(`reviews/${id}`, { headers });
alert('Review deleted');
};
return (
<div className="w-full h-40 p-2">
......@@ -27,7 +28,7 @@ export const Review = ({userId, text, averageRating, userName}: ReviewProps) =>
<p>Username: {userName}</p>
<p>Average Rating: {averageRating}</p>
{(user?.role === 'ADMIN' || user?.sub == userId) &&
(<button className="border-solid border-2 rounded-lg border-slate-900 p-1 bg-red-600">
(<button onClick={deleteReview} className="border-solid border-2 rounded-lg border-slate-900 p-1 bg-red-600">
Delete
</button>
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment