react-weekly-planning 1.0.30 → 1.0.32
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 +90 -0
- package/__tests__/page.test.js +92 -92
- package/components/AddTask/index.js +17 -17
- package/components/CalendarForWeek.js +49 -50
- package/components/CalendarForWeek.tsx +7 -3
- package/components/CalendarForday.js +33 -34
- package/components/CalendarForday.tsx +3 -2
- package/components/DayContainer/index.js +15 -15
- package/components/GroupContainer/index.js +15 -15
- package/components/GroupsHeadContainer/index.js +9 -9
- package/components/SumHoursContainer/index.js +16 -15
- package/components/SumHoursContainer/index.tsx +2 -1
- package/components/SumHoursHead/index.js +9 -9
- package/components/TaskContainer/index.js +35 -35
- package/components/TaskList/index.js +4 -5
- package/components/TaskList/index.tsx +6 -13
- package/contexts/CalendarContext.js +12 -12
- package/definitions/index.js +1 -1
- package/definitions/index.ts +1 -0
- package/hooks/useCalendarDateState.js +19 -19
- package/hooks/useCalendarDateState.ts +5 -4
- package/index.js +70 -70
- package/index.tsx +1 -1
- package/jest.config.js +9 -9
- package/lib/slyles.js +21 -21
- package/lib/utils.js +636 -605
- package/lib/utils.ts +107 -64
- package/package.json +28 -31
package/README.md
CHANGED
|
@@ -55,6 +55,39 @@ It is possible to use either Weekoffset or Date, or even both simultaneously.
|
|
|
55
55
|
<Calendar date={currentDate} ... />
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
#### `timeZone`
|
|
59
|
+
|
|
60
|
+
- **Description**: This prop sets the timezone to be used by the calendar for all date and time calculations.
|
|
61
|
+
- **Type**: `TimeZone` (e.g., `"America/New_York"`, `"Europe/Paris"`, etc.)
|
|
62
|
+
- **Use Case**: Use this prop to align the calendar's display and event calculations to a specific global timezone instead of relying on the user's local browser timezone. This ensures consistency across different geographical locations.
|
|
63
|
+
|
|
64
|
+
**Example**:
|
|
65
|
+
```jsx
|
|
66
|
+
<Calendar timeZone="Europe/Paris" ... />
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### `scope`
|
|
70
|
+
|
|
71
|
+
- **Description**: This prop sets the view scope of the calendar.
|
|
72
|
+
- **Type**: `"day" | "week"`
|
|
73
|
+
- **Use Case**: Use this prop to define whether the calendar should display a full week or only a single day. If omitted, it defaults to a weekly view.
|
|
74
|
+
|
|
75
|
+
**Example**:
|
|
76
|
+
```jsx
|
|
77
|
+
<Calendar scope="day" dayOffset={0} ... />
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### `dayOffset`
|
|
81
|
+
|
|
82
|
+
- **Description**: This prop specifies which day of the week to display when the scope is set to "day".
|
|
83
|
+
- **Type**: `0 | 1 | 2 | 3 | 4 | 5 | 6`
|
|
84
|
+
- **Use Case**: If `scope="day"`, use this prop to target a specific day of the week (`0` being the first day of the week, up to `6`).
|
|
85
|
+
|
|
86
|
+
**Example**:
|
|
87
|
+
```jsx
|
|
88
|
+
<Calendar scope="day" dayOffset={2} ... />
|
|
89
|
+
```
|
|
90
|
+
|
|
58
91
|
#### `tasks`
|
|
59
92
|
|
|
60
93
|
- **Description**: This prop is an array of tasks to be displayed in the calendar.
|
|
@@ -94,7 +127,61 @@ It is possible to use either Weekoffset or Date, or even both simultaneously.
|
|
|
94
127
|
|
|
95
128
|
<Calendar tasks={tasks} ... />
|
|
96
129
|
```
|
|
130
|
+
|
|
97
131
|
---
|
|
132
|
+
|
|
133
|
+
## Full Example for Beginners
|
|
134
|
+
|
|
135
|
+
Here is a complete, minimal example showing how to set up the `Calendar` with simple groups and tasks.
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
import React, { useState } from "react";
|
|
139
|
+
import Calendar from "react-pweekly-planning"; // Verify your exact import path based on package.json
|
|
140
|
+
import "react-pweekly-planning/dist/style.css"; // Ensure CSS is imported depending on your setup
|
|
141
|
+
|
|
142
|
+
const App = () => {
|
|
143
|
+
const [date] = useState(new Date());
|
|
144
|
+
|
|
145
|
+
// Define groups (e.g., resources, team members, or projects)
|
|
146
|
+
const groups = [
|
|
147
|
+
{ id: "1", label: "Developer A" },
|
|
148
|
+
{ id: "2", label: "Developer B" }
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
// Create start and end times in milliseconds
|
|
152
|
+
const todayAt10 = new Date().setHours(10, 0, 0, 0);
|
|
153
|
+
const todayAt12 = new Date().setHours(12, 0, 0, 0);
|
|
154
|
+
|
|
155
|
+
// Define your tasks
|
|
156
|
+
const tasks = [
|
|
157
|
+
{
|
|
158
|
+
taskId: "t1",
|
|
159
|
+
groupId: "1", // Belongs to "Developer A"
|
|
160
|
+
taskStart: todayAt10,
|
|
161
|
+
taskEnd: todayAt12,
|
|
162
|
+
taskDate: new Date(),
|
|
163
|
+
dayIndex: new Date().getDay(), // Matches the task's day of week
|
|
164
|
+
taskSummary: "Code Review"
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div style={{ padding: "20px" }}>
|
|
170
|
+
<h1>My Weekly Planner</h1>
|
|
171
|
+
<Calendar
|
|
172
|
+
date={date}
|
|
173
|
+
weekOffset={0}
|
|
174
|
+
groups={groups}
|
|
175
|
+
tasks={tasks}
|
|
176
|
+
scope="week" // Change to "day" for daily view
|
|
177
|
+
/>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export default App;
|
|
183
|
+
```
|
|
184
|
+
|
|
98
185
|
---
|
|
99
186
|
|
|
100
187
|
## `CalendarPropsType`
|
|
@@ -105,10 +192,13 @@ Props for the Calendar component.
|
|
|
105
192
|
| Prop Name | Type | Description |
|
|
106
193
|
|------------------------------|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
|
|
107
194
|
| `weekOffset` | number | Offset for the week (e.g., -7 for last week, 0 for current week, 7 for next week). |
|
|
195
|
+
| `scope` | "day" \| "week" | Sets the calendar view to either a full week or a single day. |
|
|
196
|
+
| `dayOffset` | 0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6 | Offset index for the day column (0 = first day of week, …, 6 = last day) when scope is "day". |
|
|
108
197
|
| `groups` | GroupFeildsType[] | Array of group data to be displayed in the calendar. |
|
|
109
198
|
| `className` | string | Additional class names for the calendar component. |
|
|
110
199
|
| `style` | React.CSSProperties \| undefined | Additional styles for the calendar component. |
|
|
111
200
|
| `date` | Date | The current date to display in the calendar. |
|
|
201
|
+
| `timeZone` | TimeZone | The timezone to use for displaying and manipulating the calendar dates. |
|
|
112
202
|
| `groupRender` | ({ currentGroup }: { currentGroup: GroupFeildsType }) => React.ReactNode | Custom render function for a group. |
|
|
113
203
|
| `dayRender` | ({ dayIndex, day, dayOfTheMonth, dayMonth, dayYear }: { dayIndex: number; day: string; dayOfTheMonth: number; dayMonth: string; dayYear: number; }) => React.ReactNode | Custom render function for a day. |
|
|
114
204
|
| `taskRender` | ({ currentTask, handleDragTask }: { currentTask: TaskFeildsType}) => React.ReactNode | Custom render function for a task. |
|
package/__tests__/page.test.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import "@testing-library/jest-dom";
|
|
11
|
-
import ical from "ical";
|
|
12
|
-
export function parseICSToTasks(icsData, group) {
|
|
13
|
-
var _a;
|
|
14
|
-
const events = ical.parseICS(icsData);
|
|
15
|
-
const tasks = [];
|
|
16
|
-
for (const key in events) {
|
|
17
|
-
const event = events[key];
|
|
18
|
-
if (event.type === "VEVENT") {
|
|
19
|
-
const taskStart = event.start
|
|
20
|
-
? new Date(event.start).getTime()
|
|
21
|
-
: new Date().getTime();
|
|
22
|
-
const taskEnd = event.end
|
|
23
|
-
? new Date(event.end).getTime()
|
|
24
|
-
: new Date().getTime();
|
|
25
|
-
const taskDate = event.start ? new Date(event.start) : new Date();
|
|
26
|
-
const taskSummary = event.summary || "";
|
|
27
|
-
const taskLocation = event.location || "";
|
|
28
|
-
const taskTimezone = "";
|
|
29
|
-
const taskCreatedAt = event.created
|
|
30
|
-
? new Date(event.created)
|
|
31
|
-
: new Date();
|
|
32
|
-
const taskExpiryDate = ((_a = event.rrule) === null || _a === void 0 ? void 0 : _a.options.until)
|
|
33
|
-
? new Date(event.rrule.options.until)
|
|
34
|
-
: new Date();
|
|
35
|
-
const task = {
|
|
36
|
-
taskStart,
|
|
37
|
-
taskEnd,
|
|
38
|
-
taskDate,
|
|
39
|
-
taskSummary,
|
|
40
|
-
taskLocation,
|
|
41
|
-
taskTimzone: taskTimezone,
|
|
42
|
-
groupId: group,
|
|
43
|
-
dayIndex: taskDate.getDay() || 0,
|
|
44
|
-
taskId: event.uid || "",
|
|
45
|
-
taskCreatedAt,
|
|
46
|
-
taskExpiryDate,
|
|
47
|
-
};
|
|
48
|
-
tasks.push(task);
|
|
49
|
-
if (!event.start)
|
|
50
|
-
return [];
|
|
51
|
-
// Gestion des occurrences récurrentes
|
|
52
|
-
if (event.rrule) {
|
|
53
|
-
const occurrences = event.rrule.between(event.start, taskExpiryDate || new Date());
|
|
54
|
-
occurrences.forEach((occurrence) => {
|
|
55
|
-
tasks.push(Object.assign(Object.assign({}, task), { taskStart: occurrence.getTime(), taskEnd: occurrence.getTime() + (taskEnd - taskStart), taskDate: new Date(occurrence.getTime()), dayIndex: new Date(occurrence.getTime()).getDay() }));
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return tasks;
|
|
61
|
-
}
|
|
62
|
-
import axios from "axios";
|
|
63
|
-
// Get ICS text however you like, example below
|
|
64
|
-
// Make sure you have the right CORS settings if needed
|
|
65
|
-
const convert = (fileLocation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
try {
|
|
67
|
-
const task = fileLocation.map((link) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
const icsRes = yield axios.get(link);
|
|
69
|
-
const icstext = yield icsRes.data;
|
|
70
|
-
const data = parseICSToTasks(icstext, "morel");
|
|
71
|
-
return data;
|
|
72
|
-
}));
|
|
73
|
-
console.log(task);
|
|
74
|
-
return "success";
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
return "error";
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
export function convertTasksToIcsFormat(tasks) {
|
|
81
|
-
const ics = tasks.reduce((previousIcs, task) => {
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import "@testing-library/jest-dom";
|
|
11
|
+
import ical from "ical";
|
|
12
|
+
export function parseICSToTasks(icsData, group) {
|
|
13
|
+
var _a;
|
|
14
|
+
const events = ical.parseICS(icsData);
|
|
15
|
+
const tasks = [];
|
|
16
|
+
for (const key in events) {
|
|
17
|
+
const event = events[key];
|
|
18
|
+
if (event.type === "VEVENT") {
|
|
19
|
+
const taskStart = event.start
|
|
20
|
+
? new Date(event.start).getTime()
|
|
21
|
+
: new Date().getTime();
|
|
22
|
+
const taskEnd = event.end
|
|
23
|
+
? new Date(event.end).getTime()
|
|
24
|
+
: new Date().getTime();
|
|
25
|
+
const taskDate = event.start ? new Date(event.start) : new Date();
|
|
26
|
+
const taskSummary = event.summary || "";
|
|
27
|
+
const taskLocation = event.location || "";
|
|
28
|
+
const taskTimezone = "";
|
|
29
|
+
const taskCreatedAt = event.created
|
|
30
|
+
? new Date(event.created)
|
|
31
|
+
: new Date();
|
|
32
|
+
const taskExpiryDate = ((_a = event.rrule) === null || _a === void 0 ? void 0 : _a.options.until)
|
|
33
|
+
? new Date(event.rrule.options.until)
|
|
34
|
+
: new Date();
|
|
35
|
+
const task = {
|
|
36
|
+
taskStart,
|
|
37
|
+
taskEnd,
|
|
38
|
+
taskDate,
|
|
39
|
+
taskSummary,
|
|
40
|
+
taskLocation,
|
|
41
|
+
taskTimzone: taskTimezone,
|
|
42
|
+
groupId: group,
|
|
43
|
+
dayIndex: taskDate.getDay() || 0,
|
|
44
|
+
taskId: event.uid || "",
|
|
45
|
+
taskCreatedAt,
|
|
46
|
+
taskExpiryDate,
|
|
47
|
+
};
|
|
48
|
+
tasks.push(task);
|
|
49
|
+
if (!event.start)
|
|
50
|
+
return [];
|
|
51
|
+
// Gestion des occurrences récurrentes
|
|
52
|
+
if (event.rrule) {
|
|
53
|
+
const occurrences = event.rrule.between(event.start, taskExpiryDate || new Date());
|
|
54
|
+
occurrences.forEach((occurrence) => {
|
|
55
|
+
tasks.push(Object.assign(Object.assign({}, task), { taskStart: occurrence.getTime(), taskEnd: occurrence.getTime() + (taskEnd - taskStart), taskDate: new Date(occurrence.getTime()), dayIndex: new Date(occurrence.getTime()).getDay() }));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return tasks;
|
|
61
|
+
}
|
|
62
|
+
import axios from "axios";
|
|
63
|
+
// Get ICS text however you like, example below
|
|
64
|
+
// Make sure you have the right CORS settings if needed
|
|
65
|
+
const convert = (fileLocation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
try {
|
|
67
|
+
const task = fileLocation.map((link) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const icsRes = yield axios.get(link);
|
|
69
|
+
const icstext = yield icsRes.data;
|
|
70
|
+
const data = parseICSToTasks(icstext, "morel");
|
|
71
|
+
return data;
|
|
72
|
+
}));
|
|
73
|
+
console.log(task);
|
|
74
|
+
return "success";
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return "error";
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
export function convertTasksToIcsFormat(tasks) {
|
|
81
|
+
const ics = tasks.reduce((previousIcs, task) => {
|
|
82
82
|
previousIcs += `
|
|
83
83
|
|
|
84
84
|
BEGIN:VCALENDAR
|
|
@@ -93,14 +93,14 @@ export function convertTasksToIcsFormat(tasks) {
|
|
|
93
93
|
END:VEVENT
|
|
94
94
|
END:VCALENDAR
|
|
95
95
|
|
|
96
|
-
`;
|
|
97
|
-
return previousIcs;
|
|
98
|
-
}, "");
|
|
99
|
-
return ics;
|
|
100
|
-
}
|
|
101
|
-
test("the fetch fails with an error", () => {
|
|
102
|
-
return convert([
|
|
103
|
-
"https://firebasestorage.googleapis.com/v0/b/ashtonv2.appspot.com/o/example.ics?alt=media&token=679cab97-cde2-4074-b96f-b63c10f1b7e2",
|
|
104
|
-
"https://firebasestorage.googleapis.com/v0/b/ashtonv2.appspot.com/o/example.ics?alt=media&token=679cab97-cde2-4074-b96f-b63c10f1b7e2",
|
|
105
|
-
]).catch((error) => expect(error).toMatch("error"));
|
|
106
|
-
});
|
|
96
|
+
`;
|
|
97
|
+
return previousIcs;
|
|
98
|
+
}, "");
|
|
99
|
+
return ics;
|
|
100
|
+
}
|
|
101
|
+
test("the fetch fails with an error", () => {
|
|
102
|
+
return convert([
|
|
103
|
+
"https://firebasestorage.googleapis.com/v0/b/ashtonv2.appspot.com/o/example.ics?alt=media&token=679cab97-cde2-4074-b96f-b63c10f1b7e2",
|
|
104
|
+
"https://firebasestorage.googleapis.com/v0/b/ashtonv2.appspot.com/o/example.ics?alt=media&token=679cab97-cde2-4074-b96f-b63c10f1b7e2",
|
|
105
|
+
]).catch((error) => expect(error).toMatch("error"));
|
|
106
|
+
});
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from "react";
|
|
3
|
-
const AddTask = ({ currentGroup, handleAddTask, addTaskRender, dayInfo, addTaskStyle, addTaskClassName, }) => {
|
|
4
|
-
if (addTaskRender) {
|
|
5
|
-
return (_jsx(_Fragment, { children: addTaskRender({
|
|
6
|
-
currentGroup,
|
|
7
|
-
dayInfo,
|
|
8
|
-
}) }));
|
|
9
|
-
}
|
|
10
|
-
const handleClick = () => {
|
|
11
|
-
if (!handleAddTask)
|
|
12
|
-
return;
|
|
13
|
-
handleAddTask(currentGroup, dayInfo);
|
|
14
|
-
};
|
|
15
|
-
return (_jsx("div", { onClick: handleClick, style: addTaskStyle, className: `addPlanStyle ${addTaskClassName}`, children: "+" }));
|
|
16
|
-
};
|
|
17
|
-
export default memo(AddTask);
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
const AddTask = ({ currentGroup, handleAddTask, addTaskRender, dayInfo, addTaskStyle, addTaskClassName, }) => {
|
|
4
|
+
if (addTaskRender) {
|
|
5
|
+
return (_jsx(_Fragment, { children: addTaskRender({
|
|
6
|
+
currentGroup,
|
|
7
|
+
dayInfo,
|
|
8
|
+
}) }));
|
|
9
|
+
}
|
|
10
|
+
const handleClick = () => {
|
|
11
|
+
if (!handleAddTask)
|
|
12
|
+
return;
|
|
13
|
+
handleAddTask(currentGroup, dayInfo);
|
|
14
|
+
};
|
|
15
|
+
return (_jsx("div", { onClick: handleClick, style: addTaskStyle, className: `addPlanStyle ${addTaskClassName}`, children: "+" }));
|
|
16
|
+
};
|
|
17
|
+
export default memo(AddTask);
|
|
@@ -1,50 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, [props.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
prevProps.
|
|
49
|
-
prevProps.
|
|
50
|
-
prevProps.weekOffset === nextProps.weekOffset);
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import GroupContainer from "./GroupContainer";
|
|
3
|
+
import GroupsHeadContainer from "./GroupsHeadContainer";
|
|
4
|
+
import { groupTdStyle, theadTrStyle } from "../lib/slyles";
|
|
5
|
+
import DayContainer from "./DayContainer";
|
|
6
|
+
import SumHoursHead from "./SumHoursHead";
|
|
7
|
+
import { compareWeekOffset, getSessionStorageRecordForDragAndDrop, saveTasksToLocalStorage, sumHoursByGroups, } from "../lib/utils";
|
|
8
|
+
import TaskContainer from "./TaskContainer";
|
|
9
|
+
import AddTask from "./AddTask";
|
|
10
|
+
import SumHoursContainer from "./SumHoursContainer";
|
|
11
|
+
import { memo, useEffect } from "react";
|
|
12
|
+
import useCalendarDateState from "../hooks/useCalendarDateState";
|
|
13
|
+
function CalendarForWeek(props) {
|
|
14
|
+
var _a;
|
|
15
|
+
const { dailyHours, weekDays } = useCalendarDateState(props.date, props.weekOffset, props.timeZone);
|
|
16
|
+
const handleDragOver = (event) => {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
};
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
saveTasksToLocalStorage(props.tasks);
|
|
21
|
+
}, [props.tasks]);
|
|
22
|
+
return (_jsxs("table", { className: `planningCalendar ${props.className}`, style: Object.assign({}, props.style), children: [_jsx("thead", { children: _jsxs("tr", { className: `${props.rowsClassName}`, style: Object.assign(Object.assign({}, theadTrStyle), props.rowsStyle), children: [_jsx("th", { className: `dayTh ${props.groupsColsClassName}`, style: Object.assign({}, props.groupsColsStyle), children: _jsx(GroupsHeadContainer, { className: `${props.groupHeadContainerClassName}`, style: props.groupHeadContainerStyle, groupsHeadRender: props.groupsHeadRender }) }), weekDays.map((day, i) => (_jsx("th", { className: `${props.daysColsClassName}`, style: Object.assign({}, props.daysColsStyle), children: _jsx(DayContainer, { style: props.dayStyle, className: props.dayClassName, dayIndex: i, dayRender: props.dayRender, day: day.day, dayOfTheMonth: day.dayOfTheMonth, dayMonth: day.dayMonth, dayYear: day.dayYear }) }, i))), _jsx("th", { className: `totalTh ${props.hoursColsClassName}`, style: props.hoursColsStyle, children: _jsx(SumHoursHead, { className: props.sumHoursHeadClassName, style: props.sumHoursHeadStyle, sumHoursHeadRender: props.sumHoursHeadRender }) })] }, "") }), _jsx("tbody", { children: (_a = props.groups) === null || _a === void 0 ? void 0 : _a.map((group, i) => (_jsxs("tr", { className: `${props.rowsClassName}`, style: Object.assign({}, props.rowsStyle), children: [_jsx("td", { className: `${props.groupsColsClassName}`, style: Object.assign(Object.assign({}, groupTdStyle), props.groupsColsStyle), children: _jsx(GroupContainer, { style: props.groupContainerStyle, className: props.groupContainerClassName, groupRender: props.groupRender, currentGroup: group, handleClickGroup: props.handleClickGroup }) }, i), dailyHours.map((_, positionDay) => (_jsx("td", { onDragOver: handleDragOver, onDrop: (event) => {
|
|
23
|
+
if (!props.handleDropTask || !props.tasks)
|
|
24
|
+
return;
|
|
25
|
+
const dropInfo = getSessionStorageRecordForDragAndDrop(props.tasks, positionDay, group.id);
|
|
26
|
+
if (!dropInfo)
|
|
27
|
+
return;
|
|
28
|
+
props.handleDropTask(event, dropInfo.taskDropStart, dropInfo.taskDropEnd, dropInfo.taskDropDate, group.id, positionDay, dropInfo.newTask, dropInfo.newTasks);
|
|
29
|
+
}, id: `td-${group.id}day-i`, className: props.dayColsClassName, style: props.dayColsStyle, children: _jsxs("div", { style: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
width: "100%",
|
|
32
|
+
height: "100%",
|
|
33
|
+
flexDirection: "column",
|
|
34
|
+
padding: "5px",
|
|
35
|
+
}, children: [_jsx(_Fragment, { children: props.tasks
|
|
36
|
+
.map((task, taskKey) => {
|
|
37
|
+
if (task.dayIndex === positionDay &&
|
|
38
|
+
task.groupId === group.id &&
|
|
39
|
+
compareWeekOffset(props.date, props.weekOffset || 0, task.taskDate, props.timeZone)) {
|
|
40
|
+
return (_jsx(TaskContainer, { handleDragTask: props.handleDragTask, taskRender: props.taskRender, handleDragTaskEnd: props.handleDragTaskEnd, style: props.taskContainerStyle, className: `${props.taskContainerClassName}`, currentTask: task, handleClickTask: props.handleClickTask }, `${taskKey} task`));
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
return "";
|
|
44
|
+
}) }), _jsx(AddTask, { addTaskStyle: props.addTaskStyle, addTaskClassName: props.addTaskClassName, currentGroup: group, dayInfo: dailyHours[positionDay], addTaskRender: props.addTaskRender, handleAddTask: props.handleAddTask })] }, positionDay) }, `td-${group.id}day-i${positionDay}`))), _jsx("td", { style: props.hoursColsStyle, className: props.hoursColsClassName, children: _jsx(SumHoursContainer, { groupId: group.id, tasks: props.tasks, weekOffset: props.weekOffset || 0, calendarDate: props.date, sumHoursRender: props.sumHoursRender, sumHoursByGroups: sumHoursByGroups(group.id, props.tasks, props.weekOffset || 0, props.date, props.timeZone), className: props.sumHoursContainerClassName, style: props.sumHoursContainerStyle }) }, `${i}sumHours`)] }, `${i} tr`))) })] }));
|
|
45
|
+
}
|
|
46
|
+
export default memo(CalendarForWeek, (prevProps, nextProps) => prevProps.tasks === nextProps.tasks &&
|
|
47
|
+
prevProps.date === nextProps.date &&
|
|
48
|
+
prevProps.groups === nextProps.groups &&
|
|
49
|
+
prevProps.weekOffset === nextProps.weekOffset);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import {
|
|
3
3
|
CalendarPropsType,
|
|
4
4
|
CalendarTablePropsType,
|
|
@@ -27,6 +27,8 @@ import { memo, useEffect } from "react";
|
|
|
27
27
|
import useCalendarDateState from "../hooks/useCalendarDateState";
|
|
28
28
|
|
|
29
29
|
function CalendarForWeek(props: CalendarTablePropsType) {
|
|
30
|
+
|
|
31
|
+
|
|
30
32
|
const { dailyHours, weekDays } = useCalendarDateState(
|
|
31
33
|
props.date,
|
|
32
34
|
props.weekOffset,
|
|
@@ -158,7 +160,8 @@ function CalendarForWeek(props: CalendarTablePropsType) {
|
|
|
158
160
|
compareWeekOffset(
|
|
159
161
|
props.date,
|
|
160
162
|
props.weekOffset || 0,
|
|
161
|
-
task.taskDate
|
|
163
|
+
task.taskDate,
|
|
164
|
+
props.timeZone
|
|
162
165
|
)
|
|
163
166
|
) {
|
|
164
167
|
return (
|
|
@@ -203,7 +206,8 @@ function CalendarForWeek(props: CalendarTablePropsType) {
|
|
|
203
206
|
group.id,
|
|
204
207
|
props.tasks,
|
|
205
208
|
props.weekOffset || 0,
|
|
206
|
-
props.date
|
|
209
|
+
props.date,
|
|
210
|
+
props.timeZone
|
|
207
211
|
)}
|
|
208
212
|
className={props.sumHoursContainerClassName}
|
|
209
213
|
style={props.sumHoursContainerStyle}
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import "
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
prevProps.
|
|
33
|
-
prevProps.
|
|
34
|
-
prevProps.weekOffset === nextProps.weekOffset);
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "../style.css";
|
|
3
|
+
import { memo, useEffect } from "react";
|
|
4
|
+
import { compareWeekOffset, saveTasksToLocalStorage } from "../lib/utils";
|
|
5
|
+
import useCalendarDateState from "../hooks/useCalendarDateState";
|
|
6
|
+
import AddTask from "./AddTask";
|
|
7
|
+
import TaskContainer from "./TaskContainer";
|
|
8
|
+
import GroupContainer from "./GroupContainer";
|
|
9
|
+
import DayContainer from "./DayContainer";
|
|
10
|
+
function CalendarForDay(props) {
|
|
11
|
+
const { dailyHours, weekDays } = useCalendarDateState(props.date, props.weekOffset, props.timeZone);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
saveTasksToLocalStorage(props.tasks);
|
|
14
|
+
}, [props.tasks]);
|
|
15
|
+
const currentDay = weekDays[props.dayOffset || 0];
|
|
16
|
+
const currentDailyHours = dailyHours[props.dayOffset || 0];
|
|
17
|
+
return (_jsxs("div", { className: ` CalendarTableForDay ${props.className}`, style: Object.assign({}, props.style), children: [currentDay && (_jsx(DayContainer, { style: props.dayStyle, className: props.dayClassName, dayIndex: props.dayOffset || 0, dayRender: props.dayRender, day: currentDay.day, dayOfTheMonth: currentDay.dayOfTheMonth, dayMonth: currentDay.dayMonth, dayYear: currentDay.dayYear })), _jsx("div", { className: `CalendarTableForDayTasksContainer`, children: currentDailyHours &&
|
|
18
|
+
props.groups.map((group, i) => {
|
|
19
|
+
return (_jsxs("div", { style: Object.assign({ width: "100%", height: "auto", background: "#f2f8f8", padding: "5px", borderBottom: "1.5px solid #0f52737e", borderRight: "0.74px solid rgba(198, 219, 225, 0.68)", borderLeft: "0.74px solid rgba(198, 219, 225, 0.68)" }, props.rowsStyle), className: `${props.rowsClassName}`, children: [_jsx("div", { style: Object.assign({ width: "auto", height: "auto" }, props.groupsColsStyle), className: props.groupsColsClassName, children: _jsx(GroupContainer, { style: props.groupContainerStyle, className: props.groupContainerClassName, groupRender: props.groupRender, currentGroup: group, handleClickGroup: props.handleClickGroup }) }), props.tasks.map((task, taskKey) => {
|
|
20
|
+
if (task.dayIndex === (props.dayOffset || 0) &&
|
|
21
|
+
task.groupId === group.id &&
|
|
22
|
+
compareWeekOffset(props.date, props.weekOffset || 0, task.taskDate, props.timeZone)) {
|
|
23
|
+
return (_jsx(TaskContainer, { handleDragTask: props.handleDragTask, taskRender: props.taskRender, handleDragTaskEnd: props.handleDragTaskEnd, style: props.taskContainerStyle, className: `${props.taskContainerClassName}`, currentTask: task, handleClickTask: props.handleClickTask }, `${taskKey} task`));
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
return "";
|
|
27
|
+
}), _jsx(AddTask, { addTaskStyle: props.addTaskStyle, addTaskClassName: props.addTaskClassName, currentGroup: group, dayInfo: currentDailyHours, addTaskRender: props.addTaskRender, handleAddTask: props.handleAddTask })] }, i));
|
|
28
|
+
}) })] }));
|
|
29
|
+
}
|
|
30
|
+
export default memo(CalendarForDay, (prevProps, nextProps) => prevProps.tasks === nextProps.tasks &&
|
|
31
|
+
prevProps.date === nextProps.date &&
|
|
32
|
+
prevProps.groups === nextProps.groups &&
|
|
33
|
+
prevProps.weekOffset === nextProps.weekOffset);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import "../style.css";
|
|
3
3
|
import { memo, useEffect } from "react";
|
|
4
4
|
|
|
@@ -84,7 +84,8 @@ function CalendarForDay(props: CalendarTablePropsType) {
|
|
|
84
84
|
compareWeekOffset(
|
|
85
85
|
props.date,
|
|
86
86
|
props.weekOffset || 0,
|
|
87
|
-
task.taskDate
|
|
87
|
+
task.taskDate,
|
|
88
|
+
props.timeZone
|
|
88
89
|
)
|
|
89
90
|
) {
|
|
90
91
|
return (
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from "react";
|
|
3
|
-
const DayContainer = ({ dayIndex, dayOfTheMonth, day, dayMonth, dayYear, dayRender, className, style, }) => {
|
|
4
|
-
if (dayRender) {
|
|
5
|
-
return (_jsx(_Fragment, { children: dayRender({
|
|
6
|
-
dayIndex,
|
|
7
|
-
day,
|
|
8
|
-
dayOfTheMonth,
|
|
9
|
-
dayMonth,
|
|
10
|
-
dayYear,
|
|
11
|
-
}) }));
|
|
12
|
-
}
|
|
13
|
-
return (_jsx("div", { className: `${className}`, style: style, children: `${day}. ${dayOfTheMonth}` }));
|
|
14
|
-
};
|
|
15
|
-
export default memo(DayContainer);
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
const DayContainer = ({ dayIndex, dayOfTheMonth, day, dayMonth, dayYear, dayRender, className, style, }) => {
|
|
4
|
+
if (dayRender) {
|
|
5
|
+
return (_jsx(_Fragment, { children: dayRender({
|
|
6
|
+
dayIndex,
|
|
7
|
+
day,
|
|
8
|
+
dayOfTheMonth,
|
|
9
|
+
dayMonth,
|
|
10
|
+
dayYear,
|
|
11
|
+
}) }));
|
|
12
|
+
}
|
|
13
|
+
return (_jsx("div", { className: `${className}`, style: style, children: `${day}. ${dayOfTheMonth}` }));
|
|
14
|
+
};
|
|
15
|
+
export default memo(DayContainer);
|