Skip to content

Commit

Permalink
fix: rebase 664
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Mar 13, 2023
1 parent 4d9086b commit 128291a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 16 deletions.
62 changes: 61 additions & 1 deletion apps/storefront/src/components/filter/B3FilterMore.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import FilterListIcon from '@mui/icons-material/FilterList'
import {
Box,
Grid,
} from '@mui/material'

import Button from '@mui/material/Button'
Expand All @@ -15,6 +16,7 @@ import {
useRef,
BaseSyntheticEvent,
ReactElement,
useEffect,
} from 'react'

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

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

Expand All @@ -98,13 +102,40 @@ const B3FilterMore:<T, Y> ({
setOpen(false)
}

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] === '')
Object.keys(submitData).forEach((item) => {
if (submitData[item] !== '') {
filterCountArr.push(item)
}
})

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

// useEffect(() => {
// handleFilterStatus()
// }, [startPicker, endPicker])

const handleSaveFilters = (event: BaseSyntheticEvent<object, any, any> | undefined) => {
handleSubmit((data) => {
const getPickerValues = pickerRef.current?.getPickerValue()
if (onChange) {
const submitData: any = {
...getPickerValues, ...data,
}

handleFilterStatus(submitData)
onChange(submitData)
}
handleClose()
Expand All @@ -117,6 +148,8 @@ const B3FilterMore:<T, Y> ({
})
pickerRef.current?.setClearPickerValue()

handleFilterStatus()

if (handleChange) {
handleChange()
}
Expand All @@ -133,7 +166,34 @@ const B3FilterMore:<T, Y> ({
{
((fiterMoreInfo && fiterMoreInfo.length) || isShowMore) && (
<Box onClick={handleDialogClick}>
<FilterListIcon />
{
!isFiltering && <FilterListIcon />
}
{
isFiltering && (
<>
<FilterListIcon />
<Box
sx={{
display: 'flex',
flexFlow: 'row wrap',
backgroundColor: '#ff8a65',
borderRadius: '50px',
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
position: 'absolute',
top: '7px',
padding: '0 7px',
transform: 'scale(1) translate(50%, -50%)',
transformOrigin: '100% 0%',
}}
>
{filterCounter}
</Box>
</>
)
}
</Box>
)
}
Expand Down
2 changes: 0 additions & 2 deletions apps/storefront/src/components/filter/B3FilterPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const B3FilterPickers = ({
const setClearPickerValue = () => {
setStartValue(isMonthlySpacing ? distanceDay(30) : '')
setEndValue(isMonthlySpacing ? distanceDay() : '')
console.log(startPicker?.defaultValue, 'startPicker?.defaultValue')
console.log(endPicker?.defaultValue, 'endPicker?.defaultValue')
}

useEffect(() => {
Expand Down
15 changes: 2 additions & 13 deletions apps/storefront/src/pages/order/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,7 @@ const Order = ({
orderBy: value,
})
} else if (key === 'clear') {
// const search: Partial<FilterSearchProps> = {
// beginDateAt: null,
// endDateAt: null,
// createdBy: '',
// statusCode: '',
// companyName: '',
// }
// setFilterData({
// ...filterData,
// })
setIsClearFilter(true)
console.log(isClearFilter)
}
}

Expand Down Expand Up @@ -315,13 +304,13 @@ const Order = ({
startPicker={{
isEnabled: true,
label: 'From',
defaultValue: isClearFilter ? null : (filterData?.beginDateAt || null),
defaultValue: filterData?.beginDateAt || null,
pickerKey: 'start',
}}
endPicker={{
isEnabled: true,
label: 'To',
defaultValue: isClearFilter ? null : (filterData?.beginDateAt || null),
defaultValue: filterData?.beginDateAt || null,
pickerKey: 'end',
}}
fiterMoreInfo={filterInfo}
Expand Down

0 comments on commit 128291a

Please sign in to comment.