willba-component-library 0.1.41 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/FilterBar/hooks/useFilterBar.d.ts +3 -2
- package/lib/index.esm.js +47 -22
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +47 -22
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +47 -22
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/FilterBar.stories.tsx +1 -1
- package/src/components/FilterBar/FilterBar.tsx +1 -1
- package/src/components/FilterBar/components/calendar/Calendar.tsx +1 -1
- package/src/components/FilterBar/components/guests/GuestCount/GuestCount.tsx +2 -6
- package/src/components/FilterBar/components/guests/Guests.tsx +1 -1
- package/src/components/FilterBar/hooks/useFilterBar.tsx +60 -15
package/package.json
CHANGED
|
@@ -61,7 +61,7 @@ export default function FilterBar({
|
|
|
61
61
|
handleSubmit,
|
|
62
62
|
updateGuestsCount,
|
|
63
63
|
setSelectedPath,
|
|
64
|
-
} = useFilterBar({ redirectUrl, currentViewApply })
|
|
64
|
+
} = useFilterBar({ redirectUrl, currentViewApply, ageCategories })
|
|
65
65
|
|
|
66
66
|
// Default selected tab
|
|
67
67
|
useEffect(() => {
|
|
@@ -12,10 +12,6 @@ export default function GuestCount({
|
|
|
12
12
|
count,
|
|
13
13
|
minVal,
|
|
14
14
|
}: GuestsCountPropsType) {
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (minVal) updateGuestsCount(`guests-${id}`, minVal)
|
|
17
|
-
}, [])
|
|
18
|
-
|
|
19
15
|
const handleDecrement = () => {
|
|
20
16
|
if (count > minVal) {
|
|
21
17
|
updateGuestsCount(`guests-${id}`, count - 1)
|
|
@@ -34,10 +30,10 @@ export default function GuestCount({
|
|
|
34
30
|
<button
|
|
35
31
|
className="will-guests-filter-counter-button"
|
|
36
32
|
onClick={handleDecrement}
|
|
37
|
-
disabled={minVal && count
|
|
33
|
+
disabled={minVal && count <= minVal ? true : false}
|
|
38
34
|
style={{
|
|
39
35
|
cursor:
|
|
40
|
-
minVal && count
|
|
36
|
+
minVal && count <= minVal
|
|
41
37
|
? 'initial'
|
|
42
38
|
: !minVal && count < 1
|
|
43
39
|
? 'initial'
|
|
@@ -2,14 +2,19 @@ import { useEffect, useState } from 'react'
|
|
|
2
2
|
import { DateRange } from 'react-day-picker'
|
|
3
3
|
import { format } from 'date-fns'
|
|
4
4
|
|
|
5
|
-
import { AgeCategoryCount } from '../FilterBarTypes'
|
|
5
|
+
import { AgeCategoryCount, AgeCategoryType } from '../FilterBarTypes'
|
|
6
6
|
|
|
7
7
|
type Props = {
|
|
8
8
|
redirectUrl?: string
|
|
9
9
|
currentViewApply?: string
|
|
10
|
+
ageCategories?: AgeCategoryType[]
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export const useFilterBar = ({
|
|
13
|
+
export const useFilterBar = ({
|
|
14
|
+
redirectUrl,
|
|
15
|
+
currentViewApply,
|
|
16
|
+
ageCategories,
|
|
17
|
+
}: Props) => {
|
|
13
18
|
const [selectedPath, setSelectedPath] = useState('/events')
|
|
14
19
|
|
|
15
20
|
const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
|
|
@@ -44,6 +49,7 @@ export const useFilterBar = ({ redirectUrl, currentViewApply }: Props) => {
|
|
|
44
49
|
}, [])
|
|
45
50
|
|
|
46
51
|
useEffect(() => {
|
|
52
|
+
// Handle hide scroll bar on mobile
|
|
47
53
|
if (typeof window === 'undefined') return
|
|
48
54
|
|
|
49
55
|
document.body.style.overflow =
|
|
@@ -55,16 +61,16 @@ export const useFilterBar = ({ redirectUrl, currentViewApply }: Props) => {
|
|
|
55
61
|
}, [selectedFilter])
|
|
56
62
|
|
|
57
63
|
useEffect(() => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
// Handle default selected tab
|
|
65
|
+
if (typeof window === 'undefined') return
|
|
66
|
+
|
|
67
|
+
const currentPath = window.location.pathname.includes('/events')
|
|
68
|
+
? '/events'
|
|
69
|
+
: window.location.pathname.includes('/rooms')
|
|
70
|
+
? '/rooms'
|
|
71
|
+
: '/events'
|
|
72
|
+
|
|
73
|
+
setSelectedPath(currentPath)
|
|
68
74
|
}, [])
|
|
69
75
|
|
|
70
76
|
const updateGuestsCount = (id: string, newCount: number) => {
|
|
@@ -85,9 +91,10 @@ export const useFilterBar = ({ redirectUrl, currentViewApply }: Props) => {
|
|
|
85
91
|
: '',
|
|
86
92
|
endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
|
|
87
93
|
categories,
|
|
88
|
-
ageCategoryCounts:
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
ageCategoryCounts: handleAgeCategoryRules({
|
|
95
|
+
ageCategoryCounts,
|
|
96
|
+
ageCategories,
|
|
97
|
+
}),
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
if (currentViewApply) {
|
|
@@ -151,3 +158,41 @@ export const useFilterBar = ({ redirectUrl, currentViewApply }: Props) => {
|
|
|
151
158
|
setSelectedPath,
|
|
152
159
|
}
|
|
153
160
|
}
|
|
161
|
+
|
|
162
|
+
////////////
|
|
163
|
+
|
|
164
|
+
const handleAgeCategoryRules = ({
|
|
165
|
+
ageCategoryCounts,
|
|
166
|
+
ageCategories,
|
|
167
|
+
}: {
|
|
168
|
+
ageCategoryCounts: AgeCategoryCount
|
|
169
|
+
ageCategories?: AgeCategoryType[]
|
|
170
|
+
}) => {
|
|
171
|
+
if (ageCategories?.length) {
|
|
172
|
+
ageCategories?.map((a) => {
|
|
173
|
+
if (a.minVal) {
|
|
174
|
+
// Age categories rules
|
|
175
|
+
const totalAgeCategories = Object.entries(ageCategoryCounts).reduce(
|
|
176
|
+
(acc, c) => {
|
|
177
|
+
return acc + c[1]
|
|
178
|
+
},
|
|
179
|
+
0
|
|
180
|
+
)
|
|
181
|
+
const ageCategory = ageCategoryCounts[`guests-${a.id}`]
|
|
182
|
+
|
|
183
|
+
if (
|
|
184
|
+
!totalAgeCategories ||
|
|
185
|
+
(totalAgeCategories === 1 && ageCategory === 1)
|
|
186
|
+
) {
|
|
187
|
+
ageCategoryCounts[`guests-${a.id}`] = 2
|
|
188
|
+
} else if (totalAgeCategories > 1 && !ageCategory) {
|
|
189
|
+
ageCategoryCounts[`guests-${a.id}`] = a.minVal
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return Object.entries(ageCategoryCounts).length
|
|
196
|
+
? JSON.stringify(ageCategoryCounts)
|
|
197
|
+
: ''
|
|
198
|
+
}
|