-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
59 lines (50 loc) · 1.79 KB
/
App.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
import React, { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import "./App.css";
import ReservationCard from "./components/ReservationCard";
import { addReservation } from "./features/reservationSlice";
import { RootState } from "./features";
import CustomerCard from "./components/CustomerCard";
function App() {
const [reservationNameInput, setReservationNameInput] = useState("");
const reservations = useSelector(
(state: RootState) => state.reservations.value
);
const customers = useSelector(
(state: RootState) => state.customer.value
);
const dispatch = useDispatch();
const handleAddReservations = () => {
// an empty string by default returns falsy
if(!reservationNameInput) return;
dispatch(addReservation(reservationNameInput));
setReservationNameInput("");
}
return (
<div className="App">
<div className="container">
<div className="reservation-container">
<div>
<h5 className="reservation-header">Reservations</h5>
<div className="reservation-cards-container">
{reservations.map((name, index) => {
return <ReservationCard name={name} index={index}/>
})}
</div>
</div>
<div className="reservation-input-container">
<input value={reservationNameInput}
onChange={(e) => setReservationNameInput(e.target.value)}/>
<button onClick={handleAddReservations}>Add</button>
</div>
</div>
<div className="customer-food-container">
{customers.map((customer) => {
return <CustomerCard id={customer.id} food={customer.food} name={customer.name}/>
})}
</div>
</div>
</div>
);
}
export default App;