Skip to content
Snippets Groups Projects

fix: open correct month for newsletter editing

All threads resolved!
1 file
+ 11
7
Compare changes
  • Side-by-side
  • Inline
@@ -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)
 
: new Date(currentYear, currentMonth + 1, 1)
}
}
const [date, setDate] = useState<Date>(getCurrentNewsletterDate())
const [date, setDate] = useState<Date>(getCurrentNewsletterDate())
Loading