Skip to content

Commit

Permalink
Feat: show delete only to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhannedNoman committed Nov 28, 2020
1 parent afca624 commit 2fe20cf
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions front-end/src/components/Movies/MoviesTable.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Link } from 'react-router-dom';
import { getCurrentUser } from '../../services/authService';
import Table from '../Table';
import Like from './../Like';

Expand All @@ -21,19 +22,25 @@ const MoviesTable = ({ movies, sort, onLike, onDelete, onSort }) => {
<Like liked={movie.liked} onClick={() => onLike(movie)} />
),
},
{
key: 'delete',
content: (movie) => (
<button
className="btn btn-danger btn-sm"
onClick={() => onDelete(movie)}
>
Delete
</button>
),
},
];

const deleteColumn = {
key: 'delete',
content: (movie) => (
<button
className="btn btn-danger btn-sm"
onClick={() => onDelete(movie)}
>
Delete
</button>
),
}

const user = getCurrentUser();
if (user && user.isAdmin) {
columns.push(deleteColumn)
}

return <Table data={movies} columns={columns} sort={sort} onSort={onSort} />;
};

Expand Down

0 comments on commit 2fe20cf

Please sign in to comment.