Skip to content

Commit

Permalink
fix: leave prompt, hide leave options if missing permissions (#1935)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 authored Sep 19, 2023
2 parents 9069479 + 6c5e4e1 commit 5cbe08a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const DesktopLeaveRoom = ({
const permissions = useHMSStore(selectPermissions);
const { isStreamingOn } = useRecordingStreaming();
const showStream = screenType !== 'hls_live_streaming' && isStreamingOn;
const showLeaveOptions = (permissions?.hlsStreaming && isStreamingOn) || permissions?.endRoom;

useDropdownList({ open: open || showEndStreamAlert || showLeaveRoomAlert, name: 'LeaveRoom' });

Expand All @@ -38,7 +39,7 @@ export const DesktopLeaveRoom = ({

return (
<Fragment>
{screenType !== 'hls_live_streaming' && (permissions?.hlsStreaming || permissions?.endRoom) ? (
{showLeaveOptions ? (
<Flex>
<LeaveIconButton
key="LeaveRoom"
Expand All @@ -47,9 +48,7 @@ export const DesktopLeaveRoom = ({
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
}}
onClick={() => {
leaveRoom({ endstream: false });
}}
onClick={() => setShowLeaveRoomAlert(true)}
>
<Tooltip title="Leave Room">
<Box>
Expand Down Expand Up @@ -92,42 +91,37 @@ export const DesktopLeaveRoom = ({
css={{ p: 0 }}
/>
</Dropdown.Item>
{permissions?.endRoom || permissions?.hlsStreaming ? (
<Dropdown.Item
css={{
bg: '$alert_error_dim',
color: '$alert_error_bright',
'&:hover': { bg: '$alert_error_dim', color: '$alert_error_brighter' },

<Dropdown.Item
css={{
bg: '$alert_error_dim',
color: '$alert_error_bright',
'&:hover': { bg: '$alert_error_dim', color: '$alert_error_brighter' },
}}
data-testid="end_room_btn"
>
<LeaveCard
title={showStream ? 'End Stream' : 'End Session'}
subtitle={`The ${
showStream ? 'stream' : 'session'
} will end for everyone. You can't undo this action.`}
bg=""
titleColor="$alert_error_brighter"
icon={<StopIcon height={24} width={24} />}
onClick={() => {
setOpen(false);
setShowEndStreamAlert(true);
}}
data-testid="end_room_btn"
>
<LeaveCard
title={showStream ? 'End Stream' : 'End Session'}
subtitle={`The ${
showStream ? 'stream' : 'session'
} will end for everyone. You can't undo this action.`}
bg=""
titleColor="$alert_error_brighter"
icon={<StopIcon height={24} width={24} />}
onClick={() => {
setOpen(false);
setShowEndStreamAlert(true);
}}
css={{ p: 0 }}
/>
</Dropdown.Item>
) : null}
css={{ p: 0 }}
/>
</Dropdown.Item>
</Dropdown.Content>
</Dropdown.Root>
</Flex>
) : (
<LeaveIconButton
onClick={() => {
if (screenType === 'hls_live_streaming') {
setShowLeaveRoomAlert(true);
} else {
leaveRoom({ endstream: false });
}
setShowLeaveRoomAlert(true);
}}
key="LeaveRoom"
data-testid="leave_room_btn"
Expand All @@ -154,16 +148,14 @@ export const DesktopLeaveRoom = ({
</Dialog.Portal>
</Dialog.Root>

{screenType === 'hls_live_streaming' ? (
<Dialog.Root open={showLeaveRoomAlert} modal={false}>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content css={{ w: 'min(420px, 90%)', p: '$8', bg: '$surface_dim' }}>
<LeaveSessionContent setShowLeaveRoomAlert={setShowLeaveRoomAlert} leaveRoom={leaveRoom} isModal />
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
) : null}
<Dialog.Root open={showLeaveRoomAlert} modal={false}>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content css={{ w: 'min(420px, 90%)', p: '$8', bg: '$surface_dim' }}>
<LeaveSessionContent setShowLeaveRoomAlert={setShowLeaveRoomAlert} leaveRoom={leaveRoom} isModal />
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const MwebLeaveRoom = ({
const permissions = useHMSStore(selectPermissions);
const { isStreamingOn } = useRecordingStreaming();
const showStream = screenType !== 'hls_live_streaming' && isStreamingOn;
const showLeaveOptions = (permissions?.hlsStreaming && isStreamingOn) || permissions?.endRoom;

useDropdownList({ open, name: 'LeaveRoom' });

Expand All @@ -39,7 +40,7 @@ export const MwebLeaveRoom = ({

return (
<Fragment>
{screenType !== 'hls_live_streaming' ? (
{showLeaveOptions ? (
<Sheet.Root open={open} onOpenChange={setOpen}>
<Sheet.Trigger asChild>
<LeaveIconButton
Expand Down Expand Up @@ -70,36 +71,24 @@ export const MwebLeaveRoom = ({
css={{ pt: 0, mt: '$10', color: '$on_surface_low', '&:hover': { color: '$on_surface_high' } }}
/>

{permissions?.endRoom || permissions?.hlsStreaming ? (
<LeaveCard
title={showStream ? 'End Stream' : 'End Session'}
subtitle={`The will end the ${
showStream ? 'stream' : 'session'
} for everyone. You can't undo this action.`}
bg="$alert_error_dim"
titleColor="$alert_error_brighter"
css={{ color: '$alert_error_bright', '&:hover': { color: '$alert_error_brighter' } }}
icon={<StopIcon height={24} width={24} />}
onClick={() => {
setOpen(false);
setShowEndStreamAlert(true);
}}
/>
) : null}
<LeaveCard
title={showStream ? 'End Stream' : 'End Session'}
subtitle={`The will end the ${
showStream ? 'stream' : 'session'
} for everyone. You can't undo this action.`}
bg="$alert_error_dim"
titleColor="$alert_error_brighter"
css={{ color: '$alert_error_bright', '&:hover': { color: '$alert_error_brighter' } }}
icon={<StopIcon height={24} width={24} />}
onClick={() => {
setOpen(false);
setShowEndStreamAlert(true);
}}
/>
</Sheet.Content>
</Sheet.Root>
) : (
<LeaveIconButton
key="LeaveRoom"
data-testid="leave_room_btn"
onClick={() => {
if (screenType === 'hls_live_streaming') {
setShowLeaveRoomAlert(true);
} else {
leaveRoom({ endstream: false });
}
}}
>
<LeaveIconButton key="LeaveRoom" data-testid="leave_room_btn" onClick={() => setShowLeaveRoomAlert(true)}>
<Tooltip title="Leave Room">
<Box>
<ExitIcon style={{ transform: 'rotate(180deg)' }} />
Expand All @@ -116,13 +105,12 @@ export const MwebLeaveRoom = ({
/>
</Sheet.Content>
</Sheet.Root>
{screenType === 'hls_live_streaming' ? (
<Sheet.Root open={showLeaveRoomAlert} onOpenChange={setShowLeaveRoomAlert}>
<Sheet.Content css={{ bg: '$surface_dim', p: '$10', pb: '$12' }}>
<LeaveSessionContent setShowLeaveRoomAlert={setShowLeaveRoomAlert} leaveRoom={leaveRoom} />
</Sheet.Content>
</Sheet.Root>
) : null}

<Sheet.Root open={showLeaveRoomAlert} onOpenChange={setShowLeaveRoomAlert}>
<Sheet.Content css={{ bg: '$surface_dim', p: '$10', pb: '$12' }}>
<LeaveSessionContent setShowLeaveRoomAlert={setShowLeaveRoomAlert} leaveRoom={leaveRoom} />
</Sheet.Content>
</Sheet.Root>
</Fragment>
);
};

0 comments on commit 5cbe08a

Please sign in to comment.