Skip to content

Commit

Permalink
fix: clear filters issue
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Mar 13, 2023
1 parent 3917ee8 commit e21bcd4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions apps/storefront/src/components/filter/B3FilterMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ const B3FilterMore:<T, Y> ({
}

const handleFilterStatus = (submitData?: any) => {
const startTime = startPicker?.defaultValue
const endTime = endPicker?.defaultValue

if (submitData) {
const filterCountArr = []
const isNotFiltering = Object.keys(submitData).every((item) => submitData[item] === '')
Expand All @@ -111,10 +108,7 @@ const B3FilterMore:<T, Y> ({
})

setIsFiltering(!isNotFiltering)
setFilterCounter(startTime && endTime ? filterCountArr.length - 1 : filterCountArr.length)
} else {
setIsFiltering(false)
setFilterCounter(0)
setFilterCounter(filterCountArr.length)
}
}

Expand All @@ -134,12 +128,25 @@ const B3FilterMore:<T, Y> ({
}

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

handleFilterStatus()
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 e21bcd4

Please sign in to comment.