react-weekly-planning 1.0.14 → 1.0.16

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/README.md CHANGED
@@ -83,7 +83,7 @@ Props for the Calendar component.
83
83
  | `date` | Date | The current date to display in the calendar. |
84
84
  | `groupRender` | ({ currentGroup }: { currentGroup: GroupFeildsType }) => React.ReactNode | Custom render function for a group. |
85
85
  | `dayRender` | ({ dayIndex, day, dayOfTheMonth, dayMonth, dayYear }: { dayIndex: number; day: string; dayOfTheMonth: number; dayMonth: string; dayYear: number; }) => React.ReactNode | Custom render function for a day. |
86
- | `taskRender` | ({ currentTask, handleDragTask }: { currentTask: TaskFeildsType; handleDragTask?: (event: React.DragEvent<HTMLDivElement>, currentTask: TaskFeildsType) => void; }) => React.ReactNode | Custom render function for a task. |
86
+ | `taskRender` | ({ currentTask, handleDragTask }: { currentTask: TaskFeildsType}) => React.ReactNode | Custom render function for a task. |
87
87
  | `rowsStyle` | React.CSSProperties \| undefined | Additional styles for the rows. |
88
88
  | `rowsClassName` | string | Additional class names for the rows. |
89
89
  | `groupsColsStyle` | React.CSSProperties \| undefined | Additional styles for the group columns. |
@@ -161,6 +161,15 @@ Props for the Calendar component.
161
161
  const formattedTime = millisecondsToHours(1716905215397);
162
162
  console.log(formattedTime); // Logs the formatted time for 14h06
163
163
  ```
164
+ ### `checkDuplicates`
165
+
166
+ - **Description**: Checks if a new task overlaps with any existing tasks in the schedule. This function helps prevent overlapping tasks when scheduling.
167
+ - **Parameters**:
168
+ - `tasks` (TasksType): An array of existing tasks. Each task should have `taskStart` and `taskEnd` properties representing the start and end times of the task.
169
+ - `taskStart` (number): The start time in milliseconds of the new task to be checked.
170
+ - `taskEnd` (number): The end time in milliseconds of the new task to be checked.
171
+ - **Returns**: `boolean` - Returns `true` if there is an overlap with any existing task, otherwise returns `false`.
172
+
164
173
 
165
174
  ---
166
175
 
@@ -152,13 +152,8 @@ export type CalendarPropsType = {
152
152
  /** Custom render function for a task. */
153
153
  taskRender?: ({
154
154
  currentTask,
155
- handleDragTask,
156
155
  }: {
157
156
  currentTask: TaskFeildsType;
158
- handleDragTask?: (
159
- event: React.DragEvent<HTMLDivElement>,
160
- currentTask: TaskFeildsType
161
- ) => void;
162
157
  }) => React.ReactNode;
163
158
  /** Additional styles for the rows. */
164
159
  rowsStyle?: React.CSSProperties | undefined;
@@ -333,13 +328,8 @@ export type TaskContainerPropsType = {
333
328
  /** Custom render function for a task. */
334
329
  taskRender?: ({
335
330
  currentTask,
336
- handleDragTask,
337
331
  }: {
338
332
  currentTask: TaskFeildsType;
339
- handleDragTask?: (
340
- event: React.DragEvent<HTMLDivElement>,
341
- currentTask: TaskFeildsType
342
- ) => void;
343
333
  }) => React.ReactNode;
344
334
  /** Handler function for ending the drag of a task. */
345
335
  handleDragTaskEnd?: (event: React.DragEvent<HTMLDivElement>) => void;
package/index.js CHANGED
@@ -221,4 +221,13 @@ export const updateOffsetWithDateCalendar = (calendarDate) => {
221
221
  export const millisecondsToHours = (milliseconds) => {
222
222
  return millisecondsToDate(milliseconds).formattedDate;
223
223
  };
224
+ export const checkDuplicates = (tasks, taskStart, taskEnd) => {
225
+ const findDuplicates = tasks === null || tasks === void 0 ? void 0 : tasks.filter((task) => (taskStart >= task.taskStart && taskStart < task.taskEnd) ||
226
+ (taskEnd > task.taskStart && taskEnd < task.taskEnd) ||
227
+ (taskStart <= task.taskStart &&
228
+ taskEnd > task.taskStart &&
229
+ taskEnd >= task.taskEnd &&
230
+ taskStart <= task.taskEnd));
231
+ return findDuplicates.length > 0;
232
+ };
224
233
  export default Calendar;
package/index.tsx CHANGED
@@ -9,6 +9,9 @@ import {
9
9
  GroupsHeadContainerPropsType,
10
10
  SumHoursContainerPropsType,
11
11
  SumHoursHeadContainerPropsType,
12
+ TaskType,
13
+ TaskFeildsType,
14
+ TasksType,
12
15
  } from "./definitions";
13
16
  import {
14
17
  getWeekDays,
@@ -588,4 +591,20 @@ export const millisecondsToHours = (milliseconds: number) => {
588
591
  return millisecondsToDate(milliseconds).formattedDate;
589
592
  };
590
593
 
594
+ export const checkDuplicates = (
595
+ tasks: TasksType,
596
+ taskStart: number,
597
+ taskEnd: number
598
+ ) => {
599
+ const findDuplicates = tasks?.filter(
600
+ (task) =>
601
+ (taskStart >= task.taskStart && taskStart < task.taskEnd) ||
602
+ (taskEnd > task.taskStart && taskEnd < task.taskEnd) ||
603
+ (taskStart <= task.taskStart &&
604
+ taskEnd > task.taskStart &&
605
+ taskEnd >= task.taskEnd &&
606
+ taskStart <= task.taskEnd)
607
+ );
608
+ return findDuplicates.length > 0;
609
+ };
591
610
  export default Calendar;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-weekly-planning",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest",