@@ -13,6 +13,20 @@ import {
13
13
} from "@material-ui/core" ;
14
14
import PropTypes from "prop-types" ;
15
15
16
+ const createBill = data => {
17
+ fetch ( "/api/bill_exec/create_bill" , {
18
+ method : "POST" ,
19
+ body : JSON . stringify ( data ) ,
20
+ headers : {
21
+ "Content-Type" : "application/json"
22
+ }
23
+ } )
24
+ . then ( res => {
25
+ return res ;
26
+ } )
27
+ . catch ( err => console . log ( err ) ) ;
28
+ } ;
29
+
16
30
class Split extends Component {
17
31
constructor ( props ) {
18
32
super ( props ) ;
@@ -88,15 +102,17 @@ class Split extends Component {
88
102
outstanding_payments : paymentArray
89
103
} ;
90
104
91
- this . createBill ( bill ) ;
105
+ createBill ( bill ) ;
92
106
93
107
if ( ! title ) {
94
108
alert ( "Please enter a title description for this bill." ) ;
95
109
return ;
96
- } if ( ! cost ) {
110
+ }
111
+ if ( ! cost ) {
97
112
alert ( "Please enter an amount for this bill." ) ;
98
113
return ;
99
- } if ( transaction . users . length < 2 ) {
114
+ }
115
+ if ( transaction . users . length < 2 ) {
100
116
alert (
101
117
"There is not enough people to split a bill. Please make sure at least 2 people are on the list."
102
118
) ;
@@ -110,22 +126,6 @@ class Split extends Component {
110
126
history . push ( "/home/transactions" ) ;
111
127
}
112
128
113
- createBill ( data ) {
114
- fetch ( "/api/bill_exec/create_bill" , {
115
- method : "POST" ,
116
- body : JSON . stringify ( data ) ,
117
- headers : {
118
- "Content-Type" : "application/json"
119
- }
120
- } )
121
- . then ( res => {
122
- // If "this" is not called in the createBill method, you may have to create the function outside of the class (es-lint rule)
123
- this . setState ( { } ) ;
124
- return res ;
125
- } )
126
- . catch ( err => console . log ( err ) ) ;
127
- }
128
-
129
129
render ( ) {
130
130
const { transaction } = this . state ;
131
131
return (
0 commit comments