Skip to content
Snippets Groups Projects
Commit 682d3db8 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

fix: open correct month for newsletter editing

parent 78e0e525
No related branches found
No related tags found
1 merge request!103fix: open correct month for newsletter editing
Pipeline #61627 passed
...@@ -30,14 +30,18 @@ export type ContentItems = ...@@ -30,14 +30,18 @@ export type ContentItems =
| '' | ''
const Newsletter: React.FC = () => { const Newsletter: React.FC = () => {
// Functional rule : /**
// Display next month after the 3rd of the current month * Display previous month until the newsletter is sent on the 3rd day of the month
*/
const getCurrentNewsletterDate = (): Date => { const getCurrentNewsletterDate = (): Date => {
const newsletterDate = new Date() const today = new Date()
if (newsletterDate.getDate() >= 3) { const currentDay: number = today.getDate()
newsletterDate.setMonth(newsletterDate.getMonth() + 1) const currentMonth: number = today.getMonth()
} const currentYear: number = today.getFullYear()
return newsletterDate
return currentDay < 3
? new Date(currentYear, currentMonth - 1, 1)
: new Date(currentYear, currentMonth, 1)
} }
const [date, setDate] = useState<Date>(getCurrentNewsletterDate()) const [date, setDate] = useState<Date>(getCurrentNewsletterDate())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment