-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDashboardContainer.tsx
More file actions
49 lines (43 loc) · 1.67 KB
/
DashboardContainer.tsx
File metadata and controls
49 lines (43 loc) · 1.67 KB
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
import {useManualQuery, useMutation} from 'graphql-hooks'
import * as React from 'react'
import {ErrorMessage} from '../base/ErrorMessage'
import {Loading} from '../base/Loading'
import {Feature, Kind, MutationCreateOrderArgs, Query} from '../graphQLTypes'
import {CreateOrder} from '../order/CreateOrder'
import {createOrderMutation} from '../order/createOrderMutation'
import {ListOrders} from '../order/ListOrders'
import {ordersQuery} from '../order/ordersQuery'
export const DashboardContainer = () => {
const [fetchOrders, ordersFetchStatus] = useManualQuery<{orders: Query['orders']}>(ordersQuery)
React.useEffect(() => {
fetchOrders()
}, [false])
const dumbOrderArgs: MutationCreateOrderArgs = {
deliveryAddress: 'New York',
customerName: 'Mr. Muffin',
items: [
{kind: Kind.savoury, features: [Feature.sugarFree], name: 'One'},
{kind: Kind.sweet, features: [Feature.vegan], name: 'Two'},
{kind: Kind.sweet, features: [Feature.exclusive], name: 'Three'},
],
}
const [runCreateOrder, createOrderStatus] = useMutation(createOrderMutation, {variables: dumbOrderArgs})
const createNewOrder = async () => {
await runCreateOrder()
fetchOrders()
}
return (
<>
<h1>
Create <small style={{color: 'silver'}}>fake</small> Order
</h1>
{createOrderStatus.loading && <Loading />}
{createOrderStatus.error && <ErrorMessage message="😿" />}
<CreateOrder onCreateClick={createNewOrder} />
<h1>Orders so far</h1>
{ordersFetchStatus.loading && <Loading />}
{ordersFetchStatus.error && <ErrorMessage message="🙀" />}
<ListOrders orders={ordersFetchStatus.data?.orders} />
</>
)
}