-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.tsx
89 lines (77 loc) · 2.18 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React, { useState } from 'react';
import { FiEdit3, FiTrash } from 'react-icons/fi';
import { Container } from './styles';
interface IFoodPlate {
id: number;
name: string;
image: string;
price: string;
description: string;
available: boolean;
}
interface IProps {
food: IFoodPlate;
handleDelete: (id: number) => {};
handleEditFood: (food: IFoodPlate) => void;
}
const Food: React.FC<IProps> = ({
food,
handleDelete,
handleEditFood,
}: IProps) => {
const [isAvailable, setIsAvailable] = useState(food.available);
async function toggleAvailable(): Promise<void> {
// TODO UPDATE STATUS (available)
}
function setEditingFood(): void {
// TODO - SET THE ID OF THE CURRENT ITEM TO THE EDITING FOOD AND OPEN MODAL
}
return (
<Container available={isAvailable}>
<header>
<img src={food.image} alt={food.name} />
</header>
<section className="body">
<h2>{food.name}</h2>
<p>{food.description}</p>
<p className="price">
R$ <b>{food.price}</b>
</p>
</section>
<section className="footer">
<div className="icon-container">
<button
type="button"
className="icon"
onClick={() => setEditingFood()}
data-testid={`edit-food-${food.id}`}
>
<FiEdit3 size={20} />
</button>
<button
type="button"
className="icon"
onClick={() => handleDelete(food.id)}
data-testid={`remove-food-${food.id}`}
>
<FiTrash size={20} />
</button>
</div>
<div className="availability-container">
<p>{isAvailable ? 'Disponível' : 'Indisponível'}</p>
<label htmlFor={`available-switch-${food.id}`} className="switch">
<input
id={`available-switch-${food.id}`}
type="checkbox"
checked={isAvailable}
onChange={toggleAvailable}
data-testid={`change-status-food-${food.id}`}
/>
<span className="slider" />
</label>
</div>
</section>
</Container>
);
};
export default Food;