Files
workavia-calendar-front/src/features/Calendars/services/createCalendarAsync.ts
T
Camille Moussu d6e464afad [#421] added eslint check to CI (#534)
Co-authored-by: Camille Moussu <cmoussu@linagora.com>
2026-02-10 10:41:37 +01:00

52 lines
1.3 KiB
TypeScript

import { userData } from "@/features/User/userDataTypes";
import { toRejectedError } from "@/utils/errorUtils";
import { createAsyncThunk } from "@reduxjs/toolkit";
import { postCalendar } from "../CalendarApi";
import { RejectedError } from "../types/RejectedError";
export const createCalendarAsync = createAsyncThunk<
{
userId: string;
calId: string;
color: Record<string, string>;
name: string;
desc: string;
owner: string;
ownerEmails: string[];
},
{
userData: userData;
calId: string;
color: Record<string, string>;
name: string;
desc: string;
},
{ rejectValue: RejectedError }
>(
"calendars/createCalendar",
async ({ userData, calId, color, name, desc }, { rejectWithValue }) => {
try {
if (!userData.openpaasId) {
throw new Error("No openpaasId");
}
await postCalendar(userData.openpaasId, calId, color, name, desc);
const owner = [userData.given_name, userData.family_name]
.filter(Boolean)
.join(" ");
return {
userId: userData.openpaasId,
calId,
color,
name,
desc,
owner,
ownerEmails: userData.email ? [userData.email] : [],
};
} catch (err) {
return rejectWithValue(toRejectedError(err));
}
}
);