|
1 | 1 | import React from 'react'; |
2 | | -import { useHistory } from 'react-router-dom'; |
3 | | -import { routes } from 'core/router'; |
4 | 2 | import { |
5 | 3 | TableContainer, |
6 | | - RowComponent, |
7 | 4 | RowRendererProps, |
8 | | -} from 'common/components/table'; |
9 | | -import { Typography } from '@material-ui/core'; |
| 5 | + useSearchBar, |
| 6 | +} from 'common/components'; |
| 7 | +import { Employee } from './employee-list.vm'; |
| 8 | +import { EmployeeRowComponent } from './components'; |
10 | 9 |
|
11 | | -export const EmployeeListComponent: React.FunctionComponent = () => { |
12 | | - const history = useHistory(); |
13 | | - const goToEmployee = ( |
14 | | - event: React.MouseEvent<HTMLParagraphElement, MouseEvent> |
15 | | - ) => { |
16 | | - event.preventDefault(); |
17 | | - history.push({ |
18 | | - pathname: routes.editEmployee('1'), |
19 | | - }); |
| 10 | +interface Props { |
| 11 | + employeeList: Employee[]; |
| 12 | + onCreate: () => void; |
| 13 | + onEdit: (id: string) => void; |
| 14 | + onDelete: (id: string) => void; |
| 15 | +} |
| 16 | + |
| 17 | +export const EmployeeListComponent: React.FunctionComponent<Props> = ({ |
| 18 | + employeeList, |
| 19 | + onCreate, |
| 20 | + onEdit, |
| 21 | + onDelete, |
| 22 | +}) => { |
| 23 | + const { filteredList, onSearch, search } = useSearchBar(employeeList, [ |
| 24 | + 'name', |
| 25 | + ]); |
| 26 | + |
| 27 | + const renderContent = ({ itemName }) => { |
| 28 | + return ( |
| 29 | + <> |
| 30 | + ¿Seguro que quiere borrar a <strong>{itemName}</strong>? |
| 31 | + </> |
| 32 | + ); |
20 | 33 | }; |
| 34 | + |
21 | 35 | return ( |
22 | | - <> |
23 | | - <h1>Hello Employee list component</h1> |
24 | | - <p onClick={goToEmployee}>Go to edit employee page</p> |
25 | | - <TableContainer |
26 | | - columns={['Column 1']} |
27 | | - rows={[{ id: '1', name: 'test 1' }]} |
28 | | - rowRenderer={(props: RowRendererProps<any>) => ( |
29 | | - <RowComponent> |
30 | | - <Typography>{props.row.name}</Typography> |
31 | | - </RowComponent> |
32 | | - )} |
33 | | - /> |
34 | | - </> |
| 36 | + <TableContainer |
| 37 | + columns={['Activo', 'Id', 'Nombre', 'Email', 'Fecha último incurrido']} |
| 38 | + rows={filteredList} |
| 39 | + rowRenderer={(rowProps: RowRendererProps<Employee>) => ( |
| 40 | + <EmployeeRowComponent {...rowProps} /> |
| 41 | + )} |
| 42 | + onCreate={onCreate} |
| 43 | + onEdit={onEdit} |
| 44 | + onDelete={onDelete} |
| 45 | + labels={{ |
| 46 | + searchPlaceholder: 'Buscar empleado', |
| 47 | + createButton: 'Nuevo empleado', |
| 48 | + deleteTitle: 'Eliminar Empleado', |
| 49 | + deleteContent: props => renderContent(props), |
| 50 | + closeButton: 'Cancelar', |
| 51 | + acceptButton: 'Aceptar', |
| 52 | + }} |
| 53 | + enableSearch={true} |
| 54 | + search={search} |
| 55 | + onSearch={onSearch} |
| 56 | + enablePagination={true} |
| 57 | + pageSize={5} |
| 58 | + /> |
35 | 59 | ); |
36 | 60 | }; |
0 commit comments