Skip to content

Commit 4aca13d

Browse files
fix: monthly date offsets (#476)
* fix: next occurrence date in monthly schedule * fix: console warning on home page * chore: remove unused type * chore: add comment about timezone use in monthly schedule * Update HomeButtons.test.tsx * test: update homelink mock in homebutton.test Co-authored-by: Jeremiah Tabb <51095001+jollyjerr@users.noreply.github.com>
1 parent 30f4904 commit 4aca13d

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

packages/web/src/components/HomeButtons.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import Box from "@material-ui/core/Box";
1616
import Grid from "@material-ui/core/Grid";
1717
import HomeButton from "./HomeButton";
18-
import { HomeRouterLink } from "./HomeLink";
18+
import HomeLink from "./HomeLink";
1919
import React from "react";
2020
import { THomeButtonRouterLink } from "../webTypes";
2121
import { colors } from "@upswyng/common";
@@ -139,7 +139,7 @@ const HomeButtons = () => {
139139
<Grid item xs={6} key={button.text}>
140140
<Box
141141
alignContent="stretch"
142-
component={HomeRouterLink}
142+
component={HomeLink}
143143
display="flex"
144144
height="100%"
145145
{...button}
@@ -158,7 +158,7 @@ const HomeButtons = () => {
158158
<Grid item xs={12}>
159159
<Box
160160
alignContent="stretch"
161-
component={HomeRouterLink}
161+
component={HomeLink}
162162
display="flex"
163163
height="100%"
164164
{...coordinatedEntryButton}
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1-
import { THomeButtonAnchor, THomeButtonRouterLink } from "../webTypes";
2-
31
import { Link } from "react-router-dom";
42
import React from "react";
3+
import { THomeButtonRouterLink } from "../webTypes";
54

65
interface HomeLinkPropsBase {
76
children: React.ReactElement | React.ReactElement[];
87
}
98

10-
type HomeRouterLinkProps = HomeLinkPropsBase & THomeButtonRouterLink;
11-
type HomeAnchorProps = HomeLinkPropsBase &
12-
THomeButtonAnchor &
13-
React.HTMLProps<HTMLAnchorElement>;
9+
type HomeLink = HomeLinkPropsBase & THomeButtonRouterLink;
1410

15-
export const HomeRouterLink = (props: HomeRouterLinkProps) => {
16-
const { children, linkProps, ...rest } = props;
11+
const HomeLink = (props: HomeLink) => {
12+
const { children, linkProps } = props;
1713
return (
18-
<Link {...linkProps} {...rest}>
14+
<Link style={{ textDecoration: "none" }} {...linkProps}>
1915
{children}
2016
</Link>
2117
);
2218
};
2319

24-
export const HomeAnchorLink = (props: HomeAnchorProps) => {
25-
const { children, ...rest } = props;
26-
return <a {...rest}>{children}</a>;
27-
};
28-
29-
export default HomeRouterLink;
20+
export default HomeLink;

packages/web/src/components/MonthlySchedule.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,23 @@ const MonthlySchedule = ({ items }: { items: TScheduleItem[] }) => {
4040
return null;
4141
}
4242

43-
const nextOccurenceDate = items[0].recurrenceRule
44-
.all()[0]
45-
.toLocaleString(undefined, { month: "short", day: "numeric" });
43+
const nextOccurrenceDate = items[0].recurrenceRule.all()[0];
44+
const nextOccurenceDateString = new Date(
45+
nextOccurrenceDate
46+
).toLocaleString(undefined, {
47+
month: "short",
48+
day: "numeric",
49+
// the rrule date is UTC-based
50+
timeZone: "UTC",
51+
});
52+
4653
return (
4754
<Grid item xs={12} key={rRuleText}>
4855
<Grid container spacing={6}>
4956
<Grid item xs={6}>
50-
<Typography component="h3">{nextOccurenceDate}</Typography>
57+
<Typography component="h3">
58+
{nextOccurenceDateString}
59+
</Typography>
5160
<Typography variant="caption">repeats {rRuleText}</Typography>
5261
</Grid>
5362
<Grid item xs={6}>

packages/web/src/components/__tests__/HomeButtons.test.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import HomeButtons, { routerLinkButtons } from "../HomeButtons";
33
import React from "react";
44
import { render } from "@testing-library/react";
55

6-
jest.mock("../HomeLink", () => ({
7-
HomeRouterLink: ({ children }: { children: React.ReactChildren }) => (
6+
jest.mock(
7+
"../HomeLink",
8+
() => ({ children }: { children: React.ReactChildren }) => (
89
<div>{children}</div>
9-
),
10-
}));
10+
)
11+
);
12+
1113
jest.mock("react-i18next", () => ({
12-
// this mock makes sure any components using the translate hook can use it without a warning being shown
1314
useTranslation: () => {
1415
return {
1516
t: (str: string) => str,
@@ -24,6 +25,7 @@ describe("<HomeButtons/>", () => {
2425
const routerLinkTexts = routerLinkButtons.map(
2526
({ translationKey }) => translationKey
2627
);
28+
2729
it.each(routerLinkTexts)("renders the %s button", text => {
2830
const { getByText } = render(<HomeButtons />);
2931
expect(getByText(text)).toBeInTheDocument();

packages/web/src/webTypes.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ interface THomeButtonBase {
5454
text: string;
5555
translationKey: string;
5656
}
57-
export interface THomeButtonAnchor extends THomeButtonBase {
58-
href: string;
59-
target: string;
60-
rel: string;
61-
}
6257

6358
export interface THomeButtonRouterLink extends THomeButtonBase {
6459
linkProps: LinkProps;

0 commit comments

Comments
 (0)