Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate away from react-infinite-calendar #1419 #1621

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"history": "4.10.1",
"postinstall-postinstall": "^2.1.0",
"react": "18.2.0",
"react-calendar": "^5.1.0",
"react-dom": "18.2.0",
"react-infinite-calendar": "2.3.1",
"react-number-format": "4.9.4",
"react-router": "5.3.4",
"react-router-dom": "5.3.4",
Expand Down
90 changes: 18 additions & 72 deletions src/components/TransactionDateRangeFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import React, { useState } from "react";
import { styled } from "@mui/material/styles";
import { format as formatDate } from "date-fns";
import { Popover, Chip, useTheme, Drawer, Button, useMediaQuery, colors } from "@mui/material";
import { Popover, Chip, useTheme, Drawer, Button, useMediaQuery } from "@mui/material";
import { ArrowDropDown as ArrowDropDownIcon, Cancel as CancelIcon } from "@mui/icons-material";
import InfiniteCalendar, { Calendar, withRange } from "react-infinite-calendar";
import Calendar from "react-calendar";
import "react-calendar/dist/Calendar.css";

import "react-infinite-calendar/styles.css";
import { TransactionDateRangePayload } from "../models";
import { hasDateQueryFields } from "../utils/transactionUtils";

Expand All @@ -26,9 +26,6 @@ const Root = styled("div")(({ theme }) => ({
},
}));

const { indigo } = colors;
const CalendarWithRange = withRange(Calendar);

export type TransactionListDateRangeFilterProps = {
filterDateRange: Function;
dateRangeFilters: TransactionDateRangePayload;
Expand All @@ -44,13 +41,15 @@ const TransactionListDateRangeFilter: React.FC<TransactionListDateRangeFilterPro
const xsBreakpoint = useMediaQuery(theme.breakpoints.only("xs"));
const queryHasDateFields = dateRangeFilters && hasDateQueryFields(dateRangeFilters);

const [dateRangeAnchorEl, setDateRangeAnchorEl] = React.useState<HTMLDivElement | null>(null);
const [dateRangeAnchorEl, setDateRangeAnchorEl] = useState<HTMLDivElement | null>(null);
const [dateRange, setDateRange] = useState<[Date, Date] | null>(null);

const onCalendarSelect = (e: { eventType: number; start: any; end: any }) => {
if (e.eventType === 3) {
const onCalendarSelect = (value: Date | [Date, Date]) => {
if (Array.isArray(value)) {
setDateRange(value);
filterDateRange({
dateRangeStart: new Date(e.start.setUTCHours(0, 0, 0, 0)).toISOString(),
dateRangeEnd: new Date(e.end.setUTCHours(23, 59, 59, 999)).toISOString(),
dateRangeStart: value[0].toISOString(),
dateRangeEnd: value[1].toISOString(),
});
setDateRangeAnchorEl(null);
}
Expand All @@ -67,9 +66,7 @@ const TransactionListDateRangeFilter: React.FC<TransactionListDateRangeFilterPro
const dateRangeOpen = Boolean(dateRangeAnchorEl);
const dateRangeId = dateRangeOpen ? "date-range-popover" : undefined;

const formatButtonDate = (date: string) => {
return formatDate(new Date(date), "MMM, d yyyy");
};
const formatButtonDate = (date: string) => formatDate(new Date(date), "MMM d, yyyy");

const dateRangeLabel = (dateRangeFields: TransactionDateRangePayload) => {
const { dateRangeStart, dateRangeEnd } = dateRangeFields;
Expand All @@ -83,7 +80,6 @@ const TransactionListDateRangeFilter: React.FC<TransactionListDateRangeFilterPro
color="primary"
variant="outlined"
onClick={handleDateRangeClick}
data-test="transaction-list-filter-date-range-button"
label={"Date: ALL"}
deleteIcon={<ArrowDropDownIcon />}
onDelete={handleDateRangeClick}
Expand All @@ -94,12 +90,9 @@ const TransactionListDateRangeFilter: React.FC<TransactionListDateRangeFilterPro
color="primary"
variant="outlined"
onClick={handleDateRangeClick}
data-test="transaction-list-filter-date-range-button"
label={`Date: ${dateRangeLabel(dateRangeFilters)}`}
deleteIcon={<CancelIcon data-test="transaction-list-filter-date-clear-button" />}
onDelete={() => {
resetDateRange();
}}
deleteIcon={<CancelIcon />}
onDelete={() => resetDateRange()}
/>
)}
{!xsBreakpoint && (
Expand All @@ -118,65 +111,18 @@ const TransactionListDateRangeFilter: React.FC<TransactionListDateRangeFilterPro
}}
className={classes.popover}
>
<InfiniteCalendar
data-test="transaction-list-filter-date-range"
width={xsBreakpoint ? window.innerWidth : 350}
height={xsBreakpoint ? window.innerHeight : 300}
rowHeight={50}
Component={CalendarWithRange}
selected={false}
onSelect={onCalendarSelect}
locale={{
headerFormat: "MMM Do",
}}
theme={{
accentColor: indigo["400"],
headerColor: indigo["500"],
weekdayColor: indigo["300"],
selectionColor: indigo["300"],
floatingNav: {
background: indigo["400"],
color: "#FFF",
chevron: "#FFA726",
},
}}
/>
<Calendar selectRange onChange={onCalendarSelect} value={dateRange} />
</Popover>
)}
{xsBreakpoint && (
<Drawer
id={dateRangeId}
open={dateRangeOpen}
ModalProps={{ onClose: handleDateRangeClose }}
onClose={handleDateRangeClose}
anchor="bottom"
data-test="date-range-filter-drawer"
>
<Button data-test="date-range-filter-drawer-close" onClick={() => handleDateRangeClose()}>
Close
</Button>
<InfiniteCalendar
data-test="transaction-list-filter-date-range"
width={window.innerWidth}
height={window.innerHeight - 185}
rowHeight={50}
Component={CalendarWithRange}
selected={false}
onSelect={onCalendarSelect}
locale={{
headerFormat: "MMM Do",
}}
theme={{
accentColor: indigo["400"],
headerColor: indigo["500"],
weekdayColor: indigo["300"],
selectionColor: indigo["300"],
floatingNav: {
background: indigo["400"],
color: "#FFF",
chevron: "#FFA726",
},
}}
/>
<Button onClick={handleDateRangeClose}>Close</Button>
<Calendar selectRange onChange={onCalendarSelect} value={dateRange} />
</Drawer>
)}
</Root>
Expand Down
Loading