feat: token management screen
This commit is contained in:
parent
5434e9f8e6
commit
4b44e1ef97
5 changed files with 165 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ const customers = require('../../customers')
|
|||
const { machineAction } = require('../machines')
|
||||
const logs = require('../../logs')
|
||||
const settingsLoader = require('../../new-settings-loader')
|
||||
const tokenManager = require('../../token-manager')
|
||||
|
||||
const serverVersion = require('../../../package.json').version
|
||||
|
||||
|
|
@ -155,6 +156,12 @@ const typeDefs = gql`
|
|||
uptime: Int!
|
||||
}
|
||||
|
||||
type UserToken {
|
||||
token: String!
|
||||
name: String!
|
||||
created: Date!
|
||||
}
|
||||
|
||||
type Transaction {
|
||||
id: ID!
|
||||
txClass: String!
|
||||
|
|
@ -217,6 +224,7 @@ const typeDefs = gql`
|
|||
transactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
accounts: JSONObject
|
||||
config: JSONObject
|
||||
userTokens: [UserToken]
|
||||
}
|
||||
|
||||
enum MachineAction {
|
||||
|
|
@ -273,7 +281,8 @@ const resolvers = {
|
|||
transactionsCsv: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.batch(from, until, limit, offset).then(parseAsync),
|
||||
config: () => settingsLoader.loadLatestConfigOrNone(),
|
||||
accounts: () => settingsLoader.loadAccounts()
|
||||
accounts: () => settingsLoader.loadAccounts(),
|
||||
userTokens: () => tokenManager.getTokenList()
|
||||
},
|
||||
Mutation: {
|
||||
machineAction: (...[, { deviceId, action, cassette1, cassette2, newName }]) => machineAction({ deviceId, action, cassette1, cassette2, newName }),
|
||||
|
|
|
|||
8
lib/token-manager.js
Normal file
8
lib/token-manager.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
const db = require('./db')
|
||||
|
||||
function getTokenList() {
|
||||
const sql = `select * from user_tokens`
|
||||
return db.any(sql);
|
||||
}
|
||||
|
||||
module.exports = { getTokenList }
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
import { useQuery } from '@apollo/react-hooks'
|
||||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import gql from 'graphql-tag'
|
||||
import moment from 'moment'
|
||||
import * as R from 'ramda'
|
||||
import React from 'react'
|
||||
|
||||
import Title from 'src/components/Title'
|
||||
// import DataTable from 'src/components/tables/DataTable'
|
||||
import { Table as EditableTable } from 'src/components/editableTable'
|
||||
|
||||
import { mainStyles } from './TokenManagement.styles'
|
||||
|
||||
const useStyles = makeStyles(mainStyles)
|
||||
|
||||
const GET_USER_TOKENS = gql`
|
||||
{
|
||||
userTokens {
|
||||
token
|
||||
name
|
||||
created
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const Tokens = () => {
|
||||
const classes = useStyles()
|
||||
|
||||
const { data: tknResponse } = useQuery(GET_USER_TOKENS)
|
||||
|
||||
const elements = [
|
||||
{
|
||||
name: 'name',
|
||||
header: 'Name',
|
||||
width: 312,
|
||||
textAlign: 'center',
|
||||
size: 'sm'
|
||||
},
|
||||
{
|
||||
name: 'token',
|
||||
header: 'Token',
|
||||
width: 520,
|
||||
textAlign: 'center',
|
||||
size: 'sm'
|
||||
},
|
||||
{
|
||||
name: 'created',
|
||||
header: 'Date (UTC)',
|
||||
width: 140,
|
||||
textAlign: 'right',
|
||||
size: 'sm',
|
||||
view: t => moment.utc(t).format('YYYY-MM-DD')
|
||||
},
|
||||
{
|
||||
name: 'created',
|
||||
header: 'Time (UTC)',
|
||||
width: 140,
|
||||
textAlign: 'right',
|
||||
size: 'sm',
|
||||
view: t => moment.utc(t).format('HH:mm:ss')
|
||||
}
|
||||
]
|
||||
|
||||
return (
|
||||
<>
|
||||
{console.log(tknResponse)}
|
||||
<div className={classes.titleWrapper}>
|
||||
<div className={classes.titleAndButtonsContainer}>
|
||||
<Title>Token Management</Title>
|
||||
</div>
|
||||
</div>
|
||||
<EditableTable
|
||||
name="tokenList"
|
||||
elements={elements}
|
||||
data={R.path(['userTokens'])(tknResponse)}
|
||||
enableDelete
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
||||
/* return (
|
||||
<>
|
||||
{console.log(tknResponse)}
|
||||
<div className={classes.titleWrapper}>
|
||||
<div className={classes.titleAndButtonsContainer}>
|
||||
<Title>Token Management</Title>
|
||||
</div>
|
||||
</div>
|
||||
<DataTable
|
||||
elements={elements}
|
||||
data={R.path(['userTokens'])(tknResponse)}
|
||||
/>
|
||||
</>
|
||||
) */
|
||||
}
|
||||
|
||||
export default Tokens
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import typographyStyles from 'src/components/typography/styles'
|
||||
import baseStyles from 'src/pages/Logs.styles'
|
||||
|
||||
const { label1 } = typographyStyles
|
||||
const { titleWrapper, titleAndButtonsContainer, buttonsWrapper } = baseStyles
|
||||
|
||||
const mainStyles = {
|
||||
titleWrapper,
|
||||
titleAndButtonsContainer,
|
||||
buttonsWrapper,
|
||||
headerLabels: {
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
'& div': {
|
||||
display: 'flex',
|
||||
alignItems: 'center'
|
||||
},
|
||||
'& > div:first-child': {
|
||||
marginRight: 24
|
||||
},
|
||||
'& span': {
|
||||
extend: label1,
|
||||
marginLeft: 6
|
||||
}
|
||||
},
|
||||
overflowTd: {
|
||||
overflow: 'hidden',
|
||||
whiteSpace: 'nowrap',
|
||||
textOverflow: 'ellipsis'
|
||||
}
|
||||
}
|
||||
|
||||
export { mainStyles }
|
||||
|
|
@ -22,6 +22,7 @@ import Notifications from 'src/pages/Notifications/Notifications'
|
|||
import OperatorInfo from 'src/pages/OperatorInfo/OperatorInfo'
|
||||
import ServerLogs from 'src/pages/ServerLogs'
|
||||
import Services from 'src/pages/Services/Services'
|
||||
import TokenManagement from 'src/pages/TokenManagement/TokenManagement'
|
||||
import Transactions from 'src/pages/Transactions/Transactions'
|
||||
import Triggers from 'src/pages/Triggers'
|
||||
import WalletSettings from 'src/pages/Wallet/Wallet'
|
||||
|
|
@ -153,6 +154,22 @@ const tree = [
|
|||
component: CustomerProfile
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
key: 'system',
|
||||
label: 'System',
|
||||
route: '/system',
|
||||
get component() {
|
||||
return () => <Redirect to={this.children[0].route} />
|
||||
},
|
||||
children: [
|
||||
{
|
||||
key: 'token-management',
|
||||
label: 'Token Management',
|
||||
route: '/system/token-management',
|
||||
component: TokenManagement
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue