Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open repo button #19

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/parking-place/react-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
4 changes: 2 additions & 2 deletions src/parking-place/react-app/src/components/Header/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AppBar from "@mui/material/AppBar";
import Toolbar from "@mui/material/Toolbar";
import IconButton from "@mui/material/IconButton";
import MenuIcon from "@mui/icons-material/Menu";
import LoginButton from "./LoginButton";
import PageFunctionsButton from "./PageFunctionButton";
import { NavBarStyles } from "./styles";
import { useTheme } from "@mui/material";

Expand Down Expand Up @@ -31,7 +31,7 @@ export default function NavBar() {
loading="eager"
/>

<LoginButton />
<PageFunctionsButton />
</Toolbar>
</AppBar>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { useOidcAuthentication } from "@sensenet/authentication-oidc-react";
import { Button, IconButton, Menu, MenuItem, useTheme } from "@mui/material";
import AccountCircle from "@mui/icons-material/AccountCircle";
import { LoginButtonStyle } from "./styles";
import { useRepository } from "@sensenet/hooks-react";
import { sensenetAdminUrl } from "../../utils/configurations";

function LoginButton() {
function PageFunctionsButton() {
const { oidcUser, login, logout } = useOidcAuthentication();
const theme = useTheme();
const styles = LoginButtonStyle(theme);

const repository = useRepository();

const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);

const handleMenu = (event: React.MouseEvent<HTMLElement>) => {
Expand All @@ -19,6 +23,18 @@ function LoginButton() {
setAnchorEl(null);
};

const handleOpenRepo = () => {
const url = new URL(process.env.REACT_APP_AdminUrl || sensenetAdminUrl);

url.searchParams.append(
"repoUrl",
encodeURI(repository.configuration.repositoryUrl)
);

window.open(url.toString(), "_blank");
setAnchorEl(null);
};

if (!oidcUser) {
return (
<Button variant="outlined" onClick={login} sx={styles.LoginButton}>
Expand Down Expand Up @@ -54,11 +70,11 @@ function LoginButton() {
open={Boolean(anchorEl)}
onClose={handleClose}
>
<MenuItem onClick={handleClose}>Open Repository</MenuItem>
<MenuItem onClick={handleOpenRepo}>Open Repository</MenuItem>
<MenuItem onClick={logout}>Log out</MenuItem>
</Menu>
</>
);
}

export default LoginButton;
export default PageFunctionsButton;
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { useEffect } from "react";
import { redirect } from "react-router";

export const NotAuthenticatedOverride = () => {
useEffect(() => {
console.log("Redirecting");
window.location.replace("/");
}, []);
redirect("/");

return null;
};
12 changes: 9 additions & 3 deletions src/parking-place/react-app/src/utils/configurations.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
export const repositoryUrl = "https://sampleapps.test.sensenet.cloud";
export const repositoryUrl =
process.env.REACT_APP_RepoUrl || "https://sampleapps.test.sensenet.cloud";

export const configuration = {
client_id: "TdDZR9am6OVoYQgZ", // clientID of your repository
client_id: process.env.REACT_APP_ClientId || "TdDZR9am6OVoYQgZ", // clientID of your repository
automaticSilentRenew: true,
redirect_uri: `${window.location.origin}/authentication/login_callback`,
response_type: "code",
post_logout_redirect_uri: `${window.location.origin}/`,
scope: "openid profile sensenet",
authority: "https://sampleapps-is.test.sensenet.cloud",
authority:
process.env.REACT_APP_Authority ||
"https://sampleapps-is.test.sensenet.cloud",
silent_redirect_uri: `${window.location.origin}/authentication/silent_callback`,
extraQueryParams: { snrepo: repositoryUrl },
};

export const sensenetAdminUrl =
process.env.REACT_APP_AdminUrl || "https://admin.sensenet.com/";
Loading