Skip to content

Commit 874c256

Browse files
committed
feat: added dedicated volunteers section to home and shelter pages
1 parent fc6c587 commit 874c256

File tree

4 files changed

+78
-23
lines changed

4 files changed

+78
-23
lines changed

src/components/ShelterListItem/ShelterListItem.tsx

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

66
import { IShelterListItemProps, IShelterAvailabilityProps } from './types';
7-
import { cn, getAvailabilityProps, getSupplyPriorityProps } from '@/lib/utils';
7+
import { cn, getAvailabilityProps, getCategoriesToFilterVolunteers, getSupplyPriorityProps } from '@/lib/utils';
88
import { Separator } from '../ui/separator';
99
import { Chip } from '../Chip';
1010
import { Button } from '../ui/button';
@@ -22,13 +22,20 @@ const ShelterListItem = (props: IShelterListItemProps) => {
2222
);
2323

2424
const tags = useMemo(
25-
() =>
26-
data.shelterSupplies
27-
.filter((s) => s.priority >= SupplyPriority.Needing)
28-
.sort((a, b) => b.priority - a.priority),
25+
() => {
26+
return data.shelterSupplies?.filter((s) => !getCategoriesToFilterVolunteers().some(c => c.includes(s.supply?.supplyCategory?.name.toLowerCase())))
27+
.sort((a, b) => b.priority - a.priority).slice(0, 10)
28+
},
2929
[data.shelterSupplies]
3030
);
3131

32+
const volunteerTags = useMemo(
33+
() => {
34+
return data.shelterSupplies?.filter((s) => getCategoriesToFilterVolunteers().some(c => c.includes(s.supply?.supplyCategory?.name.toLowerCase()))).reverse()
35+
},
36+
[data.shelterSupplies]
37+
)
38+
3239
return (
3340
<div className="flex flex-col p-4 w-full border-2 border-border rounded-md gap-1 relative">
3441
<Button
@@ -57,21 +64,41 @@ const ShelterListItem = (props: IShelterListItemProps) => {
5764
{data.address}
5865
</h6>
5966
{data.shelterSupplies.length > 0 && (
60-
<div className="flex flex-col gap-3">
61-
<Separator className="mt-2" />
62-
<p className="text-muted-foreground text-sm md:text-lg font-medium">
63-
Precisa urgente de doações de:
64-
</p>
65-
<div className="flex gap-2 flex-wrap">
66-
{tags.map((s, idx) => (
67-
<Chip
68-
className={getSupplyPriorityProps(s.priority).className}
69-
key={idx}
70-
label={s.supply.name}
71-
/>
72-
))}
67+
<>
68+
<div className="flex flex-col gap-3">
69+
<Separator className="mt-2" />
70+
<p className="text-muted-foreground text-sm md:text-lg font-medium">
71+
Status voluntários:
72+
</p>
73+
<div className="flex gap-2 flex-wrap">
74+
{volunteerTags.length == 0 ?
75+
<p> Não informado. <i> (Pode ser adicionado ao clickar no abrigo) </i></p>
76+
:
77+
volunteerTags.map((s, idx) => (
78+
<Chip
79+
className={getSupplyPriorityProps(s.priority).className}
80+
key={idx}
81+
label={s.supply.name}
82+
/>
83+
))}
84+
</div>
85+
</div>
86+
<div className="flex flex-col gap-3">
87+
<Separator className="mt-2" />
88+
<p className="text-muted-foreground text-sm md:text-lg font-medium">
89+
Necessita urgente de doações de:
90+
</p>
91+
<div className="flex gap-2 flex-wrap">
92+
{tags.map((s, idx) => (
93+
<Chip
94+
className={getSupplyPriorityProps(s.priority).className}
95+
key={idx}
96+
label={s.supply.name}
97+
/>
98+
))}
99+
</div>
73100
</div>
74-
</div>
101+
</>
75102
)}
76103
{data.updatedAt && (
77104
<small className="text-sm md:text-md font-light text-muted-foreground mt-2">

src/hooks/useShelters/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export interface IUseSheltersData {
1717
}
1818

1919
export interface IUseSheltersDataSupplyData {
20-
supply: { name: string };
20+
supply: { name: string, supplyCategory: { name: string}};
2121
priority: number;
2222
}

src/lib/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ function group<T extends Record<string, any>>(
106106
return data;
107107
}
108108

109+
function getCategoriesToFilterVolunteers(): string[] {
110+
return ['voluntariado', 'especialistas e profissionais']
111+
}
112+
109113
export {
110114
cn,
111115
getAvailabilityProps,
@@ -114,4 +118,5 @@ export {
114118
variantStatusPriority,
115119
colorStatusPriority,
116120
nameStatusPriority,
121+
getCategoriesToFilterVolunteers,
117122
};

src/pages/Shelter/Shelter.tsx

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

5-
import { CardAboutShelter, Header, LoadingScreen } from '@/components';
5+
import { CardAboutShelter, Chip, Header, LoadingScreen } from '@/components';
66
import { useShelter } from '@/hooks';
77
import { IShelterAvailabilityProps } from '@/components/ShelterListItem/types';
8-
import { cn, getAvailabilityProps, group } from '@/lib/utils';
8+
import { cn, getAvailabilityProps, getCategoriesToFilterVolunteers, getSupplyPriorityProps, 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';
1415

1516
const Shelter = () => {
1617
const params = useParams();
@@ -20,8 +21,9 @@ const Shelter = () => {
2021
const { data: shelters } = useShelter(id);
2122

2223
const shelterCategories: IShelterCategoryItemsProps[] = useMemo(() => {
23-
const grouped = group(shelters?.shelterSupplies ?? [], 'priority');
24+
const grouped = group(shelter?.shelterSupplies?.filter((s) => !getCategoriesToFilterVolunteers().some(c => c.includes(s.supply?.supplyCategory?.name?.toLowerCase()))) ?? [], 'priority');
2425
delete grouped[SupplyPriority.NotNeeded];
26+
2527
return Object.entries(grouped)
2628
.sort(([a], [b]) => (+a > +b ? -1 : 1))
2729
.map(([key, values]) => ({
@@ -30,6 +32,10 @@ const Shelter = () => {
3032
}));
3133
}, [shelters.shelterSupplies]);
3234

35+
const volunteerTags: IUseShelterDataSupply[] = useMemo(() => {
36+
return shelter?.shelterSupplies?.filter((s) => getCategoriesToFilterVolunteers().some(c => c.includes(s.supply?.supplyCategory?.name?.toLowerCase()))).reverse()
37+
}, [shelter.shelterSupplies])
38+
3339
const { availability, className: availabilityClassName } =
3440
useMemo<IShelterAvailabilityProps>(
3541
() => getAvailabilityProps(shelter?.capacity, shelter?.shelteredPeople),
@@ -93,6 +99,23 @@ const Shelter = () => {
9399
</div>
94100
</div>
95101
<div className="flex flex-col gap-8 p-4 ">
102+
103+
<div className="flex flex-col gap-3">
104+
<div className="flex gap-2 items-center">
105+
<h3>
106+
Voluntários
107+
</h3>
108+
</div>
109+
<div className="flex gap-2 flex-wrap">
110+
{volunteerTags.map((v, idx) => (
111+
<Chip
112+
className={getSupplyPriorityProps(v.priority).className}
113+
key={idx}
114+
label={v.supply.name}
115+
/>
116+
))}
117+
</div>
118+
</div>
96119
{shelterCategories.map((categoryProps, idx) => (
97120
<ShelterCategoryItems key={idx} {...categoryProps} />
98121
))}

0 commit comments

Comments
 (0)