-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestaurantsListPage.js
79 lines (73 loc) · 2.56 KB
/
RestaurantsListPage.js
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
import React from "react";
import { Table, Container, Button, Col, Image } from "react-bootstrap";
import AlertMessage from "../../components/AlertMessage";
import AddRestaurantPage from "./AddRestaurantPage";
const RestaurantsListPage = () => {
const [restaurants, setRestaurants] = React.useState(
JSON.parse(localStorage.getItem("restaurants")) || []
);
const deleteHandler = (id) => {
const restaurantsListUpdated = restaurants.filter(
(restaurant) => restaurant.id != id
);
setRestaurants(restaurantsListUpdated);
};
const [showRestaurant, setShowRestaurant] = React.useState(true)
const handleAddRestaurant = (e) => {
e.preventDefault();
setShowRestaurant(false)
}
return (
<>
{showRestaurant && restaurants.length == 0 && (
<AlertMessage variant="info" message="No restaurant created" />
)}
{showRestaurant && restaurants.length > 0 && (
<Container>
{/* <LinkContainer to="/admin/restaurant/new"> */}
<Button className="my-3" variant="outline-info" onClick={(e) => handleAddRestaurant(e)}>Add Restaurant</Button>
{/* </LinkContainer> */}
<Table striped hover bordered className="table-sm">
<thead>
<tr class="text-center">
<th>Id</th>
<th>Restaurant Image</th>
<th>Restaurant Name</th>
<th>Restaurant Address</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{restaurants.map((restaurant, index) => (
<tr key={restaurant.id} class="text-center">
<td>{restaurant.id}</td>
<td><Image src={restaurant.image} width={80} height={80} /></td>
<td>{restaurant.name}</td>
<td>{restaurant.address}</td>
<td>
<Col>
<Button variant="info" className="mb-3">
Edit
</Button>
</Col>
<Col>
<Button
variant="danger"
className="mb-3"
onClick={() => deleteHandler(restaurant.id)}
>
Delete
</Button>
</Col>
</td>
</tr>
))}
</tbody>
</Table>
</Container>
)}
{!showRestaurant && <AddRestaurantPage />}
</>
);
};
export default RestaurantsListPage;