[#31] fixed sending data
This commit is contained in:
@@ -4,7 +4,7 @@ import { CalendarEvent } from "../Events/EventsTypes";
|
||||
import { getCalendar, getCalendars } from "./CalendarApi";
|
||||
import getOpenPaasUserId from "../User/userAPI";
|
||||
import { parseCalendarEvent } from "../Events/eventUtils";
|
||||
import { getEvent, putEvent } from "../Events/EventApi";
|
||||
import { putEvent } from "../Events/EventApi";
|
||||
import { formatDateToYYYYMMDDTHHMMSS } from "../../utils/dateUtils";
|
||||
|
||||
export const getCalendarsListAsync = createAsyncThunk<
|
||||
@@ -50,18 +50,28 @@ export const getCalendarDetailAsync = createAsyncThunk<
|
||||
});
|
||||
|
||||
export const putEventAsync = createAsyncThunk<
|
||||
{ calId: string; event: CalendarEvent }, // Return type
|
||||
{ calId: string; events: CalendarEvent[] }, // Return type
|
||||
{ cal: Calendars; newEvent: CalendarEvent } // Arg type
|
||||
>("calendars/putEvent", async ({ cal, newEvent }) => {
|
||||
const response = await putEvent(cal, newEvent);
|
||||
const now = new Date();
|
||||
const event = (await getCalendar(cal.id, {
|
||||
start: formatDateToYYYYMMDDTHHMMSS(now),
|
||||
end: formatDateToYYYYMMDDTHHMMSS(new Date(now.getDate() + 1)),
|
||||
const calEvents = (await getCalendar(cal.id, {
|
||||
start: formatDateToYYYYMMDDTHHMMSS(newEvent.start),
|
||||
end: formatDateToYYYYMMDDTHHMMSS(
|
||||
new Date(newEvent.start.getTime() + 86400000)
|
||||
),
|
||||
})) as Record<string, any>;
|
||||
const events: CalendarEvent[] = calEvents._embedded["dav:item"].flatMap(
|
||||
(eventdata: any) => {
|
||||
const vevents = eventdata.data[2] as any[][];
|
||||
return vevents.map((vevent: any[]) => {
|
||||
return parseCalendarEvent(vevent[1], cal.color ?? "", cal.id);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
calId: cal.id,
|
||||
event: parseCalendarEvent([event[1]], "", cal.id),
|
||||
events,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -133,7 +143,7 @@ const CalendarSlice = createSlice({
|
||||
putEventAsync.fulfilled,
|
||||
(
|
||||
state,
|
||||
action: PayloadAction<{ calId: string; event: CalendarEvent }>
|
||||
action: PayloadAction<{ calId: string; events: CalendarEvent[] }>
|
||||
) => {
|
||||
state.pending = false;
|
||||
if (!state.list[action.payload.calId]) {
|
||||
@@ -142,11 +152,13 @@ const CalendarSlice = createSlice({
|
||||
events: {},
|
||||
} as Calendars;
|
||||
}
|
||||
state.list[action.payload.calId].events[action.payload.event.uid] =
|
||||
action.payload.event;
|
||||
state.list[action.payload.calId].events[
|
||||
action.payload.event.uid
|
||||
].color = state.list[action.payload.calId].color;
|
||||
action.payload.events.forEach((event) => {
|
||||
state.list[action.payload.calId].events[event.uid] = event;
|
||||
});
|
||||
Object.keys(state.list[action.payload.calId].events).forEach((id) => {
|
||||
state.list[action.payload.calId].events[id].color =
|
||||
state.list[action.payload.calId].color;
|
||||
});
|
||||
}
|
||||
)
|
||||
.addCase(getCalendarDetailAsync.pending, (state) => {
|
||||
|
||||
Reference in New Issue
Block a user