Функц кнопки убраты

This commit is contained in:
DyCTaTOR 2024-01-12 15:26:20 +04:00
parent b45991ed26
commit e040fd5ce6
3 changed files with 15 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import {
} from 'react-bootstrap-icons'; } from 'react-bootstrap-icons';
const UpdateNew = ({ const UpdateNew = ({
item, onEdit, onDelete, item, onEdit, onDelete, obj,
}) => { }) => {
const handleAnchorClick = (event, action) => { const handleAnchorClick = (event, action) => {
event.preventDefault(); event.preventDefault();
@ -16,8 +16,15 @@ const UpdateNew = ({
<img src={item.image} width="100%" alt={item.name} /> <img src={item.image} width="100%" alt={item.name} />
<div className="rectNewsTextBox text-center"> <div className="rectNewsTextBox text-center">
<span className="rectNewsText"> <span className="rectNewsText">
{obj === null || obj.role === 'user' ? (
<>
</>
) : (
<>
<a href="#" onClick={(event) => handleAnchorClick(event, onEdit)}><PencilFill /></a> <a href="#" onClick={(event) => handleAnchorClick(event, onEdit)}><PencilFill /></a>
<a href="#" onClick={(event) => handleAnchorClick(event, onDelete)}><Trash3 /></a> <a href="#" onClick={(event) => handleAnchorClick(event, onDelete)}><Trash3 /></a>
</>
)}
{item.description} {item.description}
</span> </span>
</div> </div>
@ -31,6 +38,7 @@ UpdateNew.propTypes = {
item: PropTypes.object, item: PropTypes.object,
onDelete: PropTypes.func, onDelete: PropTypes.func,
onEdit: PropTypes.func, onEdit: PropTypes.func,
obj: PropTypes.func,
}; };
export default UpdateNew; export default UpdateNew;

View File

@ -18,7 +18,7 @@ import { AuthContext } from '../../logins/login/context/AuthContext.jsx';
// должно все перерисовываться // должно все перерисовываться
const UpdateNews = () => { const UpdateNews = () => {
const { state, dispatch } = useContext(AuthContext); const { state } = useContext(AuthContext);
let obj = null; let obj = null;
if (state.user !== null) { if (state.user !== null) {
@ -64,6 +64,7 @@ const UpdateNews = () => {
lines.map((item) => { lines.map((item) => {
return <UpdateNew key={item.id} return <UpdateNew key={item.id}
item={item} item={item}
obj = {obj}
/>; />;
})} })}
</div> </div>
@ -77,7 +78,7 @@ const UpdateNews = () => {
type='text' required /> type='text' required />
<div className="text-center"> <div className="text-center">
<Button variant='info' onClick={() => showFormModal()}> <Button variant='info' onClick={() => showFormModal()}>
Добавить товар</Button> Добавить Новость</Button>
</div> </div>
<div className="mainDiv row"> <div className="mainDiv row">
@ -87,6 +88,7 @@ const UpdateNews = () => {
item={item} item={item}
onDelete={() => showDeleteModal(item.id)} onDelete={() => showDeleteModal(item.id)}
onEdit={() => showFormModal(item.id)} onEdit={() => showFormModal(item.id)}
obj = {obj}
/>; />;
})} })}
</div> </div>