Skip to content

Commit 0422fd3

Browse files
committed
wip: donation tags
1 parent c3d3158 commit 0422fd3

File tree

5 files changed

+29
-76
lines changed

5 files changed

+29
-76
lines changed

src/components/Header/Header.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
23
import { IHeader } from './types';
34
import { cn } from '@/lib/utils';
45

@@ -25,13 +26,6 @@ const Header = React.forwardRef<HTMLDivElement, IHeader>((props, ref) => {
2526
<h3 className="font-medium text-white">{title}</h3>
2627
</div>
2728
<div className="flex items-center">
28-
<a
29-
href="https://forms.gle/2S7L2gR529Dc8P3T9"
30-
className="bg-white hover:bg-rose-50 text-red-600 font-medium text-xs md:text-base py-2 px-1 md:py-2 md:px-4 rounded-full"
31-
target="_blank"
32-
>
33-
Cadastrar abrigo
34-
</a>
3529
<div className="cursor-pointer ">{endAdornment}</div>
3630
</div>
3731
</div>

src/components/ShelterListItem/ShelterListItem.tsx

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ import { useNavigate } from 'react-router-dom';
44
import { ChevronRight } from 'lucide-react';
55

66
import { IShelterListItemProps, IShelterAvailabilityProps } from './types';
7-
import {
8-
cn,
9-
getAvailabilityProps,
10-
getCategoriesToFilterVolunteers,
11-
getSupplyPriorityProps,
12-
} from '@/lib/utils';
7+
import { cn, getAvailabilityProps, getSupplyPriorityProps } from '@/lib/utils';
138
import { Separator } from '../ui/separator';
149
import { Chip } from '../Chip';
1510
import { Button } from '../ui/button';
1611
import { VerifiedBadge } from '@/components/VerifiedBadge/VerifiedBadge.tsx';
17-
import { SupplyPriority } from '@/service/supply/types';
1812

1913
const ShelterListItem = (props: IShelterListItemProps) => {
2014
const { data, onClick } = props;
@@ -28,37 +22,10 @@ const ShelterListItem = (props: IShelterListItemProps) => {
2822

2923
const tags = useMemo(() => {
3024
return data.shelterSupplies
31-
?.filter(
32-
(s) =>
33-
!getCategoriesToFilterVolunteers().some((c) =>
34-
c.includes(s.supply?.supplyCategory?.name.toLowerCase())
35-
) && !(s.priority === SupplyPriority.Remaining)
36-
)
3725
.sort((a, b) => b.priority - a.priority)
3826
.slice(0, 10);
3927
}, [data.shelterSupplies]);
4028

41-
const volunteerTags = useMemo(() => {
42-
return data.shelterSupplies
43-
?.filter((s) =>
44-
getCategoriesToFilterVolunteers().some((c) =>
45-
c.includes(s.supply?.supplyCategory?.name.toLowerCase())
46-
)
47-
)
48-
.reverse();
49-
}, [data.shelterSupplies]);
50-
51-
const donationsTags = useMemo(() => {
52-
return data.shelterSupplies
53-
?.filter(
54-
(s) =>
55-
!getCategoriesToFilterVolunteers().some((c) =>
56-
c.includes(s.supply?.supplyCategory?.name.toLowerCase())
57-
) && s.priority === SupplyPriority.Remaining
58-
)
59-
.reverse();
60-
}, [data.shelterSupplies]);
61-
6229
return (
6330
<div
6431
className="flex flex-col p-4 w-full border-2 border-border rounded-md gap-1 relative"
@@ -90,14 +57,14 @@ const ShelterListItem = (props: IShelterListItemProps) => {
9057
Necessita voluntários:
9158
</p>
9259
<div className="flex gap-2 flex-wrap">
93-
{volunteerTags.length == 0 ? (
60+
{tags.length == 0 ? (
9461
<p>
9562
{' '}
9663
Não informado.{' '}
9764
<i> (Pode ser adicionado ao clicar no abrigo) </i>
9865
</p>
9966
) : (
100-
volunteerTags.map((s, idx) => (
67+
tags.map((s, idx) => (
10168
<Chip
10269
className={getSupplyPriorityProps(s.priority).className}
10370
key={idx}
@@ -128,7 +95,7 @@ const ShelterListItem = (props: IShelterListItemProps) => {
12895
Sobrando, para doações:
12996
</p>
13097
<div className="flex gap-2 flex-wrap">
131-
{donationsTags.map((s, idx) => (
98+
{tags.map((s, idx) => (
13299
<Chip
133100
className={getSupplyPriorityProps(s.priority).className}
134101
key={idx}

src/hooks/useShelters/useShelters.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const useShelters = (options: IUseShelterOptions = {}) => {
2929
params: {
3030
orderBy: 'prioritySum',
3131
order: 'desc',
32-
search: search ?? new URLSearchParams(window.location.search),
32+
search:
33+
search ?? new URLSearchParams(window.location.search).toString(),
3334
...rest,
3435
},
3536
})

src/pages/Home/Home.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useContext, useMemo, useState } from 'react';
22
import { useNavigate, useSearchParams } from 'react-router-dom';
3-
import { RotateCw, LogOutIcon } from 'lucide-react';
3+
import { RotateCw, LogOutIcon, PlusIcon } from 'lucide-react';
44
import qs from 'qs';
55

66
import { Footer, Header } from '@/components';
@@ -53,7 +53,8 @@ const Home = () => {
5353
setSearch('');
5454
setFilterData(initialFilterData);
5555
setSearchParams('');
56-
}, [setSearch, setSearchParams]);
56+
refresh();
57+
}, [refresh, setSearch, setSearchParams]);
5758

5859
const hasMore = useMemo(
5960
() => shelters.page * shelters.perPage < shelters.count,
@@ -112,6 +113,17 @@ const Home = () => {
112113
Bem vindo, {session.name}
113114
</h3>
114115
)}
116+
<Button
117+
variant="ghost"
118+
size="sm"
119+
className="text-white gap-1 flex flex-gap items-center [&_svg]:hover:stroke-black"
120+
onClick={() =>
121+
window.open('https://forms.gle/2S7L2gR529Dc8P3T9', '_blank')
122+
}
123+
>
124+
<PlusIcon className="h-5 w-5 stroke-white" />
125+
Cadastrar abrigo
126+
</Button>
115127
<Button
116128
loading={loading}
117129
variant="ghost"

src/pages/Shelter/Shelter.tsx

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@ import { useMemo } from 'react';
22
import { ChevronLeft, Pencil } from 'lucide-react';
33
import { useNavigate, useParams } from 'react-router-dom';
44

5-
import { CardAboutShelter, Chip, Header, LoadingScreen } from '@/components';
5+
import { CardAboutShelter, Header, LoadingScreen } from '@/components';
66
import { useShelter } from '@/hooks';
77
import { IShelterAvailabilityProps } from '@/components/ShelterListItem/types';
8-
import { cn, getAvailabilityProps, getCategoriesToFilterVolunteers, getSupplyPriorityProps, group } from '@/lib/utils';
8+
import { cn, getAvailabilityProps, group } from '@/lib/utils';
99
import { Button } from '@/components/ui/button';
1010
import { ShelterCategoryItems } from './components';
1111
import { IShelterCategoryItemsProps } from './components/ShelterCategoryItems/types';
1212
import { SupplyPriority } from '@/service/supply/types';
1313
import { VerifiedBadge } from '@/components/VerifiedBadge/VerifiedBadge.tsx';
14-
import { IUseShelterDataSupply } from '@/hooks/useShelter/types';
1514

1615
const Shelter = () => {
1716
const params = useParams();
1817
const { id = '-1' } = params;
1918
const navigate = useNavigate();
2019
const { data: shelter, loading } = useShelter(id ?? '-1');
21-
const { data: shelters } = useShelter(id);
2220

2321
const shelterCategories: IShelterCategoryItemsProps[] = useMemo(() => {
24-
const grouped = group(shelter?.shelterSupplies?.filter((s) => !getCategoriesToFilterVolunteers().some(c => c.includes(s.supply?.supplyCategory?.name?.toLowerCase()))) ?? [], 'priority');
22+
const grouped = group(shelter?.shelterSupplies ?? [], 'priority');
2523
delete grouped[SupplyPriority.NotNeeded];
2624

2725
return Object.entries(grouped)
@@ -30,11 +28,7 @@ const Shelter = () => {
3028
priority: +key,
3129
tags: values.map((v) => v.supply.name),
3230
}));
33-
}, [shelters.shelterSupplies]);
34-
35-
const volunteerTags: IUseShelterDataSupply[] = useMemo(() => {
36-
return shelter?.shelterSupplies?.filter((s) => getCategoriesToFilterVolunteers().some(c => c.includes(s.supply?.supplyCategory?.name?.toLowerCase())) && s.priority > SupplyPriority.Remaining).reverse()
37-
}, [shelter.shelterSupplies])
31+
}, [shelter?.shelterSupplies]);
3832

3933
const { availability, className: availabilityClassName } =
4034
useMemo<IShelterAvailabilityProps>(
@@ -97,26 +91,11 @@ const Shelter = () => {
9791
</div>
9892
</div>
9993
<div className="flex flex-col gap-8 p-4 ">
100-
101-
<div className="flex flex-col gap-3">
102-
<div className="flex gap-2 items-center">
103-
<h3>
104-
Voluntários
105-
</h3>
106-
</div>
107-
<div className="flex gap-2 flex-wrap">
108-
{ volunteerTags.length == 0 ? <p>Não informado. <i> (Pode ser adicionado ao clicar em Editar itens) </i></p> : volunteerTags.map((v, idx) => (
109-
<Chip
110-
className={getSupplyPriorityProps(v.priority).className}
111-
key={idx}
112-
label={v.supply.name}
113-
/>
114-
))}
115-
</div>
94+
<div className="flex flex-col gap-3">
95+
{shelterCategories.map((categoryProps, idx) => (
96+
<ShelterCategoryItems key={idx} {...categoryProps} />
97+
))}
11698
</div>
117-
{shelterCategories.map((categoryProps, idx) => (
118-
<ShelterCategoryItems key={idx} {...categoryProps} />
119-
))}
12099
</div>
121100
</div>
122101
</div>

0 commit comments

Comments
 (0)