@@ -7,11 +7,12 @@ import React, { FC, useCallback, useEffect } from 'react'
77import { Collapsible , ConfirmModal , LoadingCircles } from '~/libs/ui'
88import { UserProfile } from '~/libs/core'
99
10- import { editPayment , getMemberHandle , getPayments } from '../../../lib/services/wallet'
10+ import { editPayment , getMemberHandle , getPaymentMethods , getPayments , getTaxForms } from '../../../lib/services/wallet'
1111import { Winning , WinningDetail } from '../../../lib/models/WinningDetail'
1212import { FilterBar , formatIOSDateString , PaymentView } from '../../../lib'
1313import { ConfirmFlowData } from '../../../lib/models/ConfirmFlowData'
1414import { PaginationInfo } from '../../../lib/models/PaginationInfo'
15+ import { TaxForm } from '../../../lib/models/TaxForm'
1516import PaymentEditForm from '../../../lib/components/payment-edit/PaymentEdit'
1617import PaymentsTable from '../../../lib/components/payments-table/PaymentTable'
1718
@@ -25,9 +26,9 @@ interface ListViewProps {
2526function formatStatus ( status : string ) : string {
2627 switch ( status ) {
2728 case 'ON_HOLD' :
28- return 'Owed '
29+ return 'ON_HOLD '
2930 case 'ON_HOLD_ADMIN' :
30- return 'On Hold'
31+ return 'On Hold (Admin) '
3132 case 'OWED' :
3233 return 'Owed'
3334 case 'PAID' :
@@ -97,7 +98,7 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
9798 } , [ ] )
9899
99100 const convertToWinnings = useCallback (
100- ( payments : WinningDetail [ ] , handleMap : Map < number , string > ) => payments . map ( payment => {
101+ ( payments : WinningDetail [ ] , handleMap : Map < number , string > , userHasTaxFormSetup : Map < string , boolean > , userHasPaymentProvider : Map < string , boolean > ) : ReadonlyArray < Winning > => payments . map ( payment => {
101102 const now = new Date ( )
102103 const releaseDate = new Date ( payment . releaseDate )
103104 const diffMs = releaseDate . getTime ( ) - now . getTime ( )
@@ -123,6 +124,16 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
123124 status = 'Cancelled'
124125 }
125126
127+ if ( status === 'ON_HOLD' ) {
128+ if ( ! userHasTaxFormSetup . get ( payment . winnerId ) ) {
129+ status = 'On Hold (Tax Form)'
130+ } else if ( ! userHasPaymentProvider . get ( payment . winnerId ) ) {
131+ status = 'On Hold (Payment Provider)'
132+ } else {
133+ status = 'On Hold (Member)'
134+ }
135+ }
136+
126137 return {
127138 createDate : formatIOSDateString ( payment . createdAt ) ,
128139 currency : payment . details [ 0 ] . currency ,
@@ -153,8 +164,31 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
153164 try {
154165 const payments = await getPayments ( pagination . pageSize , ( pagination . currentPage - 1 ) * pagination . pageSize , filters )
155166 const winnerIds = payments . winnings . map ( winning => winning . winnerId )
167+
168+ const onHoldUserIds = payments . winnings
169+ . filter ( winning => winning . details [ 0 ] . status === 'ON_HOLD' )
170+ . map ( winning => winning . winnerId )
171+
172+ const userHasTaxFormSetup : Map < string , boolean > = new Map ( )
173+ const userHasPaymentProvider : Map < string , boolean > = new Map ( )
174+
175+ try {
176+ const missingTaxForms = await getTaxForms ( 100 , 0 , onHoldUserIds )
177+ const missingPaymentProviders = await getPaymentMethods ( 100 , 0 , onHoldUserIds )
178+
179+ missingTaxForms . forms . forEach ( ( form : TaxForm ) => {
180+ userHasTaxFormSetup . set ( form . userId , true )
181+ } )
182+
183+ missingPaymentProviders . paymentMethods . forEach ( ( method : { userId : string } ) => {
184+ userHasPaymentProvider . set ( method . userId , true )
185+ } )
186+ } catch ( err ) {
187+ // Ignore errors
188+ }
189+
156190 const handleMap = await getMemberHandle ( winnerIds )
157- const winningsData = convertToWinnings ( payments . winnings , handleMap )
191+ const winningsData = convertToWinnings ( payments . winnings , handleMap , userHasTaxFormSetup , userHasPaymentProvider )
158192 setWinnings ( winningsData )
159193 setPagination ( payments . pagination )
160194 } catch ( apiError ) {
@@ -245,7 +279,10 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
245279 } ,
246280 content : (
247281 < PaymentEditForm
248- payment = { payment }
282+ payment = { {
283+ ...payment ,
284+ status : [ 'On Hold (Member)' , 'On Hold (Tax Form)' , 'On Hold (Payment Provider)' ] . indexOf ( payment . status ) !== - 1 ? 'Owed' : payment . status ,
285+ } }
249286 canSave = { setIsConfirmFormValid }
250287 onValueUpdated = { handleValueUpdated }
251288 />
@@ -272,48 +309,6 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
272309 label : 'Username/Handle' ,
273310 type : 'member_autocomplete' ,
274311 } ,
275- // {
276- // key: 'date',
277- // label: 'Date',
278- // options: [
279- // {
280- // label: 'Last 7 days',
281- // value: 'last7days',
282- // },
283- // {
284- // label: 'Last 30 days',
285- // value: 'last30days',
286- // },
287- // {
288- // label: 'All',
289- // value: 'all',
290- // },
291- // ],
292- // type: 'dropdown',
293- // },
294- // {
295- // key: 'type',
296- // label: 'Type',
297- // options: [
298- // {
299- // label: 'Task Payment',
300- // value: 'TASK_PAYMENT',
301- // },
302- // {
303- // label: 'Contest Payment',
304- // value: 'CONTEST_PAYMENT',
305- // },
306- // {
307- // label: 'Copilot Payment',
308- // value: 'COPILOT_PAYMENT',
309- // },
310- // {
311- // label: 'Review Board Payment',
312- // value: 'REVIEW_BOARD_PAYMENT',
313- // },
314- // ],
315- // type: 'dropdown',
316- // },
317312 {
318313 key : 'status' ,
319314 label : 'Status' ,
0 commit comments