Skip to content

Commit 9b7f0e3

Browse files
fagundesjgmarcodmc
authored andcommitted
fix: conflicts with master branch
1 parent af9d35b commit 9b7f0e3

File tree

5 files changed

+331
-311
lines changed

5 files changed

+331
-311
lines changed
Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
import { IUseSheltersData } from '@/hooks/useShelters/types';
2-
import { ICardAboutShelter } from './types';
1+
import { IUseShelterData } from '@/hooks/useShelter/types';
32

43
const formatShelterAddressFields = (
5-
shelter: ICardAboutShelter['shelter'] | IUseSheltersData
6-
) =>
7-
[shelter.street, shelter.streetNumber, shelter.neighbourhood]
8-
.filter(Boolean)
9-
.join(', ');
4+
payload: Partial<
5+
Pick<IUseShelterData, 'street' | 'streetNumber' | 'neighbourhood'>
6+
>
7+
): string => {
8+
const { street, streetNumber, neighbourhood } = payload;
9+
return [street, streetNumber, neighbourhood].filter(Boolean).join(', ');
10+
};
1011

11-
export const checkAndFormatAddress = (
12-
shelter: ICardAboutShelter['shelter'] | IUseSheltersData,
12+
const checkAndFormatAddress = (
13+
payload: Partial<
14+
Pick<
15+
IUseShelterData,
16+
'address' | 'city' | 'street' | 'streetNumber' | 'neighbourhood'
17+
>
18+
>,
1319
showCity = true
14-
) =>
15-
shelter.address ??
16-
`${formatShelterAddressFields(shelter)}${
17-
showCity ? ` - ${shelter.city}` : ''
18-
}`;
20+
): string => {
21+
const { address, city, ...rest } = payload;
22+
return (
23+
address ??
24+
`${formatShelterAddressFields(rest)}${showCity ? ` - ${city}` : ''}`
25+
);
26+
};
27+
28+
export { checkAndFormatAddress };

src/lib/utils.ts

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { ShelterCategory, SupplyMeasure } from '@/hooks/useShelter/types';
12
import { IUseSheltersDataSupplyData } from '@/hooks/useShelters/types';
3+
import { ShelterAvailabilityStatus } from '@/pages/Home/components/Filter/types';
24
import {
35
ShelterTagInfo,
46
ShelterTagType,
57
} from '@/pages/Home/components/ShelterListItem/types';
8+
import { DonateOrderStatus } from '@/service/donationOrder/types';
69
import { SupplyPriority } from '@/service/supply/types';
710
import { type ClassValue, clsx } from 'clsx';
811
import { twMerge } from 'tailwind-merge';
@@ -11,41 +14,18 @@ function cn(...inputs: ClassValue[]) {
1114
return twMerge(clsx(inputs));
1215
}
1316

14-
/**
15-
* deprecated
16-
*/
17-
function variantStatusPriority(priority: SupplyPriority) {
18-
if (priority === SupplyPriority.Needing) return 'danger';
19-
if (priority === SupplyPriority.Urgent) return 'warn';
20-
if (priority === SupplyPriority.NotNeeded) return 'alert';
21-
if (priority === SupplyPriority.Remaining) return 'success';
22-
}
23-
24-
/**
25-
* deprecated
26-
*/
27-
const colorStatusPriority = (priority: SupplyPriority) => {
28-
if (priority === SupplyPriority.Needing) return 'bg-[#f69f9d]';
29-
if (priority === SupplyPriority.Urgent) return 'bg-[#f8b993]';
30-
if (priority === SupplyPriority.NotNeeded) return 'bg-[#f9cf8d]';
31-
if (priority === SupplyPriority.Remaining) return 'bg-[#63bc43]';
32-
};
33-
34-
/**
35-
* deprecated
36-
*/
37-
function nameStatusPriority(priority: SupplyPriority) {
38-
if (priority === SupplyPriority.Needing) return 'Precisa urgentimente';
39-
if (priority === SupplyPriority.Urgent) return 'Precisa';
40-
if (priority === SupplyPriority.NotNeeded) return 'Não preciso';
41-
if (priority === SupplyPriority.Remaining) return 'Disponível para doação';
42-
}
43-
44-
function getAvailabilityProps(
45-
capacity?: number | null,
46-
shelteredPeople?: number | null
47-
) {
48-
if (capacity && (shelteredPeople || shelteredPeople === 0)) {
17+
function getAvailabilityProps(props: {
18+
capacity?: number | null;
19+
shelteredPeople?: number | null;
20+
category: ShelterCategory;
21+
}) {
22+
const { category, capacity, shelteredPeople } = props;
23+
if (category === ShelterCategory.DistributionCenter) {
24+
return {
25+
availability: 'Centro de Distribuição',
26+
className: 'text-green-600',
27+
};
28+
} else if (capacity && (shelteredPeople || shelteredPeople === 0)) {
4929
if (shelteredPeople < capacity)
5030
return {
5131
availability: 'Abrigo disponível',
@@ -64,7 +44,7 @@ function getAvailabilityProps(
6444
}
6545

6646
const priorityOptions: Record<SupplyPriority, string> = {
67-
[SupplyPriority.Urgent]: 'Necessita urgente',
47+
[SupplyPriority.Urgent]: 'Precisa com urgência',
6848
[SupplyPriority.Needing]: 'Precisa',
6949
[SupplyPriority.Remaining]: 'Disponível para doação',
7050
[SupplyPriority.NotNeeded]: 'Não preciso',
@@ -76,38 +56,22 @@ function getSupplyPriorityProps(priority: SupplyPriority) {
7656
case SupplyPriority.NotNeeded:
7757
return {
7858
label,
79-
<<<<<<< HEAD
8059
className: 'bg-gray-200 text-gray-800',
81-
=======
82-
className: 'bg-gray-200',
83-
>>>>>>> 3d3f437 (merge: develop -> master (#91))
8460
};
8561
case SupplyPriority.Remaining:
8662
return {
8763
label,
88-
<<<<<<< HEAD
8964
className: 'bg-light-green text-green-800',
90-
=======
91-
className: 'bg-light-green',
92-
>>>>>>> 3d3f437 (merge: develop -> master (#91))
9365
};
9466
case SupplyPriority.Needing:
9567
return {
9668
label,
97-
<<<<<<< HEAD
9869
className: 'bg-light-orange text-orange-800',
99-
=======
100-
className: 'bg-light-orange',
101-
>>>>>>> 3d3f437 (merge: develop -> master (#91))
10270
};
10371
case SupplyPriority.Urgent:
10472
return {
10573
label,
106-
<<<<<<< HEAD
10774
className: 'bg-light-red text-red-800',
108-
=======
109-
className: 'bg-light-red',
110-
>>>>>>> 3d3f437 (merge: develop -> master (#91))
11175
};
11276
}
11377
}
@@ -157,7 +121,6 @@ function groupShelterSuppliesByTag(data: IUseSheltersDataSupplyData[]) {
157121
[category]: values.sort((a, b) => b.priority - a.priority),
158122
};
159123
}, initialGroup);
160-
<<<<<<< HEAD
161124
}
162125

163126
function removeDuplicatesByField(
@@ -170,22 +133,57 @@ function removeDuplicatesByField(
170133
if (prev.some((p) => p[key] === current[key])) return prev;
171134
else return [...prev, current];
172135
}, []);
173-
=======
174-
>>>>>>> 3d3f437 (merge: develop -> master (#91))
175136
}
176137

138+
function normalizedCompare(a: string, b: string): boolean {
139+
return a
140+
.toLowerCase()
141+
.normalize('NFD')
142+
.replace(/[\u0300-\u036f]/g, '')
143+
.includes(
144+
b
145+
.toLowerCase()
146+
.normalize('NFD')
147+
.replace(/[\u0300-\u036f]/g, '')
148+
);
149+
}
150+
151+
function checkIsNull(v?: any | null) {
152+
return v !== null && v !== undefined;
153+
}
154+
155+
const SupplyMeasureMap: Record<SupplyMeasure, string> = {
156+
Box: 'caixa(s)',
157+
Kg: 'kg',
158+
Litters: 'litro(s)',
159+
Piece: 'peça(s)',
160+
Unit: 'un',
161+
};
162+
163+
const ShelterAvailabilityStatusMap: Record<ShelterAvailabilityStatus, string> =
164+
{
165+
available: 'Abrigo Disponivel',
166+
unavailable: 'Abrigo Indisponivel',
167+
waiting: 'Sem informação de disponibilidade',
168+
};
169+
170+
const DonationStatusMap: Record<DonateOrderStatus, string> = {
171+
[DonateOrderStatus.Canceled]: 'Cancelado',
172+
[DonateOrderStatus.Pending]: 'Pendente',
173+
[DonateOrderStatus.Complete]: 'Entregue',
174+
};
175+
177176
export {
178177
cn,
179178
getAvailabilityProps,
180179
group,
181180
getSupplyPriorityProps,
182-
variantStatusPriority,
183-
colorStatusPriority,
184-
nameStatusPriority,
185181
priorityOptions,
186182
groupShelterSuppliesByTag,
187-
<<<<<<< HEAD
188183
removeDuplicatesByField,
189-
=======
190-
>>>>>>> 3d3f437 (merge: develop -> master (#91))
191-
};
184+
normalizedCompare,
185+
checkIsNull,
186+
SupplyMeasureMap,
187+
ShelterAvailabilityStatusMap,
188+
DonationStatusMap,
189+
};

0 commit comments

Comments
 (0)