1
+ /* eslint-disable react/jsx-no-bind */
2
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1
3
import React , { useState } from 'react'
2
4
3
5
import { Button } from '~/libs/ui'
@@ -14,34 +16,33 @@ const PaymentsTable: React.FC<PaymentTableProps> = (props: PaymentTableProps) =>
14
16
const [ selectedPayments , setSelectedPayments ] = useState < { [ paymentId : string ] : boolean } > ( { } )
15
17
16
18
const togglePaymentSelection = ( paymentId : string ) => {
17
- setSelectedPayments ( ( prevSelected ) => ( {
19
+ setSelectedPayments ( prevSelected => ( {
18
20
...prevSelected ,
19
21
[ paymentId ] : ! prevSelected [ paymentId ] ,
20
22
} ) )
21
23
}
22
24
23
- const isAllSelected = props . payments . length > 0 && props . payments . every ( ( payment ) => selectedPayments [ payment . id ] )
25
+ const isAllSelected = props . payments . length > 0 && props . payments . every ( payment => selectedPayments [ payment . id ] )
24
26
25
27
const toggleAllPayments = ( ) => {
26
28
if ( isAllSelected ) {
27
29
setSelectedPayments ( { } )
28
30
} else {
29
31
const newSelections : { [ paymentId : string ] : boolean } = { }
30
- props . payments . forEach ( ( payment ) => {
32
+ props . payments . forEach ( payment => {
31
33
newSelections [ payment . id ] = true
32
34
} )
33
35
setSelectedPayments ( newSelections )
34
36
}
35
37
}
36
38
37
- const calculateTotal = ( ) =>
38
- props . payments . reduce ( ( acc : number , payment : Winning ) => {
39
- if ( selectedPayments [ payment . id ] ) {
40
- return acc + parseFloat ( payment . netPayment . replace ( / [ ^ 0 - 9 . - ] + / g, '' ) )
41
- }
39
+ const calculateTotal = ( ) => props . payments . reduce ( ( acc : number , payment : Winning ) => {
40
+ if ( selectedPayments [ payment . id ] ) {
41
+ return acc + parseFloat ( payment . netPayment . replace ( / [ ^ 0 - 9 . - ] + / g, '' ) )
42
+ }
42
43
43
- return acc
44
- } , 0 )
44
+ return acc
45
+ } , 0 )
45
46
46
47
const total = calculateTotal ( )
47
48
@@ -70,7 +71,7 @@ const PaymentsTable: React.FC<PaymentTableProps> = (props: PaymentTableProps) =>
70
71
</ tr >
71
72
</ thead >
72
73
< tbody >
73
- { props . payments . map ( ( payment ) => (
74
+ { props . payments . map ( payment => (
74
75
< tr key = { payment . id } className = { selectedPayments [ payment . id ] ? 'selected' : '' } >
75
76
< td className = 'body-main' > { payment . description } </ td >
76
77
< td className = 'body-main-bold' > { payment . type } </ td >
@@ -95,12 +96,16 @@ const PaymentsTable: React.FC<PaymentTableProps> = (props: PaymentTableProps) =>
95
96
</ table >
96
97
</ div >
97
98
< div className = { styles . paymentFooter } >
98
- < div className = { styles . total } > Total: ${ total . toFixed ( 2 ) } </ div >
99
+ < div className = { styles . total } >
100
+ Total: $
101
+ { total . toFixed ( 2 ) }
102
+ </ div >
99
103
< Button
100
104
primary
101
105
onClick = { ( ) => {
102
106
props . onPayMeClick ( selectedPayments )
103
- } } >
107
+ } }
108
+ >
104
109
PAY ME
105
110
</ Button >
106
111
</ div >
0 commit comments