6
6
FulfillMutation ,
7
7
ReceiptInfoFragment ,
8
8
useFulfillMutation ,
9
+ useRefundMutation ,
9
10
} from '../../__generated__/types' ;
10
11
import ReceiptMenu from './SimplyMenu' ;
11
12
@@ -14,6 +15,7 @@ type Props = {
14
15
displayStudentName : boolean ;
15
16
displayListingName : boolean ;
16
17
editPurchase : any ;
18
+ deletePurchase : any ;
17
19
} ;
18
20
19
21
function determineMiddleText ( displayListingName : boolean , displayStudentName : boolean ) {
@@ -31,21 +33,36 @@ export function PurchaseCard({
31
33
displayListingName,
32
34
displayStudentName,
33
35
editPurchase,
36
+ deletePurchase,
34
37
} : Props ) {
35
38
const middleText = determineMiddleText ( displayListingName , displayStudentName ) ;
36
39
37
- const onMutationCompleted = ( data : FulfillMutation ) => {
40
+ const onFulfillCompleted = ( data : FulfillMutation ) => {
38
41
console . log ( 'Mutation Completed' ) ;
39
42
editPurchase ( data . fulfillPurchase ) ;
40
43
} ;
41
44
42
- const onMutationError = ( e : ApolloError ) => {
45
+ const onRefundCompleted = ( ) => {
46
+ console . log ( 'Mutation Completed' ) ;
47
+ deletePurchase ( purchase . receiptId ) ;
48
+ } ;
49
+
50
+ const onFulfillError = ( e : ApolloError ) => {
51
+ console . log ( e . message ) ;
52
+ } ;
53
+
54
+ const onRefundError = ( e : ApolloError ) => {
43
55
console . log ( e . message ) ;
44
56
} ;
45
57
46
- const [ fulfill , { loading : mutationLoading } ] = useFulfillMutation ( {
47
- onCompleted : onMutationCompleted ,
48
- onError : onMutationError ,
58
+ const [ fulfill , { loading : fulfillLoading } ] = useFulfillMutation ( {
59
+ onCompleted : onFulfillCompleted ,
60
+ onError : onFulfillError ,
61
+ } ) ;
62
+
63
+ const [ refund ] = useRefundMutation ( {
64
+ onCompleted : onRefundCompleted ,
65
+ onError : onRefundError ,
49
66
} ) ;
50
67
51
68
const onClickFulfill = ( ) => {
@@ -68,9 +85,22 @@ export function PurchaseCard({
68
85
} ) . catch ( ( e ) => console . log ( e ) ) ;
69
86
} ;
70
87
88
+ const onClickRefund = ( ) => {
89
+ refund ( {
90
+ variables : {
91
+ course : purchase . course ,
92
+ receiptId : purchase . receiptId ,
93
+ } ,
94
+ } ) . catch ( ( e ) => console . log ( e ) ) ;
95
+ } ;
96
+
71
97
return (
72
98
< div className = "purchase-card" >
73
- < ReceiptMenu onClickUnfulfill = { onClickUnFulfill } fulfilled = { purchase . fulfilled } />
99
+ < ReceiptMenu
100
+ onClickUnfulfill = { onClickUnFulfill }
101
+ fulfilled = { purchase . fulfilled }
102
+ onClickRefund = { onClickRefund }
103
+ />
74
104
{ ! purchase . fulfilled ? (
75
105
< div >
76
106
< Button
@@ -86,7 +116,7 @@ export function PurchaseCard({
86
116
onClick = { onClickFulfill }
87
117
>
88
118
< span > Fulfill </ span >
89
- { mutationLoading ? < CircularProgress size = { 15 } /> : < > </ > }
119
+ { fulfillLoading ? < CircularProgress size = { 15 } /> : < > </ > }
90
120
</ Button >
91
121
</ div >
92
122
) : (
0 commit comments