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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "willba-component-library",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "description": "A stroybook 6 with TypeScript demo",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -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 { AgeCategoryType, FilterSections } from './FilterBarTypes'
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({ redirectUrl, currentViewApply, ageCategories })
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 === 'roomFilters') {
79
+ if (currentViewApply === ViewApply.ROOMS) {
69
80
  setSelectedPath('/rooms')
70
81
  }
71
82
  }, [])
@@ -23,3 +23,9 @@ export enum FilterSections {
23
23
  GUESTS = 'guests',
24
24
  CATEGORIES = 'categories',
25
25
  }
26
+
27
+ export type Filters = { [key: string]: string | number }
28
+
29
+ export enum ViewApply {
30
+ ROOMS = 'roomFilters',
31
+ }
@@ -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
- return (window.location.href = `${redirectUrl}/${selectedPath}${
133
- querySearchParams ? `?${querySearchParams.toString()}` : ''
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
 
@@ -1 +1,3 @@
1
- export { default } from "./FilterBar";
1
+ export { default } from './FilterBar'
2
+
3
+ export * from './FilterBarTypes'