@kivacore/ui-pro-shared 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +167 -1
- package/src/.kiva/config.json +27 -0
- package/src/components/avatar-group.tsx +222 -0
- package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
- package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
- package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
- package/src/components/kiva/calendar/animations.ts +40 -0
- package/src/components/kiva/calendar/calendar-body.tsx +106 -0
- package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
- package/src/components/kiva/calendar/calendar.tsx +243 -0
- package/src/components/kiva/calendar/constants.ts +12 -0
- package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
- package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
- package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
- package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
- package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
- package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
- package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
- package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
- package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
- package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
- package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
- package/src/components/kiva/calendar/header/filter.tsx +80 -0
- package/src/components/kiva/calendar/header/today-button.tsx +49 -0
- package/src/components/kiva/calendar/header/user-select.tsx +111 -0
- package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
- package/src/components/kiva/calendar/helpers.ts +617 -0
- package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
- package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
- package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
- package/src/components/kiva/calendar/hooks.ts +5 -0
- package/src/components/kiva/calendar/index.tsx +27 -0
- package/src/components/kiva/calendar/interfaces.ts +35 -0
- package/src/components/kiva/calendar/schemas.ts +20 -0
- package/src/components/kiva/calendar/settings/settings.tsx +116 -0
- package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
- package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
- package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
- package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
- package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
- package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
- package/src/components/kiva/calendar/types.ts +25 -0
- package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
- package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
- package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
- package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
- package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
- package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
- package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
- package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
- package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
- package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
- package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
- package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
- package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
- package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
- package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
- package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
- package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
- package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
- package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
- package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
- package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
- package/src/components/kiva/date-time-picker.tsx +163 -0
- package/src/components/kiva/editable-record-detail.tsx +809 -0
- package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
- package/src/components/kiva/enum-option-editor/index.tsx +26 -0
- package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
- package/src/components/kiva/enum-option-editor/types.ts +90 -0
- package/src/components/kiva/kanban.tsx +1376 -0
- package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
- package/src/components/kiva/map.tsx +1631 -0
- package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
- package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
- package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
- package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
- package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
- package/src/components/kiva/pivot-calendar/index.tsx +32 -0
- package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
- package/src/components/kiva/pivot-calendar/types.ts +154 -0
- package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
- package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
- package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
- package/src/components/kiva/pivot-filter/index.tsx +9 -0
- package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
- package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
- package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
- package/src/components/kiva/pivot-filter/types.ts +82 -0
- package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
- package/src/components/kiva/pivot-grid/index.tsx +23 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
- package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
- package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
- package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
- package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
- package/src/components/kiva/pivot-grid/types.ts +195 -0
- package/src/components/kiva/place-autocomplete.tsx +484 -0
- package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
- package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
- package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
- package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
- package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
- package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
- package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
- package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
- package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
- package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
- package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
- package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
- package/src/hooks/kiva/use-data-export.tsx +265 -0
- package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
- package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
- package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
- package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
- package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
- package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
- package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
- package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
- package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
- package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
- package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
- package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
- package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
6
|
+
|
|
7
|
+
import { format, isWithinInterval, parseISO } from 'date-fns';
|
|
8
|
+
import { Calendar, Clock, User } from 'lucide-react';
|
|
9
|
+
|
|
10
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
11
|
+
|
|
12
|
+
import { Calendar as DayPicker } from '@kivacore/ui-pro-shared/components/calendar';
|
|
13
|
+
import { ScrollArea } from '@kivacore/ui-pro-shared/components/scroll-area';
|
|
14
|
+
import { useDateFormat } from '@kivacore/ui-pro-shared/hooks/kiva/use-date-format';
|
|
15
|
+
|
|
16
|
+
import { type IEvent } from '../../interfaces';
|
|
17
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
18
|
+
|
|
19
|
+
import { AddEditEventDialog } from '../../dialogs/add-edit-event-dialog';
|
|
20
|
+
import { DroppableArea } from '../../dnd/droppable-area';
|
|
21
|
+
import { getHoursInRange, groupEvents } from '../../helpers';
|
|
22
|
+
import { CalendarTimeline } from './calendar-time-line';
|
|
23
|
+
import { DayViewMultiDayEventsRow } from './day-view-multi-day-events-row';
|
|
24
|
+
import { RenderGroupedEvents } from './render-grouped-events';
|
|
25
|
+
|
|
26
|
+
const DEFAULT_HOUR_SLOT_HEIGHT = 96;
|
|
27
|
+
|
|
28
|
+
const resolveCssLength = (value: number | string | undefined, fallback: number): string => {
|
|
29
|
+
if (value == null) return `${fallback}px`;
|
|
30
|
+
|
|
31
|
+
return typeof value === 'number' ? `${value}px` : value;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
interface IProps {
|
|
35
|
+
singleDayEvents: Array<IEvent>;
|
|
36
|
+
multiDayEvents: Array<IEvent>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const weekdayShortFormatter = new Intl.DateTimeFormat(undefined, { weekday: 'short' });
|
|
40
|
+
|
|
41
|
+
export function CalendarDayView({ singleDayEvents, multiDayEvents }: IProps) {
|
|
42
|
+
const {
|
|
43
|
+
selectedDate, setSelectedDate, users, use24HourFormat,
|
|
44
|
+
startHour, endHour, hourSlotHeight,
|
|
45
|
+
disableHoverHighlight, hoverHighlightClassName
|
|
46
|
+
} = useCalendar();
|
|
47
|
+
const { formatDate } = useDateFormat();
|
|
48
|
+
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
|
49
|
+
|
|
50
|
+
const hours = useMemo(() => getHoursInRange(startHour, endHour), [startHour, endHour]);
|
|
51
|
+
const slotHeight = resolveCssLength(hourSlotHeight, DEFAULT_HOUR_SLOT_HEIGHT);
|
|
52
|
+
const halfSlotHeight = typeof hourSlotHeight === 'number' ? `${hourSlotHeight / 2}px` : `calc(${slotHeight} / 2)`;
|
|
53
|
+
const hoverClassName = disableHoverHighlight ? 'pointer-events-none' : cn('absolute inset-0 cursor-pointer transition-colors hover:bg-accent/40', hoverHighlightClassName);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const handleDragOver = (e: DragEvent) => {
|
|
57
|
+
if (!scrollAreaRef.current) return;
|
|
58
|
+
|
|
59
|
+
const scrollArea = scrollAreaRef.current;
|
|
60
|
+
const rect = scrollArea.getBoundingClientRect();
|
|
61
|
+
const scrollSpeed = 15;
|
|
62
|
+
|
|
63
|
+
const scrollContainer
|
|
64
|
+
= scrollArea.querySelector('[data-radix-scroll-area-viewport]')
|
|
65
|
+
|| scrollArea;
|
|
66
|
+
|
|
67
|
+
if (e.clientY < rect.top + 60) {
|
|
68
|
+
scrollContainer.scrollTop -= scrollSpeed;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (e.clientY > rect.bottom - 60) {
|
|
72
|
+
scrollContainer.scrollTop += scrollSpeed;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
document.addEventListener('dragover', handleDragOver);
|
|
77
|
+
|
|
78
|
+
return () => {
|
|
79
|
+
document.removeEventListener('dragover', handleDragOver);
|
|
80
|
+
};
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
const getCurrentEvents = (events: Array<IEvent>) => {
|
|
84
|
+
const now = new Date();
|
|
85
|
+
|
|
86
|
+
return events.filter(event => isWithinInterval(now, {
|
|
87
|
+
start: parseISO(event.startDate),
|
|
88
|
+
end: parseISO(event.endDate)
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const currentEvents = getCurrentEvents(singleDayEvents);
|
|
93
|
+
|
|
94
|
+
const dayEvents = singleDayEvents.filter((event) => {
|
|
95
|
+
const eventDate = parseISO(event.startDate);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
eventDate.getDate() === selectedDate.getDate()
|
|
99
|
+
&& eventDate.getMonth() === selectedDate.getMonth()
|
|
100
|
+
&& eventDate.getFullYear() === selectedDate.getFullYear()
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const groupedEvents = groupEvents(dayEvents);
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div className="flex">
|
|
108
|
+
<div className="flex flex-1 flex-col">
|
|
109
|
+
<div>
|
|
110
|
+
<DayViewMultiDayEventsRow
|
|
111
|
+
selectedDate={selectedDate}
|
|
112
|
+
multiDayEvents={multiDayEvents} />
|
|
113
|
+
|
|
114
|
+
{/* Day header */}
|
|
115
|
+
<div className="relative z-20 flex border-b">
|
|
116
|
+
<div className="w-18" />
|
|
117
|
+
<span className="flex-1 border-l py-2 text-center text-xs font-medium text-muted-foreground">
|
|
118
|
+
{weekdayShortFormatter.format(selectedDate)}{' '}
|
|
119
|
+
<span className="font-semibold text-foreground">
|
|
120
|
+
{selectedDate.getDate()}
|
|
121
|
+
</span>
|
|
122
|
+
</span>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<ScrollArea className="h-200" type="always" ref={scrollAreaRef}>
|
|
127
|
+
<div className="flex">
|
|
128
|
+
{/* Hours column */}
|
|
129
|
+
<div className="relative w-18">
|
|
130
|
+
{hours.map((hour, index) => (
|
|
131
|
+
<div key={hour} className="relative" style={{ height: slotHeight }}>
|
|
132
|
+
<div className="absolute -top-3 right-2 flex h-6 items-center">
|
|
133
|
+
{index !== 0 && (
|
|
134
|
+
<span className="text-xs text-muted-foreground">
|
|
135
|
+
{format(
|
|
136
|
+
new Date().setHours(hour, 0, 0, 0),
|
|
137
|
+
use24HourFormat ? 'HH:00' : 'h a'
|
|
138
|
+
)}
|
|
139
|
+
</span>
|
|
140
|
+
)}
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
))}
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
{/* Day grid */}
|
|
147
|
+
<div className="relative flex-1 border-l">
|
|
148
|
+
<div className="relative">
|
|
149
|
+
{hours.map((hour, index) => (
|
|
150
|
+
<div
|
|
151
|
+
key={hour}
|
|
152
|
+
className="relative"
|
|
153
|
+
style={{ height: slotHeight }}>
|
|
154
|
+
{index !== 0 && (
|
|
155
|
+
<div className="pointer-events-none absolute inset-x-0 top-0 border-b" />
|
|
156
|
+
)}
|
|
157
|
+
|
|
158
|
+
<DroppableArea
|
|
159
|
+
date={selectedDate}
|
|
160
|
+
hour={hour}
|
|
161
|
+
minute={0}
|
|
162
|
+
className="absolute inset-x-0 top-0"
|
|
163
|
+
style={{ height: halfSlotHeight }}>
|
|
164
|
+
<AddEditEventDialog
|
|
165
|
+
startDate={selectedDate}
|
|
166
|
+
startTime={{ hour, minute: 0 }}>
|
|
167
|
+
<div className={hoverClassName} />
|
|
168
|
+
</AddEditEventDialog>
|
|
169
|
+
</DroppableArea>
|
|
170
|
+
|
|
171
|
+
<div className="pointer-events-none absolute inset-x-0 top-1/2 border-b border-dashed border-border" />
|
|
172
|
+
|
|
173
|
+
<DroppableArea
|
|
174
|
+
date={selectedDate}
|
|
175
|
+
hour={hour}
|
|
176
|
+
minute={30}
|
|
177
|
+
className="absolute inset-x-0 bottom-0"
|
|
178
|
+
style={{ height: halfSlotHeight }}>
|
|
179
|
+
<AddEditEventDialog
|
|
180
|
+
startDate={selectedDate}
|
|
181
|
+
startTime={{ hour, minute: 30 }}>
|
|
182
|
+
<div className={hoverClassName} />
|
|
183
|
+
</AddEditEventDialog>
|
|
184
|
+
</DroppableArea>
|
|
185
|
+
</div>
|
|
186
|
+
))}
|
|
187
|
+
|
|
188
|
+
<RenderGroupedEvents
|
|
189
|
+
groupedEvents={groupedEvents}
|
|
190
|
+
day={selectedDate} />
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<CalendarTimeline />
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
</ScrollArea>
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
<div className="hidden w-72 divide-y border-l md:block">
|
|
200
|
+
<DayPicker
|
|
201
|
+
className="mx-auto w-fit"
|
|
202
|
+
mode="single"
|
|
203
|
+
selected={selectedDate}
|
|
204
|
+
onSelect={date => date && setSelectedDate(date)}
|
|
205
|
+
autoFocus />
|
|
206
|
+
|
|
207
|
+
<div className="flex-1 space-y-3">
|
|
208
|
+
{currentEvents.length > 0 ? (
|
|
209
|
+
<div className="flex items-start gap-2 px-4 pt-4">
|
|
210
|
+
<span className="relative mt-[5px] flex size-2.5">
|
|
211
|
+
<span className="absolute inline-flex size-full animate-ping rounded-full bg-green-400 opacity-75" />
|
|
212
|
+
<span className="relative inline-flex size-2.5 rounded-full bg-green-600" />
|
|
213
|
+
</span>
|
|
214
|
+
|
|
215
|
+
<p className="text-sm font-semibold text-foreground">
|
|
216
|
+
Happening now
|
|
217
|
+
</p>
|
|
218
|
+
</div>
|
|
219
|
+
) : (
|
|
220
|
+
<p className="p-4 text-center text-sm italic text-muted-foreground">
|
|
221
|
+
No appointments or consultations at the moment
|
|
222
|
+
</p>
|
|
223
|
+
)}
|
|
224
|
+
|
|
225
|
+
{currentEvents.length > 0 && (
|
|
226
|
+
<ScrollArea className="h-[422px] px-4" type="always">
|
|
227
|
+
<div className="space-y-6 pb-4">
|
|
228
|
+
{currentEvents.map((event) => {
|
|
229
|
+
const user = users.find(u => u.id === event.user.id);
|
|
230
|
+
|
|
231
|
+
return (
|
|
232
|
+
<div key={event.id} className="space-y-1.5">
|
|
233
|
+
<p className="line-clamp-2 text-sm font-semibold">
|
|
234
|
+
{event.title}
|
|
235
|
+
</p>
|
|
236
|
+
|
|
237
|
+
{user && (
|
|
238
|
+
<div className="flex items-center gap-1.5">
|
|
239
|
+
<User className="size-4 text-muted-foreground" />
|
|
240
|
+
<span className="text-sm text-muted-foreground">
|
|
241
|
+
{user.name}
|
|
242
|
+
</span>
|
|
243
|
+
</div>
|
|
244
|
+
)}
|
|
245
|
+
|
|
246
|
+
<div className="flex items-center gap-1.5">
|
|
247
|
+
<Calendar className="size-4 text-muted-foreground" />
|
|
248
|
+
<span className="text-sm text-muted-foreground">
|
|
249
|
+
{formatDate(new Date(event.startDate))}
|
|
250
|
+
</span>
|
|
251
|
+
</div>
|
|
252
|
+
|
|
253
|
+
<div className="flex items-center gap-1.5">
|
|
254
|
+
<Clock className="size-4 text-muted-foreground" />
|
|
255
|
+
<span className="text-sm text-muted-foreground">
|
|
256
|
+
{format(
|
|
257
|
+
parseISO(event.startDate),
|
|
258
|
+
use24HourFormat ? 'HH:mm' : 'hh:mm a'
|
|
259
|
+
)}{' '}
|
|
260
|
+
-
|
|
261
|
+
{format(
|
|
262
|
+
parseISO(event.endDate),
|
|
263
|
+
use24HourFormat ? 'HH:mm' : 'hh:mm a'
|
|
264
|
+
)}
|
|
265
|
+
</span>
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
);
|
|
269
|
+
})}
|
|
270
|
+
</div>
|
|
271
|
+
</ScrollArea>
|
|
272
|
+
)}
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
</div>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
8
|
+
import { formatTime } from '../../helpers';
|
|
9
|
+
|
|
10
|
+
export function CalendarTimeline() {
|
|
11
|
+
const { use24HourFormat, startHour, endHour } = useCalendar();
|
|
12
|
+
const [currentTime, setCurrentTime] = useState(() => new Date());
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const timer = setInterval(() => setCurrentTime(new Date()), 60 * 1000);
|
|
16
|
+
|
|
17
|
+
return () => clearInterval(timer);
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
const getCurrentTimePosition = () => {
|
|
21
|
+
const minutes = currentTime.getHours() * 60 + currentTime.getMinutes();
|
|
22
|
+
const rangeStart = startHour * 60;
|
|
23
|
+
const rangeMinutes = Math.max(1, (endHour - startHour) * 60);
|
|
24
|
+
|
|
25
|
+
return ((minutes - rangeStart) / rangeMinutes) * 100;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const position = getCurrentTimePosition();
|
|
29
|
+
|
|
30
|
+
if (position < 0 || position > 100) return null;
|
|
31
|
+
|
|
32
|
+
const formatCurrentTime = () => {
|
|
33
|
+
return formatTime(currentTime, use24HourFormat);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
className="pointer-events-none absolute inset-x-0 z-50 border-t border-primary"
|
|
39
|
+
style={{ top: `${position}%` }}>
|
|
40
|
+
<div className="absolute -left-1.5 -top-1.5 size-3 rounded-full bg-primary" />
|
|
41
|
+
|
|
42
|
+
<div className="absolute -left-18 flex w-16 -translate-y-1/2 justify-end bg-background pr-1 text-xs font-medium text-primary">
|
|
43
|
+
{formatCurrentTime()}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
addDays, format, isSameDay, parseISO, startOfWeek
|
|
9
|
+
} from 'date-fns';
|
|
10
|
+
import { motion } from 'motion/react';
|
|
11
|
+
|
|
12
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
13
|
+
|
|
14
|
+
import { ScrollArea } from '@kivacore/ui-pro-shared/components/scroll-area';
|
|
15
|
+
|
|
16
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
17
|
+
|
|
18
|
+
import { type IEvent } from '../../interfaces';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
fadeIn,
|
|
22
|
+
staggerContainer,
|
|
23
|
+
transition
|
|
24
|
+
} from '../../animations';
|
|
25
|
+
import { useCalendar } from '../../contexts/calendar-context';
|
|
26
|
+
import { AddEditEventDialog } from '../../dialogs/add-edit-event-dialog';
|
|
27
|
+
import { DroppableArea } from '../../dnd/droppable-area';
|
|
28
|
+
import { getHoursInRange, groupEvents } from '../../helpers';
|
|
29
|
+
import { CalendarTimeline } from './calendar-time-line';
|
|
30
|
+
import { RenderGroupedEvents } from './render-grouped-events';
|
|
31
|
+
import { WeekViewMultiDayEventsRow } from './week-view-multi-day-events-row';
|
|
32
|
+
|
|
33
|
+
const DEFAULT_HOUR_SLOT_HEIGHT = 96;
|
|
34
|
+
|
|
35
|
+
const resolveCssLength = (value: number | string | undefined, fallback: number): string => {
|
|
36
|
+
if (value == null) return `${fallback}px`;
|
|
37
|
+
|
|
38
|
+
return typeof value === 'number' ? `${value}px` : value;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
interface IProps {
|
|
42
|
+
singleDayEvents: Array<IEvent>;
|
|
43
|
+
multiDayEvents: Array<IEvent>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const weekdayShortFormatter = new Intl.DateTimeFormat(undefined, { weekday: 'short' });
|
|
47
|
+
|
|
48
|
+
export function CalendarWeekView({ singleDayEvents, multiDayEvents }: IProps) {
|
|
49
|
+
const { t } = useUiTranslation();
|
|
50
|
+
const {
|
|
51
|
+
selectedDate, use24HourFormat, weekStartsOn,
|
|
52
|
+
startHour, endHour, hourSlotHeight,
|
|
53
|
+
disableHoverHighlight, hoverHighlightClassName
|
|
54
|
+
} = useCalendar();
|
|
55
|
+
|
|
56
|
+
const weekStart = useMemo(
|
|
57
|
+
() => startOfWeek(selectedDate, { weekStartsOn }),
|
|
58
|
+
[selectedDate, weekStartsOn]
|
|
59
|
+
);
|
|
60
|
+
const weekDays = useMemo(
|
|
61
|
+
() => Array.from({ length: 7 }, (_, i) => addDays(weekStart, i)),
|
|
62
|
+
[weekStart]
|
|
63
|
+
);
|
|
64
|
+
const hours = useMemo(() => getHoursInRange(startHour, endHour), [startHour, endHour]);
|
|
65
|
+
const slotHeight = resolveCssLength(hourSlotHeight, DEFAULT_HOUR_SLOT_HEIGHT);
|
|
66
|
+
const halfSlotHeight = typeof hourSlotHeight === 'number' ? `${hourSlotHeight / 2}px` : `calc(${slotHeight} / 2)`;
|
|
67
|
+
const hoverClassName = disableHoverHighlight ? 'pointer-events-none' : cn('absolute inset-0 cursor-pointer transition-colors hover:bg-accent/40', hoverHighlightClassName);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<motion.div
|
|
71
|
+
initial="initial"
|
|
72
|
+
animate="animate"
|
|
73
|
+
exit="exit"
|
|
74
|
+
variants={fadeIn}
|
|
75
|
+
transition={transition}>
|
|
76
|
+
<motion.div
|
|
77
|
+
className="flex flex-col items-center justify-center border-b p-4 text-sm sm:hidden"
|
|
78
|
+
initial={{ opacity: 0, y: -20 }}
|
|
79
|
+
animate={{ opacity: 1, y: 0 }}
|
|
80
|
+
transition={transition}>
|
|
81
|
+
<p>{t('ui.calendar.weeklyNotRecommended', 'Weekly view is not recommended on mobile devices.')}</p>
|
|
82
|
+
<p>{t('ui.calendar.switchToDesktop', 'Please switch to a desktop device or use the daily view instead.')}</p>
|
|
83
|
+
</motion.div>
|
|
84
|
+
|
|
85
|
+
<motion.div className="flex-col sm:flex" variants={staggerContainer}>
|
|
86
|
+
<div>
|
|
87
|
+
<WeekViewMultiDayEventsRow
|
|
88
|
+
selectedDate={selectedDate}
|
|
89
|
+
multiDayEvents={multiDayEvents} />
|
|
90
|
+
|
|
91
|
+
{/* Week header */}
|
|
92
|
+
<motion.div
|
|
93
|
+
className="relative z-20 flex border-b"
|
|
94
|
+
initial={{ opacity: 0, y: -20 }}
|
|
95
|
+
animate={{ opacity: 1, y: 0 }}
|
|
96
|
+
transition={transition}>
|
|
97
|
+
{/* Time column header - responsive width */}
|
|
98
|
+
<div className="w-18" />
|
|
99
|
+
<div className="grid flex-1 grid-cols-7 border-l">
|
|
100
|
+
{weekDays.map((day, index) => (
|
|
101
|
+
<motion.span
|
|
102
|
+
key={day.toISOString()}
|
|
103
|
+
className="py-1 sm:py-2 text-center text-xs font-medium text-muted-foreground"
|
|
104
|
+
initial={{ opacity: 0, y: -10 }}
|
|
105
|
+
animate={{ opacity: 1, y: 0 }}
|
|
106
|
+
transition={{ delay: index * 0.05, ...transition }}>
|
|
107
|
+
{/* Mobile: Show only day abbreviation and number */}
|
|
108
|
+
<span className="block sm:hidden">
|
|
109
|
+
{weekdayShortFormatter.format(day).charAt(0)}
|
|
110
|
+
<span className="block font-semibold text-foreground text-xs">
|
|
111
|
+
{day.getDate()}
|
|
112
|
+
</span>
|
|
113
|
+
</span>
|
|
114
|
+
{/* Desktop: Show full format */}
|
|
115
|
+
<span className="hidden sm:inline">
|
|
116
|
+
{weekdayShortFormatter.format(day)}{' '}
|
|
117
|
+
<span className="ml-1 font-semibold text-foreground">
|
|
118
|
+
{day.getDate()}
|
|
119
|
+
</span>
|
|
120
|
+
</span>
|
|
121
|
+
</motion.span>
|
|
122
|
+
))}
|
|
123
|
+
</div>
|
|
124
|
+
</motion.div>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<ScrollArea className="h-184" type="always">
|
|
128
|
+
<div className="flex">
|
|
129
|
+
{/* Hours column */}
|
|
130
|
+
<motion.div className="relative w-18" variants={staggerContainer}>
|
|
131
|
+
{hours.map((hour, index) => (
|
|
132
|
+
<motion.div
|
|
133
|
+
key={hour}
|
|
134
|
+
className="relative"
|
|
135
|
+
style={{ height: slotHeight }}
|
|
136
|
+
initial={{ opacity: 0, x: -20 }}
|
|
137
|
+
animate={{ opacity: 1, x: 0 }}
|
|
138
|
+
transition={{ delay: index * 0.02, ...transition }}>
|
|
139
|
+
<div className="absolute -top-3 right-2 flex h-6 items-center">
|
|
140
|
+
{index !== 0 && (
|
|
141
|
+
<span className="text-xs text-muted-foreground">
|
|
142
|
+
{format(
|
|
143
|
+
new Date().setHours(hour, 0, 0, 0),
|
|
144
|
+
use24HourFormat ? 'HH:00' : 'h a'
|
|
145
|
+
)}
|
|
146
|
+
</span>
|
|
147
|
+
)}
|
|
148
|
+
</div>
|
|
149
|
+
</motion.div>
|
|
150
|
+
))}
|
|
151
|
+
</motion.div>
|
|
152
|
+
|
|
153
|
+
{/* Week grid */}
|
|
154
|
+
<motion.div
|
|
155
|
+
className="relative flex-1 border-l"
|
|
156
|
+
variants={staggerContainer}>
|
|
157
|
+
<div className="grid grid-cols-7 divide-x">
|
|
158
|
+
{weekDays.map((day, dayIndex) => {
|
|
159
|
+
const dayEvents = singleDayEvents.filter(
|
|
160
|
+
event => isSameDay(parseISO(event.startDate), day)
|
|
161
|
+
|| isSameDay(parseISO(event.endDate), day)
|
|
162
|
+
);
|
|
163
|
+
const groupedEvents = groupEvents(dayEvents);
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<motion.div
|
|
167
|
+
key={day.toISOString()}
|
|
168
|
+
className="relative"
|
|
169
|
+
initial={{ opacity: 0 }}
|
|
170
|
+
animate={{ opacity: 1 }}
|
|
171
|
+
transition={{ delay: dayIndex * 0.1, ...transition }}>
|
|
172
|
+
{hours.map((hour, index) => (
|
|
173
|
+
<motion.div
|
|
174
|
+
key={hour}
|
|
175
|
+
className="relative"
|
|
176
|
+
style={{ height: slotHeight }}
|
|
177
|
+
initial={{ opacity: 0 }}
|
|
178
|
+
animate={{ opacity: 1 }}
|
|
179
|
+
transition={{ delay: index * 0.01, ...transition }}>
|
|
180
|
+
{index !== 0 && (
|
|
181
|
+
<div className="pointer-events-none absolute inset-x-0 top-0 border-b" />
|
|
182
|
+
)}
|
|
183
|
+
|
|
184
|
+
<DroppableArea
|
|
185
|
+
date={day}
|
|
186
|
+
hour={hour}
|
|
187
|
+
minute={0}
|
|
188
|
+
className="absolute inset-x-0 top-0"
|
|
189
|
+
style={{ height: halfSlotHeight }}>
|
|
190
|
+
<AddEditEventDialog
|
|
191
|
+
startDate={day}
|
|
192
|
+
startTime={{ hour, minute: 0 }}>
|
|
193
|
+
<div className={hoverClassName} />
|
|
194
|
+
</AddEditEventDialog>
|
|
195
|
+
</DroppableArea>
|
|
196
|
+
|
|
197
|
+
<div className="pointer-events-none absolute inset-x-0 top-1/2 border-b border-dashed border-border" />
|
|
198
|
+
|
|
199
|
+
<DroppableArea
|
|
200
|
+
date={day}
|
|
201
|
+
hour={hour}
|
|
202
|
+
minute={30}
|
|
203
|
+
className="absolute inset-x-0 bottom-0"
|
|
204
|
+
style={{ height: halfSlotHeight }}>
|
|
205
|
+
<AddEditEventDialog
|
|
206
|
+
startDate={day}
|
|
207
|
+
startTime={{ hour, minute: 30 }}>
|
|
208
|
+
<div className={hoverClassName} />
|
|
209
|
+
</AddEditEventDialog>
|
|
210
|
+
</DroppableArea>
|
|
211
|
+
</motion.div>
|
|
212
|
+
))}
|
|
213
|
+
|
|
214
|
+
<RenderGroupedEvents
|
|
215
|
+
groupedEvents={groupedEvents}
|
|
216
|
+
day={day} />
|
|
217
|
+
</motion.div>
|
|
218
|
+
);
|
|
219
|
+
})}
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
<CalendarTimeline />
|
|
223
|
+
</motion.div>
|
|
224
|
+
</div>
|
|
225
|
+
</ScrollArea>
|
|
226
|
+
</motion.div>
|
|
227
|
+
</motion.div>
|
|
228
|
+
);
|
|
229
|
+
}
|
package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
differenceInDays,
|
|
7
|
+
endOfDay,
|
|
8
|
+
isWithinInterval,
|
|
9
|
+
parseISO,
|
|
10
|
+
startOfDay
|
|
11
|
+
} from 'date-fns';
|
|
12
|
+
|
|
13
|
+
import { type IEvent } from '../../interfaces';
|
|
14
|
+
|
|
15
|
+
import { MonthEventBadge } from '../month-view/month-event-badge';
|
|
16
|
+
|
|
17
|
+
interface IProps {
|
|
18
|
+
selectedDate: Date;
|
|
19
|
+
multiDayEvents: Array<IEvent>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function DayViewMultiDayEventsRow({
|
|
23
|
+
selectedDate,
|
|
24
|
+
multiDayEvents
|
|
25
|
+
}: IProps) {
|
|
26
|
+
const dayStart = startOfDay(selectedDate);
|
|
27
|
+
const dayEnd = endOfDay(selectedDate);
|
|
28
|
+
|
|
29
|
+
const multiDayEventsInDay = multiDayEvents
|
|
30
|
+
.filter((event) => {
|
|
31
|
+
const eventStart = parseISO(event.startDate);
|
|
32
|
+
const eventEnd = parseISO(event.endDate);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
isWithinInterval(dayStart, { start: eventStart, end: eventEnd })
|
|
36
|
+
|| isWithinInterval(dayEnd, { start: eventStart, end: eventEnd })
|
|
37
|
+
|| (eventStart <= dayStart && eventEnd >= dayEnd)
|
|
38
|
+
);
|
|
39
|
+
})
|
|
40
|
+
.sort((a, b) => {
|
|
41
|
+
const durationA = differenceInDays(
|
|
42
|
+
parseISO(a.endDate),
|
|
43
|
+
parseISO(a.startDate)
|
|
44
|
+
);
|
|
45
|
+
const durationB = differenceInDays(
|
|
46
|
+
parseISO(b.endDate),
|
|
47
|
+
parseISO(b.startDate)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return durationB - durationA;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (multiDayEventsInDay.length === 0) return null;
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div className="flex border-b">
|
|
57
|
+
<div className="w-18" />
|
|
58
|
+
<div className="flex flex-1 flex-col gap-1 border-l py-1">
|
|
59
|
+
{multiDayEventsInDay.map((event) => {
|
|
60
|
+
const eventStart = startOfDay(parseISO(event.startDate));
|
|
61
|
+
const eventEnd = startOfDay(parseISO(event.endDate));
|
|
62
|
+
const currentDate = startOfDay(selectedDate);
|
|
63
|
+
|
|
64
|
+
const eventTotalDays = differenceInDays(eventEnd, eventStart) + 1;
|
|
65
|
+
const eventCurrentDay = differenceInDays(currentDate, eventStart) + 1;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<MonthEventBadge
|
|
69
|
+
key={event.id}
|
|
70
|
+
event={event}
|
|
71
|
+
cellDate={selectedDate}
|
|
72
|
+
eventCurrentDay={eventCurrentDay}
|
|
73
|
+
eventTotalDays={eventTotalDays} />
|
|
74
|
+
);
|
|
75
|
+
})}
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|