-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
265 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ yarn-error.log* | |
next-env.d.ts | ||
|
||
.idea | ||
.turbo | ||
|
||
/private | ||
/.react-email |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/app/(site)/(internal)/dashboard/calendar/components/Calendar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
"use client" | ||
|
||
import {FC, useState} from "react"; | ||
import Select from "@/app/(site)/components/inputs/Select"; | ||
import { | ||
createDaysForCurrentMonth, | ||
createDaysForNextMonth, createDaysForPreviousMonth, | ||
daysOfWeek | ||
} from "@/app/(site)/(internal)/dashboard/calendar/utils/calendar-utils"; | ||
|
||
const Calendar: FC = () => { | ||
const [[year, month], setCurrentYearAndMonth] = useState<[number, number]>([new Date().getFullYear(), new Date().getMonth() + 1]); | ||
|
||
let currentMonthDays = createDaysForCurrentMonth(year, month); | ||
let previousMonthDays = createDaysForPreviousMonth( | ||
year, | ||
month, | ||
currentMonthDays | ||
); | ||
let nextMonthDays = createDaysForNextMonth(year, month, currentMonthDays); | ||
let calendarGridDayObjects = [ | ||
...previousMonthDays, | ||
...currentMonthDays, | ||
...nextMonthDays | ||
]; | ||
|
||
return ( | ||
<div id="calendar-root" className="flex flex-col justify-center w-3/4 phone:w-5/6"> | ||
<div id="calendar-nav" className="flex justify-center mb-12 gap-4"> | ||
<div className="flex w-1/2 gap-2"> | ||
<Select | ||
label="Month" | ||
id="month_selector" | ||
items={[]} | ||
> | ||
{(item) => <></>} | ||
</Select> | ||
<Select | ||
label="Year" | ||
id="year_selector" | ||
items={[]} | ||
> | ||
{(item) => <></>} | ||
</Select> | ||
</div> | ||
|
||
</div> | ||
<div id="days_of_week" className="grid grid-cols-7 mb-4 tablet:hidden"> | ||
{daysOfWeek.map((day, i) => ( | ||
<p | ||
className="text-center font-semibold" | ||
key={i} | ||
> | ||
{day} | ||
</p> | ||
|
||
))} | ||
</div> | ||
<div id="days_of_week" | ||
className="grid grid-cols-7 bg-primary p-2 font-semibold text-xl phone:text-medium tablet:border-x-1 tablet:border-primary tablet-min:hidden"> | ||
{daysOfWeek.map((day, i) => ( | ||
<p | ||
key={i} | ||
className="text-center font-semibold" | ||
> | ||
{day.charAt(0)} | ||
</p> | ||
|
||
))} | ||
</div> | ||
<div id="days-grid" className="grid grid-cols-7 tablet:border-x-1 tablet:border-primary"> | ||
{ | ||
calendarGridDayObjects.map(day => ( | ||
<div | ||
key={day.dateString} | ||
className="h-fit border border-primary tablet:border-0 tablet:border-b-1" | ||
> | ||
<div | ||
className="bg-primary tablet:bg-[#9E23FF1A] p-2 font-semibold text-xl phone:text-medium"> | ||
{day.dayOfMonth} | ||
</div> | ||
<div className="p-2 bg-[#9E23FF1A]"> | ||
hi | ||
</div> | ||
</div> | ||
)) | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Calendar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {FC, Fragment} from "react"; | ||
import Calendar from "@/app/(site)/(internal)/dashboard/calendar/components/Calendar"; | ||
|
||
const CalendarPage: FC = () => { | ||
return ( | ||
<Fragment> | ||
<h1 className="font-bold text-7xl phone:text-5xl mb-24 phone:mb-10">Dream Calendar</h1> | ||
<Calendar/> | ||
</Fragment> | ||
) | ||
} | ||
|
||
export default CalendarPage |
100 changes: 100 additions & 0 deletions
100
src/app/(site)/(internal)/dashboard/calendar/utils/calendar-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { range } from "ramda"; | ||
import dayjs from "dayjs"; | ||
import weekday from "dayjs/plugin/weekday"; | ||
import weekOfYear from "dayjs/plugin/weekOfYear"; | ||
|
||
dayjs.extend(weekday); | ||
dayjs.extend(weekOfYear); | ||
|
||
export const daysOfWeek = [ | ||
"Sunday", | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
"Saturday" | ||
]; | ||
|
||
export function getYearDropdownOptions(currentYear: number) { | ||
let minYear = currentYear - 4; | ||
let maxYear = currentYear + 5; | ||
return range(minYear, maxYear + 1).map((y) => ({ label: `${y}`, value: y })); | ||
} | ||
|
||
export function getMonthDropdownOptions() { | ||
return range(1, 13).map((m) => ({ | ||
value: m, | ||
label: dayjs() | ||
.month(m - 1) | ||
.format("MMMM") | ||
})); | ||
} | ||
|
||
export function getNumberOfDaysInMonth(year: number, month: number) { | ||
return dayjs(`${year}-${month}-01`).daysInMonth(); | ||
} | ||
|
||
export function createDaysForCurrentMonth(year: number, month: number) { | ||
return [...Array(getNumberOfDaysInMonth(year, month))].map((_, index) => { | ||
return { | ||
dateString: dayjs(`${year}-${month}-${index + 1}`).format("YYYY-MM-DD"), | ||
dayOfMonth: index + 1, | ||
isCurrentMonth: true | ||
}; | ||
}); | ||
} | ||
|
||
export function createDaysForPreviousMonth(year: number, month: number, currentMonthDays: any[]) { | ||
const firstDayOfTheMonthWeekday = getWeekday(currentMonthDays[0].dateString); | ||
const previousMonth = dayjs(`${year}-${month}-01`).subtract(1, "month"); | ||
|
||
const visibleNumberOfDaysFromPreviousMonth = firstDayOfTheMonthWeekday; | ||
|
||
const previousMonthLastMondayDayOfMonth = dayjs( | ||
currentMonthDays[0].dateString | ||
) | ||
.subtract(visibleNumberOfDaysFromPreviousMonth, "day") | ||
.date(); | ||
|
||
return [...Array(visibleNumberOfDaysFromPreviousMonth)].map((_, index) => { | ||
return { | ||
dateString: dayjs( | ||
`${previousMonth.year()}-${previousMonth.month() + 1}-${ | ||
previousMonthLastMondayDayOfMonth + index | ||
}` | ||
).format("YYYY-MM-DD"), | ||
dayOfMonth: previousMonthLastMondayDayOfMonth + index, | ||
isCurrentMonth: false, | ||
isPreviousMonth: true | ||
}; | ||
}); | ||
} | ||
|
||
export function createDaysForNextMonth(year: number, month: number, currentMonthDays: any) { | ||
const lastDayOfTheMonthWeekday = getWeekday( | ||
`${year}-${month}-${currentMonthDays.length}` | ||
); | ||
const nextMonth = dayjs(`${year}-${month}-01`).add(1, "month"); | ||
const visibleNumberOfDaysFromNextMonth = 6 - lastDayOfTheMonthWeekday; | ||
|
||
return [...Array(visibleNumberOfDaysFromNextMonth)].map((day, index) => { | ||
return { | ||
dateString: dayjs( | ||
`${nextMonth.year()}-${nextMonth.month() + 1}-${index + 1}` | ||
).format("YYYY-MM-DD"), | ||
dayOfMonth: index + 1, | ||
isCurrentMonth: false, | ||
isNextMonth: true | ||
}; | ||
}); | ||
} | ||
|
||
// sunday === 0, saturday === 6 | ||
export function getWeekday(dateString: string) { | ||
return dayjs(dateString).weekday(); | ||
} | ||
|
||
export function isWeekendDay(dateString: string) { | ||
return [6, 0].includes(getWeekday(dateString)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "https://turbo.build/schema.json", | ||
"pipeline": { | ||
"build": { | ||
"outputs": [".next/**", "!.next/cache/**"] | ||
}, | ||
"lint": {} | ||
} | ||
} |