ghost-portal/packages/app-addresses/src/index.js
Jaco Greeff ea50c4f1fe
Pull in ui-app components only (#46)
* Pull in ui-app components only

* Undefined check

* Small overall layout updates (buttons)

* Password hide/unhide icons

* Automatically assign name to inputs
2018-05-12 15:05:41 +02:00

77 lines
1.8 KiB
JavaScript

// Copyright 2017-2018 Jaco Greeff
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow
import type { I18nProps } from '@polkadot/ui-app/types';
import './index.css';
import React from 'react';
import Button from '@polkadot/ui-app/src/Button';
import Creator from './Creator';
import Editor from './Editor';
import translate from './translate';
type Props = I18nProps & {};
type Actions = 'create' | 'edit';
type State = {
action: Actions
}
// FIXME React-router would probably be the best route, not home-grown
const Components: { [Actions]: React$ComponentType<*> } = {
'create': Creator,
'edit': Editor
};
class App extends React.PureComponent<Props, State> {
state: State = { action: 'edit' };
render (): React$Node {
const { className, style, t } = this.props;
const { action } = this.state;
const Component = Components[action];
return (
<div
className={['addresses--App', className].join(' ')}
style={style}
>
<Button.Group className='addresses--App-navigation'>
<Button
isPrimary={action === 'edit'}
onClick={this.selectEdit}
text={t('app.edit', {
defaultValue: 'Edit address'
})}
/>
<Button.Or />
<Button
isPrimary={action === 'create'}
onClick={this.selectCreate}
text={t('app.create', {
defaultValue: 'Add address'
})}
/>
</Button.Group>
<Component onBack={this.selectEdit} />
</div>
);
}
selectCreate = (): void => {
this.setState({ action: 'create' });
}
selectEdit = (): void => {
this.setState({ action: 'edit' });
}
}
export default translate(App);