Skip to content

Commit

Permalink
Merge pull request #177 from Frnn4268/Frnn
Browse files Browse the repository at this point in the history
Adding new Users.jsx components
  • Loading branch information
Frnn4268 authored Nov 12, 2024
2 parents 23e4152 + 2a44d3a commit c9dba35
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 230 deletions.
52 changes: 52 additions & 0 deletions frontend/components/user/UsersDrawer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { Drawer, Form, Input, Radio, Button } from 'antd';

const UsersDrawer = ({ drawerVisible, setDrawerVisible, form, onFinish, selectedRole, setSelectedRole }) => (
<Drawer
title="Editar usuario"
width={500}
onClose={() => setDrawerVisible(false)}
visible={drawerVisible}
>
<Form form={form} onFinish={onFinish}>
<Form.Item
label="Nombre"
name="name"
rules={[
{
required: true,
message: '¡Por favor ingrese el nombre del usuario!',
},
]}
>
<Input />
</Form.Item>
<Form.Item
label="Email"
name="email"
rules={[
{
required: true,
message: '¡Por favor ingrese el email del usuario!',
},
]}
>
<Input />
</Form.Item>
<Form.Item
label="Rol"
name="role"
>
<Radio.Group onChange={(e) => setSelectedRole(e.target.value)}>
<Radio.Button value="Empleado">Empleado</Radio.Button>
<Radio.Button value="Administrador">Administrador</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" style={{ textAlign: 'center' }}>Guardar cambios</Button>
</Form.Item>
</Form>
</Drawer>
);

export default UsersDrawer;
13 changes: 13 additions & 0 deletions frontend/components/user/UsersHeader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { Layout } from 'antd';
import TopMenu from '../../src/pages/dashboard/TopMenu.jsx';

const { Header } = Layout;

const UsersHeader = () => (
<Header className='home-header-dashboard'>
<TopMenu />
</Header>
);

export default UsersHeader;
16 changes: 16 additions & 0 deletions frontend/components/user/UsersLayout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { Layout } from 'antd';
import LeftMenu from '../../src/pages/dashboard/LeftMenu.jsx';

const UsersLayout = ({ children }) => (
<Layout>
<Layout.Sider>
<LeftMenu />
</Layout.Sider>
<Layout.Content className='layout-content-user'>
{children}
</Layout.Content>
</Layout>
);

export default UsersLayout;
74 changes: 74 additions & 0 deletions frontend/components/user/UsersTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import { Table, Tag, Button, Space, Switch } from 'antd';
import { DeleteOutlined, SyncOutlined } from '@ant-design/icons';

const UsersTable = ({ users, handleUpdate, handleDelete, handleSwitchChange, getRandomColor }) => {
const columns = [
{
title: 'ID',
dataIndex: 'id',
key: 'id',
},
{
title: 'Nombre',
dataIndex: 'name',
key: 'name',
},
{
title: 'Email',
dataIndex: 'email',
key: 'email',
render: (email) => (
<Tag color={getRandomColor()}>{email}</Tag>
),
},
{
title: 'Rol',
dataIndex: 'role',
key: 'role',
render: (role) => (
<Tag color={role === 'Administrador' ? 'green' : 'blue'}>{role}</Tag>
),
},
{
title: 'Estado',
dataIndex: 'active',
key: 'active',
render: (active, record) => (
<Switch
checked={active}
checkedChildren="Activo"
unCheckedChildren="Inactivo"
onChange={(checked) => handleSwitchChange(record.id, checked)}
style={{ backgroundColor: active ? 'green' : 'red', transition: 'background-color 0.3s' }}
/>
),
},
{
title: 'Acción',
key: 'action',
render: (_, record) => (
<Space size="middle">
<Button type="primary" icon={<SyncOutlined />} onClick={() => handleUpdate(record)}>Editar</Button>
<Button danger icon={<DeleteOutlined />} onClick={() => handleDelete(record.id)}>Eliminar</Button>
</Space>
),
},
];

return (
<Table
dataSource={users}
columns={columns}
rowKey="id"
pagination={{
pageSize: 10,
showSizeChanger: false,
pageSizeOptions: ['5', '10', '20'],
showTotal: (total, range) => `${range[0]}-${range[1]} de ${total} filas`,
}}
/>
);
};

export default UsersTable;
Loading

0 comments on commit c9dba35

Please sign in to comment.