willba-component-library 0.1.47 → 0.1.48
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/FilterBarTypes.d.ts +6 -0
- package/lib/components/FilterBar/hooks/useFilterBar.d.ts +4 -3
- package/lib/components/FilterBar/index.d.ts +2 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.esm.js +24 -5
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +24 -5
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +24 -5
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/FilterBar.stories.tsx +2 -1
- package/src/components/FilterBar/FilterBar.tsx +15 -4
- package/src/components/FilterBar/FilterBarTypes.ts +6 -0
- package/src/components/FilterBar/hooks/useFilterBar.tsx +22 -4
- package/src/components/FilterBar/index.ts +3 -1
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react'
|
|
|
2
2
|
import type { Meta, StoryObj } from '@storybook/react'
|
|
3
3
|
|
|
4
4
|
import FilterBar from './FilterBar'
|
|
5
|
+
import { Filters } from './FilterBarTypes'
|
|
5
6
|
|
|
6
7
|
const meta: Meta<typeof FilterBar> = {
|
|
7
8
|
title: 'Components/FilterBar',
|
|
@@ -44,7 +45,7 @@ export const Primary: Story = {
|
|
|
44
45
|
},
|
|
45
46
|
render: (args) => (
|
|
46
47
|
<div style={{ background: 'grey', padding: '30px', height: '100vh' }}>
|
|
47
|
-
<FilterBar {...args} />
|
|
48
|
+
<FilterBar {...args} onSubmit={(val: Filters) => console.log(val)} />
|
|
48
49
|
</div>
|
|
49
50
|
),
|
|
50
51
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import React, { useEffect } from 'react'
|
|
2
2
|
import { useTranslation } from 'react-i18next'
|
|
3
|
-
import { format } from 'date-fns'
|
|
4
3
|
|
|
5
4
|
import useTheme, { Palette } from '../../themes/useTheme'
|
|
6
5
|
import '../../themes/Default.css'
|
|
7
6
|
|
|
8
7
|
import { parseDates, parseGuests } from './utils'
|
|
9
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
AgeCategoryType,
|
|
10
|
+
FilterSections,
|
|
11
|
+
Filters,
|
|
12
|
+
ViewApply,
|
|
13
|
+
} from './FilterBarTypes'
|
|
10
14
|
import {
|
|
11
15
|
useCloseFilterSection,
|
|
12
16
|
useFilterBar,
|
|
@@ -33,6 +37,7 @@ export type FilterBarProps = {
|
|
|
33
37
|
redirectUrl?: string
|
|
34
38
|
palette?: Palette
|
|
35
39
|
currentViewApply?: string
|
|
40
|
+
onSubmit?: (val: Filters) => void
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
export default function FilterBar({
|
|
@@ -41,6 +46,7 @@ export default function FilterBar({
|
|
|
41
46
|
redirectUrl = REDIRECT_URL_FALLBACK,
|
|
42
47
|
palette,
|
|
43
48
|
currentViewApply,
|
|
49
|
+
onSubmit,
|
|
44
50
|
}: FilterBarProps) {
|
|
45
51
|
const themePalette = useTheme({ palette })
|
|
46
52
|
|
|
@@ -61,11 +67,16 @@ export default function FilterBar({
|
|
|
61
67
|
handleSubmit,
|
|
62
68
|
updateGuestsCount,
|
|
63
69
|
setSelectedPath,
|
|
64
|
-
} = useFilterBar({
|
|
70
|
+
} = useFilterBar({
|
|
71
|
+
redirectUrl,
|
|
72
|
+
currentViewApply,
|
|
73
|
+
ageCategories,
|
|
74
|
+
onSubmit,
|
|
75
|
+
})
|
|
65
76
|
|
|
66
77
|
// Default selected tab when tabs are hidden
|
|
67
78
|
useEffect(() => {
|
|
68
|
-
if (currentViewApply ===
|
|
79
|
+
if (currentViewApply === ViewApply.ROOMS) {
|
|
69
80
|
setSelectedPath('/rooms')
|
|
70
81
|
}
|
|
71
82
|
}, [])
|
|
@@ -2,18 +2,20 @@ 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, AgeCategoryType } from '../FilterBarTypes'
|
|
5
|
+
import { AgeCategoryCount, AgeCategoryType, Filters } from '../FilterBarTypes'
|
|
6
6
|
|
|
7
7
|
type Props = {
|
|
8
8
|
redirectUrl?: string
|
|
9
9
|
currentViewApply?: string
|
|
10
10
|
ageCategories?: AgeCategoryType[]
|
|
11
|
+
onSubmit?: (val: Filters) => void
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export const useFilterBar = ({
|
|
14
15
|
redirectUrl,
|
|
15
16
|
currentViewApply,
|
|
16
17
|
ageCategories,
|
|
18
|
+
onSubmit,
|
|
17
19
|
}: Props) => {
|
|
18
20
|
const [selectedPath, setSelectedPath] = useState('/events')
|
|
19
21
|
|
|
@@ -118,6 +120,19 @@ export const useFilterBar = ({
|
|
|
118
120
|
const updatedUrl = `${baseUrl}?${updatedParams.toString()}`
|
|
119
121
|
|
|
120
122
|
handleSelectedFilter(false)
|
|
123
|
+
|
|
124
|
+
if (onSubmit) {
|
|
125
|
+
const updatedParamsObject: { [key: string]: string | number } = {}
|
|
126
|
+
|
|
127
|
+
updatedParams.forEach((value, key) => {
|
|
128
|
+
updatedParamsObject[key] = value
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
console.log('sdasdasdsad', updatedParamsObject)
|
|
132
|
+
|
|
133
|
+
return onSubmit(updatedParamsObject)
|
|
134
|
+
}
|
|
135
|
+
|
|
121
136
|
return (window.location.href = updatedUrl)
|
|
122
137
|
} else {
|
|
123
138
|
const querySearchParams = new URLSearchParams()
|
|
@@ -129,9 +144,12 @@ export const useFilterBar = ({
|
|
|
129
144
|
}
|
|
130
145
|
|
|
131
146
|
handleSelectedFilter(false)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
147
|
+
|
|
148
|
+
return onSubmit
|
|
149
|
+
? onSubmit(newParams)
|
|
150
|
+
: (window.location.href = `${redirectUrl}/${selectedPath}${
|
|
151
|
+
querySearchParams ? `?${querySearchParams.toString()}` : ''
|
|
152
|
+
}`)
|
|
135
153
|
}
|
|
136
154
|
}
|
|
137
155
|
|