ghost-portal/packages/page-sudo/src/index.tsx
2021-03-21 09:31:43 +01:00

71 lines
1.7 KiB
TypeScript

// Copyright 2017-2021 @polkadot/app-js authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AppProps as Props } from '@polkadot/react-components/types';
import React, { useRef } from 'react';
import { Route, Switch } from 'react-router';
import { Icon, Tabs } from '@polkadot/react-components';
import { useSudo } from '@polkadot/react-hooks';
import SetKey from './SetKey';
import Sudo from './Sudo';
import { useTranslation } from './translate';
function SudoApp ({ basePath }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { allAccounts, hasSudoKey, sudoKey } = useSudo();
const itemsRef = useRef([
{
isRoot: true,
name: 'index',
text: t<string>('Sudo access')
},
{
name: 'key',
text: t<string>('Set sudo key')
}
]);
return (
<main>
<Tabs
basePath={basePath}
items={itemsRef.current}
/>
{hasSudoKey
? (
<Switch>
<Route path={`${basePath}/key`}>
<SetKey
allAccounts={allAccounts}
isMine={hasSudoKey}
sudoKey={sudoKey}
/>
</Route>
<Route>
<Sudo
allAccounts={allAccounts}
isMine={hasSudoKey}
sudoKey={sudoKey}
/>
</Route>
</Switch>
)
: (
<article className='error padded'>
<div>
<Icon icon='ban' />
{t<string>('You do not have access to the current sudo key')}
</div>
</article>
)
}
</main>
);
}
export default React.memo(SudoApp);