Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions web-ui/src/pages/AnniversaryReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,47 @@ import SearchBirthdayAnniversaryResults from '../components/search-results/Searc
import { sortAnniversaries } from '../context/util';

import { selectCsrfToken } from '../context/selectors';
import { useQueryParameters } from '../helpers/query-parameters';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here are identical to those in the PR at #2301.


const months = [
{ month: 'January' },
{ month: 'February' },
{ month: 'March' },
{ month: 'April' },
{ month: 'May' },
{ month: 'June' },
{ month: 'July' },
{ month: 'August' },
{ month: 'September' },
{ month: 'October' },
{ month: 'November' },
{ month: 'December' }
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];

const AnniversaryReportPage = () => {
const currentMonth = new Date().getMonth();
const defaultMonths = [months[currentMonth]];

const { state } = useContext(AppContext);
const csrf = selectCsrfToken(state);
const [searchAnniversaryResults, setSearchAnniversaryResults] = useState([]);
const currentMonth = new Date().getMonth();
const [selectedMonths, setSelectedMonths] = useState([months[currentMonth]]);
const [selectedMonths, setSelectedMonths] = useState(defaultMonths);
const [hasSearched, setHasSearched] = useState(false);

useQueryParameters([
{
name: 'months',
default: defaultMonths,
value: selectedMonths,
setter: setSelectedMonths,
toQP(value) {
return value ? value.join(',') : [];
}
}
]);

const handleSearch = async monthsToSearch => {
const months = monthsToSearch.map(m => m.month);
const anniversaryResults = await getAnniversaries(months, csrf);
const anniversaryResults = await getAnniversaries(monthsToSearch, csrf);
setSearchAnniversaryResults(sortAnniversaries(anniversaryResults));
setHasSearched(true);
};
Expand All @@ -55,13 +69,12 @@ const AnniversaryReportPage = () => {
multiple
id="monthSelect"
options={months}
defaultValue={[months[currentMonth].month]}
defaultValue={defaultMonths}
value={selectedMonths}
onChange={onMonthChange}
isOptionEqualToValue={(option, value) => {
return value ? value.month === option.month : false;
return value ? value === option : false;
}}
getOptionLabel={option => option.month}
renderInput={params => (
<TextField
{...params}
Expand Down