@@ -76,12 +76,144 @@ graph LR
7676
7777** Priority:** High
7878
79+ #### API Endpoints
80+
81+ The admin app uses JWT-protected admin endpoints from the backend:
82+
83+ | Endpoint | Method | Purpose |
84+ | ----------| --------| ---------|
85+ | ` /v1/earnings/admin ` | GET | Fetch all earnings records |
86+ | ` /v1/earnings/admin ` | POST | Batch create earnings (accepts ` List<Earning> ` ) |
87+ | ` /v1/earnings/admin/{songIdOrIsrc} ` | GET | Get earnings by song ID or ISRC |
88+ | ` /v1/earnings/admin/{songIdOrIsrc} ` | POST | Create royalty splits for a song |
89+
90+ ** Earning Model Fields:**
91+ - ` id ` (UUID), ` songId ` (UUID), ` stakeAddress ` , ` amount ` (Long, 6 decimals)
92+ - ` memo ` , ` startDate ` , ` endDate ` , ` claimed ` , ` claimedAt ` , ` claimOrderId `
93+ - ` createdAt ` , ` nftPolicyId ` , ` nftAssetName `
94+
95+ ** AddSongRoyaltyRequest:** Either ` newmAmount ` or ` usdAmount ` (BigInteger, 6 decimals)
96+
97+ ---
98+
99+ #### UI Components
100+
101+ ##### Summary Boxes
102+
103+ Three summary cards at the top of the Earnings dashboard, calculated from the filtered data:
104+
105+ | Box | Description | Calculation |
106+ | -----| -------------| -------------|
107+ | ** Total Earnings** | Sum of all earnings in current filter | ` Σ earning.amount ` |
108+ | ** Claimed Earnings** | Sum of claimed earnings | ` Σ earning.amount WHERE claimed == true ` |
109+ | ** Unclaimed Earnings** | Sum of unclaimed earnings | ` Total - Claimed ` |
110+
111+ > [ !NOTE]
112+ > All amounts display in NEWM tokens with 6 decimal places, prefixed with ` Ɲ ` symbol (e.g., ` Ɲ 1,234.567890 ` ).
113+
114+ ##### Earnings Table
115+
116+ A sortable, filterable table displaying all earnings:
117+
118+ | Column | Sortable | Filterable | Notes |
119+ | --------| ----------| ------------| -------|
120+ | ID | ❌ | ❌ | UUID |
121+ | Song ID | ✅ | ✅ | UUID or display song title if available |
122+ | Stake Address | ✅ | ✅ | Cardano stake address |
123+ | Amount | ✅ | ❌ | Display as ` Ɲ X.XXXXXX ` |
124+ | Memo | ❌ | ✅ | Freeform text |
125+ | Claimed | ✅ | ✅ | Boolean (checkbox filter) |
126+ | Claimed At | ✅ | ❌ | DateTime, null if unclaimed |
127+ | Created At | ✅ | ✅ | DateTime (supports date range filter) |
128+
129+ ** Table Features:**
130+ - ** Refresh Button:** Fetches latest data from server
131+ - ** Date Range Filter:** Filter by ` createdAt ` date range (critical requirement)
132+ - ** Infinite Scroll:** Virtual list handles large datasets efficiently
133+
134+ ##### Toast Notification System
135+
136+ A toast notification system to inform users of API operation results:
137+
138+ | Toast Type | Behavior | Auto-Dismiss |
139+ | ------------| ----------| --------------|
140+ | ** Success** | Green background, checkmark icon | 5 seconds |
141+ | ** Warning** | Yellow/orange background, warning icon | Manual X close required |
142+ | ** Error** | Red background, error icon | Manual X close required |
143+
144+ Toast content should include:
145+ - Clear message describing success or failure
146+ - For failures: Include error message from API response
147+ - Position: Top-right corner of the work area, stacked if multiple
148+
149+ ---
150+
151+ #### Workflows
152+
153+ ##### Add Earnings (Single Song)
154+
155+ ** Button:** "Add Earnings" in the toolbar
156+
157+ ** Dialog Fields:**
158+ | Field | Type | Description |
159+ | -------| ------| -------------|
160+ | Song ID or ISRC | Text input | Accepts UUID or ISRC format (e.g., ` USRC12345678 ` ) |
161+ | Amount (USD) | Decimal input | User enters USD value (e.g., ` 10.50 ` ) |
162+
163+ ** Process:**
164+ 1 . User enters songId/ISRC and USD amount
165+ 2 . Convert amount to 6-decimal integer: ` 10.50 ` → ` 10500000 `
166+ 3 . Call ` POST /v1/earnings/admin/{songIdOrIsrc} ` with ` { usdAmount: 10500000 } `
167+ 4 . On success: Show success toast, refresh table
168+ 5 . On failure: Show error toast with API error message
169+
170+ ##### Upload Earnings CSV
171+
172+ ** Button:** "Upload CSV" in the toolbar
173+
174+ ** CSV Format (Input):**
175+ ``` csv
176+ songId_or_isrc,amount_usd
177+ 550e8400-e29b-41d4-a716-446655440000,10.50
178+ USRC12345678,25.00
179+ ```
180+
181+ ** Process:**
182+ 1 . User selects CSV file via native file picker
183+ 2 . Parse CSV, validate format (2 columns required)
184+ 3 . For each row:
185+ - Convert USD to 6-decimal integer
186+ - Call ` POST /v1/earnings/admin/{songIdOrIsrc} `
187+ - Record result (success or error message)
188+ 4 . Modify CSV to add result column
189+ 5 . Save modified CSV with results
190+
191+ ** CSV Format (Output):**
192+ ``` csv
193+ songId_or_isrc,amount_usd,result
194+ 550e8400-e29b-41d4-a716-446655440000,10.50,Success
195+ USRC12345678,25.00,Error: No song found with ISRC: USRC12345678
196+ ```
197+
198+ 6 . Show summary toast: "Processed X records: Y succeeded, Z failed"
199+ 7 . If any failures: Show warning toast prompting user to check output file
200+
201+ ---
202+
203+ #### Implementation Status
204+
79205| Requirement | Status |
80206| -------------| --------|
81- | List all earnings with pagination | ⬜ Not started |
82- | Filter by artist, song, date range | ⬜ Not started |
83- | View earnings details | ⬜ Not started |
84- | Export earnings data | ⬜ Not started |
207+ | List all earnings with sortable, scrollable table | ✅ Completed |
208+ | Filter by date range | ✅ Completed |
209+ | Filter by stake address, song, memo | ✅ Completed |
210+ | Summary boxes (Total/Claimed/Unclaimed) | ✅ Completed |
211+ | NEWM token display with Ɲ symbol | ✅ Completed |
212+ | Refresh button | ✅ Completed |
213+ | Toast notification system | ✅ Completed |
214+ | Add Earnings dialog | ✅ Completed |
215+ | Upload CSV workflow | ⬜ Not started |
216+ | CSV result export | ⬜ Not started |
85217
86218### 🔲 Refunds Processing
87219
@@ -178,6 +310,7 @@ The admin app communicates with the NEWM backend:
178310
179311| Date | Feature | Description |
180312| ------| ---------| -------------|
313+ | 2026-01-08 | Earnings Table | Full-featured earnings table with filtering, sorting, date range, summary stats, copy-to-clipboard |
181314| 2026-01-07 | Dashboard | Added sidebar nav with Earnings/Refunds, work area panels |
182315| 2026-01-07 | Auth | JWT admin validation, login view with environment selector |
183316| 2026-01-06 | Init | Project setup with GPUI, basic login UI |
0 commit comments