@isma91/react-scheduler 4.0.0 → 4.0.2
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/{dist/index.js → index.js} +218 -203
- package/package.json +4 -76
- package/.github/workflows/publish.yml +0 -29
- package/.github/workflows/tests.yml +0 -35
- package/.gitignore +0 -32
- package/.husky/pre-commit +0 -2
- package/.prettierignore +0 -1
- package/.prettierrc.json +0 -7
- package/.yarnrc.yml +0 -1
- package/dist/LICENSE +0 -24
- package/dist/README.md +0 -172
- package/dist/package.json +0 -65
- package/eslint.config.js +0 -79
- package/index.html +0 -41
- package/jest.config.ts +0 -194
- package/public/favicon.ico +0 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/scripts/post-pack.js +0 -34
- package/src/App.tsx +0 -25
- package/src/Page1.tsx +0 -67
- package/src/events.tsx +0 -227
- package/src/index.tsx +0 -21
- package/src/lib/SchedulerComponent.tsx +0 -78
- package/src/lib/__tests__/index.test.tsx +0 -24
- package/src/lib/components/common/Cell.tsx +0 -52
- package/src/lib/components/common/LocaleArrow.tsx +0 -38
- package/src/lib/components/common/ResourceHeader.tsx +0 -73
- package/src/lib/components/common/Tabs.tsx +0 -119
- package/src/lib/components/common/TodayTypo.tsx +0 -44
- package/src/lib/components/common/WithResources.tsx +0 -98
- package/src/lib/components/events/Actions.tsx +0 -65
- package/src/lib/components/events/AgendaEventsList.tsx +0 -115
- package/src/lib/components/events/CurrentTimeBar.tsx +0 -59
- package/src/lib/components/events/EmptyAgenda.tsx +0 -27
- package/src/lib/components/events/EventItem.tsx +0 -180
- package/src/lib/components/events/EventItemPopover.tsx +0 -179
- package/src/lib/components/events/MonthEvents.tsx +0 -141
- package/src/lib/components/events/TodayEvents.tsx +0 -99
- package/src/lib/components/hoc/DateProvider.tsx +0 -19
- package/src/lib/components/inputs/DatePicker.tsx +0 -95
- package/src/lib/components/inputs/Input.tsx +0 -113
- package/src/lib/components/inputs/SelectInput.tsx +0 -164
- package/src/lib/components/month/MonthTable.tsx +0 -207
- package/src/lib/components/nav/DayDateBtn.tsx +0 -77
- package/src/lib/components/nav/MonthDateBtn.tsx +0 -80
- package/src/lib/components/nav/Navigation.tsx +0 -201
- package/src/lib/components/nav/WeekDateBtn.tsx +0 -89
- package/src/lib/components/week/WeekTable.tsx +0 -229
- package/src/lib/helpers/constants.ts +0 -4
- package/src/lib/helpers/generals.tsx +0 -354
- package/src/lib/hooks/useArrowDisable.ts +0 -26
- package/src/lib/hooks/useCellAttributes.ts +0 -67
- package/src/lib/hooks/useDragAttributes.ts +0 -31
- package/src/lib/hooks/useEventPermissions.ts +0 -42
- package/src/lib/hooks/useStore.ts +0 -8
- package/src/lib/hooks/useSyncScroll.ts +0 -31
- package/src/lib/hooks/useWindowResize.ts +0 -37
- package/src/lib/index.tsx +0 -14
- package/src/lib/positionManger/context.ts +0 -14
- package/src/lib/positionManger/provider.tsx +0 -113
- package/src/lib/positionManger/usePosition.ts +0 -8
- package/src/lib/store/context.ts +0 -5
- package/src/lib/store/default.ts +0 -157
- package/src/lib/store/provider.tsx +0 -211
- package/src/lib/store/types.ts +0 -33
- package/src/lib/styles/styles.ts +0 -256
- package/src/lib/types.ts +0 -423
- package/src/lib/views/Day.tsx +0 -265
- package/src/lib/views/DayAgenda.tsx +0 -57
- package/src/lib/views/Editor.tsx +0 -258
- package/src/lib/views/Month.tsx +0 -82
- package/src/lib/views/MonthAgenda.tsx +0 -84
- package/src/lib/views/Week.tsx +0 -92
- package/src/lib/views/WeekAgenda.tsx +0 -81
- package/src/vite-env.d.ts +0 -3
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -27
- package/vite.config.js +0 -40
- /package/{dist/SchedulerComponent.d.ts → SchedulerComponent.d.ts} +0 -0
- /package/{dist/components → components}/common/Cell.d.ts +0 -0
- /package/{dist/components → components}/common/LocaleArrow.d.ts +0 -0
- /package/{dist/components → components}/common/ResourceHeader.d.ts +0 -0
- /package/{dist/components → components}/common/Tabs.d.ts +0 -0
- /package/{dist/components → components}/common/TodayTypo.d.ts +0 -0
- /package/{dist/components → components}/common/WithResources.d.ts +0 -0
- /package/{dist/components → components}/events/Actions.d.ts +0 -0
- /package/{dist/components → components}/events/AgendaEventsList.d.ts +0 -0
- /package/{dist/components → components}/events/CurrentTimeBar.d.ts +0 -0
- /package/{dist/components → components}/events/EmptyAgenda.d.ts +0 -0
- /package/{dist/components → components}/events/EventItem.d.ts +0 -0
- /package/{dist/components → components}/events/EventItemPopover.d.ts +0 -0
- /package/{dist/components → components}/events/MonthEvents.d.ts +0 -0
- /package/{dist/components → components}/events/TodayEvents.d.ts +0 -0
- /package/{dist/components → components}/hoc/DateProvider.d.ts +0 -0
- /package/{dist/components → components}/inputs/DatePicker.d.ts +0 -0
- /package/{dist/components → components}/inputs/Input.d.ts +0 -0
- /package/{dist/components → components}/inputs/SelectInput.d.ts +0 -0
- /package/{dist/components → components}/month/MonthTable.d.ts +0 -0
- /package/{dist/components → components}/nav/DayDateBtn.d.ts +0 -0
- /package/{dist/components → components}/nav/MonthDateBtn.d.ts +0 -0
- /package/{dist/components → components}/nav/Navigation.d.ts +0 -0
- /package/{dist/components → components}/nav/WeekDateBtn.d.ts +0 -0
- /package/{dist/components → components}/week/WeekTable.d.ts +0 -0
- /package/{dist/helpers → helpers}/constants.d.ts +0 -0
- /package/{dist/helpers → helpers}/generals.d.ts +0 -0
- /package/{dist/hooks → hooks}/useArrowDisable.d.ts +0 -0
- /package/{dist/hooks → hooks}/useCellAttributes.d.ts +0 -0
- /package/{dist/hooks → hooks}/useDragAttributes.d.ts +0 -0
- /package/{dist/hooks → hooks}/useEventPermissions.d.ts +0 -0
- /package/{dist/hooks → hooks}/useStore.d.ts +0 -0
- /package/{dist/hooks → hooks}/useSyncScroll.d.ts +0 -0
- /package/{dist/hooks → hooks}/useWindowResize.d.ts +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/positionManger → positionManger}/context.d.ts +0 -0
- /package/{dist/positionManger → positionManger}/provider.d.ts +0 -0
- /package/{dist/positionManger → positionManger}/usePosition.d.ts +0 -0
- /package/{dist/store → store}/context.d.ts +0 -0
- /package/{dist/store → store}/default.d.ts +0 -0
- /package/{dist/store → store}/provider.d.ts +0 -0
- /package/{dist/store → store}/types.d.ts +0 -0
- /package/{dist/styles → styles}/styles.d.ts +0 -0
- /package/{dist/types.d.ts → types.d.ts} +0 -0
- /package/{dist/views → views}/Day.d.ts +0 -0
- /package/{dist/views → views}/DayAgenda.d.ts +0 -0
- /package/{dist/views → views}/Editor.d.ts +0 -0
- /package/{dist/views → views}/Month.d.ts +0 -0
- /package/{dist/views → views}/MonthAgenda.d.ts +0 -0
- /package/{dist/views → views}/Week.d.ts +0 -0
- /package/{dist/views → views}/WeekAgenda.d.ts +0 -0
package/src/lib/views/Day.tsx
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { useEffect, useCallback, Fragment } from "react";
|
|
2
|
-
import { Typography } from "@mui/material";
|
|
3
|
-
import {
|
|
4
|
-
format,
|
|
5
|
-
eachMinuteOfInterval,
|
|
6
|
-
isToday,
|
|
7
|
-
isBefore,
|
|
8
|
-
isAfter,
|
|
9
|
-
startOfDay,
|
|
10
|
-
endOfDay,
|
|
11
|
-
addDays,
|
|
12
|
-
addMinutes,
|
|
13
|
-
set,
|
|
14
|
-
} from "date-fns";
|
|
15
|
-
import TodayTypo from "../components/common/TodayTypo";
|
|
16
|
-
import EventItem from "../components/events/EventItem";
|
|
17
|
-
import { DefaultResource, ProcessedEvent } from "../types";
|
|
18
|
-
import {
|
|
19
|
-
calcCellHeight,
|
|
20
|
-
calcMinuteHeight,
|
|
21
|
-
filterMultiDaySlot,
|
|
22
|
-
filterTodayEvents,
|
|
23
|
-
getHourFormat,
|
|
24
|
-
getResourcedEvents,
|
|
25
|
-
} from "../helpers/generals";
|
|
26
|
-
import { WithResources } from "../components/common/WithResources";
|
|
27
|
-
import Cell from "../components/common/Cell";
|
|
28
|
-
import TodayEvents from "../components/events/TodayEvents";
|
|
29
|
-
import { TableGrid } from "../styles/styles";
|
|
30
|
-
import { MULTI_DAY_EVENT_HEIGHT } from "../helpers/constants";
|
|
31
|
-
import useStore from "../hooks/useStore";
|
|
32
|
-
import { DayAgenda } from "./DayAgenda";
|
|
33
|
-
|
|
34
|
-
const Day = () => {
|
|
35
|
-
const {
|
|
36
|
-
day,
|
|
37
|
-
selectedDate,
|
|
38
|
-
events,
|
|
39
|
-
height,
|
|
40
|
-
getRemoteEvents,
|
|
41
|
-
triggerLoading,
|
|
42
|
-
handleState,
|
|
43
|
-
resources,
|
|
44
|
-
resourceFields,
|
|
45
|
-
resourceViewMode,
|
|
46
|
-
fields,
|
|
47
|
-
direction,
|
|
48
|
-
locale,
|
|
49
|
-
hourFormat,
|
|
50
|
-
timeZone,
|
|
51
|
-
stickyNavigation,
|
|
52
|
-
agenda,
|
|
53
|
-
stickyNavigationOffset,
|
|
54
|
-
stickyNavigationHeight,
|
|
55
|
-
currentTime,
|
|
56
|
-
showCurrentTimeBar,
|
|
57
|
-
currentTimeBarColor,
|
|
58
|
-
forceInlineMultiDay,
|
|
59
|
-
} = useStore();
|
|
60
|
-
|
|
61
|
-
const { startHour, endHour, step, cellRenderer, headRenderer, hourRenderer } = day!;
|
|
62
|
-
const START_TIME = set(selectedDate, { hours: startHour, minutes: 0, seconds: 0 });
|
|
63
|
-
const END_TIME = set(selectedDate, { hours: endHour, minutes: -step, seconds: 0 });
|
|
64
|
-
const hours = eachMinuteOfInterval(
|
|
65
|
-
{
|
|
66
|
-
start: START_TIME,
|
|
67
|
-
end: END_TIME,
|
|
68
|
-
},
|
|
69
|
-
{ step: step }
|
|
70
|
-
);
|
|
71
|
-
const CELL_HEIGHT = calcCellHeight(height, hours.length);
|
|
72
|
-
const MINUTE_HEIGHT = calcMinuteHeight(CELL_HEIGHT, step);
|
|
73
|
-
const hFormat = getHourFormat(hourFormat);
|
|
74
|
-
|
|
75
|
-
const fetchEvents = useCallback(async () => {
|
|
76
|
-
try {
|
|
77
|
-
triggerLoading(true);
|
|
78
|
-
const start = addDays(START_TIME, -1);
|
|
79
|
-
const end = addDays(END_TIME, 1);
|
|
80
|
-
const events = await getRemoteEvents!({
|
|
81
|
-
start,
|
|
82
|
-
end,
|
|
83
|
-
view: "day",
|
|
84
|
-
});
|
|
85
|
-
if (events && events?.length) {
|
|
86
|
-
handleState(events, "events");
|
|
87
|
-
}
|
|
88
|
-
} catch (error) {
|
|
89
|
-
throw error;
|
|
90
|
-
} finally {
|
|
91
|
-
triggerLoading(false);
|
|
92
|
-
}
|
|
93
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
-
}, [getRemoteEvents]);
|
|
95
|
-
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
if (getRemoteEvents instanceof Function) {
|
|
98
|
-
fetchEvents();
|
|
99
|
-
}
|
|
100
|
-
}, [fetchEvents, getRemoteEvents]);
|
|
101
|
-
|
|
102
|
-
const renderMultiDayEvents = useCallback(
|
|
103
|
-
(events: ProcessedEvent[]) => {
|
|
104
|
-
const todayMulti = filterMultiDaySlot(events, selectedDate, timeZone, forceInlineMultiDay);
|
|
105
|
-
return (
|
|
106
|
-
<div
|
|
107
|
-
className="rs__block_col"
|
|
108
|
-
style={{ height: MULTI_DAY_EVENT_HEIGHT * todayMulti.length }}
|
|
109
|
-
>
|
|
110
|
-
{todayMulti.map((event, i) => {
|
|
111
|
-
const hasPrev = isBefore(event.start, startOfDay(selectedDate));
|
|
112
|
-
const hasNext = isAfter(event.end, endOfDay(selectedDate));
|
|
113
|
-
return (
|
|
114
|
-
<div
|
|
115
|
-
key={event.event_id}
|
|
116
|
-
className="rs__multi_day"
|
|
117
|
-
style={{
|
|
118
|
-
top: i * MULTI_DAY_EVENT_HEIGHT,
|
|
119
|
-
width: "99.9%",
|
|
120
|
-
overflowX: "hidden",
|
|
121
|
-
}}
|
|
122
|
-
>
|
|
123
|
-
<EventItem event={event} multiday hasPrev={hasPrev} hasNext={hasNext} />
|
|
124
|
-
</div>
|
|
125
|
-
);
|
|
126
|
-
})}
|
|
127
|
-
</div>
|
|
128
|
-
);
|
|
129
|
-
},
|
|
130
|
-
[selectedDate, timeZone]
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
const renderTable = useCallback(
|
|
134
|
-
(resource?: DefaultResource) => {
|
|
135
|
-
let resourcedEvents = events;
|
|
136
|
-
if (resource) {
|
|
137
|
-
resourcedEvents = getResourcedEvents(events, resource, resourceFields, fields);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (agenda) {
|
|
141
|
-
return <DayAgenda resource={resource} events={resourcedEvents} />;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Equalizing multi-day section height
|
|
145
|
-
const shouldEqualize = resources.length && resourceViewMode === "default";
|
|
146
|
-
const allWeekMulti = filterMultiDaySlot(
|
|
147
|
-
shouldEqualize ? events : resourcedEvents,
|
|
148
|
-
selectedDate,
|
|
149
|
-
timeZone,
|
|
150
|
-
forceInlineMultiDay
|
|
151
|
-
);
|
|
152
|
-
const headerHeight = MULTI_DAY_EVENT_HEIGHT * allWeekMulti.length + 45;
|
|
153
|
-
return (
|
|
154
|
-
<>
|
|
155
|
-
{/* Header */}
|
|
156
|
-
<TableGrid
|
|
157
|
-
days={1}
|
|
158
|
-
sticky="1"
|
|
159
|
-
stickyNavigation={stickyNavigation}
|
|
160
|
-
stickyOffset={stickyNavigationOffset}
|
|
161
|
-
stickyHeight={stickyNavigationHeight}
|
|
162
|
-
>
|
|
163
|
-
<span className="rs__cell"></span>
|
|
164
|
-
<span
|
|
165
|
-
className={`rs__cell rs__header ${isToday(selectedDate) ? "rs__today_cell" : ""}`}
|
|
166
|
-
style={{ height: headerHeight }}
|
|
167
|
-
>
|
|
168
|
-
{typeof headRenderer === "function" ? (
|
|
169
|
-
<div>{headRenderer({ day: selectedDate, events: resourcedEvents, resource })}</div>
|
|
170
|
-
) : (
|
|
171
|
-
<TodayTypo date={selectedDate} locale={locale} />
|
|
172
|
-
)}
|
|
173
|
-
{renderMultiDayEvents(resourcedEvents)}
|
|
174
|
-
</span>
|
|
175
|
-
</TableGrid>
|
|
176
|
-
<TableGrid days={1}>
|
|
177
|
-
{/* Body */}
|
|
178
|
-
{hours.map((h, i) => {
|
|
179
|
-
const start = new Date(`${format(selectedDate, "yyyy/MM/dd")} ${format(h, hFormat)}`);
|
|
180
|
-
const end = addMinutes(start, step);
|
|
181
|
-
const field = resourceFields.idField;
|
|
182
|
-
return (
|
|
183
|
-
<Fragment key={i}>
|
|
184
|
-
{/* Time Cells */}
|
|
185
|
-
<span className="rs__cell rs__header rs__time" style={{ height: CELL_HEIGHT }}>
|
|
186
|
-
{typeof hourRenderer === "function" ? (
|
|
187
|
-
<div>{hourRenderer(format(h, hFormat, { locale }))}</div>
|
|
188
|
-
) : (
|
|
189
|
-
<Typography variant="caption">{format(h, hFormat, { locale })}</Typography>
|
|
190
|
-
)}
|
|
191
|
-
</span>
|
|
192
|
-
<span className={`rs__cell ${isToday(selectedDate) ? "rs__today_cell" : ""}`}>
|
|
193
|
-
{/* Events of this day - run once on the top hour column */}
|
|
194
|
-
{i === 0 && (
|
|
195
|
-
<TodayEvents
|
|
196
|
-
todayEvents={filterTodayEvents(
|
|
197
|
-
resourcedEvents,
|
|
198
|
-
selectedDate,
|
|
199
|
-
timeZone,
|
|
200
|
-
forceInlineMultiDay
|
|
201
|
-
)}
|
|
202
|
-
today={START_TIME}
|
|
203
|
-
minuteHeight={MINUTE_HEIGHT}
|
|
204
|
-
startHour={startHour}
|
|
205
|
-
endHour={endHour}
|
|
206
|
-
step={step}
|
|
207
|
-
direction={direction}
|
|
208
|
-
timeZone={timeZone}
|
|
209
|
-
currentTime={currentTime}
|
|
210
|
-
showCurrentTimeBar={showCurrentTimeBar}
|
|
211
|
-
currentTimeBarColor={currentTimeBarColor}
|
|
212
|
-
/>
|
|
213
|
-
)}
|
|
214
|
-
{/* Cell */}
|
|
215
|
-
<Cell
|
|
216
|
-
start={start}
|
|
217
|
-
end={end}
|
|
218
|
-
day={selectedDate}
|
|
219
|
-
height={CELL_HEIGHT}
|
|
220
|
-
resourceKey={field}
|
|
221
|
-
resourceVal={resource ? resource[field] : null}
|
|
222
|
-
cellRenderer={cellRenderer}
|
|
223
|
-
/>
|
|
224
|
-
</span>
|
|
225
|
-
</Fragment>
|
|
226
|
-
);
|
|
227
|
-
})}
|
|
228
|
-
</TableGrid>
|
|
229
|
-
</>
|
|
230
|
-
);
|
|
231
|
-
},
|
|
232
|
-
[
|
|
233
|
-
CELL_HEIGHT,
|
|
234
|
-
MINUTE_HEIGHT,
|
|
235
|
-
START_TIME,
|
|
236
|
-
agenda,
|
|
237
|
-
cellRenderer,
|
|
238
|
-
direction,
|
|
239
|
-
endHour,
|
|
240
|
-
events,
|
|
241
|
-
fields,
|
|
242
|
-
hFormat,
|
|
243
|
-
headRenderer,
|
|
244
|
-
hourRenderer,
|
|
245
|
-
hours,
|
|
246
|
-
locale,
|
|
247
|
-
renderMultiDayEvents,
|
|
248
|
-
resourceFields,
|
|
249
|
-
resourceViewMode,
|
|
250
|
-
resources.length,
|
|
251
|
-
selectedDate,
|
|
252
|
-
startHour,
|
|
253
|
-
step,
|
|
254
|
-
stickyNavigation,
|
|
255
|
-
timeZone,
|
|
256
|
-
currentTime,
|
|
257
|
-
showCurrentTimeBar,
|
|
258
|
-
currentTimeBarColor,
|
|
259
|
-
]
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
return resources.length ? <WithResources renderChildren={renderTable} /> : renderTable();
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
export { Day };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { format } from "date-fns";
|
|
3
|
-
import { AgendaDiv } from "../styles/styles";
|
|
4
|
-
import { DefaultResource, ProcessedEvent } from "../types";
|
|
5
|
-
import useStore from "../hooks/useStore";
|
|
6
|
-
import { Typography } from "@mui/material";
|
|
7
|
-
import { filterTodayAgendaEvents } from "../helpers/generals";
|
|
8
|
-
import AgendaEventsList from "../components/events/AgendaEventsList";
|
|
9
|
-
import EmptyAgenda from "../components/events/EmptyAgenda";
|
|
10
|
-
|
|
11
|
-
type Props = {
|
|
12
|
-
events: ProcessedEvent[];
|
|
13
|
-
resource?: DefaultResource;
|
|
14
|
-
};
|
|
15
|
-
const DayAgenda = ({ events, resource }: Props) => {
|
|
16
|
-
const {
|
|
17
|
-
day,
|
|
18
|
-
locale,
|
|
19
|
-
selectedDate,
|
|
20
|
-
translations,
|
|
21
|
-
alwaysShowAgendaDays,
|
|
22
|
-
stickyNavigationOffset,
|
|
23
|
-
stickyNavigationHeight,
|
|
24
|
-
} = useStore();
|
|
25
|
-
const { headRenderer } = day!;
|
|
26
|
-
|
|
27
|
-
const dayEvents = useMemo(() => {
|
|
28
|
-
return filterTodayAgendaEvents(events, selectedDate);
|
|
29
|
-
}, [events, selectedDate]);
|
|
30
|
-
|
|
31
|
-
if (!alwaysShowAgendaDays && !dayEvents.length) {
|
|
32
|
-
return <EmptyAgenda />;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<AgendaDiv stickyOffset={stickyNavigationOffset} stickyHeight={stickyNavigationHeight}>
|
|
37
|
-
<div className="rs__agenda_row rs__today_cell">
|
|
38
|
-
<div className="rs__cell rs__agenda__cell">
|
|
39
|
-
{typeof headRenderer === "function" ? (
|
|
40
|
-
<div>{headRenderer({ day: selectedDate, events, resource })}</div>
|
|
41
|
-
) : (
|
|
42
|
-
<Typography variant="body2">{format(selectedDate, "dd E", { locale })}</Typography>
|
|
43
|
-
)}
|
|
44
|
-
</div>
|
|
45
|
-
<div className="rs__cell rs__agenda_items">
|
|
46
|
-
{dayEvents.length > 0 ? (
|
|
47
|
-
<AgendaEventsList day={selectedDate} events={dayEvents} />
|
|
48
|
-
) : (
|
|
49
|
-
<Typography sx={{ padding: 1 }}>{translations.noDataToDisplay}</Typography>
|
|
50
|
-
)}
|
|
51
|
-
</div>
|
|
52
|
-
</div>
|
|
53
|
-
</AgendaDiv>
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export { DayAgenda };
|
package/src/lib/views/Editor.tsx
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Button,
|
|
3
|
-
Dialog,
|
|
4
|
-
DialogActions,
|
|
5
|
-
DialogContent,
|
|
6
|
-
DialogTitle,
|
|
7
|
-
Grid,
|
|
8
|
-
useMediaQuery,
|
|
9
|
-
useTheme,
|
|
10
|
-
} from "@mui/material";
|
|
11
|
-
import { addMinutes, differenceInMinutes } from "date-fns";
|
|
12
|
-
import { Fragment, useState } from "react";
|
|
13
|
-
import { EditorDatePicker } from "../components/inputs/DatePicker";
|
|
14
|
-
import { EditorInput } from "../components/inputs/Input";
|
|
15
|
-
import { EditorSelect } from "../components/inputs/SelectInput";
|
|
16
|
-
import { arraytizeFieldVal, revertTimeZonedDate } from "../helpers/generals";
|
|
17
|
-
import useStore from "../hooks/useStore";
|
|
18
|
-
import { SelectedRange } from "../store/types";
|
|
19
|
-
import {
|
|
20
|
-
EventActions,
|
|
21
|
-
FieldInputProps,
|
|
22
|
-
FieldProps,
|
|
23
|
-
InputTypes,
|
|
24
|
-
ProcessedEvent,
|
|
25
|
-
SchedulerHelpers,
|
|
26
|
-
} from "../types";
|
|
27
|
-
|
|
28
|
-
export type StateItem = {
|
|
29
|
-
value: any;
|
|
30
|
-
validity: boolean;
|
|
31
|
-
type: InputTypes;
|
|
32
|
-
config?: FieldInputProps;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type StateEvent = (ProcessedEvent & SelectedRange) | Record<string, any>;
|
|
36
|
-
|
|
37
|
-
const initialState = (fields: FieldProps[], event?: StateEvent): Record<string, StateItem> => {
|
|
38
|
-
const customFields = {} as Record<string, StateItem>;
|
|
39
|
-
for (const field of fields) {
|
|
40
|
-
const defVal = arraytizeFieldVal(field, field.default, event);
|
|
41
|
-
const eveVal = arraytizeFieldVal(field, event?.[field.name], event);
|
|
42
|
-
|
|
43
|
-
customFields[field.name] = {
|
|
44
|
-
value: eveVal.value || defVal.value || "",
|
|
45
|
-
validity: field.config?.required ? !!eveVal.validity || !!defVal.validity : true,
|
|
46
|
-
type: field.type,
|
|
47
|
-
config: field.config,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
event_id: {
|
|
53
|
-
value: event?.event_id || null,
|
|
54
|
-
validity: true,
|
|
55
|
-
type: "hidden",
|
|
56
|
-
},
|
|
57
|
-
title: {
|
|
58
|
-
value: event?.title || "",
|
|
59
|
-
validity: !!event?.title,
|
|
60
|
-
type: "input",
|
|
61
|
-
config: { label: "Title", required: true, min: 3 },
|
|
62
|
-
},
|
|
63
|
-
subtitle: {
|
|
64
|
-
value: event?.subtitle || "",
|
|
65
|
-
validity: true,
|
|
66
|
-
type: "input",
|
|
67
|
-
config: { label: "Subtitle", required: false },
|
|
68
|
-
},
|
|
69
|
-
start: {
|
|
70
|
-
value: event?._originalStart || event?.start || new Date(),
|
|
71
|
-
validity: true,
|
|
72
|
-
type: "date",
|
|
73
|
-
config: { label: "Start", sm: 6 },
|
|
74
|
-
},
|
|
75
|
-
end: {
|
|
76
|
-
value: event?._originalEnd || event?.end || new Date(),
|
|
77
|
-
validity: true,
|
|
78
|
-
type: "date",
|
|
79
|
-
config: { label: "End", sm: 6 },
|
|
80
|
-
},
|
|
81
|
-
...customFields,
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const Editor = () => {
|
|
86
|
-
const {
|
|
87
|
-
fields,
|
|
88
|
-
dialog,
|
|
89
|
-
triggerDialog,
|
|
90
|
-
selectedRange,
|
|
91
|
-
selectedEvent,
|
|
92
|
-
resourceFields,
|
|
93
|
-
selectedResource,
|
|
94
|
-
triggerLoading,
|
|
95
|
-
onConfirm,
|
|
96
|
-
customEditor,
|
|
97
|
-
confirmEvent,
|
|
98
|
-
dialogMaxWidth,
|
|
99
|
-
translations,
|
|
100
|
-
timeZone,
|
|
101
|
-
} = useStore();
|
|
102
|
-
const [state, setState] = useState(initialState(fields, selectedEvent || selectedRange));
|
|
103
|
-
const [touched, setTouched] = useState(false);
|
|
104
|
-
const theme = useTheme();
|
|
105
|
-
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
|
106
|
-
|
|
107
|
-
const handleEditorState = (name: string, value: any, validity: boolean) => {
|
|
108
|
-
setState((prev) => {
|
|
109
|
-
return {
|
|
110
|
-
...prev,
|
|
111
|
-
[name]: { ...prev[name], value, validity },
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const handleClose = (clearState?: boolean) => {
|
|
117
|
-
if (clearState) {
|
|
118
|
-
setState(initialState(fields));
|
|
119
|
-
}
|
|
120
|
-
triggerDialog(false);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const handleConfirm = async () => {
|
|
124
|
-
let body = {} as ProcessedEvent;
|
|
125
|
-
for (const key in state) {
|
|
126
|
-
body[key] = state[key].value;
|
|
127
|
-
if (!customEditor && !state[key].validity) {
|
|
128
|
-
return setTouched(true);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
triggerLoading(true);
|
|
133
|
-
// Auto fix date
|
|
134
|
-
body.end =
|
|
135
|
-
body.start >= body.end
|
|
136
|
-
? addMinutes(body.start, differenceInMinutes(selectedRange?.end!, selectedRange?.start!))
|
|
137
|
-
: body.end;
|
|
138
|
-
// Specify action
|
|
139
|
-
const action: EventActions = selectedEvent?.event_id ? "edit" : "create";
|
|
140
|
-
// Trigger custom/remote when provided
|
|
141
|
-
if (onConfirm) {
|
|
142
|
-
body = await onConfirm(body, action);
|
|
143
|
-
} else {
|
|
144
|
-
// Create/Edit local data
|
|
145
|
-
body.event_id =
|
|
146
|
-
selectedEvent?.event_id || Date.now().toString(36) + Math.random().toString(36).slice(2);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
body.start = revertTimeZonedDate(body.start, timeZone);
|
|
150
|
-
body.end = revertTimeZonedDate(body.end, timeZone);
|
|
151
|
-
|
|
152
|
-
confirmEvent(body, action);
|
|
153
|
-
handleClose(true);
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error(error);
|
|
156
|
-
} finally {
|
|
157
|
-
triggerLoading(false);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const renderInputs = (key: string) => {
|
|
161
|
-
const stateItem = state[key];
|
|
162
|
-
switch (stateItem.type) {
|
|
163
|
-
case "input":
|
|
164
|
-
return (
|
|
165
|
-
<EditorInput
|
|
166
|
-
value={stateItem.value}
|
|
167
|
-
name={key}
|
|
168
|
-
onChange={handleEditorState}
|
|
169
|
-
touched={touched}
|
|
170
|
-
{...stateItem.config}
|
|
171
|
-
label={translations.event[key] || stateItem.config?.label}
|
|
172
|
-
/>
|
|
173
|
-
);
|
|
174
|
-
case "date":
|
|
175
|
-
return (
|
|
176
|
-
<EditorDatePicker
|
|
177
|
-
value={stateItem.value}
|
|
178
|
-
name={key}
|
|
179
|
-
onChange={(...args) => handleEditorState(...args, true)}
|
|
180
|
-
touched={touched}
|
|
181
|
-
{...stateItem.config}
|
|
182
|
-
label={translations.event[key] || stateItem.config?.label}
|
|
183
|
-
/>
|
|
184
|
-
);
|
|
185
|
-
case "select":
|
|
186
|
-
const field = fields.find((f) => f.name === key);
|
|
187
|
-
return (
|
|
188
|
-
<EditorSelect
|
|
189
|
-
value={stateItem.value}
|
|
190
|
-
name={key}
|
|
191
|
-
options={field?.options || []}
|
|
192
|
-
onChange={handleEditorState}
|
|
193
|
-
touched={touched}
|
|
194
|
-
{...stateItem.config}
|
|
195
|
-
label={translations.event[key] || stateItem.config?.label}
|
|
196
|
-
/>
|
|
197
|
-
);
|
|
198
|
-
default:
|
|
199
|
-
return "";
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const renderEditor = () => {
|
|
204
|
-
if (customEditor) {
|
|
205
|
-
const schedulerHelpers: SchedulerHelpers = {
|
|
206
|
-
state,
|
|
207
|
-
close: () => triggerDialog(false),
|
|
208
|
-
loading: (load) => triggerLoading(load),
|
|
209
|
-
edited: selectedEvent,
|
|
210
|
-
onConfirm: confirmEvent,
|
|
211
|
-
[resourceFields.idField]: selectedResource,
|
|
212
|
-
};
|
|
213
|
-
return customEditor(schedulerHelpers);
|
|
214
|
-
}
|
|
215
|
-
return (
|
|
216
|
-
<Fragment>
|
|
217
|
-
<DialogTitle>
|
|
218
|
-
{selectedEvent ? translations.form.editTitle : translations.form.addTitle}
|
|
219
|
-
</DialogTitle>
|
|
220
|
-
<DialogContent style={{ overflowX: "hidden" }}>
|
|
221
|
-
<Grid container spacing={2}>
|
|
222
|
-
{Object.keys(state).map((key) => {
|
|
223
|
-
const item = state[key];
|
|
224
|
-
return (
|
|
225
|
-
<Grid key={key} size={{ sm: item.config?.sm, xs: 12 }}>
|
|
226
|
-
{renderInputs(key)}
|
|
227
|
-
</Grid>
|
|
228
|
-
);
|
|
229
|
-
})}
|
|
230
|
-
</Grid>
|
|
231
|
-
</DialogContent>
|
|
232
|
-
<DialogActions>
|
|
233
|
-
<Button color="inherit" fullWidth onClick={() => handleClose()}>
|
|
234
|
-
{translations.form.cancel}
|
|
235
|
-
</Button>
|
|
236
|
-
<Button color="primary" fullWidth onClick={handleConfirm}>
|
|
237
|
-
{translations.form.confirm}
|
|
238
|
-
</Button>
|
|
239
|
-
</DialogActions>
|
|
240
|
-
</Fragment>
|
|
241
|
-
);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
return (
|
|
245
|
-
<Dialog
|
|
246
|
-
open={dialog}
|
|
247
|
-
fullScreen={isMobile}
|
|
248
|
-
maxWidth={dialogMaxWidth}
|
|
249
|
-
onClose={() => {
|
|
250
|
-
triggerDialog(false);
|
|
251
|
-
}}
|
|
252
|
-
>
|
|
253
|
-
{renderEditor()}
|
|
254
|
-
</Dialog>
|
|
255
|
-
);
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
export default Editor;
|
package/src/lib/views/Month.tsx
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { useEffect, useCallback } from "react";
|
|
2
|
-
import { addDays, eachWeekOfInterval, endOfMonth, startOfMonth } from "date-fns";
|
|
3
|
-
import { DefaultResource } from "../types";
|
|
4
|
-
import { getResourcedEvents, sortEventsByTheEarliest } from "../helpers/generals";
|
|
5
|
-
import { WithResources } from "../components/common/WithResources";
|
|
6
|
-
import useStore from "../hooks/useStore";
|
|
7
|
-
import { MonthAgenda } from "./MonthAgenda";
|
|
8
|
-
import MonthTable from "../components/month/MonthTable";
|
|
9
|
-
|
|
10
|
-
const Month = () => {
|
|
11
|
-
const {
|
|
12
|
-
month,
|
|
13
|
-
selectedDate,
|
|
14
|
-
events,
|
|
15
|
-
getRemoteEvents,
|
|
16
|
-
triggerLoading,
|
|
17
|
-
handleState,
|
|
18
|
-
resources,
|
|
19
|
-
resourceFields,
|
|
20
|
-
fields,
|
|
21
|
-
agenda,
|
|
22
|
-
} = useStore();
|
|
23
|
-
|
|
24
|
-
const { weekStartOn, weekDays } = month!;
|
|
25
|
-
const monthStart = startOfMonth(selectedDate);
|
|
26
|
-
const monthEnd = endOfMonth(selectedDate);
|
|
27
|
-
const eachWeekStart = eachWeekOfInterval(
|
|
28
|
-
{
|
|
29
|
-
start: monthStart,
|
|
30
|
-
end: monthEnd,
|
|
31
|
-
},
|
|
32
|
-
{ weekStartsOn: weekStartOn }
|
|
33
|
-
);
|
|
34
|
-
const daysList = weekDays.map((d) => addDays(eachWeekStart[0], d));
|
|
35
|
-
|
|
36
|
-
const fetchEvents = useCallback(async () => {
|
|
37
|
-
try {
|
|
38
|
-
triggerLoading(true);
|
|
39
|
-
const start = eachWeekStart[0];
|
|
40
|
-
const end = addDays(eachWeekStart[eachWeekStart.length - 1], daysList.length);
|
|
41
|
-
const events = await getRemoteEvents!({
|
|
42
|
-
start,
|
|
43
|
-
end,
|
|
44
|
-
view: "month",
|
|
45
|
-
});
|
|
46
|
-
if (events && events?.length) {
|
|
47
|
-
handleState(events, "events");
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
throw error;
|
|
51
|
-
} finally {
|
|
52
|
-
triggerLoading(false);
|
|
53
|
-
}
|
|
54
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
|
-
}, [daysList.length, getRemoteEvents]);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (getRemoteEvents instanceof Function) {
|
|
59
|
-
fetchEvents();
|
|
60
|
-
}
|
|
61
|
-
}, [fetchEvents, getRemoteEvents]);
|
|
62
|
-
|
|
63
|
-
const renderTable = useCallback(
|
|
64
|
-
(resource?: DefaultResource) => {
|
|
65
|
-
if (agenda) {
|
|
66
|
-
let resourcedEvents = sortEventsByTheEarliest(events);
|
|
67
|
-
if (resource) {
|
|
68
|
-
resourcedEvents = getResourcedEvents(events, resource, resourceFields, fields);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return <MonthAgenda resource={resource} events={resourcedEvents} />;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return <MonthTable daysList={daysList} eachWeekStart={eachWeekStart} resource={resource} />;
|
|
75
|
-
},
|
|
76
|
-
[agenda, daysList, eachWeekStart, events, fields, resourceFields]
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
return resources.length ? <WithResources renderChildren={renderTable} /> : renderTable();
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export { Month };
|