Skip to content

Commit 28906d3

Browse files
authored
Merge pull request #2302 from objectcomputing/feature-2297-anniversaries-query-parameters
added use of useQueryParameters in AnniversaryReportPage.jsx
2 parents 431d98a + a2eb985 commit 28906d3

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

web-ui/src/pages/AnniversaryReportPage.jsx

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,47 @@ import SearchBirthdayAnniversaryResults from '../components/search-results/Searc
1313
import { sortAnniversaries } from '../context/util';
1414

1515
import { selectCsrfToken } from '../context/selectors';
16+
import { useQueryParameters } from '../helpers/query-parameters';
1617

1718
const months = [
18-
{ month: 'January' },
19-
{ month: 'February' },
20-
{ month: 'March' },
21-
{ month: 'April' },
22-
{ month: 'May' },
23-
{ month: 'June' },
24-
{ month: 'July' },
25-
{ month: 'August' },
26-
{ month: 'September' },
27-
{ month: 'October' },
28-
{ month: 'November' },
29-
{ month: 'December' }
19+
'January',
20+
'February',
21+
'March',
22+
'April',
23+
'May',
24+
'June',
25+
'July',
26+
'August',
27+
'September',
28+
'October',
29+
'November',
30+
'December'
3031
];
3132

3233
const AnniversaryReportPage = () => {
34+
const currentMonth = new Date().getMonth();
35+
const defaultMonths = [months[currentMonth]];
36+
3337
const { state } = useContext(AppContext);
3438
const csrf = selectCsrfToken(state);
3539
const [searchAnniversaryResults, setSearchAnniversaryResults] = useState([]);
36-
const currentMonth = new Date().getMonth();
37-
const [selectedMonths, setSelectedMonths] = useState([months[currentMonth]]);
40+
const [selectedMonths, setSelectedMonths] = useState(defaultMonths);
3841
const [hasSearched, setHasSearched] = useState(false);
3942

43+
useQueryParameters([
44+
{
45+
name: 'months',
46+
default: defaultMonths,
47+
value: selectedMonths,
48+
setter: setSelectedMonths,
49+
toQP(value) {
50+
return value ? value.join(',') : [];
51+
}
52+
}
53+
]);
54+
4055
const handleSearch = async monthsToSearch => {
41-
const months = monthsToSearch.map(m => m.month);
42-
const anniversaryResults = await getAnniversaries(months, csrf);
56+
const anniversaryResults = await getAnniversaries(monthsToSearch, csrf);
4357
setSearchAnniversaryResults(sortAnniversaries(anniversaryResults));
4458
setHasSearched(true);
4559
};
@@ -55,13 +69,12 @@ const AnniversaryReportPage = () => {
5569
multiple
5670
id="monthSelect"
5771
options={months}
58-
defaultValue={[months[currentMonth].month]}
72+
defaultValue={defaultMonths}
5973
value={selectedMonths}
6074
onChange={onMonthChange}
6175
isOptionEqualToValue={(option, value) => {
62-
return value ? value.month === option.month : false;
76+
return value ? value === option : false;
6377
}}
64-
getOptionLabel={option => option.month}
6578
renderInput={params => (
6679
<TextField
6780
{...params}

0 commit comments

Comments
 (0)