Skip to content

Commit 5e7b535

Browse files
authored
Merge pull request #932 from IQSS/930-add-warning-message-to-login-page
Add warning message to login page
2 parents 5588116 + 2fe4275 commit 5e7b535

7 files changed

Lines changed: 78 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel
1818
- Added Notifications tab in Account Page
1919
- Added runtime configuration options for homepage branding and support link.
2020
- Added an environment variable to docker-compose-dev.yml to hide the OIDC client used in the SPA from the JSF frontend: DATAVERSE_AUTH_OIDC_HIDDEN_JSF: 1
21+
- Added a message note to the login page
2122
- Download with terms of use and guestbook.
2223
- Show terms modal before download when dataset has custom terms, a non-default license (not CC0 1.0), or a guestbook. Draft datasets and dataset editors bypass the modal.
2324

src/index.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,35 @@ const AppEntrypoint = lazy(() => import('./index.app'))
1111
const container = document.getElementById('root') as HTMLElement
1212
const root = createRoot(container)
1313

14-
const appConfigInit = initAppConfig()
15-
16-
if (!appConfigInit.ok) {
14+
if (window.kcContext) {
1715
root.render(
18-
<ConfigError message={appConfigInit.message} schemaError={appConfigInit.schemaError} />
16+
<StrictMode>
17+
<KcPage kcContext={window.kcContext} />
18+
</StrictMode>
1919
)
2020
} else {
21-
const appConfig = requireAppConfig()
21+
const appConfigInit = initAppConfig()
2222

23-
ApiConfig.init(
24-
`${appConfig.backendUrl}/api/v1`,
25-
DataverseApiAuthMechanism.BEARER_TOKEN,
26-
undefined,
27-
`${appConfig.oidc.localStorageKeyPrefix}token`
28-
)
23+
if (!appConfigInit.ok) {
24+
root.render(
25+
<ConfigError message={appConfigInit.message} schemaError={appConfigInit.schemaError} />
26+
)
27+
} else {
28+
const appConfig = requireAppConfig()
2929

30-
root.render(
31-
<StrictMode>
32-
{window.kcContext ? (
33-
<KcPage kcContext={window.kcContext} />
34-
) : (
30+
ApiConfig.init(
31+
`${appConfig.backendUrl}/api/v1`,
32+
DataverseApiAuthMechanism.BEARER_TOKEN,
33+
undefined,
34+
`${appConfig.oidc.localStorageKeyPrefix}token`
35+
)
36+
37+
root.render(
38+
<StrictMode>
3539
<Suspense>
3640
<AppEntrypoint />
3741
</Suspense>
38-
)}
39-
</StrictMode>
40-
)
42+
</StrictMode>
43+
)
44+
}
4145
}

src/keycloak-theme/login/Template.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { KcContext } from './KcContext'
99
import { Alert, DropdownButton, DropdownButtonItem, Tooltip } from '@iqss/dataverse-design-system'
1010
import { ArrowUpRightSquareFill } from 'react-bootstrap-icons'
1111
import dataverse_logo from '@/assets/dataverse_brand_icon.svg'
12+
import { SignInNotice } from './components/SignInNotice'
1213
import styles from './template.module.scss'
1314

1415
/*
@@ -64,11 +65,13 @@ export default function Template(props: TemplateProps<KcContext, I18n>) {
6465

6566
return (
6667
<div className={styles.login} id="kc-login-template">
68+
{kcContext.pageId === 'login.ftl' && <SignInNotice i18n={i18n} />}
6769
<div id="kc-header">
6870
<div id="kc-header-wrapper" className={styles['header-wrapper']}>
6971
<img src={dataverse_logo} alt="Brand Logo Image" />
7072
</div>
7173
</div>
74+
7275
<div className={styles['login-card']}>
7376
<header>
7477
{enabledLanguages.length > 1 && (
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.top-notice {
2+
margin: 0.5rem;
3+
border-radius: 8px;
4+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Alert } from '@iqss/dataverse-design-system'
2+
import type { I18n } from '../i18n'
3+
import styles from './SignInNotice.module.scss'
4+
5+
const DATAVERSE_BASE_URL =
6+
(import.meta.env.VITE_DATAVERSE_BASE_URL as string) ?? 'https://dataverse.harvard.edu'
7+
const HARVARD_SIGN_UP_URL = `${DATAVERSE_BASE_URL}/dataverseuser.xhtml?editMode=CREATE&redirectPage=%2Fdataverse_homepage.xhtml`
8+
9+
interface SignInNoticeProps {
10+
i18n: I18n
11+
}
12+
13+
export function SignInNotice({ i18n }: SignInNoticeProps) {
14+
const { msg, msgStr } = i18n
15+
16+
return (
17+
<div className={styles['top-notice']}>
18+
<Alert variant="warning" customHeading={msgStr('signInNoticeTitle')} dismissible={false}>
19+
<>
20+
{msg('signInNoticeBodyPrefix')}
21+
<a href={HARVARD_SIGN_UP_URL}>{msg('signInNoticeSignUpLinkText')}</a>
22+
{msg('signInNoticeBodySuffix')}
23+
</>
24+
</Alert>
25+
</div>
26+
)
27+
}

src/keycloak-theme/login/i18n.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@ import { i18nBuilder } from 'keycloakify/login'
33
import type { ThemeName } from '../kc.gen'
44

55
/** @see: https://docs.keycloakify.dev/features/i18n */
6-
const { useI18n, ofTypeI18n } = i18nBuilder.withThemeName<ThemeName>().build()
6+
const { useI18n, ofTypeI18n } = i18nBuilder
7+
.withThemeName<ThemeName>()
8+
.withCustomTranslations({
9+
en: {
10+
signInNoticeTitle: 'Note about Federated Login options sign-in',
11+
signInNoticeBodyPrefix:
12+
'Federated Login options are available only to the existing accounts that previously authenticated with these methods. New sign-ups via these options are not supported. Please use your Harvard Login or Username/Email to ',
13+
signInNoticeSignUpLinkText: 'sign up in Harvard Dataverse',
14+
signInNoticeBodySuffix: ', then you may login here.'
15+
}
16+
})
17+
.build()
718

819
type I18n = typeof ofTypeI18n
920

src/vite-env.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
/// <reference types="vite/client" />
2+
3+
interface ImportMetaEnv {
4+
readonly VITE_DATAVERSE_BASE_URL?: string
5+
}
6+
7+
interface ImportMeta {
8+
readonly env: ImportMetaEnv
9+
}

0 commit comments

Comments
 (0)