Skip to content

Commit

Permalink
Change to functions (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigridge authored Oct 11, 2023
1 parent d2388d1 commit b910e9f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
40 changes: 20 additions & 20 deletions frontend/src/components/vibes-buttons/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { useMsal } from "@azure/msal-react";
import LoginIcon from "@mui/icons-material/Login";
import { IconButton } from "@mui/material";

const SignInButton = () => {
const { instance } = useMsal();
export default function SignInButton() {
const { instance } = useMsal();

const handleLogin = () => {
instance.loginRedirect(loginRequest).catch((e) => { console.error(`loginRedirect failed: ${e}`) })
};
function handleLogin() {
instance.loginRedirect(loginRequest).catch((e) => {
console.error(`loginRedirect failed: ${e}`);
});
}

return (
<div>
<IconButton
onClick={handleLogin}
size="small"
color="inherit"
sx={{ ml: 2 }}
>
<LoginIcon />
</IconButton>
</div>
)
};

export default SignInButton;
return (
<div>
<IconButton
onClick={handleLogin}
size="small"
color="inherit"
sx={{ ml: 2 }}
>
<LoginIcon />
</IconButton>
</div>
);
}
27 changes: 14 additions & 13 deletions frontend/src/components/vibes-buttons/SignInSignOutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import { useIsAuthenticated, useMsal } from "@azure/msal-react";
import SignInButton from "./SignInButton";
import SignOutButton from "./SignOutButton";

const SignInSignOutButton = () => {
const { inProgress } = useMsal();
const isAuthenticated = useIsAuthenticated();
export default function SignInSignOutButton() {
const { inProgress } = useMsal();
const isAuthenticated = useIsAuthenticated();

if (isAuthenticated) {
return <SignOutButton />;
} else if (inProgress !== InteractionStatus.Startup && inProgress !== InteractionStatus.HandleRedirect) {
// inProgress check prevents sign-in button from being displayed briefly after returning from a redirect sign-in. Processing the server response takes a render cycle or two
return <SignInButton />;
} else {
return null;
}
if (isAuthenticated) {
return <SignOutButton />;
} else if (
inProgress !== InteractionStatus.Startup &&
inProgress !== InteractionStatus.HandleRedirect
) {
// inProgress check prevents sign-in button from being displayed briefly after returning from a redirect sign-in. Processing the server response takes a render cycle or two
return <SignInButton />;
} else {
return null;
}
}

export default SignInSignOutButton;
4 changes: 2 additions & 2 deletions frontend/src/components/vibes-buttons/SignOutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export default function SignOutButton() {
const [anchorEl, setAnchorEl] = useState<AnchorProp>(null);
const open = Boolean(anchorEl);

const handleLogout = () => {
function handleLogout() {
instance.logoutRedirect().catch((e) => {
console.error(`logoutPopup failed: ${e}`);
});
};
}

return (
<div>
Expand Down

0 comments on commit b910e9f

Please sign in to comment.