1+ /* eslint-disable react/no-array-index-key */
12/* eslint-disable unicorn/no-null */
23/* eslint-disable max-len */
34/* eslint-disable react/jsx-no-bind */
@@ -8,7 +9,8 @@ import { TOPCODER_URL } from '~/config/environments/default.env'
89
910import { WinningsAudit } from '../../models/WinningsAudit'
1011import { Winning } from '../../models/WinningDetail'
11- import { fetchAuditLogs , getMemberHandle } from '../../services/wallet'
12+ import { PayoutAudit } from '../../models/PayoutAudit'
13+ import { fetchAuditLogs , fetchPayoutAuditLogs , getMemberHandle } from '../../services/wallet'
1214
1315import styles from './PaymentView.module.scss'
1416
@@ -17,11 +19,12 @@ interface PaymentViewProps {
1719}
1820
1921const PaymentView : React . FC < PaymentViewProps > = ( props : PaymentViewProps ) => {
20- const [ view , setView ] = React . useState < 'details' | 'audit' > ( 'details' )
22+ const [ view , setView ] = React . useState < 'details' | 'audit' | 'external_transaction' > ( 'details' )
2123 const [ auditLines , setAuditLines ] = React . useState < WinningsAudit [ ] > ( [ ] )
24+ const [ externalTransactionAudit , setExternalTransactionAudit ] = React . useState < PayoutAudit [ ] > ( [ ] )
2225
23- const handleToggleView = ( ) : void => {
24- setView ( view === 'details' ? 'audit' : 'details' )
26+ const handleToggleView = ( newView : 'audit' | 'details' | 'external_transaction' ) : void => {
27+ setView ( newView )
2528 }
2629
2730 React . useEffect ( ( ) => {
@@ -45,6 +48,11 @@ const PaymentView: React.FC<PaymentViewProps> = (props: PaymentViewProps) => {
4548 . catch ( ( ) => {
4649 setAuditLines ( [ ] )
4750 } )
51+ } else if ( view === 'external_transaction' ) {
52+ fetchPayoutAuditLogs ( props . payment . id )
53+ . then ( payoutAudit => {
54+ setExternalTransactionAudit ( payoutAudit )
55+ } )
4856 }
4957 } , [ props . payment . id , view ] )
5058
@@ -125,9 +133,15 @@ const PaymentView: React.FC<PaymentViewProps> = (props: PaymentViewProps) => {
125133
126134 < div className = { styles . infoItem } >
127135 < Button
128- onClick = { handleToggleView }
136+ onClick = { ( ) => handleToggleView ( 'audit' ) }
129137 label = 'View Audit'
130138 />
139+ { props . payment . status . toUpperCase ( ) === 'PAID' && (
140+ < Button
141+ onClick = { ( ) => handleToggleView ( 'external_transaction' ) }
142+ label = 'External Transaction Details'
143+ />
144+ ) }
131145 </ div >
132146 </ >
133147 ) }
@@ -179,12 +193,83 @@ const PaymentView: React.FC<PaymentViewProps> = (props: PaymentViewProps) => {
179193 </ div >
180194 < div className = { styles . infoItem } >
181195 < Button
182- onClick = { handleToggleView }
196+ onClick = { ( ) => handleToggleView ( 'details' ) }
197+ label = 'Back to Details'
198+ />
199+ </ div >
200+ </ >
201+ ) }
202+
203+ { view === 'external_transaction' && (
204+ < >
205+ < div className = { styles . auditSection } >
206+ { externalTransactionAudit && externalTransactionAudit . length > 0 && externalTransactionAudit . map ( ( externalTransaction : PayoutAudit , index : number ) => (
207+ < >
208+ < Collapsible
209+ key = { `internal-record${ index } ` }
210+ header = { (
211+ < h3 > Internal Record</ h3 >
212+ ) }
213+ containerClass = { styles . container }
214+ contentClass = { styles . content }
215+ >
216+ < div className = { styles . auditItem } >
217+ < div >
218+ < p >
219+ < strong > Provider Used:</ strong >
220+ { ' ' }
221+ { externalTransaction . paymentMethodUsed }
222+ </ p >
223+ < p >
224+ < strong > Status:</ strong >
225+ { ' ' }
226+ { externalTransaction . status }
227+ </ p >
228+ < p >
229+ < strong > Processed At:</ strong >
230+ { ' ' }
231+ { externalTransaction . createdAt }
232+ </ p >
233+ < p >
234+ < strong > Totl Amount Processed:</ strong >
235+ { ' ' }
236+ { externalTransaction . totalNetAmount }
237+ </ p >
238+ </ div >
239+ </ div >
240+ </ Collapsible >
241+ < Collapsible
242+ key = { `external-record${ index } ` }
243+ header = { (
244+ < h3 > External Record</ h3 >
245+ ) }
246+ containerClass = { styles . container }
247+ contentClass = { styles . content }
248+ >
249+ < div className = { styles . auditItem } >
250+ < div >
251+ < pre > { JSON . stringify ( externalTransaction . externalTransactionDetails , undefined , 2 ) } </ pre >
252+ </ div >
253+ </ div >
254+ </ Collapsible >
255+ </ >
256+ ) ) }
257+ { ( externalTransactionAudit === undefined )
258+ && (
259+ < div className = { styles . auditItem } >
260+ < p > No external transaction data is available</ p >
261+ </ div >
262+ ) }
263+ </ div >
264+ < div className = { styles . infoItem } >
265+ < Button
266+ onClick = { ( ) => handleToggleView ( 'details' ) }
183267 label = 'Back to Details'
184268 />
185269 </ div >
186270 </ >
187271 ) }
272+
188273 </ div >
189274 </ div >
190275 )
0 commit comments