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

Reroute to login page #1767

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
23 changes: 16 additions & 7 deletions src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { SHOGunAPIClient } from '@terrestris/shogun-util/dist/service/SHOGunAPIC

const App = React.lazy(() => import('./App'));

import RerouteToLogin from './components/RerouteToLogin';
import {
PluginProvider
} from './context/PluginContext';
Expand Down Expand Up @@ -811,6 +812,7 @@ const renderApp = async () => {
}

let type: AlertProps['type'] = 'warning';
let action: React.ReactNode;
let errorDescription = i18n.t('Index.errorDescription');

if ((error as Error)?.message === LoadingErrorCode.APP_ID_NOT_SET) {
Expand All @@ -820,6 +822,10 @@ const renderApp = async () => {
if ((error as Error)?.message === LoadingErrorCode.APP_UNAUTHORIZED) {
errorDescription = i18n.t('Index.permissionDeniedUnauthorized');
type = 'error';
action =
<RerouteToLogin
rerouteMsg={i18n.t('Index.rerouteToLoginPage')}
/>;
}

if ((error as Error)?.message === LoadingErrorCode.APP_CONFIG_NOT_FOUND) {
Expand All @@ -836,13 +842,16 @@ const renderApp = async () => {

root.render(
<React.StrictMode>
<Alert
className="error-boundary"
message={i18n.t('Index.errorMessage')}
description={errorDescription}
type={type}
showIcon
/>
<SHOGunAPIClientProvider client={client}>
AmandaTamanda marked this conversation as resolved.
Show resolved Hide resolved
<Alert
className="error-boundary"
message={i18n.t('Index.errorMessage')}
description={errorDescription}
type={type}
action={action}
showIcon
/>
</SHOGunAPIClientProvider>
</React.StrictMode>
);
}
Expand Down
67 changes: 67 additions & 0 deletions src/components/RerouteToLogin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, {
useEffect,
useState
} from 'react';

import {
DoubleLeftOutlined
} from '@ant-design/icons';

import {
Button,
Tooltip,
Flex
} from 'antd';

import useSHOGunAPIClient from '../../hooks/useSHOGunAPIClient';

export interface RerouteToLoginProps {
rerouteMsg: string;
}

const RerouteToLogin: React.FC<RerouteToLoginProps> = ({
rerouteMsg
}) => {

const [loginUrl, setLoginUrl] = useState<string>();

const client = useSHOGunAPIClient();
const keycloak = client?.getKeycloak();

useEffect(() => {
const getLoginUrl = async () => {
const url = await keycloak?.createLoginUrl();
AmandaTamanda marked this conversation as resolved.
Show resolved Hide resolved
if (url) {
setLoginUrl(url);
}
};

getLoginUrl();
}, [keycloak]);

const onLoginLinkClick = () => {
if (keycloak) {
window.open(loginUrl, '_self');
}
};

return (
<Flex
align='center'
>
<Tooltip
title='Login'
>
<Button
type='link'
onClick={onLoginLinkClick}
>
<DoubleLeftOutlined />
</Button>
</Tooltip>
{rerouteMsg}
</Flex>
);
};

export default RerouteToLogin;
6 changes: 4 additions & 2 deletions src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ export default {
errorDescriptionAppIdNotSet: 'Keine Applikations-ID angegeben. Bitte geben Sie die ID als Abfrageparameter an, z.B. ?applicationId=1909',
errorDescriptionAppConfigNotFound: 'Die Applikation mit der ID {{applicationId}} konnte nicht geladen werden.',
errorDescriptionAppConfigStaticNotFound: 'Die Konfiguration der Applikation konnte nicht geladen werden.',
permissionDeniedUnauthorized: 'Dies ist keine öffentliche Applikation. Anmeldung erforderlich.'
permissionDeniedUnauthorized: 'Dies ist keine öffentliche Applikation. Anmeldung erforderlich.',
rerouteToLoginPage: 'Zur Anmeldeseite.'
},
Nominatim: {
placeholder: 'Ortsname, Straßenname, Stadtteilname, POI usw.'
Expand Down Expand Up @@ -453,7 +454,8 @@ export default {
errorDescriptionAppIdNotSet: 'No application ID given. Please provide the ID as query parameter, e.g. ?applicationId=1909',
errorDescriptionAppConfigNotFound: 'The application with ID {{applicationId}} could not be loaded correctly.',
errorDescriptionAppConfigStaticNotFound: 'The configuration of the application could not be loaded correctly.',
permissionDeniedUnauthorized: 'This application is not public. Authentication required.'
permissionDeniedUnauthorized: 'This application is not public. Authentication required.',
rerouteToLoginPage: 'To login page.'
},
Nominatim: {
placeholder: 'Place name, street name, district name, POI, etc.'
Expand Down
6 changes: 6 additions & 0 deletions src/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ body,

.error-boundary {
min-width: 400px;
min-height: 125px;
AmandaTamanda marked this conversation as resolved.
Show resolved Hide resolved
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);

.ant-alert-action {
position: absolute;
top: 70%;
}
}
Loading