Skip to content

Your favorite shift management application!

feat(presets): add preset groups, multi-select stamping, and cloning (#190)

panteL6ca2194a5bd6
diff --git a/app/api/presets/[id]/route.ts b/app/api/presets/[id]/route.ts
index 5cb6642..ecd7714 100644
--- a/app/api/presets/[id]/route.ts
+++ b/app/api/presets/[id]/route.ts
@@ -4,6 +4,7 @@ import { shiftPresets, shifts, calendars } from "@/lib/db/schema";
import { eq } from "drizzle-orm";
import { getSessionUser } from "@/lib/auth/sessions";
import { canViewCalendar, canEditCalendar } from "@/lib/auth/permissions";
+import { trimOrNull } from "@/lib/utils";
// GET single preset
export async function GET(
@@ -69,11 +70,23 @@ export async function PATCH(
endTime,
color,
notes,
+ groupName,
isSecondary,
isAllDay,
hideFromStats,
} = body;
+ // groupName: undefined leaves it unchanged, null explicitly clears it,
+ // strings are trimmed (empty -> cleared), anything else is invalid input.
+ let normalizedGroupName: string | null | undefined;
+ if (groupName === undefined || groupName === null) {
+ normalizedGroupName = groupName;
+ } else if (typeof groupName === "string") {
+ normalizedGroupName = trimOrNull(groupName);
+ } else {
+ return NextResponse.json({ error: "Invalid groupName" }, { status: 400 });
+ }
+
const user = await getSessionUser(request.headers);
// Fetch preset to get calendar ID
@@ -119,6 +132,7 @@ export async function PATCH(
endTime: isAllDay ? "23:59" : endTime,
color,
notes: notes || null,
+ groupName: normalizedGroupName,
isSecondary: isSecondary !== undefined ? isSecondary : undefined,
isAllDay: isAllDay !== undefined ? isAllDay : undefined,
hideFromStats: hideFromStats !== undefined ? hideFromStats : undefined,
diff --git a/app/api/presets/route.ts b/app/api/presets/route.ts
index 5c13ccc..07d699b 100644
--- a/app/api/presets/route.ts
+++ b/app/api/presets/route.ts
@@ -4,6 +4,7 @@ import { shiftPresets, calendars } from "@/lib/db/schema";
import { eq, asc } from "drizzle-orm";
import { getSessionUser } from "@/lib/auth/sessions";
import { canViewCalendar, canEditCalendar } from "@/lib/auth/permissions";
+import { trimOrNull } from "@/lib/utils";
// GET all presets for a calendar
export async function GET(request: NextRequest) {
@@ -68,6 +69,7 @@ export async function POST(request: NextRequest) {
endTime,
color,
notes,
+ groupName,
isSecondary,
isAllDay,
hideFromStats,
@@ -124,6 +126,7 @@ export async function POST(request: NextRequest) {
endTime: isAllDay ? "23:59" : endTime,
color: color || "#3b82f6",
notes: notes || null,
+ groupName: groupName ? trimOrNull(groupName) : null,
isSecondary: isSecondary || false,
isAllDay: isAllDay || false,
hideFromStats: hideFromStats || false,
diff --git a/app/page.tsx b/app/page.tsx
index 5f6fdbc..f0924ba 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -85,7 +85,24 @@ function HomeContent() {
// Toasts are owned by CalendarWorkspace; this is only the stamping gate
const { isOnline } = useConnectionStatus({ toasts: false });
- const [selectedPresetId, setSelectedPresetId] = useState<string | undefined>();
+ const [selectedPresetIds, setSelectedPresetIds] = useState<string[]>([]);
+ const handlePresetSelection = useCallback(
+ (presetId: string | undefined, multiSelect = false) => {
+ if (!presetId) {
+ setSelectedPresetIds([]);
+ return;
+ }
+ setSelectedPresetIds((prev) => {
+ if (multiSelect) {
+ return prev.includes(presetId)
+ ? prev.filter((id) => id !== presetId)
+ : [...prev, presetId];
+ }
+ return prev.includes(presetId) ? [] : [presetId];
+ });
+ },
+ []
+ );
const [currentDate, setCurrentDate] = useState(new Date());
const [selectedDate, setSelectedDate] = useState<Date | undefined>();
const [editingShift, setEditingShift] = useState<ShiftWithCalendar | undefined>();
@@ -128,7 +145,7 @@ function HomeContent() {
currentDate,
setCurrentDate,
selectDay,
- selectedPresetId,
+ selectedPresetIds,
});
const {
@@ -265,22 +282,20 @@ function HomeContent() {
calendars.find((c) => c.id === selectedCalendar)
);
- // The armed preset is page state that outlives the stamp bar: it survives a
+ // The armed presets are page state that outlives the stamp bar: it survives a
// calendar switch, going offline and the personal toggle, none of which render
// the dock. Derived here so a day click can never stamp without it on screen.
- const armedPresetId =
- canEdit &&
- isOnline &&
- calendarView.showStampBar &&
- presets.some((p) => p.id === selectedPresetId)
- ? selectedPresetId
- : undefined;
+ const presetIdSet = new Set(presets.map((p) => p.id));
+ const armedPresetIds =
+ canEdit && isOnline && calendarView.showStampBar
+ ? selectedPresetIds.filter((id) => presetIdSet.has(id))
+ : [];
const handleDayClick = (day: Date) => {
selectDay(day);
if (!isSameMonth(day, currentDate)) setCurrentDate(day);
- if (armedPresetId) {
- shiftActions.handleAddShift(day, armedPresetId);
+ if (armedPresetIds.length > 0) {
+ shiftActions.handleAddShift(day, armedPresetIds);
} else if (!desktop) {
setDaySheetOpen(true);
}
@@ -389,8 +404,8 @@ function HomeContent() {
showShiftNotes={personalView.showShiftNotes}
highlightedWeekdays={personalView.highlightedWeekdays}
highlightColor={personalView.highlightColor}
- selectedPresetId={selectedPresetId}
- onSelectPreset={setSelectedPresetId}
+ selectedPresetIds={selectedPresetIds}
+ onSelectPreset={handlePresetSelection}
onDayClick={handleCompareDayClick}
onDayContextMenu={openCompareNotes}
onOpenDayShifts={openDayShifts}
@@ -464,8 +479,8 @@ function HomeContent() {
highlightColor={calendarView.highlightColor}
canEdit={canEdit}
showStampBar={calendarView.showStampBar}
- selectedPresetId={armedPresetId}
- onSelectPreset={setSelectedPresetId}
+ selectedPresetIds={armedPresetIds}
+ onSelectPreset={handlePresetSelection}
onManagePresets={() => dialogStates.setShowPresetManageDialog(true)}
sheetOpen={daySheetOpen}
onSheetOpenChange={setDaySheetOpen}
diff --git a/components/calendar-workspace.tsx b/components/calendar-workspace.tsx
index 15a5b92..18a2b74 100644
--- a/components/calendar-workspace.tsx
+++ b/components/calendar-workspace.tsx
@@ -44,8 +44,8 @@ interface CalendarWorkspaceProps {
highlightColor: string;
canEdit: boolean;
showStampBar: boolean;
- selectedPresetId: string | undefined;
- onSelectPreset: (id: string | undefined) => void;
+ selectedPresetIds: string[];
+ onSelectPreset: (id: string | undefined, multiSelect?: boolean) => void;
onManagePresets: () => void;
actions: DayActions;
sheetOpen: boolean;
@@ -72,7 +72,7 @@ export function CalendarWorkspace({
highlightColor,
canEdit,
showStampBar,
- selectedPresetId,
+ selectedPresetIds,
onSelectPreset,
onManagePresets,
actions,
@@ -110,7 +110,7 @@ export function CalendarWorkspace({
);
useStampShortcuts({
presetIds: stampPresetIds,
- selectedPresetId,
+ selectedPresetIds,
onSelectPreset,
enabled: stampingEnabled && desktop,
});
@@ -175,7 +175,7 @@ export function CalendarWorkspace({
{stampingEnabled && (
<StampDock
presets={presets}
- selectedPresetId={selectedPresetId}
+ selectedPresetIds={selectedPresetIds}
onSelectPreset={onSelectPreset}
onManage={onManagePresets}
/>
@@ -218,7 +218,7 @@ export function CalendarWorkspace({
{stampingEnabled && (
<MobilePresetBar
presets={presets}
- selectedPresetId={selectedPresetId}
+ selectedPresetIds={selectedPresetIds}
onSelectPreset={onSelectPreset}
onManage={onManagePresets}
/>
diff --git a/components/compare-workspace.tsx b/components/compare-workspace.tsx
index 051cd8b..2b943d6 100644
--- a/components/compare-workspace.tsx
+++ b/components/compare-workspace.tsx
@@ -17,7 +17,12 @@ import { Button } from "@/components/ui/button";
import { MonthGrid } from "@/components/month-grid";
import { MonthArrows, MonthStepper } from "@/components/app-header";
import { PresetManageSheet } from "@/components/preset-manage-sheet";
-import { MorePresets, orderStampPresets, splitStampPresets } from "@/components/stamp-dock";
+import {
+ MorePresets,
+ MultiSelectToggle,
+ orderStampPresets,
+ splitStampPresets,
+} from "@/components/stamp-dock";
import { MAX_COMPARE_CALENDARS } from "@/components/calendar-compare-sheet";
import { useDayLabels } from "@/components/day-inspector";
import { CalendarWithCount, ShiftWithCalendar } from "@/lib/types";
@@ -38,7 +43,7 @@ import { useCalendarPermission } from "@/hooks/useCalendarPermission";
import { useConnectionStatus } from "@/hooks/useConnectionStatus";
import { useStampShortcuts } from "@/hooks/useStampShortcuts";
import { DESKTOP_QUERY, useMediaQuery } from "@/hooks/useMediaQuery";
-import { cn } from "@/lib/utils";
+import { cn, isMultiSelectClick } from "@/lib/utils";
interface CompareWorkspaceProps {
calendars: CalendarWithCount[];
@@ -56,8 +61,8 @@ interface CompareWorkspaceProps {
showShiftNotes: boolean;
highlightedWeekdays: number[];
highlightColor: string;
- selectedPresetId: string | undefined;
- onSelectPreset: (id: string | undefined) => void;
+ selectedPresetIds: string[];
+ onSelectPreset: (id: string | undefined, multiSelect?: boolean) => void;
onDayClick: (calendarId: string, date: Date) => void;
onDayContextMenu: (calendarId: string, date: Date) => void;
onOpenDayShifts: (date: Date, shifts: ShiftWithCalendar[]) => void;
@@ -91,15 +96,19 @@ export function CompareWorkspace(props: CompareWorkspaceProps) {
const desktop = useMediaQuery(DESKTOP_QUERY, true);
const [manageCalendarId, setManageCalendarId] = useState<string | null>(null);
- const presetOwner = useMemo(() => {
- if (!props.selectedPresetId) return null;
+ const presetOwnerIds = useMemo(() => {
+ const selectedSet = new Set(props.selectedPresetIds);
+ const owners = new Set<string>();
for (const [calendarId, presets] of props.presetsMap) {
- if (presets.some((p) => p.id === props.selectedPresetId)) return calendarId;
+ if (presets.some((p) => selectedSet.has(p.id))) {
+ owners.add(calendarId);
+ }
}
- return null;
- }, [props.presetsMap, props.selectedPresetId]);
+ return owners;
+ }, [props.presetsMap, props.selectedPresetIds]);
- const activeColumnId = presetOwner ?? props.calendars[0]?.id;
+ const activeColumnId =
+ props.calendars.find((c) => presetOwnerIds.has(c.id))?.id ?? props.calendars[0]?.id;
const activePresets = orderStampPresets(props.presetsMap.get(activeColumnId ?? "") ?? []);
// Each column carries its own permission, and only an editable one renders the
@@ -110,7 +119,7 @@ export function CompareWorkspace(props: CompareWorkspaceProps) {
useStampShortcuts({
presetIds: activePresets.map((p) => p.id),
- selectedPresetId: props.selectedPresetId,
+ selectedPresetIds: props.selectedPresetIds,
onSelectPreset: props.onSelectPreset,
enabled: desktop && canEditActiveColumn && isOnline,
});
@@ -122,7 +131,7 @@ export function CompareWorkspace(props: CompareWorkspaceProps) {
{desktop ? (
<CompareDesktop
{...props}
- presetOwner={presetOwner}
+ presetOwnerIds={presetOwnerIds}
activeColumnId={activeColumnId}
onManagePresets={setManageCalendarId}
/>
@@ -152,12 +161,12 @@ function CompareDesktop({
onExit,
shiftsMap,
onOpenDayShifts,
- presetOwner,
+ presetOwnerIds,
activeColumnId,
onManagePresets,
...rest
}: CompareWorkspaceProps & {
- presetOwner: string | null;
+ presetOwnerIds: Set<string>;
activeColumnId: string | undefined;
onManagePresets: (calendarId: string) => void;
}) {
@@ -224,7 +233,7 @@ function CompareDesktop({
currentDate={currentDate}
selectedDay={selectedDay}
shifts={shiftsMap.get(calendar.id) ?? []}
- stampActive={presetOwner === calendar.id}
+ stampActive={presetOwnerIds.has(calendar.id)}
keysActive={activeColumnId === calendar.id}
onManagePresets={() => onManagePresets(calendar.id)}
{...rest}
@@ -288,7 +297,7 @@ function CompareColumn({
showShiftNotes,
highlightedWeekdays,
highlightColor,
- selectedPresetId,
+ selectedPresetIds,
onSelectPreset,
onDayClick,
onDayContextMenu,
@@ -314,7 +323,9 @@ function CompareColumn({
const locale = useLocale();
const { canEdit } = useCalendarPermission(calendar.id);
const { primary, secondary } = splitStampPresets(presetsMap.get(calendar.id) ?? []);
+ const activeIds = new Set(selectedPresetIds);
const totals = monthTotals(shifts, currentDate);
+ const [multiMode, setMultiMode] = useState(false);
return (
<section className="flex min-h-0 min-w-0 flex-1 flex-col pb-3">
@@ -336,13 +347,15 @@ function CompareColumn({
<div className="mt-2.5 flex h-8 items-center gap-1.5 overflow-hidden">
<div className="flex min-w-0 items-center gap-1.5 overflow-hidden empty:hidden">
{primary.map((preset, index) => {
- const active = preset.id === selectedPresetId;
+ const active = activeIds.has(preset.id);
return (
<button
key={preset.id}
type="button"
aria-pressed={active}
- onClick={() => onSelectPreset(active ? undefined : preset.id)}
+ onClick={(event) =>
+ onSelectPreset(preset.id, multiMode || isMultiSelectClick(event))
+ }
className={cn(
"flex h-7 shrink-0 items-center gap-[7px] rounded-[7px] border px-2.5 text-[12.5px] font-medium transition-colors",
active
@@ -364,8 +377,14 @@ function CompareColumn({
<MorePresets
variant="compare"
presets={secondary}
- selectedPresetId={selectedPresetId}
+ selectedPresetIds={selectedPresetIds}
onSelectPreset={onSelectPreset}
+ multiMode={multiMode}
+ />
+ <MultiSelectToggle
+ variant="compare"
+ active={multiMode}
+ onClick={() => setMultiMode((m) => !m)}
/>
<button
type="button"
diff --git a/components/preset-form.tsx b/components/preset-form.tsx
index 2f4f3e0..304ca5f 100644
--- a/components/preset-form.tsx
+++ b/components/preset-form.tsx
@@ -15,6 +15,7 @@ export const EMPTY_PRESET_FORM: PresetFormData = {
endTime: "17:00",
color: DEFAULT_COLOR,
notes: "",
+ groupName: "",
isSecondary: false,
isAllDay: false,
hideFromStats: false,
@@ -27,6 +28,7 @@ export function presetToFormData(preset: ShiftPreset): PresetFormData {
endTime: preset.endTime,
color: preset.color,
notes: preset.notes || "",
+ groupName: preset.groupName || "",
isSecondary: preset.isSecondary || false,
isAllDay: preset.isAllDay || false,
hideFromStats: preset.hideFromStats || false,
@@ -47,6 +49,8 @@ interface PresetFormCardProps {
disabled?: boolean;
cardRef?: Ref<HTMLFormElement>;
titleRef?: Ref<HTMLInputElement>;
+ /** Existing group names across this calendar's presets, offered as datalist suggestions. */
+ existingGroupNames?: string[];
}
/** "Neue Vorlage" card; the same card edits an existing preset. */
@@ -59,6 +63,7 @@ export function PresetFormCard({
disabled,
cardRef,
titleRef,
+ existingGroupNames = [],
}: PresetFormCardProps) {
const t = useTranslations();
const id = useId();
@@ -133,6 +138,23 @@ export function PresetFormCard({
/>
</Field>
+ <Field label={t("preset.group")} htmlFor={`${id}-group`}>
+ <Input
+ id={`${id}-group`}
+ list={`${id}-group-names`}
+ value={value.groupName}
+ onChange={(e) => onChange({ groupName: e.target.value })}
+ placeholder={t("preset.groupPlaceholder")}
+ className={fieldClass}
+ disabled={disabled}
+ />
+ <datalist id={`${id}-group-names`}>
+ {existingGroupNames.map((name) => (
+ <option key={name} value={name} />
+ ))}
+ </datalist>
+ </Field>
+
<div className="flex flex-col gap-2.5 pt-0.5">
<CheckRow
id={`${id}-allday`}
diff --git a/components/preset-list.tsx b/components/preset-list.tsx
index d226d1d..b9ac818 100644
--- a/components/preset-list.tsx
+++ b/components/preset-list.tsx
@@ -1,5 +1,6 @@
"use client";
+import { useMemo } from "react";
import { useTranslations } from "next-intl";
import {
DndContext,
@@ -18,9 +19,9 @@ import {
verticalListSortingStrategy,
} from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
-import { GripVertical, Pencil, Trash2 } from "lucide-react";
+import { Copy, GripVertical, Pencil, Tag, Trash2 } from "lucide-react";
import { ShiftPreset } from "@/lib/db/schema";
-import { getShiftCode, presetTime, shiftVars } from "@/lib/shift-display";
+import { getShiftCode, groupPresetsByName, presetTime, shiftVars } from "@/lib/shift-display";
import { ListRow, Pill, RowIconButton, SectionLabel } from "@/components/form-kit";
import { cn } from "@/lib/utils";
@@ -28,7 +29,9 @@ interface PresetRowActions {
readOnly: boolean;
editingId: string | null;
deletingId: string | null;
+ cloningId: string | null;
onEdit: (preset: ShiftPreset) => void;
+ onClone: (preset: ShiftPreset) => void;
onDelete: (preset: ShiftPreset) => void;
}
@@ -43,7 +46,9 @@ function SortablePresetRow({
readOnly,
editingId,
deletingId,
+ cloningId,
onEdit,
+ onClone,
onDelete,
}: SortablePresetRowProps) {
const t = useTranslations();
@@ -56,7 +61,7 @@ function SortablePresetRow({
transition,
isDragging,
} = useSortable({ id: preset.id, disabled: !draggable });
- const busy = deletingId === preset.id;
+ const busy = deletingId === preset.id || cloningId === preset.id;
return (
<div
@@ -105,6 +110,12 @@ function SortablePresetRow({
</div>
{!readOnly && (
<>
+ <RowIconButton
+ icon={Copy}
+ label={t("common.copy")}
+ onClick={() => onClone(preset)}
+ disabled={busy}
+ />
<RowIconButton
icon={Pencil}
label={t("preset.edit")}
@@ -131,39 +142,89 @@ interface PresetSectionProps extends PresetRowActions {
onReorder: (next: ShiftPreset[]) => void;
}
-/** One sortable group; primary and secondary presets are reordered separately. */
-export function PresetSection({ label, presets, onReorder, ...actions }: PresetSectionProps) {
- const sensors = useSensors(
- useSensor(PointerSensor),
- useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
- );
- const draggable = !actions.readOnly && presets.length > 1;
+interface PresetSubgroupProps extends PresetRowActions {
+ subgroupPresets: ShiftPreset[];
+ allPresets: ShiftPreset[];
+ onReorder: (next: ShiftPreset[]) => void;
+ sensors: ReturnType<typeof useSensors>;
+}
+
+// One DndContext per subgroup, so a drag can never cross a group boundary;
+// on drop the reordered slice is spliced back into the section's full order.
+function PresetSubgroup({
+ subgroupPresets,
+ allPresets,
+ onReorder,
+ sensors,
+ ...actions
+}: PresetSubgroupProps) {
+ const ids = subgroupPresets.map((p) => p.id);
+ const draggable = !actions.readOnly && subgroupPresets.length > 1;
const handleDragEnd = ({ active, over }: DragEndEvent) => {
if (!over || active.id === over.id) return;
- const oldIndex = presets.findIndex((p) => p.id === active.id);
- const newIndex = presets.findIndex((p) => p.id === over.id);
+ const oldIndex = ids.indexOf(active.id as string);
+ const newIndex = ids.indexOf(over.id as string);
if (oldIndex < 0 || newIndex < 0) return;
- onReorder(arrayMove(presets, oldIndex, newIndex));
+ const idSet = new Set(ids);
+ const queue = arrayMove(subgroupPresets, oldIndex, newIndex);
+ onReorder(allPresets.map((p) => (idSet.has(p.id) ? queue.shift()! : p)));
};
+ return (
+ <DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
+ <SortableContext items={ids} strategy={verticalListSortingStrategy}>
+ <div className="flex flex-col gap-2">
+ {subgroupPresets.map((preset) => (
+ <SortablePresetRow
+ key={preset.id}
+ preset={preset}
+ draggable={draggable}
+ {...actions}
+ />
+ ))}
+ </div>
+ </SortableContext>
+ </DndContext>
+ );
+}
+
+/** One section (primary or secondary); presets cluster under their group name. */
+export function PresetSection({ label, presets, onReorder, ...actions }: PresetSectionProps) {
+ const sensors = useSensors(
+ useSensor(PointerSensor),
+ useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
+ );
+ const { ungrouped, groups } = useMemo(() => groupPresetsByName(presets), [presets]);
+
return (
<section>
<SectionLabel>{label}</SectionLabel>
- <DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
- <SortableContext items={presets.map((p) => p.id)} strategy={verticalListSortingStrategy}>
- <div className="flex flex-col gap-2">
- {presets.map((preset) => (
- <SortablePresetRow
- key={preset.id}
- preset={preset}
- draggable={draggable}
- {...actions}
- />
- ))}
+ {ungrouped.length > 0 && (
+ <PresetSubgroup
+ subgroupPresets={ungrouped}
+ allPresets={presets}
+ onReorder={onReorder}
+ sensors={sensors}
+ {...actions}
+ />
+ )}
+ {groups.map(({ name, items }) => (
+ <div key={name} className="mt-2.5 flex flex-col gap-2">
+ <div className="flex items-center gap-1.5 px-1 text-[12px] font-medium text-fg-tertiary">
+ <Tag className="size-3" />
+ {name}
+ <span className="opacity-70">({items.length})</span>
</div>
- </SortableContext>
- </DndContext>
+ <PresetSubgroup
+ subgroupPresets={items}
+ allPresets={presets}
+ onReorder={onReorder}
+ sensors={sensors}
+ {...actions}
+ />
+ </div>
+ ))}
</section>
);
}
diff --git a/components/preset-manage-sheet.tsx b/components/preset-manage-sheet.tsx
index 9bd0a24..4dbe534 100644
--- a/components/preset-manage-sheet.tsx
+++ b/components/preset-manage-sheet.tsx
@@ -15,6 +15,7 @@ import {
samePresetForm,
} from "@/components/preset-form";
import { ShiftPreset } from "@/lib/db/schema";
+import { groupPresetsByName } from "@/lib/shift-display";
import { usePresets, type PresetFormData } from "@/hooks/usePresets";
import { useCalendarPermission } from "@/hooks/useCalendarPermission";
import { useReportDirty } from "@/hooks/useDirtyState";
@@ -53,6 +54,7 @@ export function PresetsPanel({
const [baseline, setBaseline] = useState<PresetFormData>(EMPTY_PRESET_FORM);
const [isSaving, setIsSaving] = useState(false);
const [deletingId, setDeletingId] = useState<string | null>(null);
+ const [cloningId, setCloningId] = useState<string | null>(null);
const [deleteTarget, setDeleteTarget] = useState<ShiftPreset | null>(null);
const [pendingDiscard, setPendingDiscard] = useState<(() => void) | null>(null);
// Holds the dropped order until the reorder request settles, so rows don't snap back.
@@ -71,6 +73,10 @@ export function PresetsPanel({
}, [presets, pendingOrder]);
const primary = ordered.filter((p) => !p.isSecondary);
const secondary = ordered.filter((p) => p.isSecondary);
+ const existingGroupNames = useMemo(
+ () => groupPresetsByName(presets).groups.map((g) => g.name),
+ [presets]
+ );
const resetForm = () => {
setEditingPreset(null);
@@ -108,6 +114,20 @@ export function PresetsPanel({
}
};
+ const clonePreset = async (preset: ShiftPreset) => {
+ if (isReadOnly || isSaving || cloningId) return;
+ setCloningId(preset.id);
+ try {
+ const success = await createPreset({
+ ...presetToFormData(preset),
+ title: `${preset.title} (${t("preset.copiedSuffix")})`,
+ });
+ if (success) onPresetsChange?.();
+ } finally {
+ setCloningId(null);
+ }
+ };
+
const handleDeleteConfirm = async () => {
const target = deleteTarget;
if (!target) return;
@@ -148,7 +168,9 @@ export function PresetsPanel({
readOnly: isReadOnly,
editingId: editingPreset?.id ?? null,
deletingId,
+ cloningId,
onEdit: startEdit,
+ onClone: clonePreset,
onDelete: setDeleteTarget,
};
@@ -195,6 +217,7 @@ export function PresetsPanel({
disabled={isSaving}
cardRef={formRef}
titleRef={titleRef}
+ existingGroupNames={existingGroupNames}
/>
)}
</PanelBody>
diff --git a/components/stamp-dock.tsx b/components/stamp-dock.tsx
index e579440..d0e9026 100644
--- a/components/stamp-dock.tsx
+++ b/components/stamp-dock.tsx
@@ -1,6 +1,6 @@
"use client";
-import { ComponentProps, useState } from "react";
+import { ComponentProps, useMemo, useState } from "react";
import { useTranslations } from "next-intl";
import {
Check,
@@ -8,13 +8,15 @@ import {
ChevronUp,
Ellipsis,
Hand,
+ ListChecks,
Plus,
SlidersHorizontal,
+ Tag,
} from "lucide-react";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { ShiftPreset } from "@/lib/db/schema";
-import { getShiftCode, presetTime, shiftVars } from "@/lib/shift-display";
-import { cn } from "@/lib/utils";
+import { getShiftCode, groupPresetsByName, presetTime, shiftVars } from "@/lib/shift-display";
+import { cn, isMultiSelectClick } from "@/lib/utils";
export function splitStampPresets(presets: ShiftPreset[]) {
return {
@@ -28,19 +30,32 @@ export function orderStampPresets(presets: ShiftPreset[]): ShiftPreset[] {
return splitStampPresets(presets).primary;
}
+/** Selecting a group arms every preset in it; an already fully-selected group disarms instead. */
+function toggleGroupSelection(
+ groupIds: string[],
+ activeIds: Set<string>,
+ onSelectPreset: (id: string, multiSelect: boolean) => void
+) {
+ const allSelected = groupIds.every((id) => activeIds.has(id));
+ groupIds.forEach((id) => {
+ if (allSelected || !activeIds.has(id)) onSelectPreset(id, true);
+ });
+}
+
type MoreVariant = "dock" | "compare" | "bar";
interface MoreChipProps extends ComponentProps<"button"> {
variant: MoreVariant;
count: number;
- /** The armed secondary preset; the chip shows it in place so the row keeps its layout. */
- active: ShiftPreset | undefined;
+ /** Selected secondary presets; shown inline when there's exactly one. */
+ active: ShiftPreset[];
open: boolean;
}
function MoreChip({ variant, count, active, open, className, ...props }: MoreChipProps) {
const t = useTranslations();
- const label = (
+ const single = active.length === 1 ? active[0] : undefined;
+ const countLabel = (
<span className="whitespace-nowrap">
{t("preset.secondary")}
<span className="opacity-60"> · </span>
@@ -57,7 +72,7 @@ function MoreChip({ variant, count, active, open, className, ...props }: MoreChi
{...props}
className={cn(
"flex h-12 shrink-0 items-center gap-2.5 rounded-[10px] border py-1.5 pl-2 pr-2.5 text-left transition-colors",
- active
+ active.length > 0
? "border-brand bg-brand-soft"
: open
? "border-control bg-surface-sunken"
@@ -65,43 +80,53 @@ function MoreChip({ variant, count, active, open, className, ...props }: MoreChi
className
)}
>
- {active ? (
+ {single ? (
<>
<span
className="shift-solid flex size-[22px] shrink-0 items-center justify-center rounded-[5px] text-[11px] font-bold"
- style={shiftVars(active.color)}
+ style={shiftVars(single.color)}
>
- {getShiftCode(active.title)}
+ {getShiftCode(single.title)}
</span>
<span className="min-w-0">
<span className="block max-w-[140px] truncate text-[13px] font-semibold text-brand-ink">
- {active.title}
+ {single.title}
</span>
<span className="block font-mono text-[11.5px] text-brand-ink">
- {presetTime(active, t("shift.allDayShift"))}
+ {presetTime(single, t("shift.allDayShift"))}
</span>
</span>
</>
+ ) : active.length > 1 ? (
+ <>
+ <span className="flex size-[22px] shrink-0 items-center justify-center rounded-[5px] bg-brand text-[11px] font-bold text-white">
+ {active.length}
+ </span>
+ <span className="text-[13px] font-semibold text-brand-ink">
+ {t("preset.secondary")}
+ </span>
+ </>
) : (
<>
<span className="flex size-[22px] shrink-0 items-center justify-center rounded-[5px] bg-surface-sunken text-fg-secondary">
<Ellipsis className="size-3.5" />
</span>
- <span className="text-[13px] font-semibold text-fg-strong">{label}</span>
+ <span className="text-[13px] font-semibold text-fg-strong">{countLabel}</span>
</>
)}
- <Chevron className={cn("size-4 shrink-0", active ? "text-brand-ink" : "text-fg-tertiary")} />
+ <Chevron className={cn("size-4 shrink-0", active.length > 0 ? "text-brand-ink" : "text-fg-tertiary")} />
</button>
);
}
const dock = variant === "dock";
const Chevron = dock ? ChevronUp : ChevronDown;
+ const hasActive = active.length > 0;
const tone = dock
- ? active
+ ? hasActive
? "bg-brand text-white"
: cn("text-dock-ink hover:bg-white/10", open && "bg-white/10")
- : active
+ : hasActive
? "border-brand bg-brand-soft text-brand-ink"
: cn(
"border-line bg-surface-card text-fg-body hover:bg-surface-panel",
@@ -118,42 +143,44 @@ function MoreChip({ variant, count, active, open, className, ...props }: MoreChi
className
)}
>
- {active ? (
+ {single ? (
<>
- <span className="size-[7px] shrink-0 rounded-full" style={{ backgroundColor: active.color }} />
- <span className="max-w-[140px] truncate">{active.title}</span>
+ <span className="size-[7px] shrink-0 rounded-full" style={{ backgroundColor: single.color }} />
+ <span className="max-w-[140px] truncate">{single.title}</span>
</>
+ ) : active.length > 1 ? (
+ <span className="whitespace-nowrap font-mono">{active.length}</span>
) : (
- label
+ countLabel
)}
<Chevron className="-mr-0.5 size-3.5 shrink-0 opacity-70" />
</button>
);
}
-/** Secondary presets as rows; picking the armed one disarms it. */
+/** Secondary presets as rows; picking one toggles it (additively when multiSelect is on). */
function SecondaryPresetList({
presets,
- selectedPresetId,
+ selectedPresetIds,
onPick,
touch = false,
}: {
presets: ShiftPreset[];
- selectedPresetId: string | undefined;
- onPick: (id: string | undefined) => void;
+ selectedPresetIds: string[];
+ onPick: (id: string, multiSelect: boolean) => void;
touch?: boolean;
}) {
const t = useTranslations();
return (
<div className="flex flex-col gap-px">
{presets.map((preset) => {
- const active = preset.id === selectedPresetId;
+ const active = selectedPresetIds.includes(preset.id);
return (
<button
key={preset.id}
type="button"
aria-pressed={active}
- onClick={() => onPick(active ? undefined : preset.id)}
+ onClick={(event) => onPick(preset.id, isMultiSelectClick(event))}
className={cn(
"flex items-center gap-2.5 rounded-[8px] px-2.5 text-left outline-none transition-colors",
touch ? "h-11 text-[14px]" : "h-9 text-[13px]",
@@ -183,29 +210,29 @@ function SecondaryPresetList({
interface MorePresetsProps {
/** Secondary presets only. */
presets: ShiftPreset[];
- selectedPresetId: string | undefined;
- onSelectPreset: (id: string | undefined) => void;
+ selectedPresetIds: string[];
+ onSelectPreset: (id: string | undefined, multiSelect?: boolean) => void;
+ /** When on, picking a preset never closes the popover (stamp bar's multi-select toggle). */
+ multiMode?: boolean;
}
/** Trailing "Weitere · N" chip that opens the secondary presets in a popover. */
export function MorePresets({
variant,
presets,
- selectedPresetId,
+ selectedPresetIds,
onSelectPreset,
+ multiMode = false,
}: MorePresetsProps & { variant: "dock" | "compare" }) {
const [open, setOpen] = useState(false);
if (presets.length === 0) return null;
+ const selectedSet = new Set(selectedPresetIds);
+ const active = presets.filter((p) => selectedSet.has(p.id));
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
- <MoreChip
- variant={variant}
- count={presets.length}
- active={presets.find((p) => p.id === selectedPresetId)}
- open={open}
- />
+ <MoreChip variant={variant} count={presets.length} active={active} open={open} />
</PopoverTrigger>
<PopoverContent
side={variant === "dock" ? "top" : "bottom"}
@@ -216,10 +243,11 @@ export function MorePresets({
>
<SecondaryPresetList
presets={presets}
- selectedPresetId={selectedPresetId}
- onPick={(id) => {
- onSelectPreset(id);
- setOpen(false);
+ selectedPresetIds={selectedPresetIds}
+ onPick={(id, clickMultiSelect) => {
+ const multiSelect = multiMode || clickMultiSelect;
+ onSelectPreset(id, multiSelect);
+ if (!multiSelect) setOpen(false);
}}
/>
</PopoverContent>
@@ -229,14 +257,63 @@ export function MorePresets({
interface StampProps {
presets: ShiftPreset[];
- selectedPresetId: string | undefined;
- onSelectPreset: (id: string | undefined) => void;
+ selectedPresetIds: string[];
+ onSelectPreset: (id: string | undefined, multiSelect?: boolean) => void;
onManage: () => void;
}
-export function StampDock({ presets, selectedPresetId, onSelectPreset, onManage }: StampProps) {
+/** Toggle button that switches primary chips from replace-on-click to add/remove-on-click. */
+export function MultiSelectToggle({
+ variant,
+ active,
+ onClick,
+}: {
+ variant: "dock" | "bar" | "compare";
+ active: boolean;
+ onClick: () => void;
+}) {
+ const t = useTranslations();
+ const label = t("calendarView.multiSelect");
+ return (
+ <button
+ type="button"
+ onClick={onClick}
+ aria-pressed={active}
+ aria-label={label}
+ title={label}
+ className={cn(
+ "flex shrink-0 items-center justify-center transition-colors",
+ variant === "dock"
+ ? "size-[30px] rounded-lg"
+ : variant === "bar"
+ ? "size-9 rounded-lg"
+ : "size-7 rounded-[7px]",
+ active
+ ? variant === "compare"
+ ? "bg-brand-soft text-brand-ink"
+ : "bg-brand text-white"
+ : variant === "dock"
+ ? "text-fg-faint hover:bg-white/10 hover:text-white"
+ : variant === "bar"
+ ? "text-fg-secondary hover:bg-surface-sunken"
+ : "text-fg-tertiary hover:bg-surface-sunken"
+ )}
+ >
+ <ListChecks
+ className={cn(
+ variant === "bar" ? "size-[18px]" : variant === "dock" ? "size-[15px]" : "size-3.5"
+ )}
+ />
+ </button>
+ );
+}
+
+export function StampDock({ presets, selectedPresetIds, onSelectPreset, onManage }: StampProps) {
const t = useTranslations();
const { primary, secondary } = splitStampPresets(presets);
+ const groups = useMemo(() => groupPresetsByName(presets).groups, [presets]);
+ const [multiMode, setMultiMode] = useState(false);
+ const activeIds = new Set(selectedPresetIds);
return (
<div
@@ -259,14 +336,16 @@ export function StampDock({ presets, selectedPresetId, onSelectPreset, onManage
</button>
)}
{primary.map((preset, index) => {
- const active = preset.id === selectedPresetId;
+ const active = activeIds.has(preset.id);
const key = index < 9 ? String(index + 1) : null;
return (
<button
key={preset.id}
type="button"
aria-pressed={active}
- onClick={() => onSelectPreset(active ? undefined : preset.id)}
+ onClick={(event) =>
+ onSelectPreset(preset.id, multiMode || isMultiSelectClick(event))
+ }
title={
preset.isAllDay
? preset.title
@@ -295,13 +374,38 @@ export function StampDock({ presets, selectedPresetId, onSelectPreset, onManage
</button>
);
})}
+ {groups.map((group) => {
+ const ids = group.items.map((p) => p.id);
+ const allSelected = ids.every((id) => activeIds.has(id));
+ return (
+ <button
+ key={group.name}
+ type="button"
+ aria-pressed={allSelected}
+ onClick={() => toggleGroupSelection(ids, activeIds, onSelectPreset)}
+ title={t("preset.selectGroupHint")}
+ className={cn(
+ "flex h-[30px] shrink-0 items-center gap-[7px] rounded-lg border border-dashed px-2.5 text-[12.5px] font-medium transition-colors",
+ allSelected
+ ? "border-white/40 bg-brand text-white"
+ : "border-white/15 text-dock-ink hover:bg-white/10"
+ )}
+ >
+ <Tag className="size-3" />
+ <span className="max-w-[110px] truncate">{group.name}</span>
+ <span className="opacity-70">({group.items.length})</span>
+ </button>
+ );
+ })}
</div>
<MorePresets
variant="dock"
presets={secondary}
- selectedPresetId={selectedPresetId}
+ selectedPresetIds={selectedPresetIds}
onSelectPreset={onSelectPreset}
+ multiMode={multiMode}
/>
+ <MultiSelectToggle variant="dock" active={multiMode} onClick={() => setMultiMode((m) => !m)} />
<div className="mx-0.5 h-[22px] w-px shrink-0 bg-dock-line" />
<button
type="button"
@@ -318,16 +422,19 @@ export function StampDock({ presets, selectedPresetId, onSelectPreset, onManage
export function MobilePresetBar({
presets,
- selectedPresetId,
+ selectedPresetIds,
onSelectPreset,
onManage,
}: StampProps) {
const t = useTranslations();
const [moreOpen, setMoreOpen] = useState(false);
+ const [multiMode, setMultiMode] = useState(false);
const { primary, secondary } = splitStampPresets(presets);
- const active = presets.find((p) => p.id === selectedPresetId);
- const activeSecondary = active?.isSecondary ? active : undefined;
- // Otherwise the list would pop up by itself once a preset is marked secondary again
+ const groups = useMemo(() => groupPresetsByName(presets).groups, [presets]);
+ const activeIds = new Set(selectedPresetIds);
+ const activePresets = presets.filter((p) => activeIds.has(p.id));
+ const activeSecondary = activePresets.filter((p) => p.isSecondary);
+ // Otherwise the list would pop up by itself once nothing secondary is armed anymore
if (moreOpen && secondary.length === 0) setMoreOpen(false);
return (
@@ -338,10 +445,11 @@ export function MobilePresetBar({
<SecondaryPresetList
touch
presets={secondary}
- selectedPresetId={selectedPresetId}
- onPick={(id) => {
- onSelectPreset(id);
- setMoreOpen(false);
+ selectedPresetIds={selectedPresetIds}
+ onPick={(id, clickMultiSelect) => {
+ const multiSelect = multiMode || clickMultiSelect;
+ onSelectPreset(id, multiSelect);
+ if (!multiSelect) setMoreOpen(false);
}}
/>
</div>
@@ -360,13 +468,13 @@ export function MobilePresetBar({
</button>
)}
{primary.map((preset) => {
- const on = preset.id === selectedPresetId;
+ const on = activeIds.has(preset.id);
return (
<button
key={preset.id}
type="button"
aria-pressed={on}
- onClick={() => onSelectPreset(on ? undefined : preset.id)}
+ onClick={() => onSelectPreset(preset.id, multiMode)}
className={cn(
"flex h-12 shrink-0 items-center gap-2.5 rounded-[10px] border py-1.5 pl-2 pr-3 text-left transition-colors",
on
@@ -401,6 +509,29 @@ export function MobilePresetBar({
</button>
);
})}
+ {groups.map((group) => {
+ const ids = group.items.map((p) => p.id);
+ const allSelected = ids.every((id) => activeIds.has(id));
+ return (
+ <button
+ key={group.name}
+ type="button"
+ aria-pressed={allSelected}
+ onClick={() => toggleGroupSelection(ids, activeIds, onSelectPreset)}
+ className={cn(
+ "flex h-12 shrink-0 items-center gap-2 rounded-[10px] border border-dashed px-3 text-left transition-colors",
+ allSelected
+ ? "border-brand bg-brand-soft text-brand-ink"
+ : "border-control text-fg-secondary"
+ )}
+ >
+ <Tag className="size-3.5 shrink-0" />
+ <span className="text-[13px] font-medium">
+ {group.name} ({group.items.length})
+ </span>
+ </button>
+ );
+ })}
{secondary.length > 0 && (
<MoreChip
variant="bar"
@@ -411,12 +542,15 @@ export function MobilePresetBar({
/>
)}
</div>
+ <MultiSelectToggle variant="bar" active={multiMode} onClick={() => setMultiMode((m) => !m)} />
</div>
- {active && (
+ {activePresets.length > 0 && (
<div className="flex items-center gap-2 px-4 pb-2.5 text-[12px] leading-snug text-fg-secondary">
<Hand className="size-4 shrink-0" />
<span className="min-w-0 flex-1">
- {t("calendarView.stampHint", { title: active.title })}
+ {activePresets.length === 1
+ ? t("calendarView.stampHint", { title: activePresets[0].title })
+ : t("calendarView.stampHintMulti", { count: activePresets.length })}
</span>
<button
type="button"
diff --git a/drizzle/0015_neat_serpent_society.sql b/drizzle/0015_neat_serpent_society.sql
new file mode 100644
index 0000000..0eddaaf
--- /dev/null
+++ b/drizzle/0015_neat_serpent_society.sql
@@ -0,0 +1 @@
+ALTER TABLE `shift_presets` ADD `group_name` text;
\ No newline at end of file
diff --git a/drizzle/meta/0015_snapshot.json b/drizzle/meta/0015_snapshot.json
new file mode 100644
index 0000000..bf46c64
--- /dev/null
+++ b/drizzle/meta/0015_snapshot.json
@@ -0,0 +1,1687 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "23038eda-67b6-4288-9d0e-c207b5434877",
+ "prevId": "af48f9e4-d5e2-4cd2-a283-0b41d0e35cd1",
+ "tables": {
+ "account": {
+ "name": "account",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "account_id": {
+ "name": "account_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "access_token": {
+ "name": "access_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refresh_token": {
+ "name": "refresh_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "id_token": {
+ "name": "id_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "access_token_expires_at": {
+ "name": "access_token_expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refresh_token_expires_at": {
+ "name": "refresh_token_expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "scope": {
+ "name": "scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "password": {
+ "name": "password",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "account_userId_idx": {
+ "name": "account_userId_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "account_user_id_user_id_fk": {
+ "name": "account_user_id_user_id_fk",
+ "tableFrom": "account",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "audit_logs": {
+ "name": "audit_logs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "action": {
+ "name": "action",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "resource_type": {
+ "name": "resource_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "resource_id": {
+ "name": "resource_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "ip_address": {
+ "name": "ip_address",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_agent": {
+ "name": "user_agent",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "severity": {
+ "name": "severity",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'info'"
+ },
+ "is_user_visible": {
+ "name": "is_user_visible",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "timestamp": {
+ "name": "timestamp",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {
+ "audit_logs_userId_timestamp_idx": {
+ "name": "audit_logs_userId_timestamp_idx",
+ "columns": [
+ "user_id",
+ "timestamp"
+ ],
+ "isUnique": false
+ },
+ "audit_logs_action_timestamp_idx": {
+ "name": "audit_logs_action_timestamp_idx",
+ "columns": [
+ "action",
+ "timestamp"
+ ],
+ "isUnique": false
+ },
+ "audit_logs_userVisible_userId_timestamp_idx": {
+ "name": "audit_logs_userVisible_userId_timestamp_idx",
+ "columns": [
+ "is_user_visible",
+ "user_id",
+ "timestamp"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "audit_logs_user_id_user_id_fk": {
+ "name": "audit_logs_user_id_user_id_fk",
+ "tableFrom": "audit_logs",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "calendar_access_tokens": {
+ "name": "calendar_access_tokens",
+ "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
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "permission": {
+ "name": "permission",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'read'"
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_by": {
+ "name": "created_by",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ },
+ "last_used_at": {
+ "name": "last_used_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "usage_count": {
+ "name": "usage_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ }
+ },
+ "indexes": {
+ "calendar_access_tokens_token_unique": {
+ "name": "calendar_access_tokens_token_unique",
+ "columns": [
+ "token"
+ ],
+ "isUnique": true
+ },
+ "calendar_access_tokens_token_idx": {
+ "name": "calendar_access_tokens_token_idx",
+ "columns": [
+ "token"
+ ],
+ "isUnique": false
+ },
+ "calendar_access_tokens_calendarId_isActive_idx": {
+ "name": "calendar_access_tokens_calendarId_isActive_idx",
+ "columns": [
+ "calendar_id",
+ "is_active"
+ ],
+ "isUnique": false
+ },
+ "calendar_access_tokens_createdBy_idx": {
+ "name": "calendar_access_tokens_createdBy_idx",
+ "columns": [
+ "created_by"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "calendar_access_tokens_calendar_id_calendars_id_fk": {
+ "name": "calendar_access_tokens_calendar_id_calendars_id_fk",
+ "tableFrom": "calendar_access_tokens",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "calendar_access_tokens_created_by_user_id_fk": {
+ "name": "calendar_access_tokens_created_by_user_id_fk",
+ "tableFrom": "calendar_access_tokens",
+ "tableTo": "user",
+ "columnsFrom": [
+ "created_by"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "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
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'note'"
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "recurring_pattern": {
+ "name": "recurring_pattern",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'none'"
+ },
+ "recurring_interval": {
+ "name": "recurring_interval",
+ "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": {
+ "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": {}
+ },
+ "calendar_shares": {
+ "name": "calendar_shares",
+ "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
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "permission": {
+ "name": "permission",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'read'"
+ },
+ "shared_by": {
+ "name": "shared_by",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {
+ "calendar_shares_calendarId_idx": {
+ "name": "calendar_shares_calendarId_idx",
+ "columns": [
+ "calendar_id"
+ ],
+ "isUnique": false
+ },
+ "calendar_shares_userId_idx": {
+ "name": "calendar_shares_userId_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "calendar_shares_calendar_id_calendars_id_fk": {
+ "name": "calendar_shares_calendar_id_calendars_id_fk",
+ "tableFrom": "calendar_shares",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "calendar_shares_user_id_user_id_fk": {
+ "name": "calendar_shares_user_id_user_id_fk",
+ "tableFrom": "calendar_shares",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "calendar_shares_shared_by_user_id_fk": {
+ "name": "calendar_shares_shared_by_user_id_fk",
+ "tableFrom": "calendar_shares",
+ "tableTo": "user",
+ "columnsFrom": [
+ "shared_by"
+ ],
+ "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'"
+ },
+ "owner_id": {
+ "name": "owner_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "guest_permission": {
+ "name": "guest_permission",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'none'"
+ },
+ "view_settings": {
+ "name": "view_settings",
+ "type": "text",
+ "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": {
+ "calendars_ownerId_idx": {
+ "name": "calendars_ownerId_idx",
+ "columns": [
+ "owner_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "calendars_owner_id_user_id_fk": {
+ "name": "calendars_owner_id_user_id_fk",
+ "tableFrom": "calendars",
+ "tableTo": "user",
+ "columnsFrom": [
+ "owner_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "external_syncs": {
+ "name": "external_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
+ },
+ "sync_type": {
+ "name": "sync_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'icloud'"
+ },
+ "calendar_url": {
+ "name": "calendar_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
+ },
+ "auto_sync_interval": {
+ "name": "auto_sync_interval",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "is_one_time_import": {
+ "name": "is_one_time_import",
+ "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": {
+ "external_syncs_calendar_id_calendars_id_fk": {
+ "name": "external_syncs_calendar_id_calendars_id_fk",
+ "tableFrom": "external_syncs",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "session": {
+ "name": "session",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ip_address": {
+ "name": "ip_address",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_agent": {
+ "name": "user_agent",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "impersonated_by": {
+ "name": "impersonated_by",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "session_token_unique": {
+ "name": "session_token_unique",
+ "columns": [
+ "token"
+ ],
+ "isUnique": true
+ },
+ "session_userId_idx": {
+ "name": "session_userId_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "session_user_id_user_id_fk": {
+ "name": "session_user_id_user_id_fk",
+ "tableFrom": "session",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_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
+ },
+ "group_name": {
+ "name": "group_name",
+ "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
+ },
+ "order": {
+ "name": "order",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "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
+ },
+ "external_event_id": {
+ "name": "external_event_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "external_sync_id": {
+ "name": "external_sync_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "synced_from_external": {
+ "name": "synced_from_external",
+ "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_external_sync_id_external_syncs_id_fk": {
+ "name": "shifts_external_sync_id_external_syncs_id_fk",
+ "tableFrom": "shifts",
+ "tableTo": "external_syncs",
+ "columnsFrom": [
+ "external_sync_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "sync_logs": {
+ "name": "sync_logs",
+ "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
+ },
+ "external_sync_id": {
+ "name": "external_sync_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "external_sync_name": {
+ "name": "external_sync_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "error_message": {
+ "name": "error_message",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "shifts_created": {
+ "name": "shifts_created",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "shifts_updated": {
+ "name": "shifts_updated",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "shifts_deleted": {
+ "name": "shifts_deleted",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "sync_type": {
+ "name": "sync_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'auto'"
+ },
+ "is_read": {
+ "name": "is_read",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "synced_at": {
+ "name": "synced_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "sync_logs_calendar_id_calendars_id_fk": {
+ "name": "sync_logs_calendar_id_calendars_id_fk",
+ "tableFrom": "sync_logs",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "sync_logs_external_sync_id_external_syncs_id_fk": {
+ "name": "sync_logs_external_sync_id_external_syncs_id_fk",
+ "tableFrom": "sync_logs",
+ "tableTo": "external_syncs",
+ "columnsFrom": [
+ "external_sync_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "user": {
+ "name": "user",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email_verified": {
+ "name": "email_verified",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "image": {
+ "name": "image",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "banned": {
+ "name": "banned",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "ban_reason": {
+ "name": "ban_reason",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "ban_expires": {
+ "name": "ban_expires",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "user_email_unique": {
+ "name": "user_email_unique",
+ "columns": [
+ "email"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "user_calendar_subscriptions": {
+ "name": "user_calendar_subscriptions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "calendar_id": {
+ "name": "calendar_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'subscribed'"
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'guest'"
+ },
+ "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": {
+ "user_calendar_subscriptions_userId_idx": {
+ "name": "user_calendar_subscriptions_userId_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ },
+ "user_calendar_subscriptions_calendarId_idx": {
+ "name": "user_calendar_subscriptions_calendarId_idx",
+ "columns": [
+ "calendar_id"
+ ],
+ "isUnique": false
+ },
+ "user_calendar_subscriptions_status_idx": {
+ "name": "user_calendar_subscriptions_status_idx",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "user_calendar_subscriptions_user_id_user_id_fk": {
+ "name": "user_calendar_subscriptions_user_id_user_id_fk",
+ "tableFrom": "user_calendar_subscriptions",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "user_calendar_subscriptions_calendar_id_calendars_id_fk": {
+ "name": "user_calendar_subscriptions_calendar_id_calendars_id_fk",
+ "tableFrom": "user_calendar_subscriptions",
+ "tableTo": "calendars",
+ "columnsFrom": [
+ "calendar_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "user_preferences": {
+ "name": "user_preferences",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "view_settings": {
+ "name": "view_settings",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "CURRENT_TIMESTAMP"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "user_preferences_user_id_user_id_fk": {
+ "name": "user_preferences_user_id_user_id_fk",
+ "tableFrom": "user_preferences",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "verification": {
+ "name": "verification",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "identifier": {
+ "name": "identifier",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "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 1135b61..5e552dd 100644
--- a/drizzle/meta/_journal.json
+++ b/drizzle/meta/_journal.json
@@ -106,6 +106,13 @@
"when": 1789142634528,
"tag": "0014_long_the_liberteens",
"breakpoints": true
+ },
+ {
+ "idx": 15,
+ "version": "6",
+ "when": 1789245373291,
+ "tag": "0015_neat_serpent_society",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/hooks/useCalendarShares.ts b/hooks/useCalendarShares.ts
index 8f86241..77eb03a 100644
--- a/hooks/useCalendarShares.ts
+++ b/hooks/useCalendarShares.ts
@@ -185,7 +185,7 @@ export function useCalendarShares(calendarId: string) {
// Optimistic update
const optimisticShare: CalendarShare = {
- id: `temp-${Date.now()}`,
+ id: `temp-${crypto.randomUUID()}`,
calendarId,
userId,
permission,
diff --git a/hooks/useCalendars.ts b/hooks/useCalendars.ts
index 397e94b..c5c3712 100644
--- a/hooks/useCalendars.ts
+++ b/hooks/useCalendars.ts
@@ -203,7 +203,7 @@ export function useCalendars(initialCalendarId?: string | null) {
);
const optimisticCalendar: CalendarWithCount = {
- id: `temp-${Date.now()}`,
+ id: `temp-${crypto.randomUUID()}`,
name,
color,
guestPermission: "none",
diff --git a/hooks/useCompareMode.ts b/hooks/useCompareMode.ts
index 7299d50..63c7243 100644
--- a/hooks/useCompareMode.ts
+++ b/hooks/useCompareMode.ts
@@ -16,7 +16,7 @@ interface UseCompareModeProps {
currentDate: Date;
setCurrentDate: (date: Date) => void;
selectDay: (day: Date) => void;
- selectedPresetId: string | undefined;
+ selectedPresetIds: string[];
}
export function useCompareMode({
@@ -26,7 +26,7 @@ export function useCompareMode({
currentDate,
setCurrentDate,
selectDay,
- selectedPresetId,
+ selectedPresetIds,
}: UseCompareModeProps) {
const router = useRouter();
const searchParams = useSearchParams();
@@ -143,44 +143,49 @@ export function useCompareMode({
const targetDate = toLocalDate(date);
selectDay(targetDate);
if (!isSameMonth(targetDate, currentDate)) setCurrentDate(targetDate);
- if (!selectedPresetId) return;
+ if (selectedPresetIds.length === 0) return;
const calendarPresets = compareData.presetsMap.get(calendarId) || [];
const calendarShifts = compareData.shiftsMap.get(calendarId) || [];
- const preset = calendarPresets.find((p) => p.id === selectedPresetId);
- if (!preset) return;
const dateKey = formatDateToLocal(targetDate);
if (compareTogglingDates.get(calendarId)?.has(dateKey)) return;
updateCompareToggling(calendarId, dateKey, true);
try {
- const existingShift = calendarShifts.find(
- (shift) =>
- shift.date &&
- isSameDay(shift.date as Date, targetDate) &&
- shift.title === preset.title &&
- shift.startTime === preset.startTime &&
- shift.endTime === preset.endTime
+ await Promise.all(
+ selectedPresetIds.map(async (presetId) => {
+ const preset = calendarPresets.find((p) => p.id === presetId);
+ if (!preset) return;
+
+ const existingShift = calendarShifts.find(
+ (shift) =>
+ shift.date &&
+ isSameDay(shift.date as Date, targetDate) &&
+ shift.title === preset.title &&
+ shift.startTime === preset.startTime &&
+ shift.endTime === preset.endTime
+ );
+
+ if (existingShift) {
+ await compareData.deleteShift({ calendarId, shiftId: existingShift.id });
+ } else {
+ await compareData.createShift({
+ calendarId,
+ formData: {
+ date: dateKey,
+ startTime: preset.startTime,
+ endTime: preset.endTime,
+ title: preset.title,
+ color: preset.color,
+ notes: preset.notes || "",
+ presetId: preset.id,
+ isAllDay: preset.isAllDay || false,
+ },
+ });
+ }
+ })
);
-
- if (existingShift) {
- await compareData.deleteShift({ calendarId, shiftId: existingShift.id });
- } else {
- await compareData.createShift({
- calendarId,
- formData: {
- date: dateKey,
- startTime: preset.startTime,
- endTime: preset.endTime,
- title: preset.title,
- color: preset.color,
- notes: preset.notes || "",
- presetId: preset.id,
- isAllDay: preset.isAllDay || false,
- },
- });
- }
} catch (error) {
console.error("Failed to toggle shift:", error);
toast.error(t("common.error"));
@@ -192,7 +197,7 @@ export function useCompareMode({
selectDay,
currentDate,
setCurrentDate,
- selectedPresetId,
+ selectedPresetIds,
compareData,
compareTogglingDates,
updateCompareToggling,
diff --git a/hooks/useNotes.ts b/hooks/useNotes.ts
index 345232a..1f4d8c4 100644
--- a/hooks/useNotes.ts
+++ b/hooks/useNotes.ts
@@ -152,7 +152,7 @@ export function useNotes(calendarId: string | undefined) {
// Create optimistic note
const optimisticNote: CalendarNote = {
- id: `temp-${Date.now()}`,
+ id: `temp-${crypto.randomUUID()}`,
date: parseLocalDate(formData.date),
note: formData.note,
type: formData.type || "note",
diff --git a/hooks/usePresets.ts b/hooks/usePresets.ts
index d4c4b80..278d351 100644
--- a/hooks/usePresets.ts
+++ b/hooks/usePresets.ts
@@ -13,6 +13,7 @@ export interface PresetFormData {
endTime: string;
color: string;
notes: string;
+ groupName: string;
isSecondary: boolean;
isAllDay: boolean;
hideFromStats: boolean;
@@ -101,13 +102,14 @@ function createOptimisticPreset(
formData: PresetFormData
): ShiftPreset {
return {
- id: `temp-${Date.now()}`,
+ id: `temp-${crypto.randomUUID()}`,
calendarId,
title: formData.title,
startTime: formData.startTime,
endTime: formData.endTime,
color: formData.color,
notes: formData.notes,
+ groupName: formData.groupName || null,
isSecondary: formData.isSecondary,
isAllDay: formData.isAllDay,
hideFromStats: formData.hideFromStats,
diff --git a/hooks/useShiftActions.ts b/hooks/useShiftActions.ts
index fe8570f..dc92b57 100644
--- a/hooks/useShiftActions.ts
+++ b/hooks/useShiftActions.ts
@@ -50,11 +50,8 @@ export function useShiftActions({
);
const handleAddShift = useCallback(
- async (date: Date | string, selectedPresetId: string | undefined) => {
- if (!selectedPresetId) return;
-
- const preset = presets.find((p) => p.id === selectedPresetId);
- if (!preset) return;
+ async (date: Date | string, presetIds: string[]) => {
+ if (presetIds.length === 0) return;
const targetDate = toLocalDate(date);
const dateKey = formatDateToLocal(targetDate);
@@ -64,39 +61,46 @@ export function useShiftActions({
setTogglingDates((prev) => new Set(prev).add(dateKey));
try {
- const existingShift = shifts.find(
- (shift) =>
- shift.date &&
- isSameDay(shift.date as Date, targetDate) &&
- shift.title === preset.title &&
- shift.startTime === preset.startTime &&
- shift.endTime === preset.endTime
- );
+ await Promise.all(
+ presetIds.map(async (presetId) => {
+ const preset = presets.find((p) => p.id === presetId);
+ if (!preset) return;
- if (existingShift) {
- try {
- await deleteShift(existingShift.id);
- } catch (error) {
- console.error("Failed to delete shift:", error);
- }
- } else {
- const shiftData: ShiftFormData = {
- date: dateKey,
- startTime: preset.startTime,
- endTime: preset.endTime,
- title: preset.title,
- color: preset.color,
- notes: preset.notes || "",
- presetId: preset.id,
- isAllDay: preset.isAllDay || false,
- };
+ const existingShift = shifts.find(
+ (shift) =>
+ shift.date &&
+ isSameDay(shift.date as Date, targetDate) &&
+ shift.title === preset.title &&
+ shift.startTime === preset.startTime &&
+ shift.endTime === preset.endTime
+ );
- try {
- await createShift(shiftData);
- } catch (error) {
- console.error("Failed to create shift:", error);
- }
- }
+ if (existingShift) {
+ try {
+ await deleteShift(existingShift.id);
+ } catch (error) {
+ console.error("Failed to delete shift:", error);
+ }
+ } else {
+ const shiftData: ShiftFormData = {
+ date: dateKey,
+ startTime: preset.startTime,
+ endTime: preset.endTime,
+ title: preset.title,
+ color: preset.color,
+ notes: preset.notes || "",
+ presetId: preset.id,
+ isAllDay: preset.isAllDay || false,
+ };
+
+ try {
+ await createShift(shiftData);
+ } catch (error) {
+ console.error("Failed to create shift:", error);
+ }
+ }
+ })
+ );
} finally {
setTogglingDates((prev) => {
const next = new Set(prev);
diff --git a/hooks/useShiftForm.ts b/hooks/useShiftForm.ts
index 8c41fa7..87d53cb 100644
--- a/hooks/useShiftForm.ts
+++ b/hooks/useShiftForm.ts
@@ -48,6 +48,7 @@ export function useShiftForm({
endTime: shiftData.endTime,
color: shiftData.color || DEFAULT_COLOR,
notes: shiftData.notes || "",
+ groupName: "",
isAllDay: shiftData.isAllDay || false,
isSecondary: false,
hideFromStats: false,
diff --git a/hooks/useShifts.ts b/hooks/useShifts.ts
index b04ad27..e00f9a9 100644
--- a/hooks/useShifts.ts
+++ b/hooks/useShifts.ts
@@ -145,7 +145,7 @@ export function useShifts(calendarId: string | undefined) {
// Create optimistic shift
const optimisticShift: ShiftWithCalendar = {
- id: `temp-${Date.now()}`,
+ id: `temp-${crypto.randomUUID()}`,
date: parseLocalDate(formData.date),
startTime: formData.startTime,
endTime: formData.endTime,
diff --git a/hooks/useStampShortcuts.ts b/hooks/useStampShortcuts.ts
index d43ef15..91d275d 100644
--- a/hooks/useStampShortcuts.ts
+++ b/hooks/useStampShortcuts.ts
@@ -4,8 +4,8 @@ import { useEffect } from "react";
interface UseStampShortcutsOptions {
presetIds: string[];
- selectedPresetId: string | undefined;
- onSelectPreset: (id: string | undefined) => void;
+ selectedPresetIds: string[];
+ onSelectPreset: (id: string | undefined, multiSelect?: boolean) => void;
enabled?: boolean;
}
@@ -17,10 +17,13 @@ function isTypingTarget(target: EventTarget | null): boolean {
);
}
-/** Digits 1–9 arm or disarm the matching preset, Escape disarms. */
+/**
+ * Digits 1–9 arm or disarm the matching preset (replacing the selection),
+ * Shift+digit adds/removes it from the selection instead, Escape clears all.
+ */
export function useStampShortcuts({
presetIds,
- selectedPresetId,
+ selectedPresetIds,
onSelectPreset,
enabled = true,
}: UseStampShortcutsOptions) {
@@ -33,7 +36,7 @@ export function useStampShortcuts({
// Leave keys alone while a dialog or sheet owns the focus
if (document.querySelector("[role='dialog'][data-state='open']")) return;
- if (event.key === "Escape" && selectedPresetId) {
+ if (event.key === "Escape" && selectedPresetIds.length > 0) {
onSelectPreset(undefined);
return;
}
@@ -43,10 +46,10 @@ export function useStampShortcuts({
const id = presetIds[index];
if (!id) return;
event.preventDefault();
- onSelectPreset(id === selectedPresetId ? undefined : id);
+ onSelectPreset(id, event.shiftKey);
};
window.addEventListener("keydown", handler);
return () => window.removeEventListener("keydown", handler);
- }, [enabled, presetIds, selectedPresetId, onSelectPreset]);
+ }, [enabled, presetIds, selectedPresetIds, onSelectPreset]);
}
diff --git a/lib/db/schema.ts b/lib/db/schema.ts
index 321ba7e..cbeace8 100644
--- a/lib/db/schema.ts
+++ b/lib/db/schema.ts
@@ -281,6 +281,7 @@ export const shiftPresets = sqliteTable("shift_presets", {
endTime: text("end_time").notNull(),
color: text("color").notNull().default("#3b82f6"),
notes: text("notes"),
+ groupName: text("group_name"),
isSecondary: integer("is_secondary", { mode: "boolean" })
.notNull()
.default(false),
diff --git a/lib/shift-display.ts b/lib/shift-display.ts
index e3c086e..f8e7bd0 100644
--- a/lib/shift-display.ts
+++ b/lib/shift-display.ts
@@ -1,7 +1,7 @@
import { CSSProperties } from "react";
import { isSameDay } from "date-fns";
import { ShiftWithCalendar } from "@/lib/types";
-import { ExternalSync } from "@/lib/db/schema";
+import { ExternalSync, ShiftPreset } from "@/lib/db/schema";
import { calculateShiftDuration } from "@/lib/date-utils";
export type ShiftSortType = "startTime" | "createdAt" | "title";
@@ -186,3 +186,30 @@ export function formatTimeRange(times: {
}): string {
return `${times.startTime.slice(0, 5)} – ${times.endTime.slice(0, 5)}`;
}
+
+export interface PresetGroup {
+ name: string;
+ items: ShiftPreset[];
+}
+
+/** Buckets presets by trimmed groupName; ungrouped ones stay separate, named groups sort alphabetically. */
+export function groupPresetsByName(presets: ShiftPreset[]): {
+ ungrouped: ShiftPreset[];
+ groups: PresetGroup[];
+} {
+ const ungrouped: ShiftPreset[] = [];
+ const groupsMap = new Map<string, ShiftPreset[]>();
+ for (const preset of presets) {
+ const name = preset.groupName?.trim();
+ if (!name) {
+ ungrouped.push(preset);
+ continue;
+ }
+ if (!groupsMap.has(name)) groupsMap.set(name, []);
+ groupsMap.get(name)!.push(preset);
+ }
+ const groups = [...groupsMap.entries()]
+ .sort(([a], [b]) => a.localeCompare(b))
+ .map(([name, items]) => ({ name, items }));
+ return { ungrouped, groups };
+}
diff --git a/lib/utils.ts b/lib/utils.ts
index cd38bc9..6d6e55a 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -5,6 +5,20 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
+/** Trims a string, turning an empty result into null — for optional text fields. */
+export function trimOrNull(value: string): string | null {
+ return value.trim() || null;
+}
+
+/** Whether a click should add to a selection instead of replacing it. */
+export function isMultiSelectClick(event: {
+ metaKey: boolean;
+ ctrlKey: boolean;
+ shiftKey: boolean;
+}): boolean {
+ return event.metaKey || event.ctrlKey || event.shiftKey;
+}
+
/** Up to two initials from a name, falling back to the e-mail. */
export function getUserInitials(user: { name?: string | null; email?: string }): string {
const source = user.name?.trim();
diff --git a/messages/cs.json b/messages/cs.json
index c82d193..aca4b06 100644
--- a/messages/cs.json
+++ b/messages/cs.json
@@ -207,7 +207,11 @@
"noPresets": "Zatím žádné předvolby směn",
"deleteConfirm": "Smazat tuto předvolbu? Tím se smažou i všechny směny vytvořené z této předvolby.",
"secondary": "Další",
- "hideFromStats": "Skrýt ze statistik"
+ "hideFromStats": "Skrýt ze statistik",
+ "group": "Skupina (volitelné)",
+ "groupPlaceholder": "např. Pracovní den, Víkend...",
+ "selectGroupHint": "Vybrat všechny předvolby v této skupině",
+ "copiedSuffix": "kopie"
},
"view": {
"settingsTitle": "Moje zobrazení",
@@ -703,6 +707,8 @@
"createPreset": "Vytvořit šablonu",
"manage": "Spravovat",
"stampHint": "Klepnutím na den přidáte {title}, dalším klepnutím ji odeberete.",
+ "stampHintMulti": "Klepnutím na den přidáte {count} předvoleb, dalším klepnutím je odeberete.",
+ "multiSelect": "Vícenásobný výběr",
"addShiftManually": "Přidat směnu ručně",
"sheetDescription": "Směny a poznámky vybraného dne",
"sheetExpand": "Rozbalit",
diff --git a/messages/de.json b/messages/de.json
index 17eddad..499fda3 100644
--- a/messages/de.json
+++ b/messages/de.json
@@ -207,7 +207,11 @@
"noPresets": "Noch keine Schichtvorlagen",
"deleteConfirm": "Diese Vorlage löschen? Alle aus dieser Vorlage erstellten Schichten werden ebenfalls gelöscht.",
"secondary": "Weitere",
- "hideFromStats": "Aus Statistik ausblenden"
+ "hideFromStats": "Aus Statistik ausblenden",
+ "group": "Gruppe (optional)",
+ "groupPlaceholder": "z.B. Wochentag, Wochenende...",
+ "selectGroupHint": "Alle Vorlagen dieser Gruppe auswählen",
+ "copiedSuffix": "kopiert"
},
"view": {
"settingsTitle": "Meine Ansicht",
@@ -703,6 +707,8 @@
"createPreset": "Vorlage anlegen",
"manage": "Verwalten",
"stampHint": "Tag antippen setzt {title}, nochmal antippen entfernt ihn.",
+ "stampHintMulti": "Tag antippen setzt {count} Vorlagen, nochmal antippen entfernt sie.",
+ "multiSelect": "Mehrfachauswahl",
"addShiftManually": "Schicht manuell anlegen",
"sheetDescription": "Schichten und Notizen des gewählten Tages",
"sheetExpand": "Aufziehen",
diff --git a/messages/en.json b/messages/en.json
index f6fbfb7..f33648e 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -207,7 +207,11 @@
"noPresets": "No shift presets yet",
"deleteConfirm": "Delete this preset? This will also delete all shifts created from this preset.",
"secondary": "More",
- "hideFromStats": "Hide from statistics"
+ "hideFromStats": "Hide from statistics",
+ "group": "Group (optional)",
+ "groupPlaceholder": "e.g. Weekday, Weekend...",
+ "selectGroupHint": "Select all presets in this group",
+ "copiedSuffix": "copied"
},
"view": {
"settingsTitle": "My view",
@@ -703,6 +707,8 @@
"createPreset": "Create preset",
"manage": "Manage",
"stampHint": "Tap a day to add {title}, tap again to remove it.",
+ "stampHintMulti": "Tap a day to add {count} presets, tap again to remove them.",
+ "multiSelect": "Multi-select",
"addShiftManually": "Add shift manually",
"sheetDescription": "Shifts and notes for the selected day",
"sheetExpand": "Expand",
diff --git a/messages/es.json b/messages/es.json
index 25618c4..fef2711 100644
--- a/messages/es.json
+++ b/messages/es.json
@@ -207,7 +207,11 @@
"noPresets": "Aún no hay preajustes de turno",
"deleteConfirm": "¿Eliminar este preajuste? Esto también eliminará todos los turnos creados a partir de él.",
"secondary": "Más",
- "hideFromStats": "Ocultar de las estadísticas"
+ "hideFromStats": "Ocultar de las estadísticas",
+ "group": "Grupo (opcional)",
+ "groupPlaceholder": "p. ej. Día laboral, Fin de semana...",
+ "selectGroupHint": "Seleccionar todos los preajustes de este grupo",
+ "copiedSuffix": "copiado"
},
"view": {
"settingsTitle": "Mi vista",
@@ -703,6 +707,8 @@
"createPreset": "Crear plantilla",
"manage": "Gestionar",
"stampHint": "Toca un día para añadir {title}; vuelve a tocar para quitarlo.",
+ "stampHintMulti": "Toca un día para añadir {count} preajustes; vuelve a tocar para quitarlos.",
+ "multiSelect": "Selección múltiple",
"addShiftManually": "Añadir turno manualmente",
"sheetDescription": "Turnos y notas del día seleccionado",
"sheetExpand": "Ampliar",
diff --git a/messages/fr.json b/messages/fr.json
index 0f66bd4..fc56a9b 100755
--- a/messages/fr.json
+++ b/messages/fr.json
@@ -207,7 +207,11 @@
"noPresets": "Aucun modèle de créneau pour l'instant",
"deleteConfirm": "Supprimer ce modèle ? Tous les créneaux créés à partir de ce modèle seront également supprimés.",
"secondary": "Plus",
- "hideFromStats": "Exclure des statistiques"
+ "hideFromStats": "Exclure des statistiques",
+ "group": "Groupe (facultatif)",
+ "groupPlaceholder": "p. ex. Semaine, Week-end...",
+ "selectGroupHint": "Sélectionner tous les modèles de ce groupe",
+ "copiedSuffix": "copié"
},
"view": {
"settingsTitle": "Mon affichage",
@@ -703,6 +707,8 @@
"createPreset": "Créer un modèle",
"manage": "Gérer",
"stampHint": "Touchez un jour pour ajouter {title}, touchez à nouveau pour le retirer.",
+ "stampHintMulti": "Touchez un jour pour ajouter {count} modèles, touchez à nouveau pour les retirer.",
+ "multiSelect": "Sélection multiple",
"addShiftManually": "Ajouter un service manuellement",
"sheetDescription": "Services et notes du jour sélectionné",
"sheetExpand": "Agrandir",
diff --git a/messages/it.json b/messages/it.json
index c4a8985..d606212 100644
--- a/messages/it.json
+++ b/messages/it.json
@@ -207,7 +207,11 @@
"noPresets": "Ancora nessun preset turno",
"deleteConfirm": "Eliminare questo preset? Verranno eliminati anche tutti i turni creati da questo preset.",
"secondary": "Altri",
- "hideFromStats": "Nascondi dalle statistiche"
+ "hideFromStats": "Nascondi dalle statistiche",
+ "group": "Gruppo (opzionale)",
+ "groupPlaceholder": "es. Giorno feriale, Fine settimana...",
+ "selectGroupHint": "Seleziona tutti i preset di questo gruppo",
+ "copiedSuffix": "copiato"
},
"view": {
"settingsTitle": "La mia vista",
@@ -703,6 +707,8 @@
"createPreset": "Crea modello",
"manage": "Gestisci",
"stampHint": "Tocca un giorno per aggiungere {title}, tocca di nuovo per rimuoverlo.",
+ "stampHintMulti": "Tocca un giorno per aggiungere {count} preset, tocca di nuovo per rimuoverli.",
+ "multiSelect": "Selezione multipla",
"addShiftManually": "Aggiungi turno manualmente",
"sheetDescription": "Turni e note del giorno selezionato",
"sheetExpand": "Espandi",