Applicants.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import { Table } from 'semantic-ui-react';
  3. import BN from 'bn.js';
  4. import { I18nProps } from '@polkadot/react-components/types';
  5. import { ApiProps } from '@polkadot/react-api/types';
  6. import { withCalls } from '@polkadot/react-api/with';
  7. import { AccountId } from '@polkadot/types/interfaces';
  8. import { formatNumber } from '@polkadot/util';
  9. import translate from './translate';
  10. import Applicant from './Applicant';
  11. import ApplyForm from './ApplyForm';
  12. import Section from '@polkadot/joy-utils/Section';
  13. import { queryToProp } from '@polkadot/joy-utils/index';
  14. import { withMyAccount, MyAccountProps } from '@polkadot/joy-utils/MyAccount';
  15. type Props = ApiProps & I18nProps & MyAccountProps & {
  16. candidacyLimit?: BN;
  17. applicants?: Array<AccountId>;
  18. };
  19. class Applicants extends React.PureComponent<Props> {
  20. private renderTable = (applicants: Array<AccountId>) => (
  21. <Table celled selectable compact>
  22. <Table.Header>
  23. <Table.Row>
  24. <Table.HeaderCell>#</Table.HeaderCell>
  25. <Table.HeaderCell>Applicant</Table.HeaderCell>
  26. <Table.HeaderCell>Total stake</Table.HeaderCell>
  27. <Table.HeaderCell style={{ width: '1%' }}>Actions</Table.HeaderCell>
  28. </Table.Row>
  29. </Table.Header>
  30. <Table.Body>{applicants.map((accountId, index) => (
  31. <Applicant key={index} index={index} accountId={accountId} />
  32. ))}</Table.Body>
  33. </Table>
  34. )
  35. render () {
  36. const { myAddress, applicants = [], candidacyLimit = new BN(0) } = this.props;
  37. const title = <span>Applicants <sup>{applicants.length}/{formatNumber(candidacyLimit)}</sup></span>;
  38. return <>
  39. <Section title='My application'>
  40. <ApplyForm myAddress={myAddress} />
  41. </Section>
  42. <Section title={title}>
  43. {!applicants.length
  44. ? <em>No applicants yet</em>
  45. : this.renderTable(applicants)
  46. }
  47. </Section>
  48. </>;
  49. }
  50. }
  51. // inject the actual API calls automatically into props
  52. export default translate(
  53. withCalls<Props>(
  54. queryToProp('query.councilElection.candidacyLimit'),
  55. queryToProp('query.councilElection.applicants')
  56. )(withMyAccount(Applicants))
  57. );