mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 13:09:17 +00:00
rendering accounts in admin dashboard
This commit is contained in:
parent
ab9935fac7
commit
29e93e494d
@ -44,7 +44,7 @@ export function Admin() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AdminWrapper>
|
<AdminWrapper>
|
||||||
<Dashboard password={state.token} config={state.config} />
|
<Dashboard token={state.token} config={state.config} />
|
||||||
</AdminWrapper>
|
</AdminWrapper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,34 @@
|
|||||||
export function AccountItem() {
|
import { Avatar } from 'avatar/Avatar';
|
||||||
return <div>ACCOUNT</div>
|
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 <EnableButton type="text" size="large" icon={<CloseCircleOutlined />}></EnableButton>
|
||||||
|
}
|
||||||
|
return <DisableButton type="text" size="large" icon={<CheckCircleOutlined />}></DisableButton>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AccountItemWrapper>
|
||||||
|
<div class="avatar">
|
||||||
|
<Avatar imageUrl={state.imageUrl} />
|
||||||
|
</div>
|
||||||
|
<div class="id">
|
||||||
|
<div class="handle">{ state.handle }</div>
|
||||||
|
<div class="guid">{ state.guid }</div>
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<ResetButton type="text" size="large" icon={<UnlockOutlined />}></ResetButton>
|
||||||
|
<Enable />
|
||||||
|
<DeleteButton type="text" size="large" icon={<UserDeleteOutlined />}></DeleteButton>
|
||||||
|
</div>
|
||||||
|
</AccountItemWrapper>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
`
|
@ -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 };
|
||||||
|
}
|
@ -4,9 +4,9 @@ import { SettingOutlined, UserAddOutlined, ReloadOutlined } from '@ant-design/ic
|
|||||||
import { useDashboard } from './useDashboard.hook';
|
import { useDashboard } from './useDashboard.hook';
|
||||||
import { AccountItem } from './AccountItem/AccountItem';
|
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 (
|
return (
|
||||||
<DashboardWrapper>
|
<DashboardWrapper>
|
||||||
@ -33,7 +33,7 @@ export function Dashboard({ password, config }) {
|
|||||||
itemLayout="horizontal"
|
itemLayout="horizontal"
|
||||||
dataSource={state.accounts}
|
dataSource={state.accounts}
|
||||||
loading={state.loading}
|
loading={state.loading}
|
||||||
renderItem={item => (<AccountItem item={item} />)}
|
renderItem={item => (<AccountItem token={token} item={item} />)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,7 +15,8 @@ export const DashboardWrapper = styled.div`
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
max-width: 500px;
|
min-width: 800px;
|
||||||
|
max-width: 900px;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
max-height: 80%;
|
max-height: 80%;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ export const DashboardWrapper = styled.div`
|
|||||||
}
|
}
|
||||||
|
|
||||||
.body {
|
.body {
|
||||||
|
padding-top: 8px;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
|||||||
import { setNodeConfig } from 'api/setNodeConfig';
|
import { setNodeConfig } from 'api/setNodeConfig';
|
||||||
import { getNodeAccounts } from 'api/getNodeAccounts';
|
import { getNodeAccounts } from 'api/getNodeAccounts';
|
||||||
|
|
||||||
export function useDashboard(password, config) {
|
export function useDashboard(token, config) {
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
host: "",
|
host: "",
|
||||||
@ -31,7 +31,7 @@ export function useDashboard(password, config) {
|
|||||||
if (!state.busy) {
|
if (!state.busy) {
|
||||||
updateState({ busy: true });
|
updateState({ busy: true });
|
||||||
try {
|
try {
|
||||||
await setNodeConfig(password,
|
await setNodeConfig(token,
|
||||||
{ ...state.config, domain: state.host, accountStorage: state.storage * 1073741824 });
|
{ ...state.config, domain: state.host, accountStorage: state.storage * 1073741824 });
|
||||||
updateState({ showSettings: false });
|
updateState({ showSettings: false });
|
||||||
}
|
}
|
||||||
@ -46,7 +46,16 @@ export function useDashboard(password, config) {
|
|||||||
if (!state.loading) {
|
if (!state.loading) {
|
||||||
updateState({ loading: true });
|
updateState({ loading: true });
|
||||||
try {
|
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 });
|
updateState({ accounts });
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
|
4
net/web/src/api/getAccountImageUrl.js
Normal file
4
net/web/src/api/getAccountImageUrl.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export function getAccountImageUrl(token, accountId) {
|
||||||
|
return `/admin/accounts/${accountId}/image?token=${token}`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user