[#31] added repetition and all day to events to be sent
This commit is contained in:
@@ -16,3 +16,13 @@ export async function putEvent(cal: Calendars, event: CalendarEvent) {
|
|||||||
).json();
|
).json();
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteEvent(calId: string, eventId: string) {
|
||||||
|
const response = await api(
|
||||||
|
`dav/calendars/${calId}/${eventId.split(".")[0]}.isc`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
}
|
||||||
|
).json();
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
import { Calendars } from "../Calendars/CalendarTypes";
|
import { Calendars } from "../Calendars/CalendarTypes";
|
||||||
import { putEvent } from "./EventApi";
|
import { putEvent } from "./EventApi";
|
||||||
import { TIMEZONES } from "../../utils/timezone-data";
|
import { TIMEZONES } from "../../utils/timezone-data";
|
||||||
|
import { CheckBox, Repeat } from "@mui/icons-material";
|
||||||
|
|
||||||
function EventPopover({
|
function EventPopover({
|
||||||
anchorEl,
|
anchorEl,
|
||||||
@@ -50,6 +51,8 @@ function EventPopover({
|
|||||||
const [start, setStart] = useState("");
|
const [start, setStart] = useState("");
|
||||||
const [end, setEnd] = useState("");
|
const [end, setEnd] = useState("");
|
||||||
const [calendarid, setCalendarid] = useState(0);
|
const [calendarid, setCalendarid] = useState(0);
|
||||||
|
const [allday, setAllDay] = useState(false);
|
||||||
|
const [repetition, setRepetition] = useState("");
|
||||||
const [timezone, setTimezone] = useState(
|
const [timezone, setTimezone] = useState(
|
||||||
Intl.DateTimeFormat().resolvedOptions().timeZone
|
Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||||
);
|
);
|
||||||
@@ -66,9 +69,11 @@ function EventPopover({
|
|||||||
title,
|
title,
|
||||||
start: new Date(start),
|
start: new Date(start),
|
||||||
end: new Date(end),
|
end: new Date(end),
|
||||||
|
allday,
|
||||||
uid: crypto.randomUUID(),
|
uid: crypto.randomUUID(),
|
||||||
description,
|
description,
|
||||||
location,
|
location,
|
||||||
|
repetition,
|
||||||
organizer,
|
organizer,
|
||||||
timezone,
|
timezone,
|
||||||
attendee: [
|
attendee: [
|
||||||
@@ -113,6 +118,14 @@ function EventPopover({
|
|||||||
Create Event
|
Create Event
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
label="Title"
|
||||||
|
value={title}
|
||||||
|
onChange={(e) => setTitle(e.target.value)}
|
||||||
|
size="small"
|
||||||
|
margin="dense"
|
||||||
|
/>
|
||||||
<FormControl fullWidth margin="dense" size="small">
|
<FormControl fullWidth margin="dense" size="small">
|
||||||
<InputLabel id="calendar-select-label">Calendar</InputLabel>
|
<InputLabel id="calendar-select-label">Calendar</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
@@ -131,18 +144,10 @@ function EventPopover({
|
|||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<TextField
|
|
||||||
fullWidth
|
|
||||||
label="Title"
|
|
||||||
value={title}
|
|
||||||
onChange={(e) => setTitle(e.target.value)}
|
|
||||||
size="small"
|
|
||||||
margin="dense"
|
|
||||||
/>
|
|
||||||
<TextField
|
<TextField
|
||||||
fullWidth
|
fullWidth
|
||||||
label="Start"
|
label="Start"
|
||||||
type="datetime-local"
|
type={allday ? "date" : "datetime-local"}
|
||||||
value={start}
|
value={start}
|
||||||
onChange={(e) => setStart(e.target.value)}
|
onChange={(e) => setStart(e.target.value)}
|
||||||
size="small"
|
size="small"
|
||||||
@@ -152,13 +157,21 @@ function EventPopover({
|
|||||||
<TextField
|
<TextField
|
||||||
fullWidth
|
fullWidth
|
||||||
label="End"
|
label="End"
|
||||||
type="datetime-local"
|
type={allday ? "date" : "datetime-local"}
|
||||||
value={end}
|
value={end}
|
||||||
onChange={(e) => setEnd(e.target.value)}
|
onChange={(e) => setEnd(e.target.value)}
|
||||||
size="small"
|
size="small"
|
||||||
margin="dense"
|
margin="dense"
|
||||||
InputLabelProps={{ shrink: true }}
|
InputLabelProps={{ shrink: true }}
|
||||||
/>
|
/>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={allday}
|
||||||
|
onChange={() => setAllDay(!allday)}
|
||||||
|
/>
|
||||||
|
All day
|
||||||
|
</label>
|
||||||
<TextField
|
<TextField
|
||||||
fullWidth
|
fullWidth
|
||||||
label="Description"
|
label="Description"
|
||||||
@@ -178,6 +191,22 @@ function EventPopover({
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormControl fullWidth margin="dense" size="small">
|
||||||
|
<InputLabel id="repeat">Repetition</InputLabel>
|
||||||
|
<Select
|
||||||
|
labelId="repeat"
|
||||||
|
value={repetition}
|
||||||
|
label="Time Zone"
|
||||||
|
onChange={(e: SelectChangeEvent) => setRepetition(e.target.value)}
|
||||||
|
>
|
||||||
|
<MenuItem value={""}>No Repetition</MenuItem>
|
||||||
|
<MenuItem value={"daily"}>Repeat daily</MenuItem>
|
||||||
|
<MenuItem value={"weekly"}>Repeat weekly</MenuItem>
|
||||||
|
<MenuItem value={"monthly"}>Repeat monthly</MenuItem>
|
||||||
|
<MenuItem value={"yearly"}>Repeat yearly</MenuItem>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<FormControl fullWidth margin="dense" size="small">
|
<FormControl fullWidth margin="dense" size="small">
|
||||||
<InputLabel id="timezone-select-label">Time Zone</InputLabel>
|
<InputLabel id="timezone-select-label">Time Zone</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
|
|||||||
@@ -19,4 +19,5 @@ export interface CalendarEvent {
|
|||||||
error?: string;
|
error?: string;
|
||||||
status?: string;
|
status?: string;
|
||||||
timezone: string;
|
timezone: string;
|
||||||
|
repetition?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,12 @@ export function calendarEventToJCal(event: CalendarEvent): any[] {
|
|||||||
[
|
[
|
||||||
["uid", {}, "text", event.uid],
|
["uid", {}, "text", event.uid],
|
||||||
["transp", {}, "text", event.transp ?? "OPAQUE"],
|
["transp", {}, "text", event.transp ?? "OPAQUE"],
|
||||||
["dtstart", { tzid }, "date-time", formatDateToICal(event.start)],
|
[
|
||||||
|
"dtstart",
|
||||||
|
{ tzid },
|
||||||
|
event.allday ? "date" : "date-time",
|
||||||
|
formatDateToICal(event.start, event.allday ?? false),
|
||||||
|
],
|
||||||
["class", {}, "text", event.class ?? "PUBLIC"],
|
["class", {}, "text", event.class ?? "PUBLIC"],
|
||||||
[
|
[
|
||||||
"x-openpaas-videoconference",
|
"x-openpaas-videoconference",
|
||||||
@@ -111,8 +116,8 @@ export function calendarEventToJCal(event: CalendarEvent): any[] {
|
|||||||
vevent[1].push([
|
vevent[1].push([
|
||||||
"dtend",
|
"dtend",
|
||||||
{ tzid },
|
{ tzid },
|
||||||
"date-time",
|
event.allday ? "date" : "date-time",
|
||||||
formatDateToICal(event.end),
|
formatDateToICal(event.end, event.allday ?? false),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if (event.organizer) {
|
if (event.organizer) {
|
||||||
@@ -129,6 +134,9 @@ export function calendarEventToJCal(event: CalendarEvent): any[] {
|
|||||||
if (event.description) {
|
if (event.description) {
|
||||||
vevent[1].push(["description", {}, "text", event.description]);
|
vevent[1].push(["description", {}, "text", event.description]);
|
||||||
}
|
}
|
||||||
|
if (event.repetition) {
|
||||||
|
vevent[1].push(["rrule", {}, "recur", { freq: event.repetition }]);
|
||||||
|
}
|
||||||
|
|
||||||
event.attendee.forEach((att) => {
|
event.attendee.forEach((att) => {
|
||||||
vevent[1].push([
|
vevent[1].push([
|
||||||
@@ -151,7 +159,7 @@ export function calendarEventToJCal(event: CalendarEvent): any[] {
|
|||||||
});
|
});
|
||||||
return ["vcalendar", [], [vevent, vtimezone.component.jCal]];
|
return ["vcalendar", [], [vevent, vtimezone.component.jCal]];
|
||||||
}
|
}
|
||||||
function formatDateToICal(date: Date) {
|
function formatDateToICal(date: Date, allday: Boolean) {
|
||||||
// Format date like: 20250214T110000 (local time)
|
// Format date like: 20250214T110000 (local time)
|
||||||
|
|
||||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||||
@@ -161,5 +169,8 @@ function formatDateToICal(date: Date) {
|
|||||||
const hours = pad(date.getHours());
|
const hours = pad(date.getHours());
|
||||||
const minutes = pad(date.getMinutes());
|
const minutes = pad(date.getMinutes());
|
||||||
const seconds = pad(date.getSeconds());
|
const seconds = pad(date.getSeconds());
|
||||||
|
if (allday) {
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
}
|
||||||
return `${year}${month}${day}T${hours}${minutes}${seconds}`;
|
return `${year}${month}${day}T${hours}${minutes}${seconds}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user