mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 08:04:45 -04:00

The update causes problems with the emoji picker in the production build Revert "fix: Fix sign-in-button cypress tests" Revert "chore(deps): update nextjs monorepo to v13" Revert "fix: Remove anchor hack from internal-link" Revert "fix: Remove a tag childs from NextJS link components" This reverts commitf2ae04743a
. This reverts commita7fd14a3
This reverts commit6d30448157
. This reverts commit7f7f020d91
. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import React, { useMemo } from 'react'
|
|
import { Button } from 'react-bootstrap'
|
|
import type { ButtonProps } from 'react-bootstrap/Button'
|
|
import { Trans, useTranslation } from 'react-i18next'
|
|
import { ShowIf } from '../../common/show-if/show-if'
|
|
import { useApplicationState } from '../../../hooks/common/use-application-state'
|
|
import { cypressId } from '../../../utils/cypress-attribute'
|
|
import Link from 'next/link'
|
|
import { filterOneClickProviders } from '../../login-page/auth/utils'
|
|
import { getOneClickProviderMetadata } from '../../login-page/auth/utils/get-one-click-provider-metadata'
|
|
|
|
export type SignInButtonProps = Omit<ButtonProps, 'href'>
|
|
|
|
/**
|
|
* Renders a sign-in button if auth providers are defined.
|
|
* It links to either the login page or if only a single one-click provider is configured, to that one.
|
|
*
|
|
* @param variant The style variant as inferred from the common button component.
|
|
* @param props Further props inferred from the common button component.
|
|
*/
|
|
export const SignInButton: React.FC<SignInButtonProps> = ({ variant, ...props }) => {
|
|
const { t } = useTranslation()
|
|
const authProviders = useApplicationState((state) => state.config.authProviders)
|
|
|
|
const loginLink = useMemo(() => {
|
|
const oneClickProviders = authProviders.filter(filterOneClickProviders)
|
|
if (authProviders.length === 1 && oneClickProviders.length === 1) {
|
|
const metadata = getOneClickProviderMetadata(oneClickProviders[0])
|
|
return metadata.url
|
|
}
|
|
return '/login'
|
|
}, [authProviders])
|
|
|
|
return (
|
|
<ShowIf condition={authProviders.length > 0}>
|
|
<Link href={loginLink} passHref={true}>
|
|
<Button title={t('login.signIn')} {...cypressId('sign-in-button')} variant={variant || 'success'} {...props}>
|
|
<Trans i18nKey='login.signIn' />
|
|
</Button>
|
|
</Link>
|
|
</ShowIf>
|
|
)
|
|
}
|