Advertisement
Guest User

Untitled

a guest
Jan 26th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import {Well, Table, ButtonGroup, Button, DropdownButton, Modal, NavDropdown, MenuItem} from 'react-bootstrap';
  3. import FontAwesome from 'react-fontawesome';
  4. import ModalDetails from './ModalDetails';
  5.  
  6. /*
  7. TableAdmin:
  8. buttons = un arreglo de botones que tienen que pueden ser icons o dropdowns, tienen un texto, un icono y una acción
  9. headers = un arregloque contiene las cabeceras de la tabla
  10. nameClass= una clase
  11. contents = un arreglo de contenidos
  12.  
  13. ObjectRow:
  14. rows: un arreglo que contiene los campos de una fila
  15. icons: un arreglo que contiene los iconos de una fila, se transforman en un elemento     button que accede a los datos de su fila
  16.  
  17. */
  18.  
  19. const ObjectRow = ({  idField='id', fields = [],  item = {} , buttons = []}) => {
  20.     const botones = buttons.filter( btn => !btn.dropdown);
  21.     const dropdowns = buttons.filter( btn => btn.dropdown);
  22.     return (
  23.         <tr>   
  24.             {fields.map((field, i) => <td key={`field${i}`}>{item[field]}</td>)}
  25.             <td>
  26.             <ButtonGroup>
  27.                 { botones.map((btn, i) => (
  28.                     <Button onClick={ () => btn.action( item ) }>
  29.                         { btn.icon && <FontAwesome name={btn.icon}  />}
  30.                         {btn.text && `${btn.text}`}
  31.                     </Button>
  32.                     )
  33.                 ) }
  34.                 {
  35.                     dropdowns.length ? (
  36.                         <DropdownButton pullRight className="select" noCaret title={<FontAwesome name={'ellipsis-h'}/>}>
  37.                         {
  38.                             dropdowns.map((option, i) => <MenuItem key={`option${i}`} onClick={() => option.action( item )   }><FontAwesome name={option.icon}/>{option.text}</MenuItem>)
  39.                          }
  40.                         </DropdownButton>
  41.                     ) : null
  42.                 }
  43.                 </ButtonGroup>
  44.             </td>
  45.         </tr>
  46.     );
  47. };
  48. /*
  49. buttons = [
  50.     {
  51.         icon,
  52.         text,
  53.         classname,
  54.         action,
  55.         dropdown: true|false
  56.     }
  57. ]
  58. */
  59. const TableAdmin = ({ idField='id', fields = [], headers = [], buttons = [], nameClass, contents = []}) => {
  60.     return (<Table responsive className={nameClass}>
  61.                 <thead>
  62.                     <tr>
  63.                         { headers.map((header, i) => <th key={`header${i}`}> {header} </th>) }
  64.                     </tr>
  65.                 </thead>
  66.                 <tbody>
  67.                     {
  68.                         contents.map((content, i) => <ObjectRow idField={idField} fields={fields} item={content} buttons={buttons} /> )
  69.                     }
  70.                 </tbody>
  71.             </Table>
  72.     );
  73. };
  74.  
  75. export default TableAdmin;
  76. -----------------------------------------------------------------------------------
  77.  
  78. import React from 'react';
  79. import {Well, Button} from 'react-bootstrap';
  80. import * as classnames from 'classnames';
  81.  
  82. /*Card de acciones, recibe:
  83. buttons = un arreglo de botones que tienen los parámetros ['text, href, className']
  84. text: un título
  85. nameClass= una clase
  86. contents = un arreglo de contenidos que tienen los parámetros ['text, className']
  87. */
  88.  
  89. const Card = ({ text = null, contents = [], className = '', ...props }) => {
  90.     return [
  91.         <Well {...props} className={classnames("card", className)}>
  92.             { text && <p className="card-title">{text}</p> }
  93.             {contents}
  94.         </Well>
  95.     ];
  96. };
  97.  
  98. export default Card;
  99.  
  100.  
  101. -------------------------------------------------------------------
  102.  
  103.  
  104. import React from 'react';
  105. import {Modal,Col, Row, Well, Button} from 'react-bootstrap';
  106. import AvailableBalance from '../components/AvailableBalance';
  107. import Card from '../components/Card';
  108. import TableAdmin from '../components/TableAdmin';
  109. import ModalDetails from '../components/ModalDetails';
  110.  
  111.  
  112. /*sección de resumen*/
  113.  
  114. export default class Summary extends React.Component {
  115.     state = {
  116.         showModal: false,
  117.         id: 0,
  118.     };
  119.  
  120.     confirmar = item => {
  121.         console.log(item)
  122.         this.setState({showModal: true})
  123.         this.setState({id: item.id})
  124.     }
  125.  
  126.     testing = () => {
  127.         console.log("testing here")
  128.     }
  129.     changeState = () => {
  130.         this.setState({showModal: false})
  131.     }
  132.  
  133.     render = ( ) => {
  134.         const { showModal } = this.state;
  135.         const { id } = this.state;
  136.         const contentsTable = [
  137.                     {id: 0,fecha: '2018-02-24', nombre: 'A', tipo:'Nerd', cantidad:1,comision:1.2,saldo: 500},
  138.                     {id: 1,fecha: '2018-02-24', nombre: 'B', tipo:'Nerd', cantidad:1,comision:1.2,saldo: 500},
  139.                     {id: 2,fecha: '2018-02-24', nombre: 'C', tipo:'Nerd', cantidad:1,comision:1.2,saldo: 500},
  140.                     {id: 3,fecha: '2018-02-24', nombre: 'D', tipo:'Nerd', cantidad:1,comision:1.2,saldo: 500},
  141.                 ];
  142.  
  143.         const adminTable  = <TableAdmin
  144.                     nameClass = ""
  145.                     buttons =  {
  146.                         [
  147.                             {
  148.                                 icon: 'edit',
  149.                                 action: this.confirmar,
  150.                             },
  151.                             {
  152.                                 icon: 'trash',
  153.                                 text: 'Eliminar',
  154.                                 action: this.confirmar,
  155.                                 dropdown: true
  156.                             },
  157.                             {
  158.                                 icon: 'eye',
  159.                                 text: 'Eliminar',
  160.                                 action: this.confirmar,
  161.                                 dropdown: true
  162.                             },
  163.                             {
  164.                                 icon: 'search',
  165.                                 text: 'Eliminar',
  166.                                 action: this.confirmar,
  167.                                 dropdown: true
  168.                             }
  169.                         ]
  170.                     }
  171.                     headers = {['Fecha', 'Nombre', 'Tipo', 'Neto (Bs.F)','Comisión (Bs.F)','Saldo',]}
  172.                     fields = {['fecha', 'nombre', 'tipo', 'cantidad','comision','saldo']}
  173.                     contents = {
  174.                         contentsTable
  175.                     }
  176.                 />;
  177.  
  178.         return [
  179.  
  180.             showModal && (<ModalDetails
  181.                     elements ={[
  182.                         <p className="card-title">Últimas transacciones</p>,
  183.                         <p>{contentsTable[this.state.id].nombre}</p>
  184.                     ]}
  185.                     buttons =  {[
  186.                         {
  187.                             text: 'cancelar',
  188.                             action: this.changeState,
  189.                         }
  190.                     ]}
  191.                 />),
  192.  
  193.                 <Col md={8} xs={12} key={"summarycol1"}>
  194.                     <Card className="summary-table"
  195.                             contents={[
  196.                                 <p className="card-title">Últimas transacciones</p>,
  197.                                 adminTable
  198.                             ]}
  199.                         />
  200.                 </Col>,
  201.  
  202.                 <Col md={4} xs={12} key={"summarycol2"}>
  203.                     <Card text={'Saldo'} className="card-available" contents={[<AvailableBalance/>]} />
  204.                     <Card className="card-accounts" text={"Cuentas bancarias"}
  205.                         contents={[
  206.                             <p className="description">Descubre cómo puedes aprovechar al máximo tu cuenta DigiPagos.</p>,
  207.                             <Button>Asociar cuenta bancaria</Button>
  208.                         ]} />
  209.                 </Col>
  210.         ]
  211.     };
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement