Skip to content

Commit

Permalink
Add exports for Game7 and OP-Supersim (#4969)
Browse files Browse the repository at this point in the history
* add exports for Game7 and Supersim

* ..

* fix types

* add lit protocol

* update op banner
  • Loading branch information
mattcasey authored Nov 7, 2024
1 parent 8a44860 commit c290c7e
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 95 deletions.
3 changes: 2 additions & 1 deletion apps/scoutgame/components/claim/ClaimPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Stack } from '@mui/material';
import type { BonusPartner } from '@packages/scoutgame/bonus';
import { Suspense } from 'react';

import { PointsClaimScreen } from 'components/claim/components/PointsClaimScreen/PointsClaimScreen';
Expand All @@ -12,7 +13,7 @@ import { UnclaimedPointsTable } from './components/PointsTable/UnclaimedPointsTa

export type ClaimPageProps = {
totalUnclaimedPoints: number;
bonusPartners: string[];
bonusPartners: BonusPartner[];
displayName: string;
period: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
'use client';

import { Stack } from '@mui/material';
import { Stack, Tooltip } from '@mui/material';
import type { BonusPartner } from '@packages/scoutgame/bonus';
import { bonusPartnersRecord } from '@packages/scoutgame/bonus';
import Image from 'next/image';

export function BonusPartnersDisplay({ bonusPartners, size = 20 }: { bonusPartners?: string[]; size?: number }) {
const bonusPartnerIcons = (bonusPartners ?? [])
.filter((partner) => !!bonusPartnersRecord[partner])
.map((partner) => bonusPartnersRecord[partner].icon);

if (bonusPartnerIcons.length === 0) {
export function BonusPartnersDisplay({
bonusPartners = [],
size = 20
}: {
bonusPartners?: BonusPartner[];
size?: number;
}) {
if (bonusPartners.length === 0) {
return null;
}

return (
<Stack flexDirection='row' gap={1} alignItems='center' justifyContent='flex-end'>
{bonusPartnerIcons.map((partnerIcon) => (
<Image key={partnerIcon} width={size} height={size} src={partnerIcon} alt='Bonus partner' />
{bonusPartners.map((partner) => (
<Tooltip open key={partner} title={bonusPartnersRecord[partner]?.name}>
<Image width={size} height={size} src={bonusPartnersRecord[partner]?.icon} alt='' />
</Tooltip>
))}
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { Box, Button, Dialog, Paper, Stack, Typography } from '@mui/material';
import type { BonusPartner } from '@packages/scoutgame/bonus';
import Image from 'next/image';
import { useAction } from 'next-safe-action/hooks';
import { useState } from 'react';
Expand Down Expand Up @@ -45,7 +46,7 @@ export function PointsClaimScreen({
}: {
totalUnclaimedPoints: number;
displayName: string;
bonusPartners: string[];
bonusPartners: BonusPartner[];
}) {
const { executeAsync, isExecuting, result } = useAction(claimPointsAction);
const { refreshUser } = useUser();
Expand Down
5 changes: 3 additions & 2 deletions apps/scoutgame/lib/builders/getBuilderActivities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GemsReceiptType } from '@charmverse/core/prisma-client';
import { prisma } from '@charmverse/core/prisma-client';
import type { BonusPartner } from '@packages/scoutgame/bonus';
import { isTruthy } from '@root/lib/utils/types';

import type { BasicUserInfo } from 'lib/users/interfaces';
Expand All @@ -21,7 +22,7 @@ type MergedPullRequestActivity = {
gems: number;
repo: string;
url: string;
bonusPartner: string | null;
bonusPartner: BonusPartner | null;
};

export type BuilderActivity = BasicUserInfo & {
Expand Down Expand Up @@ -113,7 +114,7 @@ export async function getBuilderActivities({
gems: event.gemsReceipt.value,
repo: `${event.githubEvent.repo.owner}/${event.githubEvent.repo.name}`,
url: event.githubEvent.url,
bonusPartner: event.bonusPartner
bonusPartner: event.bonusPartner as BonusPartner | null
};
} else {
return null;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 5 additions & 43 deletions apps/scoutgameadmin/app/api/partners/celo/route.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,16 @@
import { prisma } from '@charmverse/core/prisma-client';
import { getLastWeek } from '@packages/scoutgame/dates';

import { respondWithTSV } from 'lib/nextjs/respondWithTSV';
import { getBuildersForPartner } from 'lib/partners/getBuildersForPartner';

export const dynamic = 'force-dynamic';

export async function GET() {
const lastWeek = getLastWeek();
const events = await prisma.builderEvent.findMany({
where: {
githubEvent: {
repo: {
bonusPartner: 'celo'
}
},
type: 'merged_pull_request',
week: lastWeek
},
orderBy: {
createdAt: 'asc'
},
select: {
createdAt: true,
builder: {
select: {
email: true,
displayName: true
}
},
githubEvent: {
select: {
createdAt: true,
url: true,
repo: {
select: {
name: true,
owner: true
}
}
}
}
}
const rows = await getBuildersForPartner({
week: lastWeek,
bonusPartner: 'celo'
});
const rows = events.map((event) => ({
'Farcaster Name': event.builder.displayName,
Email: event.builder.email,
Repo: `${event.githubEvent!.repo.owner}/${event.githubEvent!.repo.name}`,
Date: event.createdAt.toDateString(),
Link: event.githubEvent!.url
}));

return respondWithTSV(rows, 'scout_users_export.tsv');
return respondWithTSV(rows, `partners-export_celo_${lastWeek}.tsv`);
}
15 changes: 15 additions & 0 deletions apps/scoutgameadmin/app/api/partners/game7/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getLastWeek } from '@packages/scoutgame/dates';

import { respondWithTSV } from 'lib/nextjs/respondWithTSV';
import { getBuildersForPartner } from 'lib/partners/getBuildersForPartner';

export const dynamic = 'force-dynamic';

export async function GET() {
const lastWeek = getLastWeek();
const rows = await getBuildersForPartner({
week: lastWeek,
bonusPartner: 'game7'
});
return respondWithTSV(rows, `partners-export_game7_${lastWeek}.tsv`);
}
16 changes: 16 additions & 0 deletions apps/scoutgameadmin/app/api/partners/lit_protocol/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getLastWeek } from '@packages/scoutgame/dates';

import { respondWithTSV } from 'lib/nextjs/respondWithTSV';
import { getBuildersForPartner } from 'lib/partners/getBuildersForPartner';

export const dynamic = 'force-dynamic';

export async function GET() {
const lastWeek = getLastWeek();
const rows = await getBuildersForPartner({
week: lastWeek,
bonusPartner: 'lit_protocol'
});

return respondWithTSV(rows, `partners-export_lit_${lastWeek}.tsv`);
}
5 changes: 3 additions & 2 deletions apps/scoutgameadmin/app/api/partners/moxie/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type MoxieBonusRow = {
};

export async function GET() {
const lastWeek = getLastWeek();
const builders = await prisma.scout.findMany({
where: {
builderStatus: 'approved'
Expand All @@ -33,7 +34,7 @@ export async function GET() {
type: {
in: ['merged_pull_request', 'daily_commit']
},
week: getLastWeek()
week: lastWeek
}
},
builderNfts: {
Expand Down Expand Up @@ -96,7 +97,7 @@ export async function GET() {
})
);

return respondWithTSV(rows, 'moxie_bonus_report.tsv');
return respondWithTSV(rows, `partners-export_moxie_${lastWeek}.tsv`);
}

type MoxieFanToken = {
Expand Down
16 changes: 16 additions & 0 deletions apps/scoutgameadmin/app/api/partners/op_supersim/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getLastWeek } from '@packages/scoutgame/dates';

import { respondWithTSV } from 'lib/nextjs/respondWithTSV';
import { getBuildersForPartner } from 'lib/partners/getBuildersForPartner';

export const dynamic = 'force-dynamic';

export async function GET() {
const lastWeek = getLastWeek();
const rows = await getBuildersForPartner({
week: lastWeek,
bonusPartner: 'op_supersim'
});

return respondWithTSV(rows, `partners-export_supersim_${lastWeek}.tsv`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ReactNode } from 'react';

import { useGETtrigger } from 'hooks/api/helpers';

export function ExportButton({
export function FileDownloadButton({
children,
src,
filename,
Expand Down
12 changes: 12 additions & 0 deletions apps/scoutgameadmin/components/common/MenuItemNoAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { TypographyProps } from '@mui/material';
import { ListItem, Typography } from '@mui/material';

export function MenuItemNoAction({ children, ...props }: { children: React.ReactNode } & TypographyProps) {
return (
<ListItem dense onClick={(e) => e.stopPropagation()}>
<Typography color='text.secondary' variant='caption' {...props}>
{children}
</Typography>
</ListItem>
);
}
17 changes: 7 additions & 10 deletions apps/scoutgameadmin/components/repos/ReposDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Container,
InputAdornment,
Link,
Typography,
Paper,
Table,
TableBody,
Expand All @@ -17,16 +16,14 @@ import {
TableHead,
TableRow,
TextField,
Box,
IconButton,
TableSortLabel,
Button
TableSortLabel
} from '@mui/material';
import type { BonusPartner } from '@packages/scoutgame/bonus';
import { bonusPartnersRecord } from '@packages/scoutgame/bonus';
import Image from 'next/image';
import React, { useState, useMemo } from 'react';

import { ExportButton } from 'components/common/ExportButton';
import { useSearchRepos } from 'hooks/api/repos';
import { useDebouncedValue } from 'hooks/useDebouncedValue';
import { revalidatePathAction } from 'lib/actions/revalidatePathAction';
Expand Down Expand Up @@ -186,7 +183,7 @@ export function ReposDashboard({ repos }: { repos: Repo[] }) {
<TableCell>{repo.closedPrs}</TableCell>
<TableCell>{repo.contributors}</TableCell>
<TableCell>
{repo.bonusPartner ? <BonusPartnersDisplay bonusPartner={repo.bonusPartner} /> : ''}
{repo.bonusPartner ? <BonusPartnersDisplay bonusPartner={repo.bonusPartner as BonusPartner} /> : ''}
</TableCell>
<TableCell align='center'>
<RepoActionButton
Expand All @@ -206,14 +203,14 @@ export function ReposDashboard({ repos }: { repos: Repo[] }) {
}

function BonusPartnersDisplay({ bonusPartner, size = 20 }: { bonusPartner: string; size?: number }) {
const info = bonusPartnersRecord[bonusPartner];
const info = bonusPartnersRecord[bonusPartner as BonusPartner];
if (!info) {
log.warn(`No partner info found for ${bonusPartner}`);
return null;
log.warn(`No bonus partner info found for ${bonusPartner}`);
return bonusPartner;
}
return (
<Stack flexDirection='row' gap={1} alignItems='center'>
<Image width={20} height={20} src={info.icon} alt='Bonus partner' />
<Image width={size} height={size} src={info.icon} alt='' />
{info.name}
</Stack>
);
Expand Down
46 changes: 37 additions & 9 deletions apps/scoutgameadmin/components/repos/components/HeaderActions.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client';

import { ArrowDropDown as ArrowDropDownIcon, Add as AddIcon } from '@mui/icons-material';
import { Menu, MenuItem, ListItemButton, Stack, Button } from '@mui/material';
import { Box, Divider, Menu, MenuItem, Stack, Button } from '@mui/material';
import { getLastWeek, getWeekStartEndFormatted, getDateFromISOWeek } from '@packages/scoutgame/dates';
import React, { useState } from 'react';

import { ExportButton } from 'components/common/ExportButton';
import { FileDownloadButton } from 'components/common/FileDownloadButton';
import { MenuItemNoAction } from 'components/common/MenuItemNoAction';

import { AddRepoButton } from './AddRepoButton/AddRepoButton';

Expand All @@ -25,19 +26,46 @@ export function HeaderActions() {
</Button>
<Menu anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={closeMenu}>
<MenuItem>
<ExportButton filename='github_repos.tsv' src='/api/repos/export' onComplete={closeMenu}>
All repositories
</ExportButton>
<FileDownloadButton size='small' filename='github_repos.tsv' src='/api/repos/export' onComplete={closeMenu}>
Export repositories
</FileDownloadButton>
</MenuItem>
<Divider />
<MenuItemNoAction>
<Box px={0.5}>Partner exports</Box>
</MenuItemNoAction>
<MenuItem>
<ExportButton filename={`Celo Weekly Report (${lastWeek}).tsv`} src='/api/partners/celo'>
<FileDownloadButton size='small' filename={`Celo Weekly Report (${lastWeek}).tsv`} src='/api/partners/celo'>
Celo Report ({lastWeek})
</ExportButton>
</FileDownloadButton>
</MenuItem>
<MenuItem>
<ExportButton filename={`Moxie Weekly Report (${lastWeek}).tsv`} src='/api/partners/moxie'>
<FileDownloadButton size='small' filename={`Game7 Weekly Report (${lastWeek}).tsv`} src='/api/partners/game7'>
Game7 Report ({lastWeek})
</FileDownloadButton>
</MenuItem>
<MenuItem>
<FileDownloadButton
size='small'
filename={`Lit Protocol Weekly Report (${lastWeek}).tsv`}
src='/api/partners/lit_protocol'
>
Lit Protocol Report ({lastWeek})
</FileDownloadButton>
</MenuItem>
<MenuItem>
<FileDownloadButton
size='small'
filename={`OP Supersim Weekly Report (${lastWeek}).tsv`}
src='/api/partners/op_supersim'
>
OP Supersim Report ({lastWeek})
</FileDownloadButton>
</MenuItem>
<MenuItem>
<FileDownloadButton size='small' filename={`Moxie Weekly Report (${lastWeek}).tsv`} src='/api/partners/moxie'>
Moxie Report ({lastWeek})
</ExportButton>
</FileDownloadButton>
</MenuItem>
</Menu>
</Stack>
Expand Down
6 changes: 3 additions & 3 deletions apps/scoutgameadmin/components/users/UsersDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '@mui/material';
import React, { useState, useMemo } from 'react';

import { ExportButton } from 'components/common/ExportButton';
import { FileDownloadButton } from 'components/common/FileDownloadButton';
import { useSearchUsers } from 'hooks/api/users';
import { useDebouncedValue } from 'hooks/useDebouncedValue';
import type { SortField, SortOrder, ScoutGameUser } from 'lib/users/getUsers';
Expand Down Expand Up @@ -108,9 +108,9 @@ export function UsersDashboard({ users }: { users: ScoutGameUser[] }) {
<AddUserButton variant='contained' color='primary' sx={{ mr: 2 }} startIcon={<AddIcon />}>
Add
</AddUserButton>
<ExportButton variant='outlined' filename='scoutgame_users.tsv' src='/api/users/export'>
<FileDownloadButton variant='outlined' filename='scoutgame_users.tsv' src='/api/users/export'>
Export
</ExportButton>
</FileDownloadButton>
</Box>
</Stack>
<TableContainer component={Paper}>
Expand Down
Loading

0 comments on commit c290c7e

Please sign in to comment.