Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email to admin dashboard #4941

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { ScoutGameUser } from 'lib/users/getUsers';

type Props = {
open: boolean;
user: Pick<ScoutGameUser, 'builderStatus' | 'id' | 'githubLogin'>;
user: Pick<ScoutGameUser, 'builderStatus' | 'id' | 'githubLogin' | 'farcasterName'>;
onClose: () => void;
onAdd: () => void;
};
Expand All @@ -47,9 +47,11 @@ export function AddBuilderModal({ user, open, onClose, onAdd }: Props) {
};

const didApply = user?.builderStatus === 'applied';
const action = didApply ? 'Approve' : 'Add';
const action = didApply ? 'Review' : 'Register';
const requireGithubLogin = !user.githubLogin;

const githubLoginDisplayed = githubLogin || user.githubLogin;

return (
<Dialog open={open} onClose={onClose} PaperProps={{ sx: { maxWidth: 400 } }} fullWidth>
<DialogTitle>
Expand All @@ -71,6 +73,22 @@ export function AddBuilderModal({ user, open, onClose, onAdd }: Props) {
required
/>
)}
{githubLoginDisplayed && (
<Stack>
<Typography variant='caption'>Github profile</Typography>
<Link href={`https://github.com/${githubLoginDisplayed}`} target='_blank'>
https://github.com/{githubLoginDisplayed}
</Link>
</Stack>
)}
{user.farcasterName && (
<Stack>
<Typography variant='caption'>Farcaster profile</Typography>
<Link href={`https://warpcast.com/${user.farcasterName}`} target='_blank'>
https://warpcast.com/{githubLoginDisplayed}
</Link>
</Stack>
)}
{createBuilderError && (
<Box p={1}>
<Typography variant='caption' color='error'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MoreHoriz as MoreHorizIcon } from '@mui/icons-material';
import { Menu, MenuItem, IconButton } from '@mui/material';
import type { TypographyProps } from '@mui/material';
import { Menu, ListItem, Divider, Typography, MenuItem, IconButton } from '@mui/material';
import { useState } from 'react';

import type { ScoutGameUser } from 'lib/users/getUsers';
Expand Down Expand Up @@ -33,22 +34,27 @@ export function UserActionButton({ user }: { user: ScoutGameUser }) {
>
<MoreHorizIcon />
</IconButton>
<Menu
id='user-menu'
anchorEl={anchorEl}
open={open}
onClose={handleClose}
onClick={handleClose}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'right'
}}
>
<Menu id='user-menu' anchorEl={anchorEl} open={open} onClose={handleClose} onClick={handleClose}>
{(user.builderStatus === 'applied' || user.builderStatus === 'rejected') && (
<MenuItem onClick={() => setIsBuilderModalOpen(true)}>Approve builder profile</MenuItem>
<MenuItem onClick={() => setIsBuilderModalOpen(true)}>Review builder profile</MenuItem>
)}
{!user.builderStatus && (
<MenuItem onClick={() => setIsBuilderModalOpen(true)}>Register builder profile</MenuItem>
)}
{!user.builderStatus && <MenuItem onClick={() => setIsBuilderModalOpen(true)}>Add builder profile</MenuItem>}
<MenuItem onClick={() => setIsTransactionsModalOpen(true)}>View NFT transactions</MenuItem>
<Divider />
<MenuItemNoAction>
Scout Id: <strong>{user.id}</strong>
</MenuItemNoAction>
<MenuItemNoAction>
Fid: <strong>{user.farcasterId || '--'}</strong>
</MenuItemNoAction>
<MenuItemNoAction>
Github: <strong>{user.githubLogin || '--'}</strong>
</MenuItemNoAction>
<MenuItemNoAction>
Wallets: <strong>{user.wallets.join(', ')}</strong>
</MenuItemNoAction>
</Menu>
<AddBuilderModal
user={user}
Expand All @@ -64,3 +70,13 @@ export function UserActionButton({ user }: { user: ScoutGameUser }) {
</>
);
}

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>
);
}
4 changes: 2 additions & 2 deletions apps/scoutgameadmin/components/users/UsersDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function UsersDashboard({ users }: { users: ScoutGameUser[] }) {
onClick={() => handleSort('displayName')}
></TableSortLabel>
</TableCell>
<TableCell>ID</TableCell>
<TableCell>Email</TableCell>
<TableCell align='center'>
<TableSortLabel
active={sortField === 'nftsPurchased'}
Expand Down Expand Up @@ -176,7 +176,7 @@ export function UsersDashboard({ users }: { users: ScoutGameUser[] }) {
{user.displayName}
</Link>
</TableCell>
<TableCell>{user.id}</TableCell>
<TableCell>{user.email}</TableCell>
<TableCell align='center'>{user.nftsPurchased}</TableCell>
<TableCell align='center'>{user.currentBalance}</TableCell>
<TableCell>{new Date(user.createdAt).toLocaleDateString()}</TableCell>
Expand Down
23 changes: 17 additions & 6 deletions apps/scoutgameadmin/lib/users/getUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ import { validate } from 'uuid';

export type ScoutGameUser = Pick<
Scout,
'builderStatus' | 'path' | 'id' | 'avatar' | 'displayName' | 'createdAt' | 'farcasterName' | 'currentBalance'
> & { githubLogin: string | null; nftsPurchased: number };
| 'builderStatus'
| 'path'
| 'id'
| 'avatar'
| 'displayName'
| 'createdAt'
| 'farcasterName'
| 'currentBalance'
| 'email'
| 'farcasterId'
> & { githubLogin: string | null; nftsPurchased: number; wallets: string[] };

export type UserFilter = 'only-builders';

Expand Down Expand Up @@ -61,13 +70,15 @@ export async function getUsers({
: undefined,
include: {
githubUser: true,
userSeasonStats: true
userSeasonStats: true,
scoutWallet: true
}
});
return users.map((user) => ({
return users.map(({ githubUser, userSeasonStats, scoutWallet, ...user }) => ({
...user,
githubLogin: user.githubUser[0]?.login || null,
nftsPurchased: user.userSeasonStats.find(({ season }) => season === '2024-W41')?.nftsPurchased || 0
githubLogin: githubUser[0]?.login || null,
nftsPurchased: userSeasonStats.find(({ season }) => season === '2024-W41')?.nftsPurchased || 0,
wallets: scoutWallet.map((wallet) => wallet.address)
}));
}

Expand Down