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)} +