Co-authored-by: lethemanh <lethemanh@lethemanhs-MacBook-Pro.local>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { OpenPaasUserData } from "@/features/User/type/OpenPaasUserData";
|
||||
import { getResourceDetails } from "@/features/User/userAPI";
|
||||
import { toRejectedError } from "@/utils/errorUtils";
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { addSharedCalendar } from "../CalendarApi";
|
||||
import { CalendarInput } from "../types/CalendarData";
|
||||
import { RejectedError } from "../types/RejectedError";
|
||||
import { User } from "@/components/Attendees/PeopleSearch";
|
||||
|
||||
export const addCalendarResourceAsync = createAsyncThunk<
|
||||
{
|
||||
calId: string;
|
||||
color: Record<string, string>;
|
||||
link: string;
|
||||
name: string;
|
||||
desc: string;
|
||||
owner: OpenPaasUserData;
|
||||
},
|
||||
{
|
||||
userId: string;
|
||||
calId: string;
|
||||
cal: Omit<CalendarInput, "owner"> & {
|
||||
owner?: Omit<User, "email"> & { email?: string };
|
||||
};
|
||||
},
|
||||
{ rejectValue: RejectedError }
|
||||
>(
|
||||
"calendars/addCalendarResource",
|
||||
async ({ userId, calId, cal }, { rejectWithValue }) => {
|
||||
try {
|
||||
await addSharedCalendar(userId, calId, cal);
|
||||
const ownerData = await getResourceDetails(
|
||||
cal.cal._links.self.href
|
||||
.replace("/calendars/", "")
|
||||
.replace(".json", "")
|
||||
.split("/")[0]
|
||||
);
|
||||
|
||||
return {
|
||||
calId: cal.cal._links.self?.href
|
||||
?.replace("/calendars/", "")
|
||||
.replace(".json", ""),
|
||||
color: cal.color,
|
||||
link: `/calendars/${userId}/${calId}.json`,
|
||||
desc: cal.cal["caldav:description"] ?? "",
|
||||
name: cal.cal["dav:name"] ?? "",
|
||||
owner: ownerData,
|
||||
};
|
||||
} catch (err) {
|
||||
return rejectWithValue(toRejectedError(err));
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user