[#50] added attendee search and tests

This commit is contained in:
Camille Moussu
2025-07-30 15:22:28 +02:00
committed by Benoit TELLIER
parent 9a58c485ac
commit d7b3d4e077
6 changed files with 260 additions and 36 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ import { createAsyncThunk, createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Calendars } from "./CalendarTypes";
import { CalendarEvent } from "../Events/EventsTypes";
import { getCalendar, getCalendars } from "./CalendarApi";
import getOpenPaasUserId from "../User/userAPI";
import { getOpenPaasUserId } from "../User/userAPI";
import { parseCalendarEvent } from "../Events/eventUtils";
import { deleteEvent, putEvent } from "../Events/EventApi";
import { formatDateToYYYYMMDDTHHMMSS } from "../../utils/dateUtils";
+37 -23
View File
@@ -1,24 +1,25 @@
import React, { useEffect, useState } from "react";
import { addEvent, putEventAsync } from "../Calendars/CalendarSlice";
import { CalendarEvent } from "./EventsTypes";
import { CalendarApi, DateSelectArg } from "@fullcalendar/core";
import { useAppDispatch, useAppSelector } from "../../app/hooks";
import {
Popover,
TextField,
Button,
Box,
Typography,
Select,
MenuItem,
SelectChangeEvent,
Button,
FormControl,
InputLabel,
MenuItem,
Popover,
Select,
SelectChangeEvent,
TextField,
Typography,
} from "@mui/material";
import { Calendars } from "../Calendars/CalendarTypes";
import { putEvent } from "./EventApi";
import React, { useEffect, useState } from "react";
import { useAppDispatch, useAppSelector } from "../../app/hooks";
import AttendeeSelector from "../../components/Attendees/AttendeeSearch";
import { TIMEZONES } from "../../utils/timezone-data";
import { CheckBox, Repeat } from "@mui/icons-material";
import { putEventAsync } from "../Calendars/CalendarSlice";
import { Calendars } from "../Calendars/CalendarTypes";
import { userAttendee } from "../User/userDataTypes";
import { CalendarEvent } from "./EventsTypes";
import { createSelector } from "@reduxjs/toolkit";
function EventPopover({
anchorEl,
@@ -39,14 +40,21 @@ function EventPopover({
const organizer = useAppSelector((state) => state.user.organiserData);
const userId = useAppSelector((state) => state.user.userData.openpaasId);
const userPersonnalCalendars: Calendars[] = useAppSelector((state) =>
Object.keys(state.calendars.list).map((id) => {
if (id.split("/")[0] === userId) {
return state.calendars.list[id];
}
return {} as Calendars;
})
).filter((calendar) => calendar.id);
const selectPersonnalCalendars = createSelector(
(state) => state.calendars,
(calendars) =>
Object.keys(calendars.list)
.map((id) => {
if (id.split("/")[0] === userId) {
return calendars.list[id];
}
return {} as Calendars;
})
.filter((calendar) => calendar.id)
);
const userPersonnalCalendars: Calendars[] = useAppSelector(
selectPersonnalCalendars
);
const timezones = TIMEZONES.aliases;
const [title, setTitle] = useState("");
@@ -57,6 +65,7 @@ function EventPopover({
const [calendarid, setCalendarid] = useState(0);
const [allday, setAllDay] = useState(false);
const [repetition, setRepetition] = useState("");
const [attendees, setAttendees] = useState<userAttendee[]>([]);
const [timezone, setTimezone] = useState(
Intl.DateTimeFormat().resolvedOptions().timeZone
);
@@ -96,6 +105,11 @@ function EventPopover({
if (end) {
newEvent.end = new Date(end);
}
if (attendees.length > 0) {
newEvent.attendee = newEvent.attendee.concat(attendees);
}
dispatch(
putEventAsync({
cal: userPersonnalCalendars[calendarid],
@@ -246,7 +260,7 @@ function EventPopover({
<MenuItem value={"yearly"}>Repeat yearly</MenuItem>
</Select>
</FormControl>
<AttendeeSelector setAttendees={setAttendees} />
<FormControl fullWidth margin="dense" size="small">
<InputLabel id="timezone-select-label">Time Zone</InputLabel>
<Select
+21
View File
@@ -4,3 +4,24 @@ export default async function getOpenPaasUser() {
const user = await api.get(`api/user`).json();
return user;
}
export async function searchUsers(query: string) {
const response: any[] = await api
.post(`api/people/search/`, {
body: JSON.stringify({
limit: 10,
objectTypes: ["user", "group", "contact", "ldap"],
q: query,
}),
})
.json();
return response
.filter((user) => user.objectType === "user")
.map((user) => ({
email: user.emailAddresses?.[0]?.value || "",
displayName:
user.names?.[0]?.displayName || user.emailAddresses?.[0]?.value,
avatarUrl: user.photos?.[0]?.url || "",
}));
}