-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMonthSelect.js
More file actions
100 lines (94 loc) · 2.14 KB
/
MonthSelect.js
File metadata and controls
100 lines (94 loc) · 2.14 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { Select } from '@chakra-ui/react'
import { any, func } from 'prop-types'
import React from 'react'
import { t } from "@lingui/core/macro"
export function MonthSelect({ selectedValue, handleChange, ...props }) {
const currentDate = new Date()
const months = [
{
value: 'January',
text: t`January`,
},
{
value: 'February',
text: t`February`,
},
{
value: 'March',
text: t`March`,
},
{
value: 'April',
text: t`April`,
},
{
value: 'May',
text: t`May`,
},
{
value: 'June',
text: t`June`,
},
{
value: 'July',
text: t`July`,
},
{
value: 'August',
text: t`August`,
},
{
value: 'September',
text: t`September`,
},
{
value: 'October',
text: t`October`,
},
{
value: 'November',
text: t`November`,
},
{
value: 'December',
text: t`December`,
},
]
const options = [
<option key="LAST30DAYS" value={`LAST30DAYS, ${currentDate.getFullYear().toString()}`}>
{t`Last 30 Days of Data`}
</option>,
]
// add dmarc date selection options
for (let i = currentDate.getMonth(), j = 13; j > 0; i--, j--) {
// handle previous year
if (i < 0) {
const value = `${months[months.length + i].value.toUpperCase()}, ${currentDate.getFullYear() - 1}`
const translatedValue = `${months[months.length + i].text.toUpperCase()}, ${currentDate.getFullYear() - 1}`
options.push(
<option key={value} value={value}>
{translatedValue}
</option>,
)
}
// handle current year
else {
const value = `${months[i].value.toUpperCase()}, ${currentDate.getFullYear()}`
const translatedValue = `${months[i].text.toUpperCase()}, ${currentDate.getFullYear()}`
options.push(
<option key={value} value={value}>
{translatedValue}
</option>,
)
}
}
return (
<Select {...props} value={selectedValue} onChange={(e) => handleChange(e)}>
{options}
</Select>
)
}
MonthSelect.propTypes = {
selectedValue: any,
handleChange: func,
}