@kivacore/ui-pro-shared 0.0.9 → 0.0.10
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 +187 -21
- 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,173 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
createContext, use, useCallback, useEffect, useMemo, useRef, useState, type ReactNode
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import { toast } from 'sonner';
|
|
10
|
+
|
|
11
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
12
|
+
|
|
13
|
+
import { type IEvent } from '../interfaces';
|
|
14
|
+
|
|
15
|
+
import { useCalendar } from './calendar-context';
|
|
16
|
+
|
|
17
|
+
interface DragDropContextType {
|
|
18
|
+
draggedEvent: IEvent | null;
|
|
19
|
+
isDragging: boolean;
|
|
20
|
+
startDrag: (event: IEvent) => void;
|
|
21
|
+
endDrag: () => void;
|
|
22
|
+
handleEventDrop: (date: Date, hour?: number, minute?: number) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DragDropContext = createContext<DragDropContextType | undefined>(
|
|
26
|
+
undefined
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export function useDragDrop() {
|
|
30
|
+
const context = use(DragDropContext);
|
|
31
|
+
|
|
32
|
+
if (!context) {
|
|
33
|
+
throw new Error('useDragDrop must be used within a DragDropProvider');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface DndProviderProps {
|
|
40
|
+
children: ReactNode;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function DndProvider({ children }: DndProviderProps) {
|
|
44
|
+
const { t } = useUiTranslation();
|
|
45
|
+
const { updateEvent, onEventDrop } = useCalendar();
|
|
46
|
+
const [dragState, setDragState] = useState<{
|
|
47
|
+
draggedEvent: IEvent | null;
|
|
48
|
+
isDragging: boolean;
|
|
49
|
+
}>({ draggedEvent: null, isDragging: false });
|
|
50
|
+
|
|
51
|
+
const onEventDroppedRef = useRef<
|
|
52
|
+
((event: IEvent, newStartDate: Date, newEndDate: Date) => void) | null
|
|
53
|
+
>(null);
|
|
54
|
+
|
|
55
|
+
const startDrag = useCallback((event: IEvent) => {
|
|
56
|
+
setDragState({ draggedEvent: event, isDragging: true });
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
const endDrag = useCallback(() => {
|
|
60
|
+
setDragState({ draggedEvent: null, isDragging: false });
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
const calculateNewDates = useCallback(
|
|
64
|
+
(event: IEvent, targetDate: Date, hour?: number, minute?: number) => {
|
|
65
|
+
const originalStart = new Date(event.startDate);
|
|
66
|
+
const originalEnd = new Date(event.endDate);
|
|
67
|
+
const duration = originalEnd.getTime() - originalStart.getTime();
|
|
68
|
+
|
|
69
|
+
const newStart = new Date(targetDate);
|
|
70
|
+
|
|
71
|
+
if (hour !== undefined) {
|
|
72
|
+
newStart.setHours(hour, minute || 0, 0, 0);
|
|
73
|
+
} else {
|
|
74
|
+
newStart.setHours(
|
|
75
|
+
originalStart.getHours(),
|
|
76
|
+
originalStart.getMinutes(),
|
|
77
|
+
0,
|
|
78
|
+
0
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
newStart,
|
|
84
|
+
newEnd: new Date(newStart.getTime() + duration)
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
[]
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const isSamePosition = useCallback((date1: Date, date2: Date) => {
|
|
91
|
+
return date1.getTime() === date2.getTime();
|
|
92
|
+
}, []);
|
|
93
|
+
|
|
94
|
+
const handleEventDrop = useCallback(
|
|
95
|
+
(targetDate: Date, hour?: number, minute?: number) => {
|
|
96
|
+
const { draggedEvent } = dragState;
|
|
97
|
+
|
|
98
|
+
if (!draggedEvent) return;
|
|
99
|
+
|
|
100
|
+
const { newStart, newEnd } = calculateNewDates(
|
|
101
|
+
draggedEvent,
|
|
102
|
+
targetDate,
|
|
103
|
+
hour,
|
|
104
|
+
minute
|
|
105
|
+
);
|
|
106
|
+
const originalStart = new Date(draggedEvent.startDate);
|
|
107
|
+
|
|
108
|
+
if (isSamePosition(originalStart, newStart)) {
|
|
109
|
+
endDrag();
|
|
110
|
+
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const callback = onEventDroppedRef.current;
|
|
115
|
+
|
|
116
|
+
if (callback) {
|
|
117
|
+
callback(draggedEvent, newStart, newEnd);
|
|
118
|
+
}
|
|
119
|
+
endDrag();
|
|
120
|
+
},
|
|
121
|
+
[
|
|
122
|
+
dragState,
|
|
123
|
+
calculateNewDates,
|
|
124
|
+
isSamePosition,
|
|
125
|
+
endDrag
|
|
126
|
+
]
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const handleEventUpdate = useCallback(
|
|
130
|
+
(event: IEvent, newStartDate: Date, newEndDate: Date) => {
|
|
131
|
+
try {
|
|
132
|
+
const updatedEvent = {
|
|
133
|
+
...event,
|
|
134
|
+
startDate: newStartDate.toISOString(),
|
|
135
|
+
endDate: newEndDate.toISOString()
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
updateEvent(updatedEvent);
|
|
139
|
+
onEventDrop?.(event, newStartDate, newEndDate);
|
|
140
|
+
toast.success(t('ui.calendar.eventUpdated', 'Event updated'));
|
|
141
|
+
} catch {
|
|
142
|
+
toast.error(t('ui.calendar.dndUpdateError', 'Failed to update event'));
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
[updateEvent, onEventDrop, t]
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
onEventDroppedRef.current = handleEventUpdate;
|
|
150
|
+
}, [handleEventUpdate]);
|
|
151
|
+
|
|
152
|
+
const contextValue = useMemo(
|
|
153
|
+
() => ({
|
|
154
|
+
draggedEvent: dragState.draggedEvent,
|
|
155
|
+
isDragging: dragState.isDragging,
|
|
156
|
+
startDrag,
|
|
157
|
+
endDrag,
|
|
158
|
+
handleEventDrop
|
|
159
|
+
}),
|
|
160
|
+
[
|
|
161
|
+
dragState,
|
|
162
|
+
startDrag,
|
|
163
|
+
endDrag,
|
|
164
|
+
handleEventDrop
|
|
165
|
+
]
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<DragDropContext value={contextValue}>
|
|
170
|
+
{children}
|
|
171
|
+
</DragDropContext>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type ReactNode, useEffect, useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { standardSchemaResolver } from '@hookform/resolvers/standard-schema';
|
|
8
|
+
import { addMinutes, format, set } from 'date-fns';
|
|
9
|
+
import { useForm } from 'react-hook-form';
|
|
10
|
+
import { toast } from 'sonner';
|
|
11
|
+
|
|
12
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
13
|
+
import {
|
|
14
|
+
Dialog,
|
|
15
|
+
DialogClose,
|
|
16
|
+
DialogContent,
|
|
17
|
+
DialogDescription,
|
|
18
|
+
DialogFooter,
|
|
19
|
+
DialogHeader,
|
|
20
|
+
DialogTitle,
|
|
21
|
+
DialogTrigger
|
|
22
|
+
} from '@kivacore/ui-pro-shared/components/dialog';
|
|
23
|
+
import {
|
|
24
|
+
Form,
|
|
25
|
+
FormControl,
|
|
26
|
+
FormField,
|
|
27
|
+
FormItem,
|
|
28
|
+
FormLabel,
|
|
29
|
+
FormMessage
|
|
30
|
+
} from '@kivacore/ui-pro-shared/components/form';
|
|
31
|
+
import { Input } from '@kivacore/ui-pro-shared/components/input';
|
|
32
|
+
import {
|
|
33
|
+
Select,
|
|
34
|
+
SelectContent,
|
|
35
|
+
SelectItem,
|
|
36
|
+
SelectTrigger,
|
|
37
|
+
SelectValue
|
|
38
|
+
} from '@kivacore/ui-pro-shared/components/select';
|
|
39
|
+
import { Textarea } from '@kivacore/ui-pro-shared/components/textarea';
|
|
40
|
+
import { DateTimePicker } from '@kivacore/ui-pro-shared/components/kiva/date-time-picker';
|
|
41
|
+
|
|
42
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
43
|
+
|
|
44
|
+
import { type IEvent } from '../interfaces';
|
|
45
|
+
import { type TEventFormData, eventSchema } from '../schemas';
|
|
46
|
+
import { COLORS } from '../constants';
|
|
47
|
+
import { useCalendar } from '../contexts/calendar-context';
|
|
48
|
+
import { useDisclosure } from '../hooks';
|
|
49
|
+
|
|
50
|
+
interface IProps {
|
|
51
|
+
children: ReactNode;
|
|
52
|
+
startDate?: Date;
|
|
53
|
+
startTime?: { hour: number; minute: number };
|
|
54
|
+
event?: IEvent;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function AddEditEventDialog({
|
|
58
|
+
children,
|
|
59
|
+
startDate,
|
|
60
|
+
startTime,
|
|
61
|
+
event
|
|
62
|
+
}: IProps) {
|
|
63
|
+
const { isOpen, onClose, onToggle } = useDisclosure();
|
|
64
|
+
const {
|
|
65
|
+
addEvent, updateEvent, onCreateEvent, onSlotClick
|
|
66
|
+
} = useCalendar();
|
|
67
|
+
const { t } = useUiTranslation();
|
|
68
|
+
const isEditing = !!event;
|
|
69
|
+
const bypassDialog = !isEditing && (!!onCreateEvent || !!onSlotClick);
|
|
70
|
+
|
|
71
|
+
const initialDates = useMemo(() => {
|
|
72
|
+
if (!isEditing) {
|
|
73
|
+
if (!startDate) {
|
|
74
|
+
const now = new Date();
|
|
75
|
+
|
|
76
|
+
return { startDate: now, endDate: addMinutes(now, 30) };
|
|
77
|
+
}
|
|
78
|
+
const start = startTime ? set(new Date(startDate), {
|
|
79
|
+
hours: startTime.hour,
|
|
80
|
+
minutes: startTime.minute,
|
|
81
|
+
seconds: 0
|
|
82
|
+
}) : new Date(startDate);
|
|
83
|
+
const end = addMinutes(start, 30);
|
|
84
|
+
|
|
85
|
+
return { startDate: start, endDate: end };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
startDate: new Date(event.startDate),
|
|
90
|
+
endDate: new Date(event.endDate)
|
|
91
|
+
};
|
|
92
|
+
}, [
|
|
93
|
+
startDate,
|
|
94
|
+
startTime,
|
|
95
|
+
event,
|
|
96
|
+
isEditing
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
const form = useForm<TEventFormData>({
|
|
100
|
+
resolver: standardSchemaResolver(eventSchema),
|
|
101
|
+
defaultValues: {
|
|
102
|
+
title: event?.title ?? '',
|
|
103
|
+
description: event?.description ?? '',
|
|
104
|
+
startDate: initialDates.startDate,
|
|
105
|
+
endDate: initialDates.endDate,
|
|
106
|
+
color: event?.color ?? 'blue'
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
form.reset({
|
|
112
|
+
title: event?.title ?? '',
|
|
113
|
+
description: event?.description ?? '',
|
|
114
|
+
startDate: initialDates.startDate,
|
|
115
|
+
endDate: initialDates.endDate,
|
|
116
|
+
color: event?.color ?? 'blue'
|
|
117
|
+
});
|
|
118
|
+
}, [event, initialDates, form]);
|
|
119
|
+
|
|
120
|
+
const onSubmit = (values: TEventFormData) => {
|
|
121
|
+
try {
|
|
122
|
+
const formattedEvent: IEvent = {
|
|
123
|
+
...values,
|
|
124
|
+
startDate: format(values.startDate, "yyyy-MM-dd'T'HH:mm:ss"),
|
|
125
|
+
endDate: format(values.endDate, "yyyy-MM-dd'T'HH:mm:ss"),
|
|
126
|
+
id: isEditing ? event.id : Math.floor(Math.random() * 1000000),
|
|
127
|
+
user: isEditing ? event.user : {
|
|
128
|
+
id: Math.floor(Math.random() * 1000000).toString(),
|
|
129
|
+
name: 'Current User',
|
|
130
|
+
picturePath: null
|
|
131
|
+
},
|
|
132
|
+
color: values.color
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
if (isEditing) {
|
|
136
|
+
updateEvent(formattedEvent);
|
|
137
|
+
toast.success(t('ui.calendar.eventUpdated', 'Event updated'));
|
|
138
|
+
} else {
|
|
139
|
+
addEvent(formattedEvent);
|
|
140
|
+
toast.success(t('ui.calendar.eventCreated', 'Event created'));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
onClose();
|
|
144
|
+
form.reset();
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.warn(`Error ${isEditing ? 'editing' : 'adding'} event:`, error);
|
|
147
|
+
toast.error(isEditing ? t('ui.calendar.eventUpdateError', 'Error updating event') : t('ui.calendar.eventCreateError', 'Error creating event'));
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
if (bypassDialog) {
|
|
152
|
+
const handleCreateClick = () => {
|
|
153
|
+
let resolvedDate: Date;
|
|
154
|
+
|
|
155
|
+
if (startDate && startTime) {
|
|
156
|
+
resolvedDate = set(new Date(startDate), { hours: startTime.hour, minutes: startTime.minute, seconds: 0 });
|
|
157
|
+
} else if (startDate) {
|
|
158
|
+
resolvedDate = new Date(startDate);
|
|
159
|
+
} else {
|
|
160
|
+
resolvedDate = new Date();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (onCreateEvent) {
|
|
164
|
+
onCreateEvent(resolvedDate);
|
|
165
|
+
} else if (onSlotClick) {
|
|
166
|
+
onSlotClick(resolvedDate, addMinutes(resolvedDate, 30));
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div
|
|
172
|
+
onClick={handleCreateClick}
|
|
173
|
+
role="button"
|
|
174
|
+
tabIndex={0}
|
|
175
|
+
onKeyDown={(e) => { if (e.key === 'Enter') handleCreateClick(); }}>
|
|
176
|
+
{children}
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<Dialog open={isOpen} onOpenChange={onToggle} modal={false}>
|
|
183
|
+
<DialogTrigger asChild>{children}</DialogTrigger>
|
|
184
|
+
<DialogContent>
|
|
185
|
+
<DialogHeader>
|
|
186
|
+
<DialogTitle>{isEditing ? t('ui.calendar.editEvent', 'Edit Event') : t('ui.calendar.addNewEvent', 'Add New Event')}</DialogTitle>
|
|
187
|
+
<DialogDescription>
|
|
188
|
+
{isEditing ? t('ui.calendar.modifyEvent', 'Modify event details') : t('ui.calendar.createNewEvent', 'Create a new event')}
|
|
189
|
+
</DialogDescription>
|
|
190
|
+
</DialogHeader>
|
|
191
|
+
|
|
192
|
+
<Form {...form}>
|
|
193
|
+
<form
|
|
194
|
+
id="event-form"
|
|
195
|
+
onSubmit={form.handleSubmit(onSubmit)}
|
|
196
|
+
className="grid gap-4 py-4">
|
|
197
|
+
<FormField
|
|
198
|
+
control={form.control}
|
|
199
|
+
name="title"
|
|
200
|
+
render={({ field, fieldState }) => (
|
|
201
|
+
<FormItem>
|
|
202
|
+
<FormLabel htmlFor="title" className="required">
|
|
203
|
+
{t('ui.calendar.title', 'Title')}
|
|
204
|
+
</FormLabel>
|
|
205
|
+
<FormControl>
|
|
206
|
+
<Input
|
|
207
|
+
id="title"
|
|
208
|
+
placeholder={t('ui.calendar.enterTitle', 'Enter title')}
|
|
209
|
+
{...field}
|
|
210
|
+
className={fieldState.invalid ? 'border-red-500' : ''} />
|
|
211
|
+
</FormControl>
|
|
212
|
+
<FormMessage />
|
|
213
|
+
</FormItem>
|
|
214
|
+
)} />
|
|
215
|
+
<FormField
|
|
216
|
+
control={form.control}
|
|
217
|
+
name="startDate"
|
|
218
|
+
render={({ field }) => (
|
|
219
|
+
<DateTimePicker form={form as never} field={field as never} />
|
|
220
|
+
)} />
|
|
221
|
+
<FormField
|
|
222
|
+
control={form.control}
|
|
223
|
+
name="endDate"
|
|
224
|
+
render={({ field }) => (
|
|
225
|
+
<DateTimePicker form={form as never} field={field as never} />
|
|
226
|
+
)} />
|
|
227
|
+
<FormField
|
|
228
|
+
control={form.control}
|
|
229
|
+
name="color"
|
|
230
|
+
render={({ field, fieldState }) => (
|
|
231
|
+
<FormItem>
|
|
232
|
+
<FormLabel className="required">{t('ui.calendar.variant', 'Color')}</FormLabel>
|
|
233
|
+
<FormControl>
|
|
234
|
+
<Select value={field.value} onValueChange={field.onChange}>
|
|
235
|
+
<SelectTrigger
|
|
236
|
+
className={`w-full ${
|
|
237
|
+
fieldState.invalid ? 'border-red-500' : ''
|
|
238
|
+
}`}>
|
|
239
|
+
<SelectValue placeholder={t('ui.calendar.selectVariant', 'Select color')} />
|
|
240
|
+
</SelectTrigger>
|
|
241
|
+
<SelectContent>
|
|
242
|
+
{COLORS.map(color => (
|
|
243
|
+
<SelectItem value={color} key={color}>
|
|
244
|
+
<div className="flex items-center gap-2">
|
|
245
|
+
<div
|
|
246
|
+
className={`size-3.5 rounded-full bg-${color}-600 dark:bg-${color}-700`} />
|
|
247
|
+
{color}
|
|
248
|
+
</div>
|
|
249
|
+
</SelectItem>
|
|
250
|
+
))}
|
|
251
|
+
</SelectContent>
|
|
252
|
+
</Select>
|
|
253
|
+
</FormControl>
|
|
254
|
+
<FormMessage />
|
|
255
|
+
</FormItem>
|
|
256
|
+
)} />
|
|
257
|
+
<FormField
|
|
258
|
+
control={form.control}
|
|
259
|
+
name="description"
|
|
260
|
+
render={({ field, fieldState }) => (
|
|
261
|
+
<FormItem>
|
|
262
|
+
<FormLabel>{t('ui.calendar.description', 'Description')}</FormLabel>
|
|
263
|
+
<FormControl>
|
|
264
|
+
<Textarea
|
|
265
|
+
{...field}
|
|
266
|
+
placeholder={t('ui.calendar.enterDescription', 'Enter description')}
|
|
267
|
+
className={fieldState.invalid ? 'border-red-500' : ''} />
|
|
268
|
+
</FormControl>
|
|
269
|
+
<FormMessage />
|
|
270
|
+
</FormItem>
|
|
271
|
+
)} />
|
|
272
|
+
</form>
|
|
273
|
+
</Form>
|
|
274
|
+
<DialogFooter className="flex justify-end gap-2">
|
|
275
|
+
<DialogClose asChild>
|
|
276
|
+
<Button type="button" variant="outline">
|
|
277
|
+
{t('ui.calendar.cancel', 'Cancel')}
|
|
278
|
+
</Button>
|
|
279
|
+
</DialogClose>
|
|
280
|
+
<Button form="event-form" type="submit">
|
|
281
|
+
{isEditing ? t('ui.calendar.saveChanges', 'Save Changes') : t('ui.calendar.createEvent', 'Create Event')}
|
|
282
|
+
</Button>
|
|
283
|
+
</DialogFooter>
|
|
284
|
+
</DialogContent>
|
|
285
|
+
</Dialog>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { TrashIcon } from 'lucide-react';
|
|
8
|
+
import { toast } from 'sonner';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
AlertDialog,
|
|
12
|
+
AlertDialogAction,
|
|
13
|
+
AlertDialogCancel,
|
|
14
|
+
AlertDialogContent,
|
|
15
|
+
AlertDialogDescription,
|
|
16
|
+
AlertDialogFooter,
|
|
17
|
+
AlertDialogHeader,
|
|
18
|
+
AlertDialogTitle
|
|
19
|
+
} from '@kivacore/ui-pro-shared/components/alert-dialog';
|
|
20
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
21
|
+
|
|
22
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
23
|
+
|
|
24
|
+
import { type TEventId } from '../interfaces';
|
|
25
|
+
|
|
26
|
+
import { useCalendar } from '../contexts/calendar-context';
|
|
27
|
+
|
|
28
|
+
interface DeleteEventDialogProps {
|
|
29
|
+
eventId: TEventId;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default function DeleteEventDialog({ eventId }: DeleteEventDialogProps) {
|
|
33
|
+
const { t } = useUiTranslation();
|
|
34
|
+
const { removeEvent } = useCalendar();
|
|
35
|
+
const [open, setOpen] = useState(false);
|
|
36
|
+
|
|
37
|
+
const deleteEvent = () => {
|
|
38
|
+
try {
|
|
39
|
+
removeEvent(eventId);
|
|
40
|
+
toast.success(t('ui.calendar.eventDeleted', 'Event deleted'));
|
|
41
|
+
setOpen(false);
|
|
42
|
+
} catch {
|
|
43
|
+
toast.error(t('ui.calendar.eventDeleteError', 'Error deleting event'));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (!eventId) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<>
|
|
53
|
+
<Button variant="destructive" onClick={() => setOpen(true)}>
|
|
54
|
+
<TrashIcon />
|
|
55
|
+
{t('ui.calendar.delete', 'Delete')}
|
|
56
|
+
</Button>
|
|
57
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
58
|
+
<AlertDialogContent>
|
|
59
|
+
<AlertDialogHeader>
|
|
60
|
+
<AlertDialogTitle>{t('ui.calendar.deleteEvent', 'Delete Event')}</AlertDialogTitle>
|
|
61
|
+
<AlertDialogDescription>
|
|
62
|
+
{t('ui.calendar.deleteConfirm', 'Are you sure you want to delete this event? This action cannot be undone.')}
|
|
63
|
+
</AlertDialogDescription>
|
|
64
|
+
</AlertDialogHeader>
|
|
65
|
+
<AlertDialogFooter>
|
|
66
|
+
<AlertDialogCancel>{t('ui.calendar.cancel', 'Cancel')}</AlertDialogCancel>
|
|
67
|
+
<AlertDialogAction onClick={deleteEvent}>{t('ui.calendar.delete', 'Delete')}</AlertDialogAction>
|
|
68
|
+
</AlertDialogFooter>
|
|
69
|
+
</AlertDialogContent>
|
|
70
|
+
</AlertDialog>
|
|
71
|
+
</>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { type ReactNode, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { parseISO } from 'date-fns';
|
|
8
|
+
import {
|
|
9
|
+
Calendar, Clock, Text, User
|
|
10
|
+
} from 'lucide-react';
|
|
11
|
+
import { toast } from 'sonner';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
AlertDialog,
|
|
15
|
+
AlertDialogAction,
|
|
16
|
+
AlertDialogCancel,
|
|
17
|
+
AlertDialogContent,
|
|
18
|
+
AlertDialogDescription,
|
|
19
|
+
AlertDialogFooter,
|
|
20
|
+
AlertDialogHeader,
|
|
21
|
+
AlertDialogTitle
|
|
22
|
+
} from '@kivacore/ui-pro-shared/components/alert-dialog';
|
|
23
|
+
import { Button } from '@kivacore/ui-pro-shared/components/button';
|
|
24
|
+
import {
|
|
25
|
+
Dialog,
|
|
26
|
+
DialogContent,
|
|
27
|
+
DialogFooter,
|
|
28
|
+
DialogHeader,
|
|
29
|
+
DialogTitle,
|
|
30
|
+
DialogTrigger
|
|
31
|
+
} from '@kivacore/ui-pro-shared/components/dialog';
|
|
32
|
+
|
|
33
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
34
|
+
import { useDateFormat } from '@kivacore/ui-pro-shared/hooks/kiva/use-date-format';
|
|
35
|
+
|
|
36
|
+
import { type IEvent } from '../interfaces';
|
|
37
|
+
import { useCalendar } from '../contexts/calendar-context';
|
|
38
|
+
import { formatTime } from '../helpers';
|
|
39
|
+
import { AddEditEventDialog } from './add-edit-event-dialog';
|
|
40
|
+
|
|
41
|
+
interface IProps {
|
|
42
|
+
event: IEvent;
|
|
43
|
+
children: ReactNode;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function EventDetailsDialog({ event, children }: IProps) {
|
|
47
|
+
const startDate = parseISO(event.startDate);
|
|
48
|
+
const endDate = parseISO(event.endDate);
|
|
49
|
+
const {
|
|
50
|
+
use24HourFormat, removeEvent, onEventClick
|
|
51
|
+
} = useCalendar();
|
|
52
|
+
const { t } = useUiTranslation();
|
|
53
|
+
const { formatDate } = useDateFormat();
|
|
54
|
+
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
55
|
+
|
|
56
|
+
if (onEventClick) {
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
onClick={(e) => {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
onEventClick(event);
|
|
62
|
+
}}
|
|
63
|
+
role="button"
|
|
64
|
+
tabIndex={0}
|
|
65
|
+
onKeyDown={(e) => { if (e.key === 'Enter') onEventClick(event); }}>
|
|
66
|
+
{children}
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const deleteEvent = () => {
|
|
72
|
+
try {
|
|
73
|
+
removeEvent(event.id);
|
|
74
|
+
toast.success(t('ui.calendar.eventDeleted', 'Event deleted'));
|
|
75
|
+
setDeleteOpen(false);
|
|
76
|
+
} catch {
|
|
77
|
+
toast.error(t('ui.calendar.eventDeleteError', 'Error deleting event'));
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Dialog>
|
|
83
|
+
<DialogTrigger asChild>{children}</DialogTrigger>
|
|
84
|
+
<DialogContent className="gap-0 p-0 sm:max-w-md">
|
|
85
|
+
<DialogHeader className="border-b px-6 pt-6 pb-4">
|
|
86
|
+
<DialogTitle className="pr-8 break-words">{event.title}</DialogTitle>
|
|
87
|
+
</DialogHeader>
|
|
88
|
+
|
|
89
|
+
<div className="max-h-[60vh] space-y-4 overflow-y-auto px-6 py-4">
|
|
90
|
+
<div className="flex items-start gap-3">
|
|
91
|
+
<User className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
|
92
|
+
<div className="min-w-0 flex-1">
|
|
93
|
+
<p className="text-sm font-medium">{t('ui.calendar.responsible', 'Responsible')}</p>
|
|
94
|
+
<p className="text-sm break-words text-muted-foreground">
|
|
95
|
+
{event.user.name}
|
|
96
|
+
</p>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<div className="flex items-start gap-3">
|
|
101
|
+
<Calendar className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
|
102
|
+
<div className="min-w-0 flex-1">
|
|
103
|
+
<p className="text-sm font-medium">{t('ui.calendar.startDate', 'Start Date')}</p>
|
|
104
|
+
<p className="text-sm break-words text-muted-foreground">
|
|
105
|
+
{formatDate(startDate)}
|
|
106
|
+
<span className="mx-1">{t('ui.calendar.at', 'at')}</span>
|
|
107
|
+
{formatTime(parseISO(event.startDate), use24HourFormat)}
|
|
108
|
+
</p>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div className="flex items-start gap-3">
|
|
113
|
+
<Clock className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
|
114
|
+
<div className="min-w-0 flex-1">
|
|
115
|
+
<p className="text-sm font-medium">{t('ui.calendar.endDate', 'End Date')}</p>
|
|
116
|
+
<p className="text-sm break-words text-muted-foreground">
|
|
117
|
+
{formatDate(endDate)}
|
|
118
|
+
<span className="mx-1">{t('ui.calendar.at', 'at')}</span>
|
|
119
|
+
{formatTime(parseISO(event.endDate), use24HourFormat)}
|
|
120
|
+
</p>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
{event.description && (
|
|
125
|
+
<div className="flex items-start gap-3">
|
|
126
|
+
<Text className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
|
127
|
+
<div className="min-w-0 flex-1">
|
|
128
|
+
<p className="text-sm font-medium">{t('ui.calendar.description', 'Description')}</p>
|
|
129
|
+
<p className="text-sm break-words whitespace-pre-wrap text-muted-foreground">
|
|
130
|
+
{event.description}
|
|
131
|
+
</p>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<DialogFooter className="border-t bg-muted/30 px-6 py-4">
|
|
138
|
+
<AddEditEventDialog event={event}>
|
|
139
|
+
<Button variant="outline">{t('ui.calendar.edit', 'Edit')}</Button>
|
|
140
|
+
</AddEditEventDialog>
|
|
141
|
+
<Button variant="destructive" onClick={() => setDeleteOpen(true)}>
|
|
142
|
+
{t('ui.calendar.delete', 'Delete')}
|
|
143
|
+
</Button>
|
|
144
|
+
</DialogFooter>
|
|
145
|
+
|
|
146
|
+
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
|
147
|
+
<AlertDialogContent>
|
|
148
|
+
<AlertDialogHeader>
|
|
149
|
+
<AlertDialogTitle>{t('ui.calendar.deleteEvent', 'Delete Event')}</AlertDialogTitle>
|
|
150
|
+
<AlertDialogDescription>
|
|
151
|
+
{t('ui.calendar.deleteConfirm', 'Are you sure you want to delete this event? This action cannot be undone.')}
|
|
152
|
+
</AlertDialogDescription>
|
|
153
|
+
</AlertDialogHeader>
|
|
154
|
+
<AlertDialogFooter>
|
|
155
|
+
<AlertDialogCancel>{t('ui.calendar.cancel', 'Cancel')}</AlertDialogCancel>
|
|
156
|
+
<AlertDialogAction onClick={deleteEvent}>{t('ui.calendar.delete', 'Delete')}</AlertDialogAction>
|
|
157
|
+
</AlertDialogFooter>
|
|
158
|
+
</AlertDialogContent>
|
|
159
|
+
</AlertDialog>
|
|
160
|
+
</DialogContent>
|
|
161
|
+
</Dialog>
|
|
162
|
+
);
|
|
163
|
+
}
|