-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathTickets.jsx
45 lines (38 loc) · 1.17 KB
/
Tickets.jsx
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
import { useEffect } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { getTickets } from '../features/tickets/ticketSlice'
import Spinner from '../components/Spinner'
import BackButton from '../components/BackButton'
import TicketItem from '../components/TicketItem'
function Tickets() {
const { tickets } = useSelector((state) => state.tickets)
const dispatch = useDispatch()
// NOTE: only need one useEffect here
useEffect(() => {
dispatch(getTickets())
}, [dispatch])
// NOTE: no need for loading state, we can check for absence of tickets
// If we don't have tickets we are loading, if we do have tickets we just
// need to update the tickets with latest tickets in the background
if (!tickets) {
return <Spinner />
}
return (
<>
<BackButton />
<h1>Tickets</h1>
<div className='tickets'>
<div className='ticket-headings'>
<div>Date</div>
<div>Product</div>
<div>Status</div>
<div></div>
</div>
{tickets.map((ticket) => (
<TicketItem key={ticket._id} ticket={ticket} />
))}
</div>
</>
)
}
export default Tickets