diff --git a/lib/new-admin/graphql/schema.js b/lib/new-admin/graphql/schema.js index 9cc8fba0..a39eb05d 100644 --- a/lib/new-admin/graphql/schema.js +++ b/lib/new-admin/graphql/schema.js @@ -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 }), diff --git a/lib/token-manager.js b/lib/token-manager.js new file mode 100644 index 00000000..74bde507 --- /dev/null +++ b/lib/token-manager.js @@ -0,0 +1,8 @@ +const db = require('./db') + +function getTokenList() { + const sql = `select * from user_tokens` + return db.any(sql); +} + +module.exports = { getTokenList } \ No newline at end of file diff --git a/new-lamassu-admin/src/pages/TokenManagement/TokenManagement.js b/new-lamassu-admin/src/pages/TokenManagement/TokenManagement.js new file mode 100644 index 00000000..1ee83b29 --- /dev/null +++ b/new-lamassu-admin/src/pages/TokenManagement/TokenManagement.js @@ -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)} +
+
+ Token Management +
+
+ + + ) + + /* return ( + <> + {console.log(tknResponse)} +
+
+ Token Management +
+
+ + + ) */ +} + +export default Tokens diff --git a/new-lamassu-admin/src/pages/TokenManagement/TokenManagement.styles.js b/new-lamassu-admin/src/pages/TokenManagement/TokenManagement.styles.js new file mode 100644 index 00000000..9d52042f --- /dev/null +++ b/new-lamassu-admin/src/pages/TokenManagement/TokenManagement.styles.js @@ -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 } diff --git a/new-lamassu-admin/src/routing/routes.js b/new-lamassu-admin/src/routing/routes.js index 0a1e1f0c..43f5deb6 100644 --- a/new-lamassu-admin/src/routing/routes.js +++ b/new-lamassu-admin/src/routing/routes.js @@ -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 () => + }, + children: [ + { + key: 'token-management', + label: 'Token Management', + route: '/system/token-management', + component: TokenManagement + } + ] } ]