forked from vtex-apps/search-result
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrderBy.js
67 lines (60 loc) · 1.44 KB
/
OrderBy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import PropTypes from 'prop-types'
import React, { useMemo } from 'react'
import { injectIntl, intlShape } from 'react-intl'
import SelectionListOrderBy from './components/SelectionListOrderBy'
import searchResult from './searchResult.css'
export const SORT_OPTIONS = [
{
value: 'OrderByTopSaleDESC',
label: 'store/ordenation.sales',
},
{
value: 'OrderByReleaseDateDESC',
label: 'store/ordenation.release.date',
},
{
value: 'OrderByBestDiscountDESC',
label: 'store/ordenation.discount',
},
{
value: 'OrderByPriceDESC',
label: 'store/ordenation.price.descending',
},
{
value: 'OrderByPriceASC',
label: 'store/ordenation.price.ascending',
},
{
value: 'OrderByNameASC',
label: 'store/ordenation.name.ascending',
},
{
value: 'OrderByNameDESC',
label: 'store/ordenation.name.descending',
},
]
const OrderBy = ({ orderBy, intl }) => {
const sortingOptions = useMemo(
() => {
return SORT_OPTIONS.map(({ value, label }) => {
return {
value: value,
label: intl.formatMessage({ id: label }),
}
})
},
[intl]
)
return (
<div className={searchResult.orderBy}>
<SelectionListOrderBy orderBy={orderBy} options={sortingOptions} />
</div>
)
}
OrderBy.propTypes = {
/** Which sorting option is selected. */
orderBy: PropTypes.string,
/** Intl instance. */
intl: intlShape,
}
export default injectIntl(OrderBy)