Skip to content

Commit 41b23d5

Browse files
committed
feat(wallet-admin): audit ui
1 parent 912a3c4 commit 41b23d5

File tree

5 files changed

+83
-15
lines changed

5 files changed

+83
-15
lines changed

src/apps/wallet-admin/src/lib/components/payment-view/PaymentView.module.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
margin-bottom: 5px;
2121
}
2222

23-
.value {
24-
// Style for your value text
25-
}
26-
2723
.inputGroup {
2824
display: flex;
2925
flex-direction: column;

src/apps/wallet-admin/src/lib/components/payment-view/PaymentView.tsx

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,73 @@ import React from 'react'
55

66
import { Button, Collapsible } from '~/libs/ui'
77

8+
import { WinningsAudit } from '../../models/WinningsAudit'
89
import { Winning } from '../../models/WinningDetail'
10+
import { fetchAuditLogs, getMemberHandle } from '../../services/wallet'
911

1012
import styles from './PaymentView.module.scss'
1113

1214
interface PaymentViewProps {
1315
payment: Winning
14-
auditLines?: {
15-
date: string
16-
userName: string
17-
action: string
18-
}[]
1916
}
2017

2118
const PaymentView: React.FC<PaymentViewProps> = (props: PaymentViewProps) => {
2219
const [view, setView] = React.useState<'details' | 'audit'>('details')
20+
const [auditLines, setAuditLines] = React.useState<WinningsAudit[]>([])
2321

2422
const handleToggleView = (): void => {
2523
setView(view === 'details' ? 'audit' : 'details')
2624
}
2725

26+
React.useEffect(() => {
27+
if (view === 'audit') {
28+
fetchAuditLogs(props.payment.id)
29+
.then(auditLogs => {
30+
const userIds = auditLogs.map(log => log.userId)
31+
getMemberHandle(userIds)
32+
.then((handles: Map<number, string>) => {
33+
auditLogs.forEach((log: WinningsAudit) => {
34+
log.userId = handles.get(parseInt(log.userId, 10)) ?? log.userId
35+
})
36+
})
37+
.catch(() => {
38+
console.error('Error fetching member handles')
39+
})
40+
.finally(() => {
41+
setAuditLines(auditLogs)
42+
})
43+
})
44+
.catch(() => {
45+
setAuditLines([])
46+
})
47+
}
48+
}, [props.payment.id, view])
49+
50+
const formatAction = (action: string): React.ReactNode => {
51+
const fromIndex = action.indexOf('from')
52+
const toIndex = action.indexOf('to')
53+
54+
if (fromIndex !== -1 && toIndex !== -1) {
55+
const beforeFrom = action.substring(0, fromIndex)
56+
const fromValue = action.substring(fromIndex + 5, toIndex)
57+
const toValue = action.substring(toIndex + 3)
58+
return (
59+
<>
60+
{beforeFrom}
61+
from
62+
{' '}
63+
<strong>{fromValue}</strong>
64+
{' '}
65+
to
66+
{' '}
67+
<strong>{toValue}</strong>
68+
</>
69+
)
70+
}
71+
72+
return action
73+
}
74+
2875
return (
2976
<div className={styles.formContainer}>
3077
<div className={styles.inputGroup}>
@@ -72,12 +119,12 @@ const PaymentView: React.FC<PaymentViewProps> = (props: PaymentViewProps) => {
72119
{view === 'audit' && (
73120
<>
74121
<div className={styles.auditSection}>
75-
{props.auditLines && props.auditLines.map(line => (
122+
{auditLines && auditLines.length > 0 && auditLines.map(line => (
76123
<Collapsible
77124
header={(
78125
<h3>
79126
{
80-
new Date(line.date)
127+
new Date(line.createdAt)
81128
.toLocaleString()
82129
}
83130
</h3>
@@ -90,18 +137,23 @@ const PaymentView: React.FC<PaymentViewProps> = (props: PaymentViewProps) => {
90137
<p>
91138
<strong>User:</strong>
92139
{' '}
93-
{line.userName}
140+
{line.userId}
94141
</p>
95142
<p>
96143
<strong>Action:</strong>
97144
{' '}
98-
{line.action}
145+
{formatAction(line.action)}
146+
</p>
147+
<p>
148+
<strong>Note:</strong>
149+
{' '}
150+
{line.note}
99151
</p>
100152
</div>
101153
</div>
102154
</Collapsible>
103155
))}
104-
{(props.auditLines === undefined || props.auditLines.length === 0)
156+
{(auditLines === undefined || auditLines.length === 0)
105157
&& (
106158
<div className={styles.auditItem}>
107159
<p>No audit data available</p>

src/apps/wallet-admin/src/lib/components/payments-table/PaymentTable.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ table {
9797
.actionButtons {
9898
padding-left: 8px;
9999
display: flex;
100-
justify-content: flex-end;
100+
justify-content: center;
101101
align-items: center;
102102
}
103103

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface WinningsAudit{
2+
id: string
3+
winningsId: string
4+
userId: string
5+
action: string
6+
note: string
7+
createdAt: string
8+
}

src/apps/wallet-admin/src/lib/services/wallet.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { TaxForm } from '../models/TaxForm'
1010
import { OtpVerificationResponse } from '../models/OtpVerificationResponse'
1111
import { TransactionResponse } from '../models/TransactionId'
1212
import { PaginationInfo } from '../models/PaginationInfo'
13+
import { WinningsAudit } from '../models/WinningsAudit'
1314
import ApiResponse from '../models/ApiResponse'
1415

1516
const baseUrl = `${EnvironmentConfig.API.V5}/payments`
@@ -44,6 +45,17 @@ export async function getUserTaxFormDetails(): Promise<TaxForm[]> {
4445
return response.data
4546
}
4647

48+
export async function fetchAuditLogs(paymentId: string): Promise<WinningsAudit[]> {
49+
const response = await xhrGetAsync<ApiResponse<WinningsAudit[]>>(`${baseUrl}/admin/winnings/${paymentId}/audit`)
50+
51+
if (response.status === 'error') {
52+
throw new Error('Error fetching audit logs')
53+
}
54+
55+
return response.data
56+
57+
}
58+
4759
export async function editPayment(updates: {
4860
winningsId: string,
4961
paymentStatus?: 'ON_HOLD_ADMIN' | 'OWED',

0 commit comments

Comments
 (0)