Skip to content

Your favorite shift management application!

feat: Adds calendar locking and preset stats exclusion (#16)

panteLc3797c6b6d83
diff --git a/app/api/calendars/[id]/route.ts b/app/api/calendars/[id]/route.ts
index 6022a95..e7f90d4 100644
--- a/app/api/calendars/[id]/route.ts
+++ b/app/api/calendars/[id]/route.ts
@@ -47,7 +47,7 @@ export async function PATCH(
try {
const { id } = await params;
const body = await request.json();
- const { name, color, password, currentPassword } = body;
+ const { name, color, password, currentPassword, isLocked } = body;
// Fetch current calendar to check password
const [existingCalendar] = await db
@@ -62,7 +62,7 @@ export async function PATCH(
);
}
- // Verify password if calendar is protected
+ // Always verify password if calendar is protected
if (existingCalendar.passwordHash) {
if (
!currentPassword ||
@@ -80,6 +80,20 @@ export async function PATCH(
if (color) updateData.color = color;
if (password !== undefined) {
updateData.passwordHash = password ? hashPassword(password) : null;
+ // If removing password, also unlock calendar
+ if (password === null) {
+ updateData.isLocked = false;
+ }
+ }
+ if (isLocked !== undefined) {
+ // Only allow locking if password exists or is being set
+ if (isLocked && !existingCalendar.passwordHash && !password) {
+ return NextResponse.json(
+ { error: "Cannot lock calendar without password" },
+ { status: 400 }
+ );
+ }
+ updateData.isLocked = isLocked;
}
const [calendar] = await db
diff --git a/app/api/calendars/route.ts b/app/api/calendars/route.ts
index 1fd298e..92b0b25 100644
--- a/app/api/calendars/route.ts
+++ b/app/api/calendars/route.ts
@@ -13,6 +13,7 @@ export async function GET() {
name: calendars.name,
color: calendars.color,
passwordHash: calendars.passwordHash,
+ isLocked: calendars.isLocked,
createdAt: calendars.createdAt,
updatedAt: calendars.updatedAt,
_count:
@@ -37,7 +38,7 @@ export async function GET() {
export async function POST(request: Request) {
try {
const body = await request.json();
- const { name, color, password } = body;
+ const { name, color, password, isLocked } = body;
if (!name) {
return NextResponse.json(
@@ -46,12 +47,21 @@ export async function POST(request: Request) {
);
}
+ // Can't lock without password
+ if (isLocked && !password) {
+ return NextResponse.json(
+ { error: "Cannot lock calendar without password" },
+ { status: 400 }
+ );
+ }
+
const [calendar] = await db
.insert(calendars)
.values({
name,
color: color || "#3b82f6",
passwordHash: password ? hashPassword(password) : null,
+ isLocked: isLocked || false,
})
.returning();
diff --git a/app/api/presets/[id]/route.ts b/app/api/presets/[id]/route.ts
index 00a0688..927979d 100644
--- a/app/api/presets/[id]/route.ts
+++ b/app/api/presets/[id]/route.ts
@@ -21,6 +21,7 @@ export async function PATCH(
notes,
isSecondary,
isAllDay,
+ hideFromStats,
password,
} = body;
@@ -67,6 +68,7 @@ export async function PATCH(
notes: notes || null,
isSecondary: isSecondary !== undefined ? isSecondary : undefined,
isAllDay: isAllDay !== undefined ? isAllDay : undefined,
+ hideFromStats: hideFromStats !== undefined ? hideFromStats : undefined,
updatedAt: new Date(),
})
.where(eq(shiftPresets.id, id))
diff --git a/app/api/presets/route.ts b/app/api/presets/route.ts
index da20652..67f92c0 100644
--- a/app/api/presets/route.ts
+++ b/app/api/presets/route.ts
@@ -45,6 +45,7 @@ export async function POST(request: NextRequest) {
notes,
isSecondary,
isAllDay,
+ hideFromStats,
password,
} = body;
@@ -89,6 +90,7 @@ export async function POST(request: NextRequest) {
notes: notes || null,
isSecondary: isSecondary || false,
isAllDay: isAllDay || false,
+ hideFromStats: hideFromStats || false,
})
.returning();
diff --git a/app/api/shifts/stats/route.ts b/app/api/shifts/stats/route.ts
index 847352f..251c266 100644
--- a/app/api/shifts/stats/route.ts
+++ b/app/api/shifts/stats/route.ts
@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";
import { db } from "@/lib/db";
-import { shifts, icloudSyncs } from "@/lib/db/schema";
+import { shifts, icloudSyncs, shiftPresets } from "@/lib/db/schema";
import { eq, and, gte, lte, sql, or, isNull } from "drizzle-orm";
import {
startOfWeek,
@@ -48,7 +48,7 @@ export async function GET(request: Request) {
break;
}
- // Fetch shifts for the period, excluding shifts from iCloud syncs that are hidden or hidden from stats
+ // Fetch shifts for the period, excluding shifts from iCloud syncs or presets that are hidden from stats
const result = await db
.select({
title: shifts.title,
@@ -56,6 +56,7 @@ export async function GET(request: Request) {
})
.from(shifts)
.leftJoin(icloudSyncs, eq(shifts.icloudSyncId, icloudSyncs.id))
+ .leftJoin(shiftPresets, eq(shifts.presetId, shiftPresets.id))
.where(
and(
eq(shifts.calendarId, calendarId),
@@ -68,7 +69,9 @@ export async function GET(request: Request) {
eq(icloudSyncs.isHidden, false),
eq(icloudSyncs.hideFromStats, false)
)
- )
+ ),
+ // Exclude shifts from presets that are hidden from stats
+ or(isNull(shifts.presetId), eq(shiftPresets.hideFromStats, false))
)
)
.groupBy(shifts.title)
diff --git a/app/page.tsx b/app/page.tsx
index 9e43d34..1f72dc5 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useState, useEffect, useCallback, Suspense } from "react";
+import { useState, useEffect, useCallback, useMemo, Suspense } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { useTranslations, useLocale } from "next-intl";
import { CalendarDialog } from "@/components/calendar-dialog";
@@ -19,6 +19,8 @@ import { AppHeader } from "@/components/app-header";
import { CalendarGrid } from "@/components/calendar-grid";
import { ShiftsList } from "@/components/shifts-list";
import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
import {
Plus,
ChevronLeft,
@@ -76,7 +78,11 @@ function HomeContent() {
refetchShifts,
} = useShifts(selectedCalendar);
- const { presets, refetchPresets } = usePresets(selectedCalendar);
+ const {
+ presets,
+ loading: presetsLoading,
+ refetchPresets,
+ } = usePresets(selectedCalendar);
const {
notes,
@@ -153,6 +159,9 @@ function HomeContent() {
const [statsRefreshTrigger, setStatsRefreshTrigger] = useState(0);
const [togglingDates, setTogglingDates] = useState<Set<string>>(new Set());
const [isConnected, setIsConnected] = useState(true);
+ const [isCalendarUnlocked, setIsCalendarUnlocked] = useState(true);
+ const [isVerifyingCalendarPassword, setIsVerifyingCalendarPassword] =
+ useState(false);
const [versionInfo, setVersionInfo] = useState<{
version: string;
githubUrl: string;
@@ -189,12 +198,72 @@ function HomeContent() {
fetchVersion();
}, []);
+ // Memoize only the isLocked property of the selected calendar to avoid unnecessary re-verification
+ const selectedCalendarIsLocked = useMemo(() => {
+ if (!selectedCalendar) return false;
+ const currentCalendar = calendars.find((c) => c.id === selectedCalendar);
+ return currentCalendar?.isLocked ?? false;
+ }, [selectedCalendar, calendars]);
+
// Update URL when selected calendar changes
useEffect(() => {
if (selectedCalendar) {
router.replace(`/?id=${selectedCalendar}`, { scroll: false });
+
+ // Check if calendar is locked
+ if (selectedCalendarIsLocked) {
+ // Check if we have a valid password in localStorage
+ const storedPassword = localStorage.getItem(
+ `calendar_password_${selectedCalendar}`
+ );
+
+ if (storedPassword) {
+ // Set loading state and verify password before unlocking
+ setIsVerifyingCalendarPassword(true);
+ setIsCalendarUnlocked(false);
+
+ // Verify the stored password
+ fetch(`/api/calendars/${selectedCalendar}/verify-password`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ password: storedPassword }),
+ })
+ .then((response) => response.json())
+ .then((data) => {
+ if (data.valid) {
+ // Password valid, unlock calendar
+ setIsCalendarUnlocked(true);
+ } else {
+ // Password invalid, remove from storage and keep locked
+ localStorage.removeItem(
+ `calendar_password_${selectedCalendar}`
+ );
+ setIsCalendarUnlocked(false);
+ }
+ })
+ .catch(() => {
+ // On error, keep calendar locked
+ setIsCalendarUnlocked(false);
+ })
+ .finally(() => {
+ // Clear loading state
+ setIsVerifyingCalendarPassword(false);
+ });
+ } else {
+ // No stored password, set unlocked to false - form will handle it
+ setIsCalendarUnlocked(false);
+ setIsVerifyingCalendarPassword(false);
+ }
+ } else {
+ // Calendar not locked, allow access
+ setIsCalendarUnlocked(true);
+ setIsVerifyingCalendarPassword(false);
+ }
+ } else {
+ setIsCalendarUnlocked(true);
+ setIsVerifyingCalendarPassword(false);
}
- }, [selectedCalendar, router]);
+ }, [selectedCalendar, selectedCalendarIsLocked, router]);
const initiateDeleteCalendar = (id: string) => {
setCalendarToDelete(id);
@@ -706,6 +775,7 @@ function HomeContent() {
return (
<div className="min-h-screen flex flex-col">
+ {/* Always show AppHeader - allows calendar switching even when locked */}
<AppHeader
calendars={calendars}
selectedCalendar={selectedCalendar}
@@ -721,107 +791,203 @@ function HomeContent() {
onICloudSync={handleICloudSyncClick}
onPresetsChange={refetchPresets}
onShiftsChange={refetchShifts}
+ onStatsRefresh={() => setStatsRefreshTrigger((prev) => prev + 1)}
onPasswordRequired={handlePresetPasswordRequired}
onManualShiftCreation={handleManualShiftCreation}
onMobileCalendarDialogChange={setShowMobileCalendarDialog}
+ presetsLoading={presetsLoading}
/>
<div className="container max-w-4xl mx-auto px-1 py-3 sm:p-4 flex-1">
- {/* Month Navigation */}
- <motion.div
- className="flex items-center justify-between mb-4 sm:mb-5 px-2 sm:px-0"
- initial={{ opacity: 0, y: -10 }}
- animate={{ opacity: 1, y: 0 }}
- transition={{ duration: 0.3 }}
- >
- <Button
- variant="outline"
- size="icon"
- className="h-10 w-10 sm:h-11 sm:w-11 rounded-full active:scale-95 transition-transform"
- onClick={() => setCurrentDate(subMonths(currentDate, 1))}
- >
- <ChevronLeft className="h-5 w-5" />
- </Button>
- <motion.h2
- className="text-lg sm:text-xl font-bold"
- key={format(currentDate, "MMMM yyyy")}
- initial={{ opacity: 0, y: 10 }}
- animate={{ opacity: 1, y: 0 }}
- transition={{ duration: 0.2 }}
- >
- {format(currentDate, "MMMM yyyy", { locale: dateLocale })}
- </motion.h2>
- <Button
- variant="outline"
- size="icon"
- className="h-10 w-10 sm:h-11 sm:w-11 rounded-full active:scale-95 transition-transform"
- onClick={() => setCurrentDate(addMonths(currentDate, 1))}
- >
- <ChevronRight className="h-5 w-5" />
- </Button>
- </motion.div>
-
- {/* Calendar Grid */}
- <CalendarGrid
- calendarDays={calendarDays}
- currentDate={currentDate}
- shifts={shifts}
- notes={notes}
- selectedPresetId={selectedPresetId}
- togglingDates={togglingDates}
- icloudSyncs={icloudSyncs}
- onDayClick={handleDayClick}
- onDayRightClick={handleDayRightClick}
- onNoteIconClick={handleNoteIconClick}
- onLongPress={handleLongPressDay}
- onShowAllShifts={handleShowAllShifts}
- onShowSyncedShifts={handleShowSyncedShifts}
- />
-
- {/* Note Hint */}
- <motion.div
- className="px-2 sm:px-0 mb-4"
- initial={{ opacity: 0, y: 10 }}
- animate={{ opacity: 1, y: 0 }}
- transition={{ delay: 0.3 }}
- >
- <div className="bg-gradient-to-r from-primary/10 to-primary/5 border border-primary/20 rounded-xl p-3 sm:p-3.5 backdrop-blur-sm">
- <div className="flex items-center gap-2.5">
- <div className="shrink-0 w-8 h-8 rounded-lg bg-primary/20 flex items-center justify-center">
- <StickyNote className="h-4 w-4 text-orange-500" />
+ {/* Show loading state while verifying password */}
+ {isVerifyingCalendarPassword ? (
+ <div className="flex flex-col items-center justify-center py-20">
+ <motion.div
+ initial={{ opacity: 0, scale: 0.9 }}
+ animate={{ opacity: 1, scale: 1 }}
+ className="text-center"
+ >
+ <div className="w-20 h-20 rounded-full bg-primary/10 flex items-center justify-center mb-6 mx-auto">
+ <div className="h-10 w-10 border-4 border-primary border-t-transparent rounded-full animate-spin" />
</div>
- <div className="flex-1">
- <p className="text-xs sm:hidden text-foreground/80 leading-relaxed">
- {t("note.hintMobile", {
- default:
- "Long press on a day to open notes. The note icon shows existing notes.",
- })}
- </p>
- <p className="hidden sm:block text-sm text-foreground/80 leading-relaxed">
- {t("note.hintDesktop", {
- default:
- "Right-click on a day to open notes. The note icon shows existing notes.",
- })}
+ <p className="text-muted-foreground">{t("common.loading")}</p>
+ </motion.div>
+ </div>
+ ) : selectedCalendar && !isCalendarUnlocked ? (
+ <div className="flex flex-col items-center justify-center py-20">
+ <motion.div
+ initial={{ opacity: 0, y: 20 }}
+ animate={{ opacity: 1, y: 0 }}
+ className="w-full max-w-md"
+ >
+ <div className="bg-gradient-to-b from-background via-background to-muted/30 backdrop-blur-xl shadow-2xl border border-border/50 rounded-2xl p-8">
+ <div className="w-20 h-20 rounded-full bg-primary/10 flex items-center justify-center mb-6 mx-auto">
+ <CalendarIcon className="h-10 w-10 text-primary" />
+ </div>
+ <h3 className="text-2xl font-semibold mb-2 text-center">
+ {t("password.currentlyLocked")}
+ </h3>
+ <p className="text-muted-foreground text-center mb-8">
+ {t("password.enterCalendarPassword")}
</p>
+ <form
+ onSubmit={(e) => {
+ e.preventDefault();
+ const formData = new FormData(e.currentTarget);
+ const password = formData.get("password") as string;
+ if (password && selectedCalendar) {
+ fetch(
+ `/api/calendars/${selectedCalendar}/verify-password`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ password }),
+ }
+ )
+ .then((response) => response.json())
+ .then((data) => {
+ if (data.valid) {
+ localStorage.setItem(
+ `calendar_password_${selectedCalendar}`,
+ password
+ );
+ setIsCalendarUnlocked(true);
+ } else {
+ toast.error(t("password.errorIncorrect"));
+ }
+ })
+ .catch(() => {
+ toast.error(t("password.errorIncorrect"));
+ });
+ }
+ }}
+ className="space-y-4"
+ >
+ <div className="space-y-2">
+ <Label
+ htmlFor="unlock-password"
+ className="text-sm font-medium"
+ >
+ {t("password.password")}
+ </Label>
+ <Input
+ id="unlock-password"
+ name="password"
+ type="password"
+ placeholder={t("password.passwordPlaceholder")}
+ className="h-11 border-primary/30 focus:border-primary/50 focus:ring-primary/20"
+ autoFocus
+ />
+ </div>
+ <Button
+ type="submit"
+ className="w-full h-11 bg-gradient-to-r from-primary to-primary/90 hover:from-primary/90 hover:to-primary/80 shadow-lg shadow-primary/25"
+ >
+ {t("common.unlock", { default: "Unlock" })}
+ </Button>
+ </form>
</div>
- </div>
+ </motion.div>
</div>
- </motion.div>
+ ) : (
+ <>
+ {/* Month Navigation */}
+ <motion.div
+ className="flex items-center justify-between mb-4 sm:mb-5 px-2 sm:px-0"
+ initial={{ opacity: 0, y: -10 }}
+ animate={{ opacity: 1, y: 0 }}
+ transition={{ duration: 0.3 }}
+ >
+ <Button
+ variant="outline"
+ size="icon"
+ className="h-10 w-10 sm:h-11 sm:w-11 rounded-full active:scale-95 transition-transform"
+ onClick={() => setCurrentDate(subMonths(currentDate, 1))}
+ >
+ <ChevronLeft className="h-5 w-5" />
+ </Button>
+ <motion.h2
+ className="text-lg sm:text-xl font-bold"
+ key={format(currentDate, "MMMM yyyy")}
+ initial={{ opacity: 0, y: 10 }}
+ animate={{ opacity: 1, y: 0 }}
+ transition={{ duration: 0.2 }}
+ >
+ {format(currentDate, "MMMM yyyy", { locale: dateLocale })}
+ </motion.h2>
+ <Button
+ variant="outline"
+ size="icon"
+ className="h-10 w-10 sm:h-11 sm:w-11 rounded-full active:scale-95 transition-transform"
+ onClick={() => setCurrentDate(addMonths(currentDate, 1))}
+ >
+ <ChevronRight className="h-5 w-5" />
+ </Button>
+ </motion.div>
- {/* Shifts List */}
- <div className="space-y-3 sm:space-y-4 px-2 sm:px-0">
- <ShiftStats
- calendarId={selectedCalendar}
- currentDate={currentDate}
- refreshTrigger={statsRefreshTrigger}
- />
-
- <ShiftsList
- shifts={shifts}
- currentDate={currentDate}
- onDeleteShift={handleDeleteShift}
- />
- </div>
+ {/* Calendar Grid */}
+ <CalendarGrid
+ calendarDays={calendarDays}
+ currentDate={currentDate}
+ shifts={shifts}
+ notes={notes}
+ selectedPresetId={selectedPresetId}
+ togglingDates={togglingDates}
+ icloudSyncs={icloudSyncs}
+ onDayClick={handleDayClick}
+ onDayRightClick={handleDayRightClick}
+ onNoteIconClick={handleNoteIconClick}
+ onLongPress={handleLongPressDay}
+ onShowAllShifts={handleShowAllShifts}
+ onShowSyncedShifts={handleShowSyncedShifts}
+ />
+
+ {/* Note Hint */}
+ <motion.div
+ className="px-2 sm:px-0 mb-4"
+ initial={{ opacity: 0, y: 10 }}
+ animate={{ opacity: 1, y: 0 }}
+ transition={{ delay: 0.3 }}
+ >
+ <div className="bg-gradient-to-r from-primary/10 to-primary/5 border border-primary/20 rounded-xl p-3 sm:p-3.5 backdrop-blur-sm">
+ <div className="flex items-center gap-2.5">
+ <div className="shrink-0 w-8 h-8 rounded-lg bg-primary/20 flex items-center justify-center">
+ <StickyNote className="h-4 w-4 text-orange-500" />
+ </div>
+ <div className="flex-1">
+ <p className="text-xs sm:hidden text-foreground/80 leading-relaxed">
+ {t("note.hintMobile", {
+ default:
+ "Long press on a day to open notes. The note icon shows existing notes.",
+ })}
+ </p>
+ <p className="hidden sm:block text-sm text-foreground/80 leading-relaxed">
+ {t("note.hintDesktop", {
+ default:
+ "Right-click on a day to open notes. The note icon shows existing notes.",
+ })}
+ </p>
+ </div>
+ </div>
+ </div>
+ </motion.div>
+
+ {/* Shifts List */}
+ <div className="space-y-3 sm:space-y-4 px-2 sm:px-0">
+ <ShiftStats
+ calendarId={selectedCalendar}
+ currentDate={currentDate}
+ refreshTrigger={statsRefreshTrigger}
+ />
+
+ <ShiftsList
+ shifts={shifts}
+ currentDate={currentDate}
+ onDeleteShift={handleDeleteShift}
+ />
+ </div>
+ </>
+ )}
</div>
{/* Floating Action Button for Manual Shift Creation - Desktop Only */}
@@ -878,6 +1044,9 @@ function HomeContent() {
hasPassword={
!!calendars.find((c) => c.id === selectedCalendar)?.passwordHash
}
+ isLocked={
+ calendars.find((c) => c.id === selectedCalendar)?.isLocked || false
+ }
onSuccess={refetchCalendars}
/>
)}
diff --git a/components/app-header.tsx b/components/app-header.tsx
index 8197689..444c900 100644
--- a/components/app-header.tsx
+++ b/components/app-header.tsx
@@ -29,9 +29,11 @@ interface AppHeaderProps {
onICloudSync: () => void;
onPresetsChange: () => void;
onShiftsChange: () => void;
+ onStatsRefresh: () => void;
onPasswordRequired: (action: () => Promise<void>) => void;
onManualShiftCreation: () => void;
onMobileCalendarDialogChange: (open: boolean) => void;
+ presetsLoading?: boolean;
}
export function AppHeader({
@@ -49,9 +51,11 @@ export function AppHeader({
onICloudSync,
onPresetsChange,
onShiftsChange,
+ onStatsRefresh,
onPasswordRequired,
onManualShiftCreation,
onMobileCalendarDialogChange,
+ presetsLoading = false,
}: AppHeaderProps) {
const t = useTranslations();
@@ -212,8 +216,10 @@ export function AppHeader({
onSelectPreset={onSelectPreset}
onPresetsChange={onPresetsChange}
onShiftsChange={onShiftsChange}
+ onStatsRefresh={onStatsRefresh}
calendarId={selectedCalendar}
onPasswordRequired={onPasswordRequired}
+ loading={presetsLoading}
/>
</div>
)}
diff --git a/components/calendar-dialog.tsx b/components/calendar-dialog.tsx
index 0bc3660..9e9d598 100644
--- a/components/calendar-dialog.tsx
+++ b/components/calendar-dialog.tsx
@@ -19,7 +19,12 @@ import { PRESET_COLORS } from "@/lib/constants";
interface CalendarDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
- onSubmit: (name: string, color: string, password?: string) => void;
+ onSubmit: (
+ name: string,
+ color: string,
+ password?: string,
+ isLocked?: boolean
+ ) => void;
}
export function CalendarDialog({
@@ -31,22 +36,49 @@ export function CalendarDialog({
const [name, setName] = useState("");
const [selectedColor, setSelectedColor] = useState(PRESET_COLORS[0].value);
const [password, setPassword] = useState("");
+ const [confirmPassword, setConfirmPassword] = useState("");
const [usePassword, setUsePassword] = useState(false);
+ const [lockCalendar, setLockCalendar] = useState(false);
+ const [error, setError] = useState("");
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
- if (name.trim()) {
- onSubmit(
- name.trim(),
- selectedColor,
- usePassword && password ? password : undefined
- );
- setName("");
- setSelectedColor(PRESET_COLORS[0].value);
- setPassword("");
- setUsePassword(false);
- onOpenChange(false);
+ setError("");
+
+ if (!name.trim()) return;
+
+ // Validate password if enabled
+ if (usePassword) {
+ if (!password) {
+ setError(t("password.errorRequired"));
+ return;
+ }
+ if (password !== confirmPassword) {
+ setError(t("password.errorMatch"));
+ return;
+ }
+ }
+
+ // Can't lock without password
+ if (lockCalendar && !usePassword) {
+ setError(t("password.lockRequiresPassword"));
+ return;
}
+
+ onSubmit(
+ name.trim(),
+ selectedColor,
+ usePassword && password ? password : undefined,
+ lockCalendar
+ );
+ setName("");
+ setSelectedColor(PRESET_COLORS[0].value);
+ setPassword("");
+ setConfirmPassword("");
+ setUsePassword(false);
+ setLockCalendar(false);
+ setError("");
+ onOpenChange(false);
};
return (
@@ -145,22 +177,60 @@ export function CalendarDialog({
animate={{ opacity: 1, height: "auto" }}
exit={{ opacity: 0, height: 0 }}
transition={{ duration: 0.2 }}
- className="space-y-2 pt-1"
+ className="space-y-3 pt-1"
>
- <Label htmlFor="password" className="text-sm">
- {t("password.password")}
- </Label>
- <Input
- id="password"
- type="password"
- placeholder={t("password.passwordPlaceholder")}
- value={password}
- onChange={(e) => setPassword(e.target.value)}
- className="h-10 border-primary/30 focus:border-primary/50 focus:ring-primary/20 bg-background/80"
- />
+ <div className="space-y-2">
+ <Label htmlFor="password" className="text-sm">
+ {t("password.password")}
+ </Label>
+ <Input
+ id="password"
+ type="password"
+ placeholder={t("password.passwordPlaceholder")}
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ className="h-10 border-primary/30 focus:border-primary/50 focus:ring-primary/20 bg-background/80"
+ />
+ </div>
+ <div className="space-y-2">
+ <Label htmlFor="confirmPassword" className="text-sm">
+ {t("password.confirmPassword")}
+ </Label>
+ <Input
+ id="confirmPassword"
+ type="password"
+ placeholder={t("password.confirmPasswordPlaceholder")}
+ value={confirmPassword}
+ onChange={(e) => setConfirmPassword(e.target.value)}
+ className="h-10 border-primary/30 focus:border-primary/50 focus:ring-primary/20 bg-background/80"
+ />
+ </div>
+ <div className="flex items-center space-x-2 pt-1">
+ <Checkbox
+ id="lockCalendar"
+ checked={lockCalendar}
+ onCheckedChange={(checked) => setLockCalendar(!!checked)}
+ />
+ <div className="flex-1">
+ <Label
+ htmlFor="lockCalendar"
+ className="text-sm font-medium cursor-pointer"
+ >
+ {t("password.lockCalendar")}
+ </Label>
+ <p className="text-xs text-muted-foreground mt-0.5">
+ {t("password.lockCalendarHint")}
+ </p>
+ </div>
+ </div>
</motion.div>
)}
</div>
+ {error && (
+ <p className="text-sm text-red-500 flex items-center gap-1.5 bg-red-500/10 p-3 rounded-lg border border-red-500/20">
+ {error}
+ </p>
+ )}
<div className="flex gap-2.5 pt-2">
<Button
type="button"
diff --git a/components/manage-password-dialog.tsx b/components/manage-password-dialog.tsx
index 8f9c25d..f5224b1 100644
--- a/components/manage-password-dialog.tsx
+++ b/components/manage-password-dialog.tsx
@@ -21,6 +21,7 @@ interface ManagePasswordDialogProps {
calendarId: string;
calendarName: string;
hasPassword: boolean;
+ isLocked: boolean;
onSuccess: () => void;
}
@@ -30,6 +31,7 @@ export function ManagePasswordDialog({
calendarId,
calendarName,
hasPassword,
+ isLocked,
onSuccess,
}: ManagePasswordDialogProps) {
const t = useTranslations();
@@ -37,6 +39,7 @@ export function ManagePasswordDialog({
const [newPassword, setNewPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [removePassword, setRemovePassword] = useState(false);
+ const [lockCalendar, setLockCalendar] = useState(isLocked);
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
@@ -46,41 +49,55 @@ export function ManagePasswordDialog({
setNewPassword("");
setConfirmPassword("");
setRemovePassword(false);
+ setLockCalendar(isLocked);
setError("");
}
- }, [open]);
+ }, [open, isLocked]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
- // Validate inputs
+ // Always require current password when calendar has password
if (hasPassword && !currentPassword) {
setError(t("password.errorRequired"));
return;
}
- if (!removePassword) {
- if (!newPassword) {
- setError(t("password.errorRequired"));
- return;
- }
+ // Validate new password fields if changing password
+ const isChangingPassword = !removePassword && newPassword;
+ if (isChangingPassword) {
if (newPassword !== confirmPassword) {
setError(t("password.errorMatch"));
return;
}
}
+ // If trying to lock without password
+ if (lockCalendar && removePassword) {
+ setError(t("password.lockRequiresPassword"));
+ return;
+ }
+
setLoading(true);
try {
+ const requestBody: any = {
+ currentPassword: hasPassword ? currentPassword : undefined,
+ isLocked: lockCalendar,
+ };
+
+ // Include password fields if changing password
+ if (removePassword) {
+ requestBody.password = null;
+ } else if (newPassword) {
+ requestBody.password = newPassword;
+ }
+
const response = await fetch(`/api/calendars/${calendarId}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- currentPassword: hasPassword ? currentPassword : undefined,
- password: removePassword ? null : newPassword,
- }),
+ body: JSON.stringify(requestBody),
});
if (response.status === 401) {
@@ -156,7 +173,14 @@ export function ManagePasswordDialog({
<Checkbox
id="removePassword"
checked={removePassword}
- onCheckedChange={(checked) => setRemovePassword(!!checked)}
+ onCheckedChange={(checked) => {
+ const isChecked = !!checked;
+ setRemovePassword(isChecked);
+ // Automatically unlock if removing password
+ if (isChecked) {
+ setLockCalendar(false);
+ }
+ }}
/>
<Label
htmlFor="removePassword"
@@ -167,6 +191,27 @@ export function ManagePasswordDialog({
</div>
)}
+ {hasPassword && !removePassword && (
+ <div className="flex items-center space-x-2 p-3 bg-muted/30 rounded-lg border border-border/30">
+ <Checkbox
+ id="lockCalendar"
+ checked={lockCalendar}
+ onCheckedChange={(checked) => setLockCalendar(!!checked)}
+ />
+ <div className="flex-1">
+ <Label
+ htmlFor="lockCalendar"
+ className="text-sm font-medium cursor-pointer"
+ >
+ {t("password.lockCalendar")}
+ </Label>
+ <p className="text-xs text-muted-foreground mt-0.5">
+ {t("password.lockCalendarHint")}
+ </p>
+ </div>
+ </div>
+ )}
+
{!removePassword && (
<motion.div
initial={{ opacity: 0, height: 0 }}
diff --git a/components/preset-edit-dialog.tsx b/components/preset-edit-dialog.tsx
index b38e1c3..9d2408a 100644
--- a/components/preset-edit-dialog.tsx
+++ b/components/preset-edit-dialog.tsx
@@ -24,6 +24,7 @@ interface PresetFormData {
notes: string;
isSecondary: boolean;
isAllDay: boolean;
+ hideFromStats: boolean;
}
interface PresetEditDialogProps {
@@ -50,6 +51,7 @@ export function PresetEditDialog({
notes: "",
isSecondary: false,
isAllDay: false,
+ hideFromStats: false,
});
useEffect(() => {
@@ -62,6 +64,7 @@ export function PresetEditDialog({
notes: preset.notes || "",
isSecondary: preset.isSecondary || false,
isAllDay: preset.isAllDay || false,
+ hideFromStats: preset.hideFromStats || false,
});
} else if (open && isCreating) {
setFormData({
@@ -72,6 +75,7 @@ export function PresetEditDialog({
notes: "",
isSecondary: false,
isAllDay: false,
+ hideFromStats: false,
});
}
}, [open, preset, isCreating]);
@@ -216,6 +220,27 @@ export function PresetEditDialog({
</Label>
</div>
+ <div className="flex items-center space-x-2 p-3 bg-muted/30 rounded-lg border border-border/30">
+ <Checkbox
+ id="preset-hide-stats"
+ checked={formData.hideFromStats}
+ onCheckedChange={(checked) =>
+ setFormData({ ...formData, hideFromStats: !!checked })
+ }
+ />
+ <div className="flex-1">
+ <Label
+ htmlFor="preset-hide-stats"
+ className="text-sm font-medium cursor-pointer"
+ >
+ {t("preset.hideFromStats")}
+ </Label>
+ <p className="text-xs text-muted-foreground mt-0.5">
+ {t("preset.hideFromStatsHint")}
+ </p>
+ </div>
+ </div>
+
<div className="flex gap-2.5 pt-2">
<Button
type="button"
diff --git a/components/preset-list.tsx b/components/preset-list.tsx
index eb5a269..c5c33e7 100644
--- a/components/preset-list.tsx
+++ b/components/preset-list.tsx
@@ -10,6 +10,7 @@ interface PresetListProps {
onSelectPreset: (presetId: string | undefined) => void;
onCreateNew: () => void;
onManageClick: () => void;
+ loading?: boolean;
}
export function PresetList({
@@ -18,6 +19,7 @@ export function PresetList({
onSelectPreset,
onCreateNew,
onManageClick,
+ loading = false,
}: PresetListProps) {
const t = useTranslations();
const [showSecondary, setShowSecondary] = React.useState(false);
@@ -25,6 +27,20 @@ export function PresetList({
const primaryPresets = presets.filter((p) => !p.isSecondary);
const secondaryPresets = presets.filter((p) => p.isSecondary);
+ // Show loading state while fetching
+ if (loading) {
+ return (
+ <div className="border-2 border-dashed rounded-lg p-4 sm:p-6 text-center">
+ <div className="flex items-center justify-center gap-2 text-muted-foreground">
+ <div className="h-4 w-4 border-2 border-primary border-t-transparent rounded-full animate-spin" />
+ <p className="text-xs sm:text-sm font-medium">
+ {t("common.loading")}
+ </p>
+ </div>
+ </div>
+ );
+ }
+
if (presets.length === 0) {
return (
<div className="border-2 border-dashed rounded-lg p-4 sm:p-6 text-center space-y-2 sm:space-y-3">
diff --git a/components/preset-selector.tsx b/components/preset-selector.tsx
index 8ce3b0e..194a79a 100644
--- a/components/preset-selector.tsx
+++ b/components/preset-selector.tsx
@@ -18,8 +18,10 @@ interface PresetSelectorProps {
onSelectPreset: (presetId: string | undefined) => void;
onPresetsChange: () => void;
onShiftsChange?: () => void;
+ onStatsRefresh?: () => void;
calendarId: string;
onPasswordRequired: (action: () => Promise<void>) => void;
+ loading?: boolean;
}
export function PresetSelector({
@@ -28,8 +30,10 @@ export function PresetSelector({
onSelectPreset,
onPresetsChange,
onShiftsChange,
+ onStatsRefresh,
calendarId,
onPasswordRequired,
+ loading = false,
}: PresetSelectorProps) {
const t = useTranslations();
const [showManageDialog, setShowManageDialog] = useState(false);
@@ -104,6 +108,7 @@ export function PresetSelector({
toast.success(t("preset.updated"));
if (onShiftsChange) onShiftsChange();
+ if (onStatsRefresh) onStatsRefresh();
}
onPresetsChange();
@@ -163,6 +168,7 @@ export function PresetSelector({
onSelectPreset={onSelectPreset}
onCreateNew={handleCreateNew}
onManageClick={() => setShowManageDialog(true)}
+ loading={loading}
/>
<PresetManageDialog
diff --git a/drizzle/0006_first_tana_nile.sql b/drizzle/0006_first_tana_nile.sql
new file mode 100644
index 0000000..7dccf99
--- /dev/null
+++ b/drizzle/0006_first_tana_nile.sql
@@ -0,0 +1,2 @@
+ALTER TABLE `calendars` ADD `is_locked` integer DEFAULT false NOT NULL;--> statement-breakpoint
+ALTER TABLE `shift_presets` ADD `hide_from_stats` integer DEFAULT false NOT NULL;
\ No newline at end of file
diff --git a/drizzle/meta/0006_snapshot.json b/drizzle/meta/0006_snapshot.json
new file mode 100644
index 0000000..8d5ee90
--- /dev/null
+++ b/drizzle/meta/0006_snapshot.json
@@ -0,0 +1,538 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "bcb20d16-59cb-4659-8304-31cc39e260fb",
+ "prevId": "d404c066-ecc7-4b20-859f-526d891db67c",
+ "tables": {
+ "calendar_notes": {
+ "name": "calendar_notes",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "calendar_id": {
+ "name": "calendar_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "date": {
+ "name": "date",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "note": {
+ "name": "note",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "calendar_notes_calendar_id_calendars_id_fk": {
+ "name": "calendar_notes_calendar_id_calendars_id_fk",
+ "tableFrom": "calendar_notes",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "calendars": {
+ "name": "calendars",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'#3b82f6'"
+ },
+ "password_hash": {
+ "name": "password_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "is_locked": {
+ "name": "is_locked",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "icloud_syncs": {
+ "name": "icloud_syncs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "calendar_id": {
+ "name": "calendar_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "icloud_url": {
+ "name": "icloud_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'#3b82f6'"
+ },
+ "display_mode": {
+ "name": "display_mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'normal'"
+ },
+ "is_hidden": {
+ "name": "is_hidden",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "hide_from_stats": {
+ "name": "hide_from_stats",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "last_synced_at": {
+ "name": "last_synced_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "icloud_syncs_calendar_id_calendars_id_fk": {
+ "name": "icloud_syncs_calendar_id_calendars_id_fk",
+ "tableFrom": "icloud_syncs",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "shift_presets": {
+ "name": "shift_presets",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "calendar_id": {
+ "name": "calendar_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "start_time": {
+ "name": "start_time",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "end_time": {
+ "name": "end_time",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'#3b82f6'"
+ },
+ "notes": {
+ "name": "notes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "is_secondary": {
+ "name": "is_secondary",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "is_all_day": {
+ "name": "is_all_day",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "hide_from_stats": {
+ "name": "hide_from_stats",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "shift_presets_calendar_id_calendars_id_fk": {
+ "name": "shift_presets_calendar_id_calendars_id_fk",
+ "tableFrom": "shift_presets",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "shifts": {
+ "name": "shifts",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "calendar_id": {
+ "name": "calendar_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "preset_id": {
+ "name": "preset_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "date": {
+ "name": "date",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "start_time": {
+ "name": "start_time",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "end_time": {
+ "name": "end_time",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'#3b82f6'"
+ },
+ "notes": {
+ "name": "notes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "is_all_day": {
+ "name": "is_all_day",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "is_secondary": {
+ "name": "is_secondary",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "icloud_event_id": {
+ "name": "icloud_event_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "icloud_sync_id": {
+ "name": "icloud_sync_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "synced_from_icloud": {
+ "name": "synced_from_icloud",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "shifts_calendar_id_calendars_id_fk": {
+ "name": "shifts_calendar_id_calendars_id_fk",
+ "tableFrom": "shifts",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "shifts_preset_id_shift_presets_id_fk": {
+ "name": "shifts_preset_id_shift_presets_id_fk",
+ "tableFrom": "shifts",
+ "tableTo": "shift_presets",
+ "columnsFrom": [
+ "preset_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "shifts_icloud_sync_id_icloud_syncs_id_fk": {
+ "name": "shifts_icloud_sync_id_icloud_syncs_id_fk",
+ "tableFrom": "shifts",
+ "tableTo": "icloud_syncs",
+ "columnsFrom": [
+ "icloud_sync_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ }
+ },
+ "views": {},
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "indexes": {}
+ }
+}
\ No newline at end of file
diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json
index bdecc6c..47af2c0 100644
--- a/drizzle/meta/_journal.json
+++ b/drizzle/meta/_journal.json
@@ -43,6 +43,13 @@
"when": 1764770255988,
"tag": "0005_silky_smiling_tiger",
"breakpoints": true
+ },
+ {
+ "idx": 6,
+ "version": "6",
+ "when": 1764788029911,
+ "tag": "0006_first_tana_nile",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/hooks/useCalendars.ts b/hooks/useCalendars.ts
index 6bf613b..7714602 100644
--- a/hooks/useCalendars.ts
+++ b/hooks/useCalendars.ts
@@ -35,7 +35,8 @@ export function useCalendars(initialCalendarId?: string | null) {
const createCalendar = async (
name: string,
color: string,
- password?: string
+ password?: string,
+ isLocked?: boolean
) => {
try {
const response = await fetch("/api/calendars", {
@@ -45,6 +46,7 @@ export function useCalendars(initialCalendarId?: string | null) {
name,
color,
password,
+ isLocked: isLocked || false,
}),
});
diff --git a/hooks/usePresets.ts b/hooks/usePresets.ts
index 7d27e9a..fb42003 100644
--- a/hooks/usePresets.ts
+++ b/hooks/usePresets.ts
@@ -3,10 +3,16 @@ import { ShiftPreset } from "@/lib/db/schema";
export function usePresets(calendarId: string | undefined) {
const [presets, setPresets] = useState<ShiftPreset[]>([]);
+ const [loading, setLoading] = useState(true);
const fetchPresets = async () => {
- if (!calendarId) return;
+ if (!calendarId) {
+ setPresets([]);
+ setLoading(false);
+ return;
+ }
+ setLoading(true);
try {
const response = await fetch(`/api/presets?calendarId=${calendarId}`);
if (!response.ok) {
@@ -19,6 +25,8 @@ export function usePresets(calendarId: string | undefined) {
} catch (error) {
console.error("Failed to fetch presets:", error);
setPresets([]);
+ } finally {
+ setLoading(false);
}
};
@@ -27,11 +35,13 @@ export function usePresets(calendarId: string | undefined) {
fetchPresets();
} else {
setPresets([]);
+ setLoading(false);
}
}, [calendarId]);
return {
presets,
+ loading,
refetchPresets: fetchPresets,
};
}
diff --git a/lib/db/schema.ts b/lib/db/schema.ts
index 84d3020..15af97c 100644
--- a/lib/db/schema.ts
+++ b/lib/db/schema.ts
@@ -8,6 +8,7 @@ export const calendars = sqliteTable("calendars", {
name: text("name").notNull(),
color: text("color").notNull().default("#3b82f6"),
passwordHash: text("password_hash"),
+ isLocked: integer("is_locked", { mode: "boolean" }).notNull().default(false),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
@@ -91,6 +92,9 @@ export const shiftPresets = sqliteTable("shift_presets", {
.notNull()
.default(false),
isAllDay: integer("is_all_day", { mode: "boolean" }).notNull().default(false),
+ hideFromStats: integer("hide_from_stats", { mode: "boolean" })
+ .notNull()
+ .default(false),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
diff --git a/lib/types.ts b/lib/types.ts
index e83ea2a..5c2820d 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -6,6 +6,7 @@ export interface CalendarWithCount {
name: string;
color: string;
passwordHash?: string | null;
+ isLocked?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
_count?: number;
diff --git a/messages/de.json b/messages/de.json
index c568b35..2c402df 100644
--- a/messages/de.json
+++ b/messages/de.json
@@ -6,7 +6,8 @@
"edit": "Bearbeiten",
"create": "Erstellen",
"loading": "Lädt...",
- "required": "erforderlich"
+ "required": "erforderlich",
+ "unlock": "Entsperren"
},
"app": {
"title": "BetterShift",
@@ -51,6 +52,10 @@
"enterCalendarPassword": "Kalenderpasswort eingeben",
"currentlyProtected": "Dieser Kalender ist derzeit passwortgeschützt.",
"notProtected": "Dieser Kalender ist derzeit nicht passwortgeschützt.",
+ "lockCalendar": "Kalender sperren",
+ "lockCalendarHint": "Kalender komplett sperren - Passwort erforderlich für alle Aktionen",
+ "lockRequiresPassword": "Kalendersperre erfordert ein Passwort",
+ "currentlyLocked": "Dieser Kalender ist derzeit gesperrt.",
"errorMatch": "Passwörter stimmen nicht überein",
"errorIncorrect": "Falsches Passwort",
"errorRequired": "Passwort erforderlich",
@@ -119,6 +124,8 @@
"deleteConfirm": "Diese Vorlage löschen? Alle aus dieser Vorlage erstellten Schichten werden ebenfalls gelöscht.",
"secondaryPresets": "Sekundäre Vorlagen",
"markAsSecondary": "Als sekundär markieren (standardmäßig eingeklappt)",
+ "hideFromStats": "Aus Statistik ausblenden",
+ "hideFromStatsHint": "Schichten dieser Vorlage aus der Statistik ausschließen",
"created": "Vorlage erfolgreich erstellt",
"updated": "Vorlage erfolgreich aktualisiert",
"deleted": "Vorlage erfolgreich gelöscht",
diff --git a/messages/en.json b/messages/en.json
index 1702aa7..fe35d14 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -6,7 +6,8 @@
"edit": "Edit",
"create": "Create",
"loading": "Loading...",
- "required": "required"
+ "required": "required",
+ "unlock": "Unlock"
},
"app": {
"title": "BetterShift",
@@ -51,6 +52,10 @@
"enterCalendarPassword": "Enter calendar password",
"currentlyProtected": "This calendar is currently password protected.",
"notProtected": "This calendar is currently not password protected.",
+ "lockCalendar": "Lock calendar",
+ "lockCalendarHint": "Lock calendar completely - password required for all actions",
+ "lockRequiresPassword": "Locking the calendar requires a password",
+ "currentlyLocked": "This calendar is currently locked.",
"errorMatch": "Passwords do not match",
"errorIncorrect": "Incorrect password",
"errorRequired": "Password required",
@@ -119,6 +124,8 @@
"deleteConfirm": "Delete this preset? This will also delete all shifts created from this preset.",
"secondaryPresets": "Secondary Presets",
"markAsSecondary": "Mark as secondary (collapsed by default)",
+ "hideFromStats": "Hide from statistics",
+ "hideFromStatsHint": "Exclude shifts from this preset from statistics",
"created": "Preset created successfully",
"updated": "Preset updated successfully",
"deleted": "Preset deleted successfully",