Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home page #11

Merged
merged 6 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import React from 'react';
import { Route, Routes } from 'react-router-dom';
import Home from './pages/home/Home';
import { ClientProvider } from './context/ClientContext';
import EditClient from './pages/editClient/EditClient';
import WebRoutes from './constants/WebRoutes';
import CreateClient from './pages/createClient/CreateClient';
import PageHeader from './components/pageHeader/PageHeader';

function App() {
return (
<>
<PageHeader />
<ClientProvider>
<Routes>
<Route path="/" element={<Home />} />
<Route path={WebRoutes.HOME} element={<Home />} />
<Route path={WebRoutes.CLIENT_EDIT} element={<EditClient />} />
<Route path={WebRoutes.CREATE_CLIENT} element={<CreateClient />} />
</Routes>
</ClientProvider>
</>
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/components/clientCard/ClientCard.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import React from 'react';
import { GoPencil } from 'react-icons/go';
import { useNavigate } from 'react-router-dom';
import IClientsStatus from '../../interfaces/IClientsStatus';
import ClientStatusCard from '../clientStatus/ClientStatus';
import formatCpf from '../../utils/formatCpf';
import formatPhoneNumber from '../../utils/formatPhoneNumber';
import './style.css';
import truncatedText from '../../utils/truncatedText';
import WebRoutes from '../../constants/WebRoutes';

interface ClientCardProps {
client: IClientsStatus;
}

function ClientCard({ client }: ClientCardProps) {
const truncatedText = (text: string, maxLength: number) => {
return text.length > maxLength ? text.substring(0, maxLength) + '...' : text;
const navigate = useNavigate();

const editRedirect = () => {
navigate(`${WebRoutes.CLIENT_EDIT_QUERRY_CLIENT_ID}${client.id}`);
};

return (
Expand All @@ -28,10 +33,12 @@ function ClientCard({ client }: ClientCardProps) {
</span>
<ClientStatusCard status={client.status.name} />
</div>
<button className="client-card-edit-btn-pencil">
<button className="client-card-edit-btn-pencil" onClick={editRedirect} type="button">
<GoPencil className="client-card-edit-btn-icon-pencil" />
</button>
<button className="client-card-edit-btn">Editar</button>
<button className="client-card-edit-btn" type="button" onClick={editRedirect}>
Editar
</button>
</div>
);
}
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/constants/WebRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enum WebRoutes {
HOME = '/',
CLIENT_EDIT = '/client/edit',
CLIENT_EDIT_QUERRY_CLIENT_ID = '/client/edit?clientId=',
CREATE_CLIENT = '/client/create',
}

export default WebRoutes;
7 changes: 7 additions & 0 deletions frontend/src/pages/createClient/CreateClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

function CreateClient() {
return <div>CreateClient</div>;
}

export default CreateClient;
12 changes: 12 additions & 0 deletions frontend/src/pages/editClient/EditClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { useLocation } from 'react-router-dom';

function EditClient() {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const clientId = queryParams.get('clientId');

return <div>hello, {clientId}</div>;
}

export default EditClient;
18 changes: 14 additions & 4 deletions frontend/src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
import React, { useContext, useEffect } from 'react';
import PageHeader from '../../components/pageHeader/PageHeader';
import { useNavigate } from 'react-router-dom';
import ClientListingHeader from '../../components/clientListingHeader/ClientListingHeader';
import './style.css';
import { ClientContext } from '../../context/ClientContext';
import ClientList from '../../components/clientList/ClientList';
import WebRoutes from '../../constants/WebRoutes';

function Home() {
const { fetchClientStatus, clientsStatus } = useContext(ClientContext);
const navigate = useNavigate();

useEffect(() => {
(async () => {
await fetchClientStatus();
})();
}, []);

const createRedirect = () => {
navigate(WebRoutes.CREATE_CLIENT);
};

return (
<main>
<PageHeader />
<section className="home-page-container">
<div className="home-page-listing-container">
<ClientListingHeader className="home-page-listing-header" />
<div className="home-page-listing-view">
<header className="home-page-listing-view-header">
<h3>Listagem de usuários</h3>
<p>Escolha um cliente para vizualizar os detalhes</p>
<div>
<h3>Listagem de usuários</h3>
<p>Escolha um cliente para vizualizar os detalhes</p>
</div>
<button type="button" onClick={createRedirect} className="home-page-listing-view-header-new-client-btn">
Novo cliente
</button>
</header>
<ClientList clients={clientsStatus} />
</div>
Expand Down
26 changes: 24 additions & 2 deletions frontend/src/pages/home/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,38 @@
}

.home-page-listing-view-header {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}

.home-page-listing-view-header h3 {
.home-page-listing-view-header div h3 {
font-weight: 400;
color: #6B747D;
margin-bottom: 8px;
}

.home-page-listing-view-header p {
.home-page-listing-view-header div p {
font-weight: 300;
color: #ACACAC;
}

.home-page-listing-view-header-new-client-btn {
height: 40px;
padding: 10px;
border-radius: 3px;
background-color: #E29934;
color: #fff;
border: none;
cursor: pointer;
}

@media (max-width: 530px) {
.home-page-listing-view-header {
flex-direction: column;
}

.home-page-listing-view-header-new-client-btn {
margin-top: 10px;
}
}
5 changes: 5 additions & 0 deletions frontend/src/utils/truncatedText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const truncatedText = (text: string, maxLength: number) => {
return text.length > maxLength ? text.substring(0, maxLength) + '...' : text;
};

export default truncatedText;