react-weekly-planning 1.0.28 → 1.0.29

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/index.tsx CHANGED
@@ -1,50 +1,7 @@
1
1
  import "./style.css";
2
- import {
3
- AddTaskPropsType,
4
- CalendarPropsType,
5
- DayPropsType,
6
- GroupPropsType,
7
- StyleType,
8
- TaskContainerPropsType,
9
- GroupsHeadContainerPropsType,
10
- SumHoursContainerPropsType,
11
- SumHoursHeadContainerPropsType,
12
- TasksType,
13
- } from "./definitions";
14
- import {
15
- getWeekDays,
16
- getDayHourly,
17
- calculerEcartSemaine,
18
- getSessionStorageRecordForDragAndDrop,
19
- sumHoursByGroups,
20
- millisecondsToDate,
21
- compareWeekOffset,
22
- saveTasksToLocalStorage,
23
- } from "./lib/utils";
2
+ import { CalendarPropsType } from "./definitions";
3
+ import CalendarTable from "./components/CalendarTable";
24
4
 
25
- const theadTrStyle: StyleType = {
26
- color: "#0f5173",
27
- fontWeight: "300",
28
- position: "sticky",
29
- top: 0,
30
- };
31
-
32
- const groupTdStyle: StyleType = {
33
- height: "auto",
34
- width: "150px",
35
- };
36
-
37
- const groupContainerStyle: StyleType = {
38
- width: "100%",
39
- height: "100%",
40
- display: "flex",
41
- alignItems: "center",
42
- justifyContent: "space-between",
43
- gap: "0.75rem", // Correspond à gap-3
44
- padding: "0.75rem", // Correspond à p-3
45
- color: "#0f5173",
46
- cursor: "pointer",
47
- };
48
5
 
49
6
  /**
50
7
  * Calendar component to display tasks and groups in a weekly view.
@@ -91,533 +48,14 @@ const groupContainerStyle: StyleType = {
91
48
  * @param {Function} [props.handleClickTask] - Handler function for clicking a task.
92
49
  * @returns {JSX.Element} The rendered Calendar component.
93
50
  */
94
- const Calendar = ({
95
- style,
96
- className,
97
- groups,
98
- weekOffset,
99
- date,
100
- groupRender,
101
- dayRender,
102
- rowsStyle,
103
- groupsColsStyle,
104
- daysColsStyle,
105
- addTaskRender,
106
- handleAddTask,
107
- dayClassName,
108
- dayStyle,
109
- groupClassName,
110
- groupStyle,
111
- addTaskClassName,
112
- addTaskStyle,
113
- tasks,
114
- handleDragTask,
115
- handleDropTask,
116
- taskRender,
117
- groupsHeadRender,
118
- sumHoursRender,
119
- sumHoursHeadRender,
120
- handleDragTaskEnd,
121
- rowsClassName,
122
- daysColsClassName,
123
- sumHoursContainerClassName,
124
- sumHoursContainerStyle,
125
- groupHeadContainerClassName,
126
- groupHeadContainerStyle,
127
- groupsColsClassName,
128
- taskContainerClassName,
129
- taskContainerStyle,
130
- sumHoursHeadClassName,
131
- sumHoursHeadStyle,
132
- handleClickGroup,
133
- handleClickTask,
134
- }: CalendarPropsType) => {
135
- const weekOffsetByDate = calculerEcartSemaine(date);
136
- const weekDays = getWeekDays(weekOffsetByDate || weekOffset || 0);
137
- const dailyHours = getDayHourly(weekOffsetByDate || weekOffset || 0);
138
-
139
- const handleDragOver = (event: React.DragEvent<HTMLTableDataCellElement>) => {
140
- event.preventDefault();
141
- };
142
-
143
- saveTasksToLocalStorage(tasks);
144
- return (
145
- <table className={`planningCalendar ${className}`} style={{ ...style }}>
146
- <thead>
147
- <tr
148
- className={`${rowsClassName}`}
149
- style={{ ...theadTrStyle, ...rowsStyle }}
150
- key=""
151
- >
152
- <th className="dayTh">
153
- <GroupsHeadContainer
154
- className={`${groupHeadContainerClassName}`}
155
- style={groupHeadContainerStyle}
156
- groupsHeadRender={groupsHeadRender}
157
- />
158
- </th>
159
- {weekDays.map((day, i) => (
160
- <th
161
- key={i}
162
- className={`${daysColsClassName}`}
163
- style={{ ...daysColsStyle }}
164
- >
165
- <DayContainer
166
- style={dayStyle}
167
- className={dayClassName}
168
- dayIndex={i}
169
- dayRender={dayRender}
170
- day={day.day}
171
- dayOfTheMonth={day.dayOfTheMonth}
172
- dayMonth={day.dayMonth}
173
- dayYear={day.dayYear}
174
- />
175
- </th>
176
- ))}
177
- <th className="totalTh">
178
- <SumHoursHead
179
- className={sumHoursHeadClassName}
180
- style={sumHoursHeadStyle}
181
- sumHoursHeadRender={sumHoursHeadRender}
182
- />
183
- </th>
184
- </tr>
185
- </thead>
186
- <tbody>
187
- {groups?.map((group, i) => (
188
- <tr
189
- key={`${i} tr`}
190
- className={`${rowsClassName}`}
191
- style={{ ...rowsStyle }}
192
- >
193
- <td
194
- className={`${groupsColsClassName}`}
195
- key={i}
196
- style={{ ...groupTdStyle, ...groupsColsStyle }}
197
- >
198
- <GroupContainer
199
- style={groupStyle}
200
- className={groupClassName}
201
- groupRender={groupRender}
202
- currentGroup={group}
203
- handleClickGroup={handleClickGroup}
204
- />
205
- </td>
206
- {dailyHours.map((_, positionDay) => (
207
- <td
208
- key={`td-${group.id}day-i${positionDay}`}
209
- onDragOver={handleDragOver}
210
- onDrop={(event) => {
211
- if (!handleDropTask || !tasks) return;
212
- const dropInfo = getSessionStorageRecordForDragAndDrop(
213
- tasks,
214
- positionDay,
215
- group.id
216
- );
217
- if (!dropInfo) return;
218
- handleDropTask(
219
- event,
220
- dropInfo.taskDropStart,
221
- dropInfo.taskDropEnd,
222
- dropInfo.taskDropDate,
223
- group.id,
224
- positionDay,
225
- dropInfo.newTask,
226
- dropInfo.newTasks
227
- );
228
- }}
229
- id={`td-${group.id}day-i`}
230
- >
231
- <div
232
- key={positionDay}
233
- style={{
234
- display: "flex",
235
- width: "100%",
236
- height: "100%",
237
- flexDirection: "column",
238
- padding: "5px",
239
- }}
240
- >
241
- <>
242
- {tasks
243
- ?.filter(
244
- (task) =>
245
- task.dayIndex === positionDay &&
246
- task.groupId === group.id &&
247
- compareWeekOffset(
248
- date,
249
- weekOffset || 0,
250
- task.taskDate
251
- )
252
- )
253
- .sort((a, b) => a.taskStart - b.taskStart)
254
- .map((task, taskKey) => {
255
- return (
256
- <TaskContainer
257
- key={`${taskKey} task`}
258
- handleDragTask={handleDragTask}
259
- taskRender={taskRender}
260
- handleDragTaskEnd={handleDragTaskEnd}
261
- style={taskContainerStyle}
262
- className={`${taskContainerClassName}`}
263
- currentTask={task}
264
- handleClickTask={handleClickTask}
265
- />
266
- );
267
- })}
268
- </>
269
-
270
- <AddTask
271
- addTaskStyle={addTaskStyle}
272
- addTaskClassName={addTaskClassName}
273
- currentGroup={group}
274
- dayInfo={dailyHours[positionDay]}
275
- addTaskRender={addTaskRender}
276
- handleAddTask={handleAddTask}
277
- />
278
- </div>
279
- </td>
280
- ))}
281
- <td key={`${i}sumHours`}>
282
- <SumHoursContainer
283
- groupId={group.id}
284
- tasks={tasks}
285
- weekOffset={weekOffset || 0}
286
- calendarDate={date}
287
- sumHoursRender={sumHoursRender}
288
- sumHoursByGroups={sumHoursByGroups(
289
- group.id,
290
- tasks,
291
- weekOffset || 0,
292
- date
293
- )}
294
- className={sumHoursContainerClassName}
295
- style={sumHoursContainerStyle}
296
- />
297
- </td>
298
- </tr>
299
- ))}
300
- </tbody>
301
- </table>
302
- );
303
- };
304
-
305
- const SumHoursHead = ({
306
- sumHoursHeadRender,
307
- className,
308
- style,
309
- }: SumHoursHeadContainerPropsType) => {
310
- if (sumHoursHeadRender) {
311
- return <>{sumHoursHeadRender()}</>;
312
- }
313
- return (
314
- <div
315
- className={`${className}`}
316
- style={{ textAlign: "right", marginRight: "5px", ...style }}
317
- >
318
- Hours
319
- </div>
320
- );
321
- };
322
-
323
- const SumHoursContainer = ({
324
- groupId,
325
- tasks,
326
- weekOffset,
327
- calendarDate,
328
- sumHoursByGroups,
329
- sumHoursRender,
330
- className,
331
- style,
332
- }: SumHoursContainerPropsType) => {
333
- if (sumHoursRender) {
334
- return (
335
- <>
336
- {sumHoursRender({
337
- groupId,
338
- tasks,
339
- weekOffset,
340
- calendarDate,
341
- sumHoursByGroups,
342
- })}
343
- </>
344
- );
345
- }
346
-
347
- return (
348
- <div
349
- style={{ textAlign: "right", marginRight: "5px", ...style }}
350
- className={`${className}`}
351
- >
352
- {sumHoursByGroups}
353
- </div>
354
- );
355
- };
356
-
357
- const DayContainer = ({
358
- dayIndex,
359
- dayOfTheMonth,
360
- day,
361
- dayMonth,
362
- dayYear,
363
- dayRender,
364
- className,
365
- style,
366
- }: DayPropsType) => {
367
- if (dayRender) {
368
- return (
369
- <>
370
- {dayRender({
371
- dayIndex,
372
- day,
373
- dayOfTheMonth,
374
- dayMonth,
375
- dayYear,
376
- })}
377
- </>
378
- );
379
- }
380
51
 
381
- return (
382
- <div className={`${className}`} style={style}>
383
- {`${day}. ${dayOfTheMonth}`}
384
- </div>
385
- );
386
- };
387
-
388
- const GroupContainer = ({
389
- className,
390
- style,
391
- groupRender,
392
- currentGroup,
393
- handleClickGroup,
394
- }: GroupPropsType) => {
395
- if (groupRender) {
396
- return <>{groupRender({ currentGroup })}</>;
397
- }
52
+ const Calendar = (props: CalendarPropsType) => {
398
53
 
399
- const handleClick = () => {
400
- if (!handleClickGroup) return;
401
- handleClickGroup(currentGroup);
402
- };
403
54
  return (
404
- <div
405
- onClick={handleClick}
406
- className={`${className}`}
407
- style={{ ...groupContainerStyle, ...style }}
408
- >
409
- {currentGroup.imageUrl && (
410
- <img
411
- width={30}
412
- height={30}
413
- src={currentGroup.imageUrl}
414
- alt="groupimg"
415
- />
416
- )}
417
- <label>{currentGroup.label && currentGroup.label}</label>
418
- </div>
55
+ <CalendarTable
56
+ {...props}
57
+ />
419
58
  );
420
59
  };
421
60
 
422
- const AddTask = ({
423
- currentGroup,
424
- handleAddTask,
425
- addTaskRender,
426
- dayInfo,
427
- addTaskStyle,
428
- addTaskClassName,
429
- }: AddTaskPropsType) => {
430
- if (addTaskRender) {
431
- return (
432
- <>
433
- {addTaskRender({
434
- currentGroup,
435
- dayInfo,
436
- })}
437
- </>
438
- );
439
- }
440
-
441
- const handleClick = () => {
442
- if (!handleAddTask) return;
443
- handleAddTask(currentGroup, dayInfo);
444
- };
445
-
446
- return (
447
- <div
448
- onClick={handleClick}
449
- style={addTaskStyle}
450
- className={`addPlanStyle ${addTaskClassName}`}
451
- >
452
- +
453
- </div>
454
- );
455
- };
456
-
457
- const TaskContainer = ({
458
- handleDragTask,
459
- taskRender,
460
- handleDragTaskEnd,
461
- style,
462
- className,
463
- currentTask,
464
- handleClickTask,
465
- }: TaskContainerPropsType) => {
466
- const handleDragStart = (event: React.DragEvent<HTMLDivElement>) => {
467
- if (!handleDragTask) return;
468
- event.dataTransfer.effectAllowed = "move";
469
- event.dataTransfer.setData("text/plain", currentTask.taskId);
470
- window.sessionStorage.setItem("calendardragtaskId", currentTask.taskId);
471
- window.sessionStorage.setItem(
472
- "calendardragtaskStart",
473
- `${currentTask.taskStart}`
474
- );
475
- window.sessionStorage.setItem(
476
- "calendardragtaskEnd",
477
- `${currentTask.taskEnd}`
478
- );
479
- window.sessionStorage.setItem(
480
- "calendardragdayIndex",
481
- `${currentTask.dayIndex}`
482
- );
483
- handleDragTask(event, currentTask);
484
- };
485
- const handleDragEnd = (event: React.DragEvent<HTMLDivElement>) => {
486
- if (!handleDragTaskEnd) return;
487
- handleDragTaskEnd(event);
488
- };
489
- const handleClick = () => {
490
- if (!handleClickTask) return;
491
- handleClickTask(currentTask);
492
- };
493
- if (taskRender) {
494
- return (
495
- <div
496
- onClick={handleClick}
497
- id={currentTask.taskId}
498
- className={`taskContainer ${className}`}
499
- style={{ ...style }}
500
- draggable
501
- onDragStart={handleDragStart}
502
- onDragEnd={handleDragEnd}
503
- >
504
- {taskRender({
505
- currentTask,
506
- })}
507
- </div>
508
- );
509
- }
510
-
511
- return (
512
- <div
513
- onClick={handleClick}
514
- id={currentTask.taskId}
515
- className={`taskContainer ${className}`}
516
- style={{ ...style }}
517
- draggable
518
- onDragStart={handleDragStart}
519
- onDragEnd={handleDragEnd}
520
- >
521
- <p className="tasklabel">{currentTask.task && currentTask.task}</p>
522
- <p className="taskhour">
523
- {currentTask.taskStart &&
524
- currentTask.taskEnd &&
525
- `${millisecondsToDate(currentTask.taskStart).formattedDate} - ${
526
- millisecondsToDate(currentTask.taskEnd).formattedDate
527
- }`}
528
- </p>
529
- </div>
530
- );
531
- };
532
-
533
- const GroupsHeadContainer = ({
534
- groupsHeadRender,
535
- style,
536
- className,
537
- }: GroupsHeadContainerPropsType) => {
538
- if (groupsHeadRender) {
539
- return <>{groupsHeadRender()}</>;
540
- }
541
- return (
542
- <div className={`${className}`} style={style}>
543
- WeeklyCalendar
544
- </div>
545
- );
546
- };
547
-
548
- export const updateCalendarDateWithOffset = (
549
- offset: number,
550
- calendarDate: Date
551
- ) => {
552
- const newDate = new Date(calendarDate);
553
- newDate.setDate(newDate.getDate() + offset);
554
- return newDate;
555
- };
556
-
557
- export const updateOffsetWithDateCalendar = (calendarDate: Date) => {
558
- return calculerEcartSemaine(calendarDate);
559
- };
560
-
561
- export const millisecondsToHours = (milliseconds: number) => {
562
- return millisecondsToDate(milliseconds).formattedDate;
563
- };
564
-
565
- export const checkDuplicates = (
566
- tasks: TasksType,
567
- taskStart: number,
568
- taskEnd: number,
569
- groupId: string
570
- ) => {
571
- const findDuplicates = tasks
572
- ?.filter(
573
- (task) =>
574
- (taskStart >= task.taskStart && taskStart < task.taskEnd) ||
575
- (taskEnd > task.taskStart && taskEnd < task.taskEnd) ||
576
- (taskStart <= task.taskStart &&
577
- taskEnd > task.taskStart &&
578
- taskEnd >= task.taskEnd &&
579
- taskStart <= task.taskEnd)
580
- )
581
- .filter((task) => task.groupId === groupId);
582
- return findDuplicates.length > 0;
583
- };
584
-
585
- export const getSavedTasks = () => {
586
- const taskSavedString = window.localStorage.getItem("CalendarTaskSaved");
587
- if (!taskSavedString) {
588
- return [];
589
- }
590
- const tasksTable: TasksType = JSON.parse(taskSavedString);
591
-
592
- const savedTasks: TasksType | any = tasksTable.map((task) => {
593
- const { taskDate, taskExpiryDate, ...rest } = task;
594
- if (taskExpiryDate) {
595
- return {
596
- taskDate: new Date(taskDate),
597
- taskExpiryDate: new Date(taskExpiryDate),
598
- ...rest,
599
- };
600
- }
601
- });
602
- return savedTasks;
603
- };
604
-
605
- export const deleteTaskSaved = (taskId: string) => {
606
- const tasksSavedString = window.localStorage.getItem("CalendarTaskSaved");
607
- if (!tasksSavedString) return;
608
- const tasksSavedTable: TasksType = JSON.parse(tasksSavedString);
609
- const taskIndex = tasksSavedTable.findIndex((task) => task.taskId === taskId);
610
- if (taskIndex) {
611
- tasksSavedTable.splice(taskIndex, 1);
612
- window.localStorage.setItem(
613
- "CalendarTaskSaved",
614
- JSON.stringify(tasksSavedTable)
615
- );
616
- }
617
- };
618
-
619
- export const deleteTasksSaved = () => {
620
- window.localStorage.removeItem("CalendarTaskSaved");
621
- };
622
-
623
61
  export default Calendar;
package/lib/slyles.js ADDED
@@ -0,0 +1,21 @@
1
+ export const theadTrStyle = {
2
+ color: "#0f5173",
3
+ fontWeight: "300",
4
+ position: "sticky",
5
+ top: 0,
6
+ };
7
+ export const groupTdStyle = {
8
+ height: "auto",
9
+ width: "150px",
10
+ };
11
+ export const groupContainerStyle = {
12
+ width: "100%",
13
+ height: "100%",
14
+ display: "flex",
15
+ alignItems: "center",
16
+ justifyContent: "space-between",
17
+ gap: "0.75rem", // Correspond à gap-3
18
+ padding: "0.75rem", // Correspond à p-3
19
+ color: "#0f5173",
20
+ cursor: "pointer",
21
+ };
package/lib/slyles.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { StyleType } from "../definitions";
2
+
3
+ export const theadTrStyle: StyleType = {
4
+ color: "#0f5173",
5
+ fontWeight: "300",
6
+ position: "sticky",
7
+ top: 0,
8
+ };
9
+
10
+ export const groupTdStyle: StyleType = {
11
+ height: "auto",
12
+ width: "150px",
13
+ };
14
+
15
+ export const groupContainerStyle: StyleType = {
16
+ width: "100%",
17
+ height: "100%",
18
+ display: "flex",
19
+ alignItems: "center",
20
+ justifyContent: "space-between",
21
+ gap: "0.75rem", // Correspond à gap-3
22
+ padding: "0.75rem", // Correspond à p-3
23
+ color: "#0f5173",
24
+ cursor: "pointer",
25
+ };