Skip to content

Commit

Permalink
Merge branch 'main' into feat/use-call-link-as-join-link
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazuh authored Oct 29, 2023
2 parents a78fc5c + f12aa58 commit 9abeef7
Show file tree
Hide file tree
Showing 15 changed files with 390 additions and 37 deletions.
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import P2PCallMain from "./features/p2p-call/P2PCallMain";
import CallCreationMain from "./features/call-selection/CallCreationMain";
import CallJoinMain from "./features/call-selection/CallJoinMain";
import PendingUserMain from "./features/call-selection/PendingUserMain";
import useValidateSession from "./hooks/useValidateSession";
import BlockedSession from "./features/auth/BlockedSession";

export default function App() {
useValidateSession();
const dispatch = useAppDispatch();

useEffect(() => {
Expand All @@ -29,6 +32,7 @@ export default function App() {
<Route path="/join" component={CallJoinMain} />
<Route path="/left" component={() => <p>Left.</p>} />
<Route path="/p2p-call/:callUid" component={P2PCallMain} />
<Route path="/blocked-session" component={BlockedSession} />
<Route>
<Redirect to="/" />
</Route>
Expand Down
3 changes: 2 additions & 1 deletion src/components/basic/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const Video = forwardRef<HTMLVideoElement | null, VideoProps>(
...sx,
height: {
xs: "120px",
md: "350px",
md: "230px",
xl: "315px",
},
objectFit: "scale-down",
}}
Expand Down
21 changes: 21 additions & 0 deletions src/components/templates/HomeTemplate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,25 @@ describe("HomeTemplate", () => {
)
).toBe(null);
});

it("does not show logout and settings buttons when user session is blocked", () => {
fullRender(
<HomeTemplate>
<p>Hello World!</p>
</HomeTemplate>,
{
preloadedState: {
user: {
...userInitialState,
uid: "123",
status: "authenticated",
isSessionBlocked: true,
},
},
}
);

expect(screen.queryByLabelText("Logout")).toBe(null);
expect(screen.queryByLabelText("Settings")).toBe(null);
});
});
25 changes: 16 additions & 9 deletions src/components/templates/HomeTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import mainCharWhiteOutlineImg from "../../assets/main-char-white-outline.png";
import mainCharPinkOutlineImg from "../../assets/main-char-pink-outline.png";
import { useAppDispatch, useAppSelector } from "../../state";
import useAgentHelper from "../../hooks/useAgentHelper";
import { logout, selectIsUserAuthenticated } from "../../state/user";
import {
logout,
selectIsSessionBlocked,
selectIsUserAuthenticated,
} from "../../state/user";
import SettingsModal from "../settings/SettingsModal";
import ErrorAlert from "../basic/ErrorAlert";
import WarningAlert from "../basic/WarningAlert";
Expand All @@ -32,6 +36,7 @@ export default function HomeTemplate({
const handleLogoutClick = () => dispatch(logout());

const isAuthenticated = useAppSelector(selectIsUserAuthenticated);
const isSessionBlocked = useAppSelector(selectIsSessionBlocked);

const { canRunWebRTC, isChromeBased, isFirefoxBased } = useAgentHelper();

Expand Down Expand Up @@ -92,7 +97,7 @@ export default function HomeTemplate({
pb: 1,
}}
>
{isAuthenticated && (
{isAuthenticated && !isSessionBlocked && (
<IconButton
aria-label="Logout"
title="Logout"
Expand All @@ -103,13 +108,15 @@ export default function HomeTemplate({
<LogoutIcon />
</IconButton>
)}
<IconButton
aria-label="Settings"
title="Settings"
onClick={openSettings}
>
<SettingsIcon />
</IconButton>
{!isSessionBlocked && (
<IconButton
aria-label="Settings"
title="Settings"
onClick={openSettings}
>
<SettingsIcon />
</IconButton>
)}
</Box>
</Box>
{!canRunWebRTC() && (
Expand Down
10 changes: 10 additions & 0 deletions src/features/auth/BlockedSession.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import "../../testing-helpers/mock-firestore-auth";
import { act } from "react-dom/test-utils";
import fullRender from "../../testing-helpers/fullRender";
import BlockedSession from "./BlockedSession";

describe("BlockedSession", () => {
it("renders", async () => {
await act(() => fullRender(<BlockedSession />));
});
});
21 changes: 21 additions & 0 deletions src/features/auth/BlockedSession.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Box from "@mui/material/Box";
import HomeTemplate from "../../components/templates/HomeTemplate";
import useRedirectionRule from "../../hooks/useRedirectionRule";
import { Redirect } from "wouter";
import ErrorAlert from "../../components/basic/ErrorAlert";

export default function BlockedSession() {
const goTo = useRedirectionRule();

if (goTo) {
return <Redirect to={goTo} />;
}

return (
<HomeTemplate>
<Box component="span" pr={1}>
<ErrorAlert message="Account in use in another device. Reload to restore this session." />
</Box>
</HomeTemplate>
);
}
11 changes: 9 additions & 2 deletions src/features/p2p-call/P2PCallMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ export default function P2PCallMain() {

const getSlotStyles = useCallback((): BoxProps["sx"] => {
return {
flexBasis: "35%",
margin: 1,
flexBasis: "30%",
margin: {
xs: 0,
md: 1,
},
width: "100%",
};
}, []);
Expand Down Expand Up @@ -125,6 +128,10 @@ export default function P2PCallMain() {
xs: "grid",
md: "flex",
},
flexWrap: {
xs: "unset",
md: "wrap",
},
gridTemplateColumns: landscape ? "repeat(5, auto)" : "auto auto",
gap: 1,
alignItems: "center",
Expand Down
Loading

0 comments on commit 9abeef7

Please sign in to comment.