mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
meeting page frontend fixes
This commit is contained in:
@@ -62,6 +62,7 @@ class Meeting(BaseModel):
|
|||||||
id: str
|
id: str
|
||||||
room_name: str
|
room_name: str
|
||||||
room_url: str
|
room_url: str
|
||||||
|
# TODO it's not always present, | None
|
||||||
host_room_url: str
|
host_room_url: str
|
||||||
start_date: datetime
|
start_date: datetime
|
||||||
end_date: datetime
|
end_date: datetime
|
||||||
@@ -502,6 +503,34 @@ async def rooms_list_active_meetings(
|
|||||||
return meetings
|
return meetings
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/rooms/{room_name}/meetings/{meeting_id}", response_model=Meeting)
|
||||||
|
async def rooms_get_meeting(
|
||||||
|
room_name: str,
|
||||||
|
meeting_id: str,
|
||||||
|
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
||||||
|
):
|
||||||
|
"""Get a single meeting by ID within a specific room."""
|
||||||
|
user_id = user["sub"] if user else None
|
||||||
|
|
||||||
|
room = await rooms_controller.get_by_name(room_name)
|
||||||
|
if not room:
|
||||||
|
raise HTTPException(status_code=404, detail="Room not found")
|
||||||
|
|
||||||
|
meeting = await meetings_controller.get_by_id(meeting_id)
|
||||||
|
if not meeting:
|
||||||
|
raise HTTPException(status_code=404, detail="Meeting not found")
|
||||||
|
|
||||||
|
if meeting.room_id != room.id:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=403, detail="Meeting does not belong to this room"
|
||||||
|
)
|
||||||
|
|
||||||
|
if user_id != room.user_id and not room.is_shared:
|
||||||
|
meeting.host_room_url = ""
|
||||||
|
|
||||||
|
return meeting
|
||||||
|
|
||||||
|
|
||||||
@router.post("/rooms/{room_name}/meetings/{meeting_id}/join", response_model=Meeting)
|
@router.post("/rooms/{room_name}/meetings/{meeting_id}/join", response_model=Meeting)
|
||||||
async def rooms_join_meeting(
|
async def rooms_join_meeting(
|
||||||
room_name: str,
|
room_name: str,
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ import { FaCheckCircle, FaExclamationCircle } from "react-icons/fa";
|
|||||||
import { useRoomIcsSync, useRoomIcsStatus } from "../../../lib/apiHooks";
|
import { useRoomIcsSync, useRoomIcsStatus } from "../../../lib/apiHooks";
|
||||||
import { toaster } from "../../../components/ui/toaster";
|
import { toaster } from "../../../components/ui/toaster";
|
||||||
import { roomAbsoluteUrl } from "../../../lib/routesClient";
|
import { roomAbsoluteUrl } from "../../../lib/routesClient";
|
||||||
import { assertExists } from "../../../lib/utils";
|
import {
|
||||||
|
assertExists,
|
||||||
|
assertExistsAndNonEmptyString,
|
||||||
|
parseNonEmptyString,
|
||||||
|
} from "../../../lib/utils";
|
||||||
|
|
||||||
interface ICSSettingsProps {
|
interface ICSSettingsProps {
|
||||||
roomName: string;
|
roomName: string;
|
||||||
@@ -80,7 +84,7 @@ export default function ICSSettings({
|
|||||||
const handleCopyRoomUrl = async () => {
|
const handleCopyRoomUrl = async () => {
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(
|
await navigator.clipboard.writeText(
|
||||||
roomAbsoluteUrl(assertExists(roomName)),
|
roomAbsoluteUrl(assertExistsAndNonEmptyString(roomName)),
|
||||||
);
|
);
|
||||||
setJustCopied(true);
|
setJustCopied(true);
|
||||||
|
|
||||||
@@ -194,7 +198,7 @@ export default function ICSSettings({
|
|||||||
<HStack gap={0} position="relative" width="100%">
|
<HStack gap={0} position="relative" width="100%">
|
||||||
<Input
|
<Input
|
||||||
ref={roomUrlInputRef}
|
ref={roomUrlInputRef}
|
||||||
value={roomAbsoluteUrl(roomName)}
|
value={roomAbsoluteUrl(parseNonEmptyString(roomName))}
|
||||||
readOnly
|
readOnly
|
||||||
onClick={handleRoomUrlClick}
|
onClick={handleRoomUrlClick}
|
||||||
cursor="pointer"
|
cursor="pointer"
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import type { components } from "../../../reflector-api";
|
|||||||
type Room = components["schemas"]["Room"];
|
type Room = components["schemas"]["Room"];
|
||||||
import { RoomTable } from "./RoomTable";
|
import { RoomTable } from "./RoomTable";
|
||||||
import { RoomCards } from "./RoomCards";
|
import { RoomCards } from "./RoomCards";
|
||||||
|
import { NonEmptyString } from "../../../lib/utils";
|
||||||
|
|
||||||
interface RoomListProps {
|
interface RoomListProps {
|
||||||
title: string;
|
title: string;
|
||||||
rooms: Room[];
|
rooms: Room[];
|
||||||
linkCopied: string;
|
linkCopied: string;
|
||||||
onCopyUrl: (roomName: string) => void;
|
onCopyUrl: (roomName: NonEmptyString) => void;
|
||||||
onEdit: (roomId: string, roomData: any) => void;
|
onEdit: (roomId: string, roomData: any) => void;
|
||||||
onDelete: (roomId: string) => void;
|
onDelete: (roomId: string) => void;
|
||||||
emptyMessage?: string;
|
emptyMessage?: string;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Meeting = components["schemas"]["Meeting"];
|
|||||||
type CalendarEventResponse = components["schemas"]["CalendarEventResponse"];
|
type CalendarEventResponse = components["schemas"]["CalendarEventResponse"];
|
||||||
import { RoomActionsMenu } from "./RoomActionsMenu";
|
import { RoomActionsMenu } from "./RoomActionsMenu";
|
||||||
import { MEETING_DEFAULT_TIME_MINUTES } from "../../../[roomName]/[meetingId]/constants";
|
import { MEETING_DEFAULT_TIME_MINUTES } from "../../../[roomName]/[meetingId]/constants";
|
||||||
|
import { NonEmptyString, parseNonEmptyString } from "../../../lib/utils";
|
||||||
|
|
||||||
// Custom icon component that combines calendar and refresh icons
|
// Custom icon component that combines calendar and refresh icons
|
||||||
const CalendarSyncIcon = () => (
|
const CalendarSyncIcon = () => (
|
||||||
@@ -57,7 +58,7 @@ const CalendarSyncIcon = () => (
|
|||||||
interface RoomTableProps {
|
interface RoomTableProps {
|
||||||
rooms: Room[];
|
rooms: Room[];
|
||||||
linkCopied: string;
|
linkCopied: string;
|
||||||
onCopyUrl: (roomName: string) => void;
|
onCopyUrl: (roomName: NonEmptyString) => void;
|
||||||
onEdit: (roomId: string, roomData: any) => void;
|
onEdit: (roomId: string, roomData: any) => void;
|
||||||
onDelete: (roomId: string) => void;
|
onDelete: (roomId: string) => void;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
@@ -292,7 +293,9 @@ export function RoomTable({
|
|||||||
) : (
|
) : (
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label="Copy URL"
|
aria-label="Copy URL"
|
||||||
onClick={() => onCopyUrl(room.name)}
|
onClick={() =>
|
||||||
|
onCopyUrl(parseNonEmptyString(room.name))
|
||||||
|
}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import {
|
|||||||
} from "../../lib/apiHooks";
|
} from "../../lib/apiHooks";
|
||||||
import { RoomList } from "./_components/RoomList";
|
import { RoomList } from "./_components/RoomList";
|
||||||
import { PaginationPage } from "../browse/_components/Pagination";
|
import { PaginationPage } from "../browse/_components/Pagination";
|
||||||
import { assertExists } from "../../lib/utils";
|
import { assertExists, NonEmptyString } from "../../lib/utils";
|
||||||
import ICSSettings from "./_components/ICSSettings";
|
import ICSSettings from "./_components/ICSSettings";
|
||||||
import { roomAbsoluteUrl } from "../../lib/routesClient";
|
import { roomAbsoluteUrl } from "../../lib/routesClient";
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ export default function RoomsList() {
|
|||||||
items: topicOptions,
|
items: topicOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleCopyUrl = (roomName: string) => {
|
const handleCopyUrl = (roomName: NonEmptyString) => {
|
||||||
navigator.clipboard.writeText(roomAbsoluteUrl(roomName)).then(() => {
|
navigator.clipboard.writeText(roomAbsoluteUrl(roomName)).then(() => {
|
||||||
setLinkCopied(roomName);
|
setLinkCopied(roomName);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ import {
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { formatDateTime, formatStartedAgo } from "../lib/timeUtils";
|
import { formatDateTime, formatStartedAgo } from "../lib/timeUtils";
|
||||||
import MeetingMinimalHeader from "../components/MeetingMinimalHeader";
|
import MeetingMinimalHeader from "../components/MeetingMinimalHeader";
|
||||||
|
import { NonEmptyString } from "../lib/utils";
|
||||||
|
|
||||||
type Meeting = components["schemas"]["Meeting"];
|
type Meeting = components["schemas"]["Meeting"];
|
||||||
|
|
||||||
interface MeetingSelectionProps {
|
interface MeetingSelectionProps {
|
||||||
roomName: string;
|
roomName: NonEmptyString;
|
||||||
isOwner: boolean;
|
isOwner: boolean;
|
||||||
isSharedRoom: boolean;
|
isSharedRoom: boolean;
|
||||||
authLoading: boolean;
|
authLoading: boolean;
|
||||||
@@ -47,7 +48,6 @@ export default function MeetingSelection({
|
|||||||
isCreatingMeeting = false,
|
isCreatingMeeting = false,
|
||||||
}: MeetingSelectionProps) {
|
}: MeetingSelectionProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const roomQuery = useRoomGetByName(roomName);
|
const roomQuery = useRoomGetByName(roomName);
|
||||||
const activeMeetingsQuery = useRoomActiveMeetings(roomName);
|
const activeMeetingsQuery = useRoomActiveMeetings(roomName);
|
||||||
const joinMeetingMutation = useRoomJoinMeeting();
|
const joinMeetingMutation = useRoomJoinMeeting();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { roomMeetingUrl, roomUrl as getRoomUrl } from "../lib/routes";
|
||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
@@ -20,7 +21,6 @@ import {
|
|||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { toaster } from "../components/ui/toaster";
|
import { toaster } from "../components/ui/toaster";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { notFound } from "next/navigation";
|
|
||||||
import { useRecordingConsent } from "../recordingConsentContext";
|
import { useRecordingConsent } from "../recordingConsentContext";
|
||||||
import {
|
import {
|
||||||
useMeetingAudioConsent,
|
useMeetingAudioConsent,
|
||||||
@@ -28,19 +28,28 @@ import {
|
|||||||
useRoomActiveMeetings,
|
useRoomActiveMeetings,
|
||||||
useRoomUpcomingMeetings,
|
useRoomUpcomingMeetings,
|
||||||
useRoomsCreateMeeting,
|
useRoomsCreateMeeting,
|
||||||
|
useRoomGetMeeting,
|
||||||
} from "../lib/apiHooks";
|
} from "../lib/apiHooks";
|
||||||
import type { components } from "../reflector-api";
|
import type { components } from "../reflector-api";
|
||||||
import MeetingSelection from "./MeetingSelection";
|
import MeetingSelection from "./MeetingSelection";
|
||||||
import useRoomMeeting from "./useRoomMeeting";
|
import useRoomDefaultMeeting from "./useRoomDefaultMeeting";
|
||||||
|
|
||||||
type Meeting = components["schemas"]["Meeting"];
|
type Meeting = components["schemas"]["Meeting"];
|
||||||
import { FaBars } from "react-icons/fa6";
|
import { FaBars } from "react-icons/fa6";
|
||||||
import { useAuth } from "../lib/AuthProvider";
|
import { useAuth } from "../lib/AuthProvider";
|
||||||
import { useWhereby } from "../lib/wherebyClient";
|
import { getWherebyUrl, useWhereby } from "../lib/wherebyClient";
|
||||||
|
import { useError } from "../(errors)/errorContext";
|
||||||
|
import {
|
||||||
|
assertExistsAndNonEmptyString,
|
||||||
|
NonEmptyString,
|
||||||
|
parseNonEmptyString,
|
||||||
|
} from "../lib/utils";
|
||||||
|
import { printApiError } from "../api/_error";
|
||||||
|
|
||||||
export type RoomDetails = {
|
export type RoomDetails = {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
roomName: string;
|
roomName: string;
|
||||||
|
meetingId?: string;
|
||||||
}>;
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -216,7 +225,7 @@ function ConsentDialogButton({
|
|||||||
meetingId,
|
meetingId,
|
||||||
wherebyRef,
|
wherebyRef,
|
||||||
}: {
|
}: {
|
||||||
meetingId: string;
|
meetingId: NonEmptyString;
|
||||||
wherebyRef: React.RefObject<HTMLElement>;
|
wherebyRef: React.RefObject<HTMLElement>;
|
||||||
}) {
|
}) {
|
||||||
const { showConsentModal, consentState, hasConsent, consentLoading } =
|
const { showConsentModal, consentState, hasConsent, consentLoading } =
|
||||||
@@ -252,37 +261,55 @@ export default function Room(details: RoomDetails) {
|
|||||||
const params = use(details.params);
|
const params = use(details.params);
|
||||||
const wherebyLoaded = useWhereby();
|
const wherebyLoaded = useWhereby();
|
||||||
const wherebyRef = useRef<HTMLElement>(null);
|
const wherebyRef = useRef<HTMLElement>(null);
|
||||||
const roomName = params.roomName;
|
const roomName = parseNonEmptyString(params.roomName);
|
||||||
useRoomMeeting(roomName);
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
const status = auth.status;
|
const status = auth.status;
|
||||||
const isAuthenticated = status === "authenticated";
|
const isAuthenticated = status === "authenticated";
|
||||||
|
const { setError } = useError();
|
||||||
|
|
||||||
const roomQuery = useRoomGetByName(roomName);
|
const roomQuery = useRoomGetByName(roomName);
|
||||||
const createMeetingMutation = useRoomsCreateMeeting();
|
const createMeetingMutation = useRoomsCreateMeeting();
|
||||||
|
|
||||||
const room = roomQuery.data;
|
const room = roomQuery.data;
|
||||||
|
|
||||||
// For non-ICS rooms, create a meeting and get Whereby URL
|
const pageMeetingId = params.meetingId;
|
||||||
const roomMeeting = useRoomMeeting(
|
|
||||||
room && !room.ics_enabled ? roomName : null,
|
// this one is called on room page
|
||||||
|
const defaultMeeting = useRoomDefaultMeeting(
|
||||||
|
room && !room.ics_enabled && !pageMeetingId ? roomName : null,
|
||||||
);
|
);
|
||||||
const roomUrl =
|
|
||||||
roomMeeting?.response?.host_room_url || roomMeeting?.response?.room_url;
|
const explicitMeeting = useRoomGetMeeting(roomName, pageMeetingId || null);
|
||||||
|
const wherebyRoomUrl = explicitMeeting.data
|
||||||
|
? getWherebyUrl(explicitMeeting.data)
|
||||||
|
: defaultMeeting.response
|
||||||
|
? getWherebyUrl(defaultMeeting.response)
|
||||||
|
: null;
|
||||||
|
const recordingType = (explicitMeeting.data || defaultMeeting.response)
|
||||||
|
?.recording_type;
|
||||||
|
const meetingId = (explicitMeeting.data || defaultMeeting.response)?.id;
|
||||||
|
|
||||||
const isLoading =
|
const isLoading =
|
||||||
status === "loading" || roomQuery.isLoading || roomMeeting?.loading;
|
status === "loading" ||
|
||||||
|
roomQuery.isLoading ||
|
||||||
|
defaultMeeting?.loading ||
|
||||||
|
explicitMeeting.isLoading;
|
||||||
|
|
||||||
|
const errors = [
|
||||||
|
explicitMeeting.error,
|
||||||
|
defaultMeeting.error,
|
||||||
|
roomQuery.error,
|
||||||
|
createMeetingMutation.error,
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
const isOwner =
|
const isOwner =
|
||||||
isAuthenticated && room ? auth.user?.id === room.user_id : false;
|
isAuthenticated && room ? auth.user?.id === room.user_id : false;
|
||||||
|
|
||||||
const meetingId = roomMeeting?.response?.id;
|
|
||||||
|
|
||||||
const recordingType = roomMeeting?.response?.recording_type;
|
|
||||||
|
|
||||||
const handleMeetingSelect = (selectedMeeting: Meeting) => {
|
const handleMeetingSelect = (selectedMeeting: Meeting) => {
|
||||||
router.push(`/${roomName}/${selectedMeeting.id}`);
|
router.push(
|
||||||
|
roomMeetingUrl(roomName, parseNonEmptyString(selectedMeeting.id)),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCreateUnscheduled = async () => {
|
const handleCreateUnscheduled = async () => {
|
||||||
@@ -307,25 +334,21 @@ export default function Room(details: RoomDetails) {
|
|||||||
}, [router]);
|
}, [router]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (isLoading || !isAuthenticated || !wherebyRoomUrl || !wherebyLoaded)
|
||||||
!isLoading &&
|
return;
|
||||||
(roomQuery.isError || roomMeeting?.error) &&
|
|
||||||
"status" in (roomQuery.error || roomMeeting?.error || {}) &&
|
|
||||||
(roomQuery.error as any)?.status === 404
|
|
||||||
) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
}, [isLoading, roomQuery.error, roomMeeting?.error]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isLoading || !isAuthenticated || !roomUrl || !wherebyLoaded) return;
|
|
||||||
|
|
||||||
wherebyRef.current?.addEventListener("leave", handleLeave);
|
wherebyRef.current?.addEventListener("leave", handleLeave);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
wherebyRef.current?.removeEventListener("leave", handleLeave);
|
wherebyRef.current?.removeEventListener("leave", handleLeave);
|
||||||
};
|
};
|
||||||
}, [handleLeave, roomUrl, isLoading, isAuthenticated, wherebyLoaded]);
|
}, [handleLeave, wherebyRoomUrl, isLoading, isAuthenticated, wherebyLoaded]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isLoading && !wherebyRoomUrl) {
|
||||||
|
setError(new Error("Whereby room URL not found"));
|
||||||
|
}
|
||||||
|
}, [isLoading, wherebyRoomUrl]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -357,7 +380,7 @@ export default function Room(details: RoomDetails) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (room.ics_enabled) {
|
if (room.ics_enabled && !params.meetingId) {
|
||||||
return (
|
return (
|
||||||
<MeetingSelection
|
<MeetingSelection
|
||||||
roomName={roomName}
|
roomName={roomName}
|
||||||
@@ -371,22 +394,42 @@ export default function Room(details: RoomDetails) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For non-ICS rooms, show Whereby embed directly
|
if (errors.length > 0) {
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
display="flex"
|
||||||
|
justifyContent="center"
|
||||||
|
alignItems="center"
|
||||||
|
height="100vh"
|
||||||
|
bg="gray.50"
|
||||||
|
p={4}
|
||||||
|
>
|
||||||
|
{errors.map((error, i) => (
|
||||||
|
<Text key={i} fontSize="lg">
|
||||||
|
{printApiError(error)}
|
||||||
|
</Text>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{roomUrl && meetingId && wherebyLoaded && (
|
{wherebyRoomUrl && wherebyLoaded && (
|
||||||
<>
|
<>
|
||||||
<whereby-embed
|
<whereby-embed
|
||||||
ref={wherebyRef}
|
ref={wherebyRef}
|
||||||
room={roomUrl}
|
room={wherebyRoomUrl}
|
||||||
style={{ width: "100vw", height: "100vh" }}
|
style={{ width: "100vw", height: "100vh" }}
|
||||||
/>
|
/>
|
||||||
{recordingType && recordingTypeRequiresConsent(recordingType) && (
|
{recordingType &&
|
||||||
<ConsentDialogButton
|
recordingTypeRequiresConsent(recordingType) &&
|
||||||
meetingId={meetingId}
|
meetingId && (
|
||||||
wherebyRef={wherebyRef}
|
<ConsentDialogButton
|
||||||
/>
|
meetingId={assertExistsAndNonEmptyString(meetingId)}
|
||||||
)}
|
wherebyRef={wherebyRef}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -6,30 +6,31 @@ import { shouldShowError } from "../lib/errorUtils";
|
|||||||
type Meeting = components["schemas"]["Meeting"];
|
type Meeting = components["schemas"]["Meeting"];
|
||||||
import { useRoomsCreateMeeting } from "../lib/apiHooks";
|
import { useRoomsCreateMeeting } from "../lib/apiHooks";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
|
import { ApiError } from "../api/_error";
|
||||||
|
|
||||||
type ErrorMeeting = {
|
type ErrorMeeting = {
|
||||||
error: Error;
|
error: ApiError;
|
||||||
loading: false;
|
loading: false;
|
||||||
response: null;
|
response: null;
|
||||||
reload: () => void;
|
reload: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type LoadingMeeting = {
|
type LoadingMeeting = {
|
||||||
|
error: null;
|
||||||
response: null;
|
response: null;
|
||||||
loading: true;
|
loading: true;
|
||||||
error: false;
|
|
||||||
reload: () => void;
|
reload: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SuccessMeeting = {
|
type SuccessMeeting = {
|
||||||
|
error: null;
|
||||||
response: Meeting;
|
response: Meeting;
|
||||||
loading: false;
|
loading: false;
|
||||||
error: null;
|
|
||||||
reload: () => void;
|
reload: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useRoomMeeting = (
|
const useRoomDefaultMeeting = (
|
||||||
roomName: string | null | undefined,
|
roomName: string | null,
|
||||||
): ErrorMeeting | LoadingMeeting | SuccessMeeting => {
|
): ErrorMeeting | LoadingMeeting | SuccessMeeting => {
|
||||||
const [response, setResponse] = useState<Meeting | null>(null);
|
const [response, setResponse] = useState<Meeting | null>(null);
|
||||||
const [reload, setReload] = useState(0);
|
const [reload, setReload] = useState(0);
|
||||||
@@ -44,7 +45,6 @@ const useRoomMeeting = (
|
|||||||
if (!roomName) return;
|
if (!roomName) return;
|
||||||
if (creatingRef.current) return;
|
if (creatingRef.current) return;
|
||||||
|
|
||||||
// For any case where we need a meeting (with or without meetingId),
|
|
||||||
const createMeeting = async () => {
|
const createMeeting = async () => {
|
||||||
creatingRef.current = true;
|
creatingRef.current = true;
|
||||||
try {
|
try {
|
||||||
@@ -78,7 +78,7 @@ const useRoomMeeting = (
|
|||||||
}, [roomName, reload]);
|
}, [roomName, reload]);
|
||||||
|
|
||||||
const loading = createMeetingMutation.isPending && !response;
|
const loading = createMeetingMutation.isPending && !response;
|
||||||
const error = createMeetingMutation.error as Error | null;
|
const error = createMeetingMutation.error;
|
||||||
|
|
||||||
return { response, loading, error, reload: reloadHandler } as
|
return { response, loading, error, reload: reloadHandler } as
|
||||||
| ErrorMeeting
|
| ErrorMeeting
|
||||||
@@ -86,4 +86,4 @@ const useRoomMeeting = (
|
|||||||
| SuccessMeeting;
|
| SuccessMeeting;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useRoomMeeting;
|
export default useRoomDefaultMeeting;
|
||||||
26
www/app/api/_error.ts
Normal file
26
www/app/api/_error.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { components } from "../reflector-api";
|
||||||
|
import { isArray } from "remeda";
|
||||||
|
|
||||||
|
export type ApiError = {
|
||||||
|
detail?: components["schemas"]["ValidationError"][];
|
||||||
|
} | null;
|
||||||
|
|
||||||
|
// errors as declared on api types is not != as they in reality e.g. detail may be a string
|
||||||
|
export const printApiError = (error: ApiError) => {
|
||||||
|
if (!error || !error.detail) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const detail = error.detail as unknown;
|
||||||
|
if (isArray(error.detail)) {
|
||||||
|
return error.detail.map((e) => e.msg).join(", ");
|
||||||
|
}
|
||||||
|
if (typeof detail === "string") {
|
||||||
|
if (detail.length > 0) {
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
console.error("Error detail is empty");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
console.error("Error detail is not a string or array");
|
||||||
|
return null;
|
||||||
|
};
|
||||||
@@ -5,9 +5,10 @@ import NextLink from "next/link";
|
|||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { roomUrl } from "../lib/routes";
|
import { roomUrl } from "../lib/routes";
|
||||||
|
import { NonEmptyString } from "../lib/utils";
|
||||||
|
|
||||||
interface MeetingMinimalHeaderProps {
|
interface MeetingMinimalHeaderProps {
|
||||||
roomName: string;
|
roomName: NonEmptyString;
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
showLeaveButton?: boolean;
|
showLeaveButton?: boolean;
|
||||||
onLeave?: () => void;
|
onLeave?: () => void;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { useAuth } from "./AuthProvider";
|
|||||||
* or, limitation or incorrect usage of .d type generator from json schema
|
* or, limitation or incorrect usage of .d type generator from json schema
|
||||||
* */
|
* */
|
||||||
|
|
||||||
const useAuthReady = () => {
|
export const useAuthReady = () => {
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -695,8 +695,6 @@ const MEETING_LIST_PATH_PARTIALS = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export function useRoomActiveMeetings(roomName: string | null) {
|
export function useRoomActiveMeetings(roomName: string | null) {
|
||||||
const { isAuthenticated } = useAuthReady();
|
|
||||||
|
|
||||||
return $api.useQuery(
|
return $api.useQuery(
|
||||||
"get",
|
"get",
|
||||||
"/v1/rooms/{room_name}/meetings/active" satisfies `/v1/rooms/{room_name}/${typeof MEETINGS_ACTIVE_PATH_PARTIAL}`,
|
"/v1/rooms/{room_name}/meetings/active" satisfies `/v1/rooms/{room_name}/${typeof MEETINGS_ACTIVE_PATH_PARTIAL}`,
|
||||||
@@ -706,7 +704,28 @@ export function useRoomActiveMeetings(roomName: string | null) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!roomName && isAuthenticated,
|
enabled: !!roomName,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRoomGetMeeting(
|
||||||
|
roomName: string | null,
|
||||||
|
meetingId: string | null,
|
||||||
|
) {
|
||||||
|
return $api.useQuery(
|
||||||
|
"get",
|
||||||
|
"/v1/rooms/{room_name}/meetings/{meeting_id}",
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
path: {
|
||||||
|
room_name: roomName!,
|
||||||
|
meeting_id: meetingId!,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: !!roomName && !!meetingId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,7 @@
|
|||||||
export const roomUrl = (roomName: string) => `/${roomName}`;
|
import { NonEmptyString } from "./utils";
|
||||||
|
|
||||||
|
export const roomUrl = (roomName: NonEmptyString) => `/${roomName}`;
|
||||||
|
export const roomMeetingUrl = (
|
||||||
|
roomName: NonEmptyString,
|
||||||
|
meetingId: NonEmptyString,
|
||||||
|
) => `${roomUrl(roomName)}/${meetingId}`;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { roomUrl } from "./routes";
|
import { roomUrl } from "./routes";
|
||||||
|
import { NonEmptyString } from "./utils";
|
||||||
|
|
||||||
export const roomAbsoluteUrl = (roomName: string) =>
|
export const roomAbsoluteUrl = (roomName: NonEmptyString) =>
|
||||||
`${window.location.origin}${roomUrl(roomName)}`;
|
`${window.location.origin}${roomUrl(roomName)}`;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { components } from "../reflector-api";
|
||||||
|
|
||||||
export const useWhereby = () => {
|
export const useWhereby = () => {
|
||||||
const [wherebyLoaded, setWherebyLoaded] = useState(false);
|
const [wherebyLoaded, setWherebyLoaded] = useState(false);
|
||||||
@@ -13,3 +14,9 @@ export const useWhereby = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
return wherebyLoaded;
|
return wherebyLoaded;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getWherebyUrl = (
|
||||||
|
meeting: Pick<components["schemas"]["Meeting"], "room_url" | "host_room_url">,
|
||||||
|
) =>
|
||||||
|
// host_room_url possible '' atm
|
||||||
|
meeting.host_room_url || meeting.room_url;
|
||||||
|
|||||||
52
www/app/reflector-api.d.ts
vendored
52
www/app/reflector-api.d.ts
vendored
@@ -234,6 +234,26 @@ export interface paths {
|
|||||||
patch?: never;
|
patch?: never;
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
|
"/v1/rooms/{room_name}/meetings/{meeting_id}": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Rooms Get Meeting
|
||||||
|
* @description Get a single meeting by ID within a specific room.
|
||||||
|
*/
|
||||||
|
get: operations["v1_rooms_get_meeting"];
|
||||||
|
put?: never;
|
||||||
|
post?: never;
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
"/v1/rooms/{room_name}/meetings/{meeting_id}/join": {
|
"/v1/rooms/{room_name}/meetings/{meeting_id}/join": {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -1993,6 +2013,38 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
v1_rooms_get_meeting: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
room_name: string;
|
||||||
|
meeting_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["Meeting"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
v1_rooms_join_meeting: {
|
v1_rooms_join_meeting: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useEffect, useState, use } from "react";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import useRoomMeeting from "../../[roomName]/useRoomMeeting";
|
import useRoomDefaultMeeting from "../../[roomName]/useRoomDefaultMeeting";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
const WherebyEmbed = dynamic(() => import("../../lib/WherebyWebinarEmbed"), {
|
const WherebyEmbed = dynamic(() => import("../../lib/WherebyWebinarEmbed"), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@@ -72,7 +72,7 @@ export default function WebinarPage(details: WebinarDetails) {
|
|||||||
const startDate = new Date(Date.parse(webinar.startsAt));
|
const startDate = new Date(Date.parse(webinar.startsAt));
|
||||||
const endDate = new Date(Date.parse(webinar.endsAt));
|
const endDate = new Date(Date.parse(webinar.endsAt));
|
||||||
|
|
||||||
const meeting = useRoomMeeting(ROOM_NAME);
|
const meeting = useRoomDefaultMeeting(ROOM_NAME);
|
||||||
const roomUrl = meeting?.response?.host_room_url
|
const roomUrl = meeting?.response?.host_room_url
|
||||||
? meeting?.response?.host_room_url
|
? meeting?.response?.host_room_url
|
||||||
: meeting?.response?.room_url;
|
: meeting?.response?.room_url;
|
||||||
|
|||||||
Reference in New Issue
Block a user