Skip to content

Commit 7626522

Browse files
author
Antonio Contreras LEMONCODE
committed
Fix employee list component, project list component, project list container and project row component
1 parent 4e32bf6 commit 7626522

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/pods/employee-list/employee-list.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const EmployeeListComponent: React.FunctionComponent<Props> = ({
2424
'name',
2525
]);
2626

27-
const renderContent = ({ itemName }) => {
27+
const contentRender = ({ itemName }) => {
2828
return (
2929
<>
3030
¿Seguro que quiere borrar a <strong>{itemName}</strong>?
@@ -46,7 +46,7 @@ export const EmployeeListComponent: React.FunctionComponent<Props> = ({
4646
searchPlaceholder: 'Buscar empleado',
4747
createButton: 'Nuevo empleado',
4848
deleteTitle: 'Eliminar Empleado',
49-
deleteContent: props => renderContent(props),
49+
deleteContent: props => contentRender(props),
5050
closeButton: 'Cancelar',
5151
acceptButton: 'Aceptar',
5252
}}

src/pods/project-list/components/project-row.component.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import IconButton from '@material-ui/core/IconButton';
99
import EditIcon from '@material-ui/icons/Edit';
1010
import DeleteIcon from '@material-ui/icons/Delete';
1111
import { Project } from '../project-list.vm';
12+
import { Lookup } from 'common/models';
1213

1314
type Props = RowRendererProps<Project>;
1415

@@ -17,6 +18,10 @@ export const ProjectRowComponent: React.FunctionComponent<Props> = ({
1718
onEdit,
1819
onDelete,
1920
}) => {
21+
const projectToDeleted: Lookup = {
22+
id: row.id,
23+
name: row.projectName,
24+
};
2025
return (
2126
<RowComponent>
2227
<CellComponent>
@@ -30,7 +35,7 @@ export const ProjectRowComponent: React.FunctionComponent<Props> = ({
3035
<IconButton onClick={() => onEdit(row.id)}>
3136
<EditIcon />
3237
</IconButton>
33-
<IconButton onClick={() => onDelete(row)}>
38+
<IconButton onClick={() => onDelete(projectToDeleted)}>
3439
<DeleteIcon />
3540
</IconButton>
3641
</CellComponent>

src/pods/project-list/project-list.component.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,27 @@ interface Props {
1111
projectList: Project[];
1212
onCreate: () => void;
1313
onEdit: (id: string) => void;
14+
onDelete: (id: string) => void;
1415
}
1516

1617
export const ProjectListComponent: React.FunctionComponent<Props> = ({
1718
projectList,
1819
onCreate,
1920
onEdit,
21+
onDelete,
2022
}) => {
2123
const { filteredList, onSearch, search } = useSearchBar(projectList, [
2224
'projectName',
2325
]);
26+
27+
const contentRender = ({ itemName }) => {
28+
return (
29+
<>
30+
¿Seguro que quiere borrar a <strong>{itemName}</strong>?
31+
</>
32+
);
33+
};
34+
2435
return (
2536
<TableContainer
2637
columns={[
@@ -36,9 +47,14 @@ export const ProjectListComponent: React.FunctionComponent<Props> = ({
3647
)}
3748
onCreate={onCreate}
3849
onEdit={onEdit}
50+
onDelete={onDelete}
3951
labels={{
4052
searchPlaceholder: 'Buscar proyecto',
4153
createButton: 'Nuevo proyecto',
54+
deleteTitle: 'Eliminar Proyecto',
55+
deleteContent: props => contentRender(props),
56+
closeButton: 'Cancelar',
57+
acceptButton: 'Aceptar',
4258
}}
4359
enableSearch={true}
4460
search={search}

src/pods/project-list/project-list.container.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ export const ProjectListContainer: React.FunctionComponent = () => {
3333
history.push(routes.editProject(id));
3434
};
3535

36+
const handleDelete = async (id: string) => {
37+
const errorMessage = 'Error al eliminar un proyecto';
38+
try {
39+
const isDeleted = await trackPromise(deleteProject(id));
40+
isDeleted ? onLoadProjectList() : showMessage(errorMessage, 'error');
41+
} catch (error) {
42+
error && showMessage(errorMessage, 'error');
43+
}
44+
};
45+
3646
React.useEffect(() => {
3747
onLoadProjectList();
3848
}, []);
@@ -42,6 +52,7 @@ export const ProjectListContainer: React.FunctionComponent = () => {
4252
projectList={projectes}
4353
onCreate={handleCreate}
4454
onEdit={handleEdit}
55+
onDelete={handleDelete}
4556
/>
4657
);
4758
};

0 commit comments

Comments
 (0)