willba-component-library 0.1.27 → 0.1.29
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/FilterBar.d.ts +3 -2
- package/lib/components/FilterBar/hooks/useFilterBar.d.ts +4 -3
- package/lib/index.d.ts +3 -2
- package/lib/index.esm.js +207 -109
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +221 -123
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +10667 -10569
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/FilterBar.css +2 -1
- package/src/components/FilterBar/FilterBar.stories.tsx +1 -0
- package/src/components/FilterBar/FilterBar.tsx +32 -16
- package/src/components/FilterBar/components/guests/Guests.css +2 -0
- package/src/components/FilterBar/hooks/useFilterBar.tsx +82 -37
- package/tsconfig.json +1 -0
package/package.json
CHANGED
|
@@ -23,8 +23,9 @@ export interface FilterBarProps {
|
|
|
23
23
|
vendor?: string
|
|
24
24
|
language?: string
|
|
25
25
|
ageCategories?: AgeCategoryType[]
|
|
26
|
-
redirectUrl
|
|
26
|
+
redirectUrl?: string
|
|
27
27
|
palette?: Palette
|
|
28
|
+
currentViewApply?: string
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export default function FilterBar({
|
|
@@ -32,11 +33,14 @@ export default function FilterBar({
|
|
|
32
33
|
ageCategories = AGE_CATEGORIES_FALLBACK,
|
|
33
34
|
redirectUrl = REDIRECT_URL_FALLBACK,
|
|
34
35
|
palette,
|
|
36
|
+
currentViewApply,
|
|
35
37
|
}: FilterBarProps) {
|
|
36
38
|
const themePalette = useTheme({ palette })
|
|
37
39
|
|
|
38
40
|
// Translations
|
|
39
41
|
const [rerenderKey, setRerenderKey] = useState(0)
|
|
42
|
+
const [isMobile, setIsMobile] = useState(true)
|
|
43
|
+
|
|
40
44
|
useEffect(() => {
|
|
41
45
|
i18n.changeLanguage(language)
|
|
42
46
|
|
|
@@ -58,13 +62,20 @@ export default function FilterBar({
|
|
|
58
62
|
handleSubmit,
|
|
59
63
|
updateGuestsCount,
|
|
60
64
|
setSelectedPath,
|
|
61
|
-
} = useFilterBar({ redirectUrl })
|
|
65
|
+
} = useFilterBar({ redirectUrl, currentViewApply })
|
|
62
66
|
|
|
63
67
|
// Scroll in to view
|
|
64
68
|
|
|
65
69
|
const targetFilterBarRef = useRef<HTMLDivElement | null>(null)
|
|
66
70
|
useEffect(() => {
|
|
67
|
-
if (
|
|
71
|
+
if (currentViewApply === 'roomFilters') {
|
|
72
|
+
setSelectedPath('/rooms')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (window !== undefined && window.innerWidth > 960) {
|
|
76
|
+
setIsMobile(false)
|
|
77
|
+
return
|
|
78
|
+
}
|
|
68
79
|
if (targetFilterBarRef.current && selectedFilter) {
|
|
69
80
|
window.scrollTo({
|
|
70
81
|
behavior: 'smooth',
|
|
@@ -91,18 +102,20 @@ export default function FilterBar({
|
|
|
91
102
|
className={`will-root ${selectedFilter ? 'isMobileAbsolute' : ''}`}
|
|
92
103
|
style={themePalette}
|
|
93
104
|
>
|
|
94
|
-
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
{!currentViewApply && (
|
|
106
|
+
<div className="will-filter-bar-tabs" ref={targetFilterBarRef}>
|
|
107
|
+
<TabButton
|
|
108
|
+
label={t('tabs.events')}
|
|
109
|
+
onClick={() => setSelectedPath('/events')}
|
|
110
|
+
active={selectedPath === '/events'}
|
|
111
|
+
/>
|
|
112
|
+
<TabButton
|
|
113
|
+
label={t('tabs.rooms')}
|
|
114
|
+
onClick={() => setSelectedPath('/rooms')}
|
|
115
|
+
active={selectedPath === '/rooms'}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
106
119
|
|
|
107
120
|
<div className="will-filter-bar-header">
|
|
108
121
|
<SelectButton
|
|
@@ -129,7 +142,10 @@ export default function FilterBar({
|
|
|
129
142
|
</div>
|
|
130
143
|
|
|
131
144
|
{selectedFilter && (
|
|
132
|
-
<div
|
|
145
|
+
<div
|
|
146
|
+
className="will-filter-bar-container"
|
|
147
|
+
style={currentViewApply && !isMobile ? { top: 66 } : {}}
|
|
148
|
+
>
|
|
133
149
|
<CloseButton handleClose={() => handleSelectedFilter(false)} />
|
|
134
150
|
|
|
135
151
|
{selectedFilter === 1 && (
|
|
@@ -5,10 +5,14 @@ import { format } from 'date-fns'
|
|
|
5
5
|
import { AgeCategoryCount } from '../FilterBarTypes'
|
|
6
6
|
|
|
7
7
|
interface UseFilterBarPropsType {
|
|
8
|
-
redirectUrl
|
|
8
|
+
redirectUrl?: string
|
|
9
|
+
currentViewApply?: string
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export default function useFilterBar({
|
|
12
|
+
export default function useFilterBar({
|
|
13
|
+
redirectUrl,
|
|
14
|
+
currentViewApply,
|
|
15
|
+
}: UseFilterBarPropsType) {
|
|
12
16
|
const [selectedPath, setSelectedPath] = useState('/events')
|
|
13
17
|
|
|
14
18
|
const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
|
|
@@ -19,13 +23,6 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
|
|
|
19
23
|
{}
|
|
20
24
|
)
|
|
21
25
|
|
|
22
|
-
const updateGuestsCount = (id: string, newCount: number) => {
|
|
23
|
-
setAgeCategoryCounts((prevCounts) => ({
|
|
24
|
-
...prevCounts,
|
|
25
|
-
[id]: newCount,
|
|
26
|
-
}))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
26
|
useEffect(() => {
|
|
30
27
|
const urlSearchParams = new URLSearchParams(window.location.search)
|
|
31
28
|
|
|
@@ -49,34 +46,6 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
|
|
|
49
46
|
setCategories(parsedCategories)
|
|
50
47
|
}, [])
|
|
51
48
|
|
|
52
|
-
const handleSelectedFilter = (id: number | boolean) => {
|
|
53
|
-
setSelectedFilter(id)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const handleSubmit = () => {
|
|
57
|
-
const queryParams = new URLSearchParams()
|
|
58
|
-
|
|
59
|
-
const params = {
|
|
60
|
-
startDate: calendarRange?.from
|
|
61
|
-
? format(calendarRange.from, 'yyyy-MM-dd')
|
|
62
|
-
: '',
|
|
63
|
-
endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
|
|
64
|
-
categories,
|
|
65
|
-
ageCategoryCounts: JSON.stringify(ageCategoryCounts),
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (const [key, value] of Object.entries(params)) {
|
|
69
|
-
if (value) {
|
|
70
|
-
queryParams.append(key, value.toString())
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
window.location.href = `${redirectUrl}/${selectedPath}${
|
|
75
|
-
queryParams ? `?${queryParams.toString()}` : ''
|
|
76
|
-
}`
|
|
77
|
-
handleSelectedFilter(false)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
49
|
useEffect(() => {
|
|
81
50
|
if (typeof window === 'undefined') return
|
|
82
51
|
|
|
@@ -101,6 +70,82 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
|
|
|
101
70
|
}
|
|
102
71
|
}, [])
|
|
103
72
|
|
|
73
|
+
const updateGuestsCount = (id: string, newCount: number) => {
|
|
74
|
+
setAgeCategoryCounts((prevCounts) => ({
|
|
75
|
+
...prevCounts,
|
|
76
|
+
[id]: newCount,
|
|
77
|
+
}))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const handleSelectedFilter = (id: number | boolean) => {
|
|
81
|
+
setSelectedFilter(id)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const handleSubmit = () => {
|
|
85
|
+
const newParams = {
|
|
86
|
+
startDate: calendarRange?.from
|
|
87
|
+
? format(calendarRange.from, 'yyyy-MM-dd')
|
|
88
|
+
: '',
|
|
89
|
+
endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
|
|
90
|
+
categories,
|
|
91
|
+
ageCategoryCounts: Object.entries(ageCategoryCounts).length
|
|
92
|
+
? JSON.stringify(ageCategoryCounts)
|
|
93
|
+
: '',
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// const getQueryParams = () => {
|
|
97
|
+
// const currentSearchParams = new URLSearchParams(window.location.search)
|
|
98
|
+
|
|
99
|
+
// const params: { [key: string]: string } = {}
|
|
100
|
+
// for (const [key, value] of currentSearchParams.entries()) {
|
|
101
|
+
// params[key] = value
|
|
102
|
+
// }
|
|
103
|
+
// return params
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
if (currentViewApply) {
|
|
107
|
+
const currentSearchParams = new URLSearchParams(window.location.search)
|
|
108
|
+
const updatedParams = new URLSearchParams()
|
|
109
|
+
|
|
110
|
+
for (const [key, value] of currentSearchParams.entries()) {
|
|
111
|
+
updatedParams.append(key, value)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const [key, value] of Object.entries(newParams)) {
|
|
115
|
+
if (value) {
|
|
116
|
+
updatedParams.set(key, value.toString())
|
|
117
|
+
} else {
|
|
118
|
+
updatedParams.delete(key)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(currentSearchParams.toString(), updatedParams.toString())
|
|
123
|
+
|
|
124
|
+
// Get the current URL without the query string
|
|
125
|
+
const baseUrl = window.location.origin + window.location.pathname
|
|
126
|
+
|
|
127
|
+
// Construct the updated URL with the modified query parameters
|
|
128
|
+
const updatedUrl = `${baseUrl}?${updatedParams.toString()}`
|
|
129
|
+
|
|
130
|
+
// Replace the current URL with the updated URL in the browser's history
|
|
131
|
+
return (window.location.href = updatedUrl)
|
|
132
|
+
} else {
|
|
133
|
+
const querySearchParams = new URLSearchParams()
|
|
134
|
+
|
|
135
|
+
for (const [key, value] of Object.entries(newParams)) {
|
|
136
|
+
if (value) {
|
|
137
|
+
querySearchParams.append(key, value.toString())
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (window.location.href = `${redirectUrl}/${selectedPath}${
|
|
142
|
+
querySearchParams ? `?${querySearchParams.toString()}` : ''
|
|
143
|
+
}`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
handleSelectedFilter(false)
|
|
147
|
+
}
|
|
148
|
+
|
|
104
149
|
const handleResetFilters = () => {
|
|
105
150
|
setAgeCategoryCounts({})
|
|
106
151
|
handleSubmit()
|