Skip to content

Commit

Permalink
feat(faq): add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
aliceoq committed Feb 7, 2024
1 parent 30b8ef2 commit 186555a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/pages/faq/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import startHereImage from '../../../public/images/faq.png'
import Pagination from 'components/pagination'
import { localeType } from 'utils/navigation-utils'
import Select from 'components/select'
import { sortBy } from 'utils/constants'
import { faqFilter, sortBy } from 'utils/constants'
import FaqCard from 'components/faq-card'
import Filter from 'components/filter'

interface Props {
sidebarfallback: any //eslint-disable-line
Expand All @@ -37,10 +38,13 @@ const FaqPage: NextPage<Props> = ({ faqData, branch }) => {
setBranchPreview(branch)
const itemsPerPage = 10
const [page, setPage] = useState({ curr: 1, total: 1 })
const [filters, setFilters] = useState<string[]>([])
const [sortByValue, setSortByValue] = useState<sortByType>('newest')

const filteredResult = useMemo(() => {
const data = faqData
const data = faqData.filter((question) => {
return filters.length === 0 || filters.includes(question.productTeam)
})

data.sort((a, b) => {
const dateA =
Expand All @@ -54,7 +58,7 @@ const FaqPage: NextPage<Props> = ({ faqData, branch }) => {
setPage({ curr: 1, total: Math.ceil(data.length / itemsPerPage) })

return data
}, [sortByValue, intl.locale])
}, [filters, sortByValue, intl.locale])

const paginatedResult = useMemo(() => {
return filteredResult.slice(
Expand Down Expand Up @@ -98,7 +102,11 @@ const FaqPage: NextPage<Props> = ({ faqData, branch }) => {
})}
/>
<Flex sx={styles.container}>
<Flex sx={styles.optionContainer}>
<Flex sx={styles.optionsContainer}>
<Filter
checkBoxFilter={faqFilter(intl)}
onApply={(newFilters) => setFilters(newFilters.checklist)}
/>
<Select
label={intl.formatMessage({ id: 'sort.label' })}
value={sortByValue}
Expand Down
62 changes: 62 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,65 @@ export const sortBy = (intl: IntlShape) => {

return data
}

export const faqFilter = (intl: IntlShape) => {
const data = {
name: intl.formatMessage({ id: 'faq_filter.title' }),
options: [
{
id: 'Shopping',
name: 'Shopping',
},
{
id: 'Post-purchase',
name: 'Post-purchase',
},
{
id: 'Marketing & Merchandising',
name: 'Marketing & Merchandising',
},
{
id: 'Financial',
name: 'Financial',
},
{
id: 'Channels',
name: 'Channels',
},
{
id: 'VTEX IO',
name: 'VTEX IO',
},
{
id: 'Master Data',
name: 'Master Data',
},
{
id: 'Identity',
name: 'Identity',
},
{
id: 'Reliability',
name: 'Reliability',
},
{
id: 'Others',
name: 'Others',
},
{
id: 'Apps',
name: 'Apps',
},
{
id: 'Billing',
name: 'Billing',
},
{
id: 'Management',
name: 'Management',
},
],
}

return data
}

0 comments on commit 186555a

Please sign in to comment.