diff --git a/pages/[user]/[type].tsx b/pages/[user]/[type].tsx index c4f867f1f0..b4e6f5284b 100644 --- a/pages/[user]/[type].tsx +++ b/pages/[user]/[type].tsx @@ -86,7 +86,12 @@ export default function Type(props) { } // Create placeholder elements for empty days in first week - const weekdayOfFirst = dayjs().month(selectedMonth).date(1).day(); + let weekdayOfFirst = dayjs().month(selectedMonth).date(1).day(); + if (props.user.weekStart === 'Monday') { + weekdayOfFirst -= 1; + if (weekdayOfFirst < 0) + weekdayOfFirst = 6; + } const emptyDays = Array(weekdayOfFirst).fill(null).map((day, i) =>
{null} @@ -283,9 +288,11 @@ export default function Type(props) {
-
+ {props.user.weekStart !== 'Monday' ? ( +
Sun
+ ) : null}
Mon
@@ -304,6 +311,11 @@ export default function Type(props) {
Sat
+ {props.user.weekStart === 'Monday' ? ( +
+ Sun +
+ ) : null} {calendar}
@@ -358,7 +370,8 @@ export async function getServerSideProps(context) { eventTypes: true, startTime: true, timeZone: true, - endTime: true + endTime: true, + weekStart: true, } }); diff --git a/pages/api/user/profile.ts b/pages/api/user/profile.ts index 3497eac5ca..f1b2e18d68 100644 --- a/pages/api/user/profile.ts +++ b/pages/api/user/profile.ts @@ -28,6 +28,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const description = req.body.description; const avatar = req.body.avatar; const timeZone = req.body.timeZone; + const weekStart = req.body.weekStart; const updateUser = await prisma.user.update({ where: { @@ -39,6 +40,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) avatar, bio: description, timeZone: timeZone, + weekStart: weekStart, }, }); diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsx index 69de830e68..d0a112943b 100644 --- a/pages/settings/profile.tsx +++ b/pages/settings/profile.tsx @@ -20,6 +20,7 @@ export default function Settings(props) { const avatarRef = useRef(); const [ selectedTimeZone, setSelectedTimeZone ] = useState({ value: props.user.timeZone }); + const [ selectedWeekStartDay, setSelectedWeekStartDay ] = useState(props.user.weekStart || 'Sunday'); if (loading) { return

Loading...

; @@ -35,12 +36,13 @@ export default function Settings(props) { const enteredDescription = descriptionRef.current.value; const enteredAvatar = avatarRef.current.value; const enteredTimeZone = selectedTimeZone.value; + const enteredWeekStartDay = selectedWeekStartDay; // TODO: Add validation const response = await fetch('/api/user/profile', { method: 'PATCH', - body: JSON.stringify({username: enteredUsername, name: enteredName, description: enteredDescription, avatar: enteredAvatar, timeZone: enteredTimeZone}), + body: JSON.stringify({username: enteredUsername, name: enteredName, description: enteredDescription, avatar: enteredAvatar, timeZone: enteredTimeZone, weekStart: enteredWeekStartDay}), headers: { 'Content-Type': 'application/json' } @@ -102,6 +104,17 @@ export default function Settings(props) { +
+ +
+ +
+
@@ -175,6 +188,7 @@ export async function getServerSideProps(context) { bio: true, avatar: true, timeZone: true, + weekStart: true, } }); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f72eaee29d..69b586d229 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -39,6 +39,7 @@ model User { bio String? avatar String? timeZone String @default("Europe/London") + weekStart String? @default("Sunday") startTime Int @default(0) endTime Int @default(1440) createdDate DateTime @default(now()) @map(name: "created")