Skip to content

Commit

Permalink
fix: clear filter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Mar 15, 2023
1 parent 8df88cb commit 9145c96
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions apps/storefront/src/components/filter/B3FilterMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useRef,
BaseSyntheticEvent,
ReactElement,
useEffect,
} from 'react'

import {
Expand Down Expand Up @@ -73,6 +74,8 @@ const B3FilterMore:<T, Y> ({
const [isFiltering, setIsFiltering] = useState<boolean>(false)
const [filterCounter, setFilterCounter] = useState<number>(0)

const [cacheData, setCacheData] = useState<CustomFieldItems | null>(null)

const pickerRef = useRef<PickerRefProps | null>(null)

const {
Expand All @@ -89,6 +92,14 @@ const B3FilterMore:<T, Y> ({

const [isMobile] = useMobile()

useEffect(() => {
if (cacheData) {
Object.keys(cacheData).forEach((item: string) => {
setValue(item, cacheData[item])
})
}
}, [open])

const handleDialogClick = () => {
setOpen(true)
}
Expand Down Expand Up @@ -122,31 +133,20 @@ const B3FilterMore:<T, Y> ({

handleFilterStatus(submitData)
onChange(submitData)

setCacheData({
...data,
})
}
handleClose()
})(event)
}

const handleClearFilters = () => {
const restFilterData: { [x: string]: string } = {}
Object.keys(getValues()).forEach((item: string) => {
setValue(item, '')
restFilterData[item] = ''
})
pickerRef.current?.setClearPickerValue()

if (startPicker && endPicker) {
startPicker.defaultValue = ''
endPicker.defaultValue = ''
}

const submitData: any = {
startValue: startPicker?.defaultValue || '',
endValue: endPicker?.defaultValue || '',
...restFilterData,
}

handleFilterStatus(submitData)
}

return (
Expand Down

0 comments on commit 9145c96

Please sign in to comment.