1
+ import { ShelterCategory , SupplyMeasure } from '@/hooks/useShelter/types' ;
1
2
import { IUseSheltersDataSupplyData } from '@/hooks/useShelters/types' ;
3
+ import { ShelterAvailabilityStatus } from '@/pages/Home/components/Filter/types' ;
2
4
import {
3
5
ShelterTagInfo ,
4
6
ShelterTagType ,
5
7
} from '@/pages/Home/components/ShelterListItem/types' ;
8
+ import { DonateOrderStatus } from '@/service/donationOrder/types' ;
6
9
import { SupplyPriority } from '@/service/supply/types' ;
7
10
import { type ClassValue , clsx } from 'clsx' ;
8
11
import { twMerge } from 'tailwind-merge' ;
@@ -11,41 +14,18 @@ function cn(...inputs: ClassValue[]) {
11
14
return twMerge ( clsx ( inputs ) ) ;
12
15
}
13
16
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 ) ) {
49
29
if ( shelteredPeople < capacity )
50
30
return {
51
31
availability : 'Abrigo disponível' ,
@@ -64,7 +44,7 @@ function getAvailabilityProps(
64
44
}
65
45
66
46
const priorityOptions : Record < SupplyPriority , string > = {
67
- [ SupplyPriority . Urgent ] : 'Necessita urgente ' ,
47
+ [ SupplyPriority . Urgent ] : 'Precisa com urgência ' ,
68
48
[ SupplyPriority . Needing ] : 'Precisa' ,
69
49
[ SupplyPriority . Remaining ] : 'Disponível para doação' ,
70
50
[ SupplyPriority . NotNeeded ] : 'Não preciso' ,
@@ -76,38 +56,22 @@ function getSupplyPriorityProps(priority: SupplyPriority) {
76
56
case SupplyPriority . NotNeeded :
77
57
return {
78
58
label,
79
- < << << << HEAD
80
59
className : 'bg-gray-200 text-gray-800' ,
81
- = === ===
82
- className : 'bg-gray-200' ,
83
- > >>> >>> 3 d3f437 ( merge : develop - > master ( #91 ) )
84
60
} ;
85
61
case SupplyPriority . Remaining :
86
62
return {
87
63
label,
88
- < << << << HEAD
89
64
className : 'bg-light-green text-green-800' ,
90
- = === ===
91
- className : 'bg-light-green' ,
92
- > >>> >>> 3 d3f437 ( merge : develop - > master ( #91 ) )
93
65
} ;
94
66
case SupplyPriority . Needing :
95
67
return {
96
68
label,
97
- < << << << HEAD
98
69
className : 'bg-light-orange text-orange-800' ,
99
- = === ===
100
- className : 'bg-light-orange' ,
101
- > >>> >>> 3 d3f437 ( merge : develop - > master ( #91 ) )
102
70
} ;
103
71
case SupplyPriority . Urgent :
104
72
return {
105
73
label,
106
- < << << << HEAD
107
74
className : 'bg-light-red text-red-800' ,
108
- = === ===
109
- className : 'bg-light-red' ,
110
- > >>> >>> 3 d3f437 ( merge : develop - > master ( #91 ) )
111
75
} ;
112
76
}
113
77
}
@@ -157,7 +121,6 @@ function groupShelterSuppliesByTag(data: IUseSheltersDataSupplyData[]) {
157
121
[ category ] : values . sort ( ( a , b ) => b . priority - a . priority ) ,
158
122
} ;
159
123
} , initialGroup ) ;
160
- < < < << << HEAD
161
124
}
162
125
163
126
function removeDuplicatesByField (
@@ -170,22 +133,57 @@ function removeDuplicatesByField(
170
133
if ( prev . some ( ( p ) => p [ key ] === current [ key ] ) ) return prev ;
171
134
else return [ ...prev , current ] ;
172
135
} , [ ] ) ;
173
- = === ===
174
- >>> >>> > 3 d3f437 ( merge : develop - > master ( #91 ) )
175
136
}
176
137
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
+
177
176
export {
178
177
cn ,
179
178
getAvailabilityProps ,
180
179
group ,
181
180
getSupplyPriorityProps ,
182
- variantStatusPriority ,
183
- colorStatusPriority ,
184
- nameStatusPriority ,
185
181
priorityOptions ,
186
182
groupShelterSuppliesByTag ,
187
- < << << << HEAD
188
183
removeDuplicatesByField ,
189
- = === ===
190
- >>> >>> > 3 d3f437 ( merge : develop - > master ( #91 ) )
191
- } ;
184
+ normalizedCompare ,
185
+ checkIsNull ,
186
+ SupplyMeasureMap ,
187
+ ShelterAvailabilityStatusMap ,
188
+ DonationStatusMap ,
189
+ } ;
0 commit comments