Skip to content

Commit aab7f9c

Browse files
authored
Merge branch 'SOS-RS:develop' into develop
2 parents 5191a26 + 17502e9 commit aab7f9c

File tree

20 files changed

+335
-101
lines changed

20 files changed

+335
-101
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 SOS-RS
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,15 @@ Este frontend foi desenvolvido utilizando as seguintes tecnologias:
1919
- [**Tailwind CSS**](https://tailwindcss.com/docs/installation): Framework CSS baseado em classes utilitárias.
2020
- [**shadcn/ui**](https://ui.shadcn.com/docs): Coleção de componentes reutilizáveis, baseado em Tailwind.
2121

22-
## Funcionalidades e Backlog
23-
24-
O app inclui as seguintes funcionalidades:
25-
26-
- [x] **Cadastro de Itens de suprimentos**: Permite que voluntários se inscrevam para ajudar.
27-
- [x] **Busca de abrigos**: Gerencia a logística de distribuição de suprimentos para as áreas mais necessitadas.
28-
- [x] **Alteração de necessidades de abrigos**: Exibe um mapa das áreas afetadas e pontos de coleta de suprimentos.
29-
- [ ] **Cadastro de abrigos**: Criar tela para cadastro de abrigos (Nome, endereço, capacidade, vagas, aceita pets) e colocar pendende de aprovação.
30-
- [ ] **Alteração de abrigos**: Pemitir alterar quantidade de vagas disponívies, se aceita pet ou endereço.
31-
- [ ] **Cadastro de usuários**: Criar tela de cadastro (nome, telefone, senha) e login.
32-
- [ ] **Filtro por item e por cidade**: Opção de filtrar abrigos por cidade ou que precisam de algum item específico.
33-
- [ ] **Alterar ordenação**: Trocar a ordenação atual para ordenação por última atualização.
34-
- [ ] **Adicionar mapa de abrigos**: Criar uma tela com um mapa e todos os abrigos. Verificar a posibilidade de usar geolocation para mostrar a posição do usuário no mapa.
35-
36-
3722
Para executar o frontend do aplicativo em seu ambiente local, siga os passos abaixo:
3823

3924
1. Clone o repositório:
4025
```
41-
git clone https://github.com/seuusuario/projeto-enchentes-frontend.git
26+
git clone https://github.com/SOS-RS/frontend
4227
```
4328
2. Entre no diretório do projeto:
4429
```
45-
cd projeto-enchentes-frontend
30+
cd frontend
4631
```
4732
3. Instale as dependências:
4833
```
@@ -52,15 +37,15 @@ Para executar o frontend do aplicativo em seu ambiente local, siga os passos aba
5237
```
5338
npm run dev
5439
```
55-
O app estará disponível em `http://localhost:3000`.
40+
O app estará disponível em `http://localhost:5173`.
5641

5742
## Contribuindo
5843

5944
Contribuições são muito bem-vindas! Se você tem interesse em ajudar a melhorar o app, por favor:
6045

6146
1. Faça um fork do repositório.
6247
2. Crie uma branch para sua feature (`git checkout -b feature/MinhaFeature`).
63-
3. Faça seus commits (`git commit -am 'Adicionando uma nova feature'`).
48+
3. Faça seus commits (`git commit -m 'Adicionando uma nova feature'`).
6449
4. Faça push para a branch (`git push origin feature/MinhaFeature`).
6550
5. Abra um Pull Request.
6651

src/api/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios, { AxiosRequestHeaders, InternalAxiosRequestConfig } from 'axios';
2-
import { getCacheRequestData, handleCacheResponse } from './cache';
2+
import { clearCache, getCacheRequestData, handleCacheResponse } from './cache';
33

44
const api = axios.create({
55
baseURL: import.meta.env.VITE_API_URL ?? 'http://localhost:4000/',
@@ -31,6 +31,7 @@ api.interceptors.response.use(
3131
},
3232
(error) => {
3333
if (error.response && error.response.status === 401) {
34+
clearCache(false);
3435
localStorage.removeItem('token');
3536
}
3637
return Promise.reject(error);

src/api/cache.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ function checkCacheHasExpired(
1616
return new Date().getTime() - timestamp >= ttl;
1717
}
1818

19-
function clearExpiredCache() {
20-
log('cache - checando caches expirados...');
19+
function clearCache(onlyExpired: boolean = true) {
20+
log(
21+
onlyExpired
22+
? 'cache - checando caches expirados...'
23+
: 'cache - limpando cache...'
24+
);
2125
Object.keys(localStorage)
2226
.filter((key: string) => key.startsWith('cache:'))
2327
.forEach((key) => {
2428
const data = localStorage.getItem(key);
2529
if (data) {
2630
const { timestamp } = JSON.parse(data);
27-
if (checkCacheHasExpired(timestamp)) {
31+
if (!onlyExpired || checkCacheHasExpired(timestamp)) {
2832
localStorage.removeItem(key);
2933
}
3034
}
@@ -74,6 +78,6 @@ function handleCacheResponse(resp: AxiosResponse<any, any>) {
7478
}
7579
}
7680

77-
clearExpiredCache();
81+
clearCache();
7882

79-
export { handleCacheResponse, getCacheRequestData };
83+
export { handleCacheResponse, getCacheRequestData, clearCache };

src/components/Authenticated/Authenticated.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { Fragment, useContext } from 'react';
22

33
import { SessionContext } from '@/contexts';
4+
import { IAuthenticatedProps } from './types';
5+
import { AccessLevel } from '@/service/sessions/types';
46

5-
const Authenticated = ({ children }: { children?: React.ReactNode }) => {
7+
const MappedRoles: Record<AccessLevel, AccessLevel[]> = {
8+
Admin: ['Admin'],
9+
DistributionCenter: ['Admin', 'DistributionCenter'],
10+
Staff: ['Admin', 'Staff'],
11+
User: ['Admin', 'Staff', 'DistributionCenter', 'User'],
12+
};
13+
14+
const Authenticated = ({ children, role = 'User' }: IAuthenticatedProps) => {
615
const { session } = useContext(SessionContext);
716

8-
if (!session) return <Fragment />;
17+
if (!session || !MappedRoles[role].includes(session.accessLevel))
18+
return <Fragment />;
919

1020
return <div className="contents">{children}</div>;
1121
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { AccessLevel } from '@/service/sessions/types';
2+
3+
export interface IAuthenticatedProps {
4+
role?: AccessLevel;
5+
children?: React.ReactNode;
6+
}

src/components/CardAboutShelter/CardAboutShelter.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ const CardAboutShelter = (props: ICardAboutShelter) => {
2424
<div className="flex flex-col flex-wrap gap-3">
2525
<InfoRow icon={<Home />} label={shelter.address} />
2626
<InfoRow
27-
className=""
2827
icon={<PawPrint />}
2928
label={
3029
check(shelter.petFriendly) ? (
3130
shelter.petFriendly ? (
3231
<p>
33-
O abrigo <b className="text-green-600">aceita</b> animais
32+
O abrigo <b>aceita</b> animais
3433
</p>
3534
) : (
3635
<p>
37-
O abrigo <b className="text-red-600">não</b> aceita animais
36+
O abrigo <b>não</b> aceita animais
3837
</p>
3938
)
4039
) : (

src/pages/CreateShelter/CreateShelter.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ICreateShelter } from '@/service/shelter/types';
1616
import { toast } from '@/components/ui/use-toast';
1717
import { ShelterServices } from '@/service';
1818
import { withAuth } from '@/hocs';
19+
import { clearCache } from '@/api/cache';
1920

2021
const CreateShelterComponent = () => {
2122
const navigate = useNavigate();
@@ -33,6 +34,7 @@ const CreateShelterComponent = () => {
3334
address: '',
3435
shelteredPeople: 0,
3536
capacity: 0,
37+
verified: false,
3638
petFriendly: false,
3739
contact: null,
3840
pix: null,
@@ -57,6 +59,7 @@ const CreateShelterComponent = () => {
5759
onSubmit: async (values, { resetForm }) => {
5860
try {
5961
await ShelterServices.create(values);
62+
clearCache(false);
6063
toast({
6164
title: 'Cadastro feita com sucesso',
6265
});

src/pages/CreateSupply/CreateSupply.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ICreateSupply, SupplyPriority } from '@/service/supply/types';
1818
import { getSupplyPriorityProps } from '@/lib/utils';
1919
import { ShelterSupplyServices, SupplyServices } from '@/service';
2020
import { ICreateShelterSupply } from '@/service/shelterSupply/types';
21+
import { clearCache } from '@/api/cache';
2122

2223
const CreateSupply = () => {
2324
const navigate = useNavigate();
@@ -60,6 +61,7 @@ const CreateSupply = () => {
6061
priority: +values.priority,
6162
shelterId,
6263
});
64+
clearCache(false);
6365
toast({
6466
title: 'Item cadastrado com sucesso',
6567
});

src/pages/EditShelterSupply/EditShelterSupply.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ShelterSupplyServices } from '@/service';
1313
import { useToast } from '@/components/ui/use-toast';
1414
import { ISupply, SupplyPriority } from '@/service/supply/types';
1515
import { IUseShelterDataSupply } from '@/hooks/useShelter/types';
16+
import { clearCache } from '@/api/cache';
1617

1718
const EditShelterSupply = () => {
1819
const navigate = useNavigate();
@@ -66,6 +67,7 @@ const EditShelterSupply = () => {
6667
const successCallback = () => {
6768
setModalOpened(false);
6869
setModalData(null);
70+
clearCache(false);
6971
refresh();
7072
};
7173

0 commit comments

Comments
 (0)