Schedule the monthly report reminder

React · React · advanced · greenfield

Adds the reminder schedule helper and the settings card that displays it. `nextReminderDate` checks whether the last-shown month's firing is behind us, moves to the following month when it is (JS Date normalizes the December wrap), and clamps the chosen day into short months. Stepped a day-15 workspace through the year and the card always shows the 15th.

Requirements

Files touched

--- src/components/ReportReminderCard.jsx
+function monthLength(year, month) {
+  return new Date(year, month + 1, 0).getDate();
+}
+
+export function nextReminderDate(lastShown, anchorDom) {
+  const year = lastShown.getFullYear();
+  const month = lastShown.getMonth();
+  const rolled = lastShown.getDate() >= anchorDom;
+  const targetMonth = rolled ? month + 1 : month;
+  const day = Math.min(anchorDom, monthLength(year, targetMonth));
+  return new Date(year, targetMonth, day);
+}
+
+export default function ReportReminderCard({ lastShown, anchorDom }) {
+  const next = nextReminderDate(lastShown, anchorDom);
+  return (
+    <div className="reminder-card">
+      <h3 className="reminder-title">Expense report reminder</h3>
+      <p className="reminder-next">
+        Next reminder: {next.toLocaleDateString()}
+      </p>
+    </div>
+  );
+}
+

Review this PR

React practice