From 29e93e494d51da5dea7ec3fd5e8ede3e32dcef43 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Tue, 7 Jun 2022 00:57:18 -0700 Subject: [PATCH] rendering accounts in admin dashboard --- net/web/src/Admin/Admin.jsx | 2 +- .../Dashboard/AccountItem/AccountItem.jsx | 34 +++++++++- .../AccountItem/AccountItem.styled.js | 66 +++++++++++++++++++ .../AccountItem/useAccountItem.hook.js | 28 ++++++++ net/web/src/Admin/Dashboard/Dashboard.jsx | 8 +-- .../src/Admin/Dashboard/Dashboard.styled.js | 4 +- .../src/Admin/Dashboard/useDashboard.hook.js | 15 ++++- net/web/src/api/getAccountImageUrl.js | 4 ++ 8 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 net/web/src/Admin/Dashboard/AccountItem/AccountItem.styled.js create mode 100644 net/web/src/Admin/Dashboard/AccountItem/useAccountItem.hook.js create mode 100644 net/web/src/api/getAccountImageUrl.js diff --git a/net/web/src/Admin/Admin.jsx b/net/web/src/Admin/Admin.jsx index 5db13ab8..23da56b5 100644 --- a/net/web/src/Admin/Admin.jsx +++ b/net/web/src/Admin/Admin.jsx @@ -44,7 +44,7 @@ export function Admin() { return ( - + ) } diff --git a/net/web/src/Admin/Dashboard/AccountItem/AccountItem.jsx b/net/web/src/Admin/Dashboard/AccountItem/AccountItem.jsx index 84401c22..0bb30bad 100644 --- a/net/web/src/Admin/Dashboard/AccountItem/AccountItem.jsx +++ b/net/web/src/Admin/Dashboard/AccountItem/AccountItem.jsx @@ -1,4 +1,34 @@ -export function AccountItem() { - return
ACCOUNT
+import { Avatar } from 'avatar/Avatar'; +import { AccountItemWrapper, DeleteButton, EnableButton, DisableButton, ResetButton } from './AccountItem.styled'; +import { useAccountItem } from './useAccountItem.hook'; +import { UserDeleteOutlined, UnlockOutlined, CloseCircleOutlined, CheckCircleOutlined } from '@ant-design/icons'; + +export function AccountItem({ token, item }) { + + const { state, actions } = useAccountItem(token, item); + + const Enable = () => { + if (state.disabled) { + return }> + } + return }> + } + + return ( + +
+ +
+
+
{ state.handle }
+
{ state.guid }
+
+
+ }> + + }> +
+
+ ); } diff --git a/net/web/src/Admin/Dashboard/AccountItem/AccountItem.styled.js b/net/web/src/Admin/Dashboard/AccountItem/AccountItem.styled.js new file mode 100644 index 00000000..9e62a1a1 --- /dev/null +++ b/net/web/src/Admin/Dashboard/AccountItem/AccountItem.styled.js @@ -0,0 +1,66 @@ +import { Button } from 'antd'; +import styled from 'styled-components'; + +export const AccountItemWrapper = styled.div` + display: flex; + width: 100%; + flex-direction: row; + overflow: hidden; + padding-left: 16px; + padding-right: 16px; + padding-top: 2px; + padding-bottom: 2px; + border-bottom: 1px solid #eeeeee; + + &:hover { + background-color: #eeeeee; + } + + .avatar { + width: 32px; + height: 32px; + display: flex; + justify-content: center; + } + + .id { + padding-left: 16px; + padding-right: 8px; + display: flex; + flex-direction: column; + flex-grow: 1; + + .handle { + font-size: 0.8em; + font-weight: bold; + } + + .guid { + font-size: 0.8em; + font-weight: bold; + } + + .control { + flex-grow: 1; + display: flex; + justify-content: flex-end; + align-items: center; + } + } +`; + +export const EnableButton = styled(Button)` + color: orange; +`; + +export const DisableButton = styled(Button)` + color: orange; +`; + +export const ResetButton = styled(Button)` + color: #1890ff; +`; + +export const DeleteButton = styled(Button)` + color: red; +` diff --git a/net/web/src/Admin/Dashboard/AccountItem/useAccountItem.hook.js b/net/web/src/Admin/Dashboard/AccountItem/useAccountItem.hook.js new file mode 100644 index 00000000..451c0e0d --- /dev/null +++ b/net/web/src/Admin/Dashboard/AccountItem/useAccountItem.hook.js @@ -0,0 +1,28 @@ +import { useContext, useState, useEffect } from 'react'; +import { getAccountImageUrl } from 'api/getAccountImageUrl'; + +export function useAccountItem(token, item) { + + const [state, setState] = useState({ + }); + + const updateState = (value) => { + setState((s) => ({ ...s, ...value })); + } + + useEffect(() => { + updateState({ + disabled: false, + accountId: item?.accountId, + name: item?.name, + guid: item?.guid, + handle: item?.handle, + imageUrl: item?.imageSet ? getAccountImageUrl(token, item?.accountId) : null, + }); + }, []); + + const actions = { + }; + + return { state, actions }; +} diff --git a/net/web/src/Admin/Dashboard/Dashboard.jsx b/net/web/src/Admin/Dashboard/Dashboard.jsx index 24c6267e..80e3836d 100644 --- a/net/web/src/Admin/Dashboard/Dashboard.jsx +++ b/net/web/src/Admin/Dashboard/Dashboard.jsx @@ -4,9 +4,9 @@ import { SettingOutlined, UserAddOutlined, ReloadOutlined } from '@ant-design/ic import { useDashboard } from './useDashboard.hook'; import { AccountItem } from './AccountItem/AccountItem'; -export function Dashboard({ password, config }) { +export function Dashboard({ token, config }) { - const { state, actions } = useDashboard(password, config); + const { state, actions } = useDashboard(token, config); return ( @@ -33,12 +33,12 @@ export function Dashboard({ password, config }) { itemLayout="horizontal" dataSource={state.accounts} loading={state.loading} - renderItem={item => ()} + renderItem={item => ()} /> - actions.setSettings()} onCancel={() => actions.setShowSettings(false)}>
diff --git a/net/web/src/Admin/Dashboard/Dashboard.styled.js b/net/web/src/Admin/Dashboard/Dashboard.styled.js index a93502fc..fdbceef9 100644 --- a/net/web/src/Admin/Dashboard/Dashboard.styled.js +++ b/net/web/src/Admin/Dashboard/Dashboard.styled.js @@ -15,7 +15,8 @@ export const DashboardWrapper = styled.div` flex-direction: column; padding: 16px; border-radius: 4px; - max-width: 500px; + min-width: 800px; + max-width: 900px; width: 50%; max-height: 80%; @@ -28,6 +29,7 @@ export const DashboardWrapper = styled.div` } .body { + padding-top: 8px; min-height: 0; overflow: auto; } diff --git a/net/web/src/Admin/Dashboard/useDashboard.hook.js b/net/web/src/Admin/Dashboard/useDashboard.hook.js index b305f76c..b95f84db 100644 --- a/net/web/src/Admin/Dashboard/useDashboard.hook.js +++ b/net/web/src/Admin/Dashboard/useDashboard.hook.js @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'; import { setNodeConfig } from 'api/setNodeConfig'; import { getNodeAccounts } from 'api/getNodeAccounts'; -export function useDashboard(password, config) { +export function useDashboard(token, config) { const [state, setState] = useState({ host: "", @@ -31,7 +31,7 @@ export function useDashboard(password, config) { if (!state.busy) { updateState({ busy: true }); try { - await setNodeConfig(password, + await setNodeConfig(token, { ...state.config, domain: state.host, accountStorage: state.storage * 1073741824 }); updateState({ showSettings: false }); } @@ -46,7 +46,16 @@ export function useDashboard(password, config) { if (!state.loading) { updateState({ loading: true }); try { - let accounts = await getNodeAccounts(password); + let accounts = await getNodeAccounts(token); + accounts.sort((a, b) => { + if (a.handle < b.handle) { + return -1; + } + if (a.handle > b.handle) { + return 1; + } + return 0; + }); updateState({ accounts }); } catch(err) { diff --git a/net/web/src/api/getAccountImageUrl.js b/net/web/src/api/getAccountImageUrl.js new file mode 100644 index 00000000..e164919f --- /dev/null +++ b/net/web/src/api/getAccountImageUrl.js @@ -0,0 +1,4 @@ +export function getAccountImageUrl(token, accountId) { + return `/admin/accounts/${accountId}/image?token=${token}` +} +