|
1 | 1 | import React from 'react'; |
2 | | -import { useHistory } from 'react-router-dom'; |
3 | | -import { routes } from 'core/router'; |
| 2 | +import { |
| 3 | + TableContainer, |
| 4 | + RowRendererProps, |
| 5 | + useSearchBar, |
| 6 | +} from 'common/components'; |
| 7 | +import { Project } from './project-list.vm'; |
| 8 | +import { ProjectRowComponent } from './components'; |
4 | 9 |
|
5 | | -export const ProjectListComponent: React.FunctionComponent = () => { |
6 | | - const history = useHistory(); |
7 | | - const goToProject = ( |
8 | | - event: React.MouseEvent<HTMLParagraphElement, MouseEvent> |
9 | | - ) => { |
10 | | - event.preventDefault(); |
11 | | - history.push({ |
12 | | - pathname: routes.editProject('1'), |
13 | | - }); |
| 10 | +interface Props { |
| 11 | + projectList: Project[]; |
| 12 | + onCreate: () => void; |
| 13 | + onEdit: (id: string) => void; |
| 14 | + onDelete: (id: string) => void; |
| 15 | +} |
| 16 | + |
| 17 | +export const ProjectListComponent: React.FunctionComponent<Props> = ({ |
| 18 | + projectList, |
| 19 | + onCreate, |
| 20 | + onEdit, |
| 21 | + onDelete, |
| 22 | +}) => { |
| 23 | + const { filteredList, onSearch, search } = useSearchBar(projectList, [ |
| 24 | + 'projectName', |
| 25 | + ]); |
| 26 | + |
| 27 | + const contentRender = ({ itemName }) => { |
| 28 | + return ( |
| 29 | + <> |
| 30 | + ¿Seguro que quiere borrar a <strong>{itemName}</strong>? |
| 31 | + </> |
| 32 | + ); |
14 | 33 | }; |
| 34 | + |
15 | 35 | return ( |
16 | | - <> |
17 | | - <h1>Hello Project list component</h1> |
18 | | - <p onClick={goToProject}>Go to edit project component</p> |
19 | | - </> |
| 36 | + <TableContainer |
| 37 | + columns={[ |
| 38 | + 'Activo', |
| 39 | + 'Código', |
| 40 | + 'Proyecto', |
| 41 | + 'Fecha Ultimo incurrido', |
| 42 | + 'Fecha creación', |
| 43 | + ]} |
| 44 | + rows={filteredList} |
| 45 | + rowRenderer={(rowProps: RowRendererProps<Project>) => ( |
| 46 | + <ProjectRowComponent {...rowProps} /> |
| 47 | + )} |
| 48 | + onCreate={onCreate} |
| 49 | + onEdit={onEdit} |
| 50 | + onDelete={onDelete} |
| 51 | + labels={{ |
| 52 | + searchPlaceholder: 'Buscar proyecto', |
| 53 | + createButton: 'Nuevo proyecto', |
| 54 | + deleteTitle: 'Eliminar Proyecto', |
| 55 | + deleteContent: props => contentRender(props), |
| 56 | + closeButton: 'Cancelar', |
| 57 | + acceptButton: 'Aceptar', |
| 58 | + }} |
| 59 | + enableSearch={true} |
| 60 | + search={search} |
| 61 | + onSearch={onSearch} |
| 62 | + enablePagination={true} |
| 63 | + pageSize={5} |
| 64 | + /> |
20 | 65 | ); |
21 | 66 | }; |
0 commit comments