Skip to content

Commit

Permalink
adjust admin payouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlauer-Hax committed Feb 14, 2024
1 parent 19947b4 commit 42730e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pages/admin/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const state = asState({
},
users: <External<ProfileData[]> | "loading">"loading",
groups: <External<Group[]> | "loading">"loading",
payouts: <External<Payout[]> | "loading">"loading",
payouts: <External<Payout[][]> | "loading">"loading",
oauth: <External<OAuthApp[]> | "loading">"loading",
files: <External<File[]> | "loading">"loading",
servers: <External<Server[]> | "loading">"loading",
Expand Down
35 changes: 23 additions & 12 deletions pages/admin/views/menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { API, HeavyList, loadMore, Navigation, placeholder } from "shared/mod.ts";
import { sumOf } from "std/collections/sum_of.ts";
import { asState, Box, Button, Color, Entry, Grid, Horizontal, isMobile, Label, ref, SheetDialog, Spacer, Table, TextInput, Vertical } from "webgen/mod.ts";
import { sumOf } from "std/collections/mod.ts";
import { asState, Box, Button, Color, Grid, Horizontal, isMobile, Label, ref, SheetDialog, Spacer, Table, TextInput, Vertical } from "webgen/mod.ts";
import { DropType } from "../../../spec/music.ts";
import { activeUser, sheetStack } from "../../_legacy/helper.ts";
import { upload } from "../loading.ts";
Expand All @@ -21,12 +21,12 @@ export const adminMenu = Navigation({
{
id: "streams",
title: "Total Streams",
subtitle: it ? `${sumOf(it.value, payout => sumOf(payout.entries, entry => sumOf(entry.data, data => data.quantity))).toLocaleString()} Streams` : "Loading..."
subtitle: it ? `${sumOf(it.value, payouts => sumOf(payouts, payout => sumOf(payout.entries, entry => sumOf(entry.data, data => data.quantity)))).toLocaleString()} Streams` : "Loading..."
},
{
id: "revenue",
title: "Calculated Revenue",
subtitle: it ? ${sumOf(it.value, payout => sumOf(payout.entries, entry => sumOf(entry.data, data => data.revenue))).toFixed(2)}` : "Loading..."
subtitle: it ? ${sumOf(it.value, payouts => sumOf(payouts, payout => sumOf(payout.entries, entry => sumOf(entry.data, data => data.revenue)))).toFixed(2)}` : "Loading..."
},
{
id: "bbnmoney",
Expand Down Expand Up @@ -114,7 +114,7 @@ export const adminMenu = Navigation({
{
id: "payouts",
title: ref`Payout`,
children: [
children: state.$payouts.map(payoutsdata => [
{
title: "Upload Payout File (.xlsx)",
id: "upload+manual",
Expand All @@ -126,16 +126,27 @@ export const adminMenu = Navigation({
title: "Sync ISRCs (release_export.xlsx)",
id: "sync+isrc",
clickHandler: () => {
upload("isrc");
upload("isrc");
}
},
HeavyList(state.$payouts, (x) => Entry({
title: x.period,
subtitle: x.moneythisperiod,
}).onClick(() => {
location.href = `/music/payout?id=${x._id}`;
...payoutsdata === "loading" || payoutsdata.status === "rejected" ? [Box()] : payoutsdata.value.map(payouts => ({
title: payouts[0].period,
id: "payouts"+payouts[0].period,
subtitle: ${sumOf(payouts, payout => sumOf(payout.entries, entry => sumOf(entry.data, data => data.revenue))).toFixed(2)}`,
children: payouts.map(payout => ({
title: payout._id,
subtitle: ${sumOf(payout.entries, entry => sumOf(entry.data, data => data.revenue)).toFixed(2)}`,
children: payout.entries.map(entry => ({
title: entry.isrc,
subtitle: ${sumOf(entry.data, data => data.revenue).toFixed(2)}`,
children: entry.data.map(data => ({
title: data.revenue,
subtitle: ${data.revenue.toFixed(2)}`
}))
}))
}))
}))
],
]),
},
{
id: "oauth",
Expand Down
2 changes: 1 addition & 1 deletion pages/shared/restSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const API = {
list: () => fetch(`${API.BASE_URL}admin/payouts`, {
headers: headers(API.getToken())
})
.then(json<Payout[]>())
.then(json<Payout[][]>())
.catch(reject)
},
servers: {
Expand Down

0 comments on commit 42730e9

Please sign in to comment.