Skip to content

Commit 420b142

Browse files
committed
feat: add chronik URLs to admin dashboard
1 parent 92b037a commit 420b142

6 files changed

Lines changed: 59 additions & 12 deletions

File tree

components/Admin/ChronikURLs.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { MainNetworkSlugsType } from 'constants/index'
2+
3+
interface IProps {
4+
chronikUrls: Record<MainNetworkSlugsType, string[]>
5+
}
6+
export default function ChronikURLs ({ chronikUrls }: IProps): JSX.Element {
7+
return <>
8+
<h2>Chronik URLs</h2>
9+
<div className="paybutton-table-ctn columns">
10+
<div>
11+
<h4>eCash</h4>
12+
<ol>
13+
{chronikUrls.ecash.map((url, idx) => <li key={idx}>{url}</li>)}
14+
</ol>
15+
</div>
16+
<div>
17+
<h4>Bitcoin Cash</h4>
18+
<ol>
19+
{chronikUrls.bitcoincash.map((url, idx) => <li key={idx}>{url}</li>)}
20+
</ol>
21+
</div>
22+
</div>
23+
</>
24+
}

components/Admin/RegisteredUsers.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ import { UserWithSupertokens } from 'services/userService'
22
import style from './admin.module.css'
33
import moment from 'moment'
44
import TableContainer from '../../components/TableContainer/TableContainer'
5+
import { Cell, CellProps } from 'react-table'
56

67
interface IProps {
78
users: UserWithSupertokens[]
89
}
910

10-
export default function RegisteredUsers({ users }: IProps): JSX.Element {
11+
export default function RegisteredUsers ({ users }: IProps): JSX.Element {
1112
if (users === undefined) return <></>
1213

1314
const columns = [
1415
{
1516
Header: 'Registered',
1617
accessor: 'registered',
17-
Cell: ({ cell }: any) => <span>{cell.value}</span>
18+
Cell: ({ cell }: CellProps<UserWithSupertokens>) => <span>{cell.value}</span>
1819
},
1920
{
2021
Header: 'Email',
2122
accessor: 'email',
22-
Cell: ({ cell }: any) => (
23+
Cell: ({ cell }: Cell<UserWithSupertokens>) => (
2324
<a
24-
href={`/api/auth/dashboard/?userid=${cell.row.original.id}&recipeId=emailpassword`}
25+
href={`/api/auth/dashboard/?userid=${cell.row.original.id as string}&recipeId=emailpassword`}
2526
target="_blank"
2627
rel="noopener noreferrer"
2728
>
@@ -32,18 +33,21 @@ export default function RegisteredUsers({ users }: IProps): JSX.Element {
3233
{
3334
Header: 'Admin',
3435
accessor: 'isAdmin',
35-
Cell: ({ cell }: any) => (
36+
Cell: ({ cell }: CellProps<UserWithSupertokens>) => (
3637
cell.value === true ? <span className={style.admin}>Yes</span> : 'No'
3738
)
3839
}
3940
]
40-
console.log({users})
41+
console.log({ users })
4142
const data = users.map(user => ({
4243
id: (user.stUser?.id === undefined || user.stUser?.id === '') ? user.userProfile?.id : user.stUser?.id,
43-
registered: user.stUser ? moment(user.stUser.timeJoined).fromNow() : 'NO ST USER FOUND',
44+
registered: (user.stUser != null) ? moment(user.stUser.timeJoined).fromNow() : 'NO ST USER FOUND',
4445
email: (user.stUser?.email === undefined || user.stUser?.email === '') ? user.userProfile?.id : user.stUser?.email,
4546
isAdmin: user.userProfile?.isAdmin
4647
}))
4748

48-
return <TableContainer columns={columns} data={data} ssr />
49+
return <>
50+
<h2>Registered Users</h2>
51+
<TableContainer columns={columns} data={data} ssr />
52+
</>
4953
}

components/Admin/SubscribedAddresses.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default function SubscribedAddresses (): JSX.Element {
4242
)
4343

4444
return <>
45+
<h2>Subscribed Addresses</h2>
4546
<h3> eCash</h3>
4647
<TableContainer columns={columns} data={ecashSubscribedAddresses ?? []} ssr/>
4748
<h3> Bitcoin Cash</h3>

pages/admin/admin.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@
2121
border-radius: 5px;
2222
max-width: 600px;
2323
}
24+
25+
.divisor {
26+
margin: 3rem;
27+
}

pages/admin/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import RegisteredUsers from 'components/Admin/RegisteredUsers'
1111
import { removeUnserializableFields } from 'utils'
1212
import { multiBlockchainClient } from 'services/chronikService'
1313
import { MainNetworkSlugsType } from 'constants/index'
14+
import SubscribedAddresses from 'components/Admin/SubscribedAddresses'
15+
import ChronikURLs from 'components/Admin/ChronikURLs'
1416

1517
export const getServerSideProps: GetServerSideProps = async (context) => {
1618
// this runs on the backend, so we must call init on supertokens-node SDK
@@ -52,7 +54,7 @@ interface IProps {
5254

5355
}
5456

55-
export default function Admin ({ user, isAdmin }: IProps): JSX.Element {
57+
export default function Admin ({ user, isAdmin, chronikUrls }: IProps): JSX.Element {
5658
const router = useRouter()
5759
const [users, setUsers] = useState<UserWithSupertokens[]>([])
5860

@@ -71,8 +73,8 @@ export default function Admin ({ user, isAdmin }: IProps): JSX.Element {
7173

7274
if (user !== null && isAdmin) {
7375
return <>
74-
<h2>Admin Dashboard</h2>
7576
<div className={style.admin_ctn}>
77+
<h2>Admin Dashboard</h2>
7678
<a
7779
target="_blank"
7880
rel="noopener noreferrer"
@@ -81,9 +83,12 @@ export default function Admin ({ user, isAdmin }: IProps): JSX.Element {
8183
>
8284
Go to Supertokens Admin Dashboard
8385
</a>
84-
<h4>Registered Users</h4>
85-
<RegisteredUsers users={users}/>
8686
</div>
87+
<ChronikURLs chronikUrls={chronikUrls}/>
88+
<hr className={style.divisor}/>
89+
<SubscribedAddresses/>
90+
<hr className={style.divisor}/>
91+
<RegisteredUsers users={users}/>
8792
</>
8893
} else {
8994
return <Page/>

styles/global.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,12 @@ body[data-theme='dark'] .button_outline:hover {
470470
.export_btn:hover {
471471
cursor: pointer;
472472
}
473+
474+
.columns {
475+
display: flex;
476+
}
477+
478+
.paybutton-table-ctn.columns > div {
479+
flex: 1;
480+
}
481+

0 commit comments

Comments
 (0)