Skip to content

Commit 3e09b9f

Browse files
committed
Merge branch 'develop' into feat/update-shelter
2 parents f36796c + 506d85a commit 3e09b9f

File tree

21 files changed

+169
-68
lines changed

21 files changed

+169
-68
lines changed

src/components/ShelterListItem/ShelterListItem.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const ShelterListItem = (props: IShelterListItemProps) => {
1414
const { data } = props;
1515
const { capacity, shelteredPeople } = data;
1616
const navigate = useNavigate();
17-
1817
const { availability, className: availabilityClassName } =
1918
useMemo<IShelterAvailabilityProps>(
2019
() => getAvailabilityProps(capacity, shelteredPeople),
@@ -23,10 +22,10 @@ const ShelterListItem = (props: IShelterListItemProps) => {
2322

2423
const tags = useMemo(
2524
() =>
26-
data.supplies
25+
data.shelterSupplies
2726
.filter((s) => s.priority >= SupplyPriority.Needing)
2827
.sort((a, b) => b.priority - a.priority),
29-
[data.supplies]
28+
[data.shelterSupplies]
3029
);
3130

3231
return (
@@ -51,7 +50,7 @@ const ShelterListItem = (props: IShelterListItemProps) => {
5150
<h6 className="text-muted-foreground text-sm md:text-lg font-medium">
5251
{data.address}
5352
</h6>
54-
{data.supplies.length > 0 && (
53+
{data.shelterSupplies.length > 0 && (
5554
<div className="flex flex-col gap-3">
5655
<Separator className="mt-2" />
5756
<p className="text-muted-foreground text-sm md:text-lg font-medium">
@@ -62,7 +61,7 @@ const ShelterListItem = (props: IShelterListItemProps) => {
6261
<Chip
6362
className={getSupplyPriorityProps(s.priority).className}
6463
key={idx}
65-
label={s.name}
64+
label={s.supply.name}
6665
/>
6766
))}
6867
</div>

src/hooks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { usePaginatedQuery } from './usePaginatedQuery';
44
import { useThrottle } from './useThrottle';
55
import { useShelter } from './useShelter';
66
import { useSupplyCategories } from './useSupplyCategories';
7+
import { useSupplies } from './useSupplies';
78

89
export {
910
useShelters,
@@ -12,4 +13,5 @@ export {
1213
useThrottle,
1314
useShelter,
1415
useSupplyCategories,
16+
useSupplies,
1517
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum PaginatedQueryPath {
22
Shelters = '/shelters',
33
SupplyCategories = '/supply-categories',
4+
Supplies = '/supplies',
45
}

src/hooks/useShelter/types.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ export interface IUseShelterData {
88
contact?: string | null;
99
petFriendly?: boolean | null;
1010
prioritySum: number;
11-
supplies: IUseShelterDataSupply[];
11+
latitude?: string | null;
12+
longitude?: string | null;
13+
shelterSupplies: IUseShelterDataSupply[];
1214
createdAt: string;
1315
updatedAt?: string | null;
1416
}
1517

1618
export interface IUseShelterDataSupply {
19+
priority: number;
20+
supply: IUseShelterDataSupplyData;
21+
}
22+
23+
export interface IUseShelterDataSupplyData {
1724
id: string;
1825
name: string;
19-
priority: number;
2026
supplyCategory: IUseShelterDataSupplyCategory;
21-
createdAt: Date;
22-
updatedAt: Date | null;
27+
createdAt: string;
28+
updatedAt?: string | null;
2329
}
2430

2531
export interface IUseShelterDataSupplyCategory {

src/hooks/useShelters/types.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
import { IShelter } from '@/service/shelter/types';
2-
import { ISupply } from '@/service/supply/types';
1+
export interface IUseSheltersData {
2+
id: string;
3+
name: string;
4+
address: string;
5+
pix?: string | null;
6+
shelteredPeople?: number | null;
7+
capacity?: number | null;
8+
contact?: string | null;
9+
petFriendly?: boolean | null;
10+
prioritySum: number;
11+
latitude?: string | null;
12+
longitude?: string | null;
13+
createdAt: string;
14+
updatedAt?: string | null;
15+
shelterSupplies: IUseSheltersDataSupplyData[];
16+
}
317

4-
export type IUseSheltersData = IShelter & { supplies: ISupply[] };
18+
export interface IUseSheltersDataSupplyData {
19+
supply: { name: string };
20+
priority: number;
21+
}

src/hooks/useSupplies/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { useSupplies } from './useSupplies';
2+
3+
export { useSupplies };

src/hooks/useSupplies/types.ts

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ISupply } from '@/service/supply/types';
2+
import { useFetch } from '../useFetch';
3+
import { PaginatedQueryPath } from '../usePaginatedQuery/paths';
4+
5+
const useSupplies = () => {
6+
return useFetch<ISupply[]>(PaginatedQueryPath.Supplies, []);
7+
};
8+
9+
export { useSupplies };

src/pages/CreateSupply/CreateSupply.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
} from '@/components/ui/select';
1717
import { ICreateSupply, SupplyPriority } from '@/service/supply/types';
1818
import { getSupplyPriorityProps } from '@/lib/utils';
19-
import { SupplyServices } from '@/service';
19+
import { ShelterSupplyServices, SupplyServices } from '@/service';
20+
import { ICreateShelterSupply } from '@/service/shelterSupply/types';
2021

2122
const CreateSupply = () => {
2223
const navigate = useNavigate();
@@ -31,12 +32,12 @@ const CreateSupply = () => {
3132
handleSubmit,
3233
setFieldValue,
3334
values,
34-
} = useFormik<ICreateSupply>({
35+
} = useFormik<ICreateSupply & Omit<ICreateShelterSupply, 'supplyId'>>({
3536
initialValues: {
3637
name: '',
37-
priority: SupplyPriority.UnderControl,
3838
supplyCategoryId: supplyCategories?.at(0)?.id ?? '-1',
3939
shelterId,
40+
priority: SupplyPriority.UnderControl,
4041
},
4142
enableReinitialize: true,
4243
validateOnBlur: false,
@@ -50,9 +51,14 @@ const CreateSupply = () => {
5051
}),
5152
onSubmit: async (values) => {
5253
try {
53-
await SupplyServices.create({
54-
...values,
54+
const resp = await SupplyServices.create({
55+
name: values.name,
56+
supplyCategoryId: values.supplyCategoryId,
57+
});
58+
await ShelterSupplyServices.create({
59+
supplyId: resp.data.id,
5560
priority: +values.priority,
61+
shelterId,
5662
});
5763
toast({
5864
title: 'Item cadastrado com sucesso',

src/pages/Home/Home.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,6 @@ const Home = () => {
9292
<Search name="search" size="20" className="stroke-zinc-300" />
9393
</div>
9494
</div>
95-
<div></div>
96-
{/* <div className="[&_svg]:stroke-blue-500">
97-
<Button variant="ghost" size="sm" className="flex gap-2 items-center">
98-
<ListFilter className="h-5 w-5" />
99-
<h1 className="font-semibold text-[16px] text-blue-500">
100-
Filtros
101-
</h1>
102-
</Button>
103-
</div> */}
10495
<main className="flex flex-col gap-4">
10596
{loading ? (
10697
<Loader className="justify-self-center self-center w-5 h-5 animate-spin" />

0 commit comments

Comments
 (0)