mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 13:38:51 +00:00
Merge pull request #9 from Nez27/feat/add-content-user-page
Add content for user page
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import styled from 'styled-components';
|
||||
|
||||
const Button = styled.button`
|
||||
padding: 10px 20px;
|
||||
|
||||
background-color: var(--primary-color);
|
||||
color: var(--light-text);
|
||||
text-transform: uppercase;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
|
||||
border-radius: var(--radius-md);
|
||||
`;
|
||||
|
||||
export default Button;
|
||||
@@ -0,0 +1,29 @@
|
||||
import styled, { css } from 'styled-components';
|
||||
|
||||
interface IDirection {
|
||||
type?: 'vertical' | 'horizontal';
|
||||
}
|
||||
|
||||
const Direction = styled.div<IDirection>`
|
||||
display: flex;
|
||||
|
||||
${(props) =>
|
||||
props.type === 'horizontal' &&
|
||||
css`
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
`}
|
||||
|
||||
${(props) =>
|
||||
props.type === 'vertical' &&
|
||||
css`
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
`}
|
||||
`;
|
||||
|
||||
Direction.defaultProps = {
|
||||
type: 'vertical',
|
||||
};
|
||||
|
||||
export default Direction;
|
||||
@@ -3,7 +3,7 @@ import styled from 'styled-components';
|
||||
// Interfaces
|
||||
import { ITable } from '../../globals/interfaces';
|
||||
|
||||
export const StyledTable = styled.div`
|
||||
const StyledTable = styled.div`
|
||||
border: 1px solid var(--border-color);
|
||||
|
||||
font-size: 20px;
|
||||
@@ -17,11 +17,11 @@ const CommonRow = styled.div<ITable>`
|
||||
align-items: center;
|
||||
`;
|
||||
|
||||
export const StyledBody = styled.div`
|
||||
const StyledBody = styled.div`
|
||||
font-size: var(--fs-sm-x);
|
||||
`;
|
||||
|
||||
export const StyledRow = styled(CommonRow)`
|
||||
const StyledRow = styled(CommonRow)`
|
||||
padding: 20px;
|
||||
|
||||
&:not(:last-child) {
|
||||
@@ -29,7 +29,7 @@ export const StyledRow = styled(CommonRow)`
|
||||
}
|
||||
`;
|
||||
|
||||
export const StyledHeader = styled(CommonRow)`
|
||||
const StyledHeader = styled(CommonRow)`
|
||||
padding: 10px 20px;
|
||||
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
@@ -41,3 +41,5 @@ export const StyledHeader = styled(CommonRow)`
|
||||
text-transform: capitalize;
|
||||
font-weight: 600;
|
||||
`;
|
||||
|
||||
export { StyledBody, StyledHeader, StyledRow, StyledTable };
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { TUser } from '../globals/types';
|
||||
|
||||
export const sampleData: TUser[] = [
|
||||
{
|
||||
id: '123',
|
||||
name: 'Nezumi',
|
||||
identifiedCode: '123',
|
||||
phone: '0937425123',
|
||||
roomId: '246',
|
||||
address: 'Da Nang',
|
||||
},
|
||||
{
|
||||
id: '456',
|
||||
name: 'Nezumi',
|
||||
identifiedCode: '123',
|
||||
phone: '123',
|
||||
roomId: '246',
|
||||
address: 'Da Nang',
|
||||
},
|
||||
{
|
||||
id: '231',
|
||||
name: 'Nezumi',
|
||||
identifiedCode: '123',
|
||||
phone: '123',
|
||||
roomId: '246',
|
||||
address: 'Da Nang',
|
||||
},
|
||||
{
|
||||
id: '241',
|
||||
name: 'Nezumi',
|
||||
identifiedCode: '123',
|
||||
phone: '123',
|
||||
roomId: '246',
|
||||
address: 'Da Nang',
|
||||
},
|
||||
{
|
||||
id: '512',
|
||||
name: 'Nezumi',
|
||||
identifiedCode: '123',
|
||||
phone: '123',
|
||||
roomId: '246',
|
||||
address: 'Da Nang',
|
||||
},
|
||||
{
|
||||
id: '524',
|
||||
name: 'Nezumi',
|
||||
identifiedCode: '123',
|
||||
phone: '123',
|
||||
roomId: '246',
|
||||
address: 'Da Nang',
|
||||
},
|
||||
{
|
||||
id: '125',
|
||||
name: 'Nezumi',
|
||||
identifiedCode: '123',
|
||||
phone: '123',
|
||||
roomId: '246',
|
||||
address: 'Da Nang',
|
||||
},
|
||||
{
|
||||
id: '111',
|
||||
name: 'Nezumi',
|
||||
identifiedCode: '123',
|
||||
phone: '123',
|
||||
roomId: '246',
|
||||
address: 'Da Nang',
|
||||
},
|
||||
];
|
||||
@@ -1,15 +0,0 @@
|
||||
import styled from 'styled-components';
|
||||
|
||||
const StyledUser = styled.main`
|
||||
padding: 20px;
|
||||
`;
|
||||
|
||||
const User = () => {
|
||||
return (
|
||||
<StyledUser>
|
||||
<p>User page</p>
|
||||
</StyledUser>
|
||||
);
|
||||
};
|
||||
|
||||
export default User;
|
||||
@@ -0,0 +1,80 @@
|
||||
// Components
|
||||
import { HiSquare2Stack } from 'react-icons/hi2';
|
||||
import { HiTrash } from 'react-icons/hi';
|
||||
import { StyledOperationTable } from './styled';
|
||||
import Menus from '../../components/Menus/Menus';
|
||||
import Table from '../../components/Table';
|
||||
import Direction from '../../commons/styles/Direction';
|
||||
import Message from '../../components/Message';
|
||||
|
||||
// Types
|
||||
import { TUser } from '../../globals/types';
|
||||
|
||||
// Constants
|
||||
import { sampleData } from '../../constants/sampleData';
|
||||
|
||||
type TUserModal = { user: TUser };
|
||||
|
||||
const UserRow = ({ user }: TUserModal) => {
|
||||
const handleOnClick = (id: string) => {
|
||||
alert(`Id: ${id}`);
|
||||
};
|
||||
|
||||
const { id, name, identifiedCode, phone, roomId } = user;
|
||||
|
||||
return (
|
||||
<Table.Row>
|
||||
<div>{id}</div>
|
||||
<div>{name}</div>
|
||||
<div>{identifiedCode}</div>
|
||||
<div>{phone}</div>
|
||||
<div>{roomId}</div>
|
||||
|
||||
<Menus.Menu>
|
||||
<Menus.Toggle id={id} />
|
||||
|
||||
<Menus.List id={id}>
|
||||
<Menus.Button
|
||||
icon={<HiSquare2Stack />}
|
||||
onClick={() => handleOnClick(id)}
|
||||
>
|
||||
Edit
|
||||
</Menus.Button>
|
||||
<Menus.Button icon={<HiTrash />} onClick={() => handleOnClick(id)}>
|
||||
Delete
|
||||
</Menus.Button>
|
||||
</Menus.List>
|
||||
</Menus.Menu>
|
||||
</Table.Row>
|
||||
);
|
||||
};
|
||||
|
||||
const UserTable = () => {
|
||||
return sampleData.length ? (
|
||||
<Direction>
|
||||
<StyledOperationTable>
|
||||
<p>Sort / Filter / Search table</p>
|
||||
</StyledOperationTable>
|
||||
|
||||
<Menus>
|
||||
<Table columns="10% 30% 20% 20% 10% 5%">
|
||||
<Table.Header>
|
||||
<div>Id</div>
|
||||
<div>Name</div>
|
||||
<div>Identified Code</div>
|
||||
<div>Phone</div>
|
||||
<div>Room</div>
|
||||
</Table.Header>
|
||||
<Table.Body<TUser>
|
||||
data={sampleData}
|
||||
render={(user: TUser) => <UserRow user={user} key={user.id} />}
|
||||
/>
|
||||
</Table>
|
||||
</Menus>
|
||||
</Direction>
|
||||
) : (
|
||||
<Message>No data to show here!</Message>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserTable;
|
||||
@@ -0,0 +1,22 @@
|
||||
// Components
|
||||
import Direction from '../../commons/styles/Direction';
|
||||
import Button from '../../commons/styles/Button';
|
||||
import UserTable from './UserTable';
|
||||
|
||||
// Styled
|
||||
import { StyledUser, Title } from './styled';
|
||||
|
||||
const User = () => {
|
||||
return (
|
||||
<StyledUser>
|
||||
<Direction type="horizontal">
|
||||
<Title>List User</Title>
|
||||
<Button>Add user</Button>
|
||||
</Direction>
|
||||
|
||||
<UserTable />
|
||||
</StyledUser>
|
||||
);
|
||||
};
|
||||
|
||||
export default User;
|
||||
@@ -0,0 +1,22 @@
|
||||
import styled from 'styled-components';
|
||||
|
||||
const StyledUser = styled.main`
|
||||
padding: 20px;
|
||||
padding-bottom: 100px;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 30px;
|
||||
`;
|
||||
|
||||
const Title = styled.h2`
|
||||
font-size: var(--fs-md);
|
||||
color: var(--dark-text);
|
||||
text-transform: capitalize;
|
||||
`;
|
||||
|
||||
const StyledOperationTable = styled.div`
|
||||
text-align: right;
|
||||
`;
|
||||
|
||||
export { StyledUser, Title, StyledOperationTable };
|
||||
Reference in New Issue
Block a user