Skip to content

Commit

Permalink
feat: auth page
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilumilak authored and Haarolean committed Dec 17, 2024
1 parent cecfab3 commit 6313aae
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 49 deletions.
25 changes: 12 additions & 13 deletions frontend/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Suspense, useContext } from 'react';
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
import { Routes, Route, Navigate, useMatch } from 'react-router-dom';
import {
accessErrorPage,
clusterPath,
Expand Down Expand Up @@ -50,17 +50,16 @@ const queryClient = new QueryClient({
});
const App: React.FC = () => {
const { isDarkMode } = useContext(ThemeModeContext);
const location = useLocation();
const isAuthPage = location.pathname === '/auth';
const isAuthRoute = useMatch('/auth/*');

return (
<QueryClientProvider client={queryClient}>
<GlobalSettingsProvider>
<ThemeProvider theme={isDarkMode ? darkTheme : theme}>
<Suspense fallback={<PageLoader fullSize />}>
{isAuthPage ? (
<AuthPage />
) : (
<ThemeProvider theme={isDarkMode ? darkTheme : theme}>
{isAuthRoute ? (
<AuthPage />
) : (
<GlobalSettingsProvider>
<Suspense fallback={<PageLoader fullSize />}>
<UserInfoRolesAccessProvider>
<ConfirmContextProvider>
<GlobalCSS />
Expand Down Expand Up @@ -100,10 +99,10 @@ const App: React.FC = () => {
<ConfirmationModal />
</ConfirmContextProvider>
</UserInfoRolesAccessProvider>
)}
</Suspense>
</ThemeProvider>
</GlobalSettingsProvider>
</Suspense>
</GlobalSettingsProvider>
)}
</ThemeProvider>
<ReactQueryDevtools initialIsOpen={false} position="bottom-right" />
</QueryClientProvider>
);
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/AuthPage/AuthPage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React from 'react';
import { useAuthSettings } from 'lib/hooks/api/appConfig';

import Footer from './Footer/Footer';
import Header from './Header/Header';
import SignIn from './SignIn/SignIn';
import * as S from './AuthPage.styled';

function AuthPage() {
const { data } = useAuthSettings();

return (
<S.AuthPageStyled>
<Header />
<SignIn type="service" />
{data && <SignIn appAuthenticationSettings={data} />}
<Footer />
</S.AuthPageStyled>
);
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/AuthPage/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { useLatestVersion } from 'lib/hooks/api/latestVersion';
import * as S from './Footer.styled';

function Footer() {
const { data: latestVersionInfo = {} } = useLatestVersion();
const { versionTag } = latestVersionInfo.latestRelease;
const { commitId } = latestVersionInfo.build;
// const { data: latestVersionInfo = {} } = useLatestVersion();
// const { versionTag } = latestVersionInfo.latestRelease;
// const { commitId } = latestVersionInfo.build;

return (
<S.FooterStyledWrapper>
<S.AppVersionStyled>
<GitHubIcon />
<S.AppVersionTextStyled>
{versionTag} ({commitId})
{/* {versionTag} ({commitId}) */}
</S.AppVersionTextStyled>
</S.AppVersionStyled>
<S.InformationTextStyled>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import styled, { css } from 'styled-components';
import GitHubIcon from 'components/common/Icons/GitHubIcon';
import { Link } from 'react-router-dom';
import { Button } from 'components/common/Button/Button';

export const AuthCardStyled = styled.div(
({ theme }) => css`
Expand Down Expand Up @@ -56,3 +58,10 @@ export const ServiceTextStyled = styled.span(
line-height: 16px;
`
);

export const ServiceButton = styled(Button)`
width: 100%;
border-radius: 8px;
font-size: 14px;
text-decoration: none;
`
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { ElementType } from 'react';
import { Button } from 'components/common/Button/Button';
import ServiceImage from 'components/common/Icons/ServiceImage';

import * as S from './AuthCard.styled';

interface Props {
serviceName: string;
authPath: string | undefined;
Icon?: ElementType;
}

function AuthCard({ serviceName, Icon = ServiceImage }: Props) {
function AuthCard({ serviceName, authPath, Icon = ServiceImage }: Props) {
return (
<S.AuthCardStyled>
<S.ServiceData>
Expand All @@ -21,14 +21,13 @@ function AuthCard({ serviceName, Icon = ServiceImage }: Props) {
</S.ServiceTextStyled>
</S.ServiceDataTextContainer>
</S.ServiceData>
<Button
<S.ServiceButton
buttonSize="L"
buttonType="primary"
onClick={() => console.log('click')}
style={{ borderRadius: '8px', fontSize: '14px' }}
to={`http://localhost:8080${authPath}`}
>
Log in with {serviceName}
</Button>
</S.ServiceButton>
</S.AuthCardStyled>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from 'styled-components';

export const ServiceSignInStyled = styled.div`
export const OAuthSignInStyled = styled.div`
display: flex;
flex-direction: column;
gap: 8px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { ElementType } from 'react';
import GitHubIcon from 'components/common/Icons/GitHubIcon';
import GoogleIcon from 'components/common/Icons/GoogleIcon';
import ServiceImage from 'components/common/Icons/ServiceImage';
import { OAuthProvider } from 'generated-sources';

import * as S from './OAuthSignIn.styled';
import AuthCard from './AuthCard/AuthCard';

interface Props {
oAuthProviders: OAuthProvider[] | undefined;
}

const ServiceIconMap: Record<string, ElementType> = {
github: GitHubIcon,
google: GoogleIcon,
unknownService: ServiceImage,
};

function OAuthSignIn({ oAuthProviders }: Props) {
return (
<S.OAuthSignInStyled>
{oAuthProviders?.map((provider) => (
<AuthCard
key={provider.clientName}
authPath={provider.authorizationUri}
Icon={ServiceIconMap[provider.clientName?.toLowerCase() || 'unknownService']}
serviceName={provider.clientName || ''}
/>
))}
</S.OAuthSignInStyled>
);
}

export default OAuthSignIn;

This file was deleted.

16 changes: 11 additions & 5 deletions frontend/src/components/AuthPage/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import React from 'react';
import { AppAuthenticationSettings, AuthType } from 'generated-sources';

import BasicSignIn from './BasicSignIn/BasicSignIn';
import * as S from './SignIn.styled';
import ServiceSignIn from './ServiceSignIn/ServiceSignIn';
import OAuthSignIn from './OAuthSignIn/OAuthSignIn';

interface Props {
type: 'service' | 'basic';
appAuthenticationSettings: AppAuthenticationSettings;
}

function SignInForm({ type }: Props) {
function SignInForm({ appAuthenticationSettings }: Props) {
const { authType, oAuthProviders } = appAuthenticationSettings;

return (
<S.SignInStyled>
<S.SignInTitle>Sign in</S.SignInTitle>
{type === 'basic' && <BasicSignIn />}
{type === 'service' && <ServiceSignIn />}
{(authType === AuthType.LDAP ||
authType === AuthType.LOGIN_FORM) && <BasicSignIn />}
{authType === AuthType.OAUTH2 && (
<OAuthSignIn oAuthProviders={oAuthProviders} />
)}
</S.SignInStyled>
);
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/common/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Props
ButtonProps {
to?: string | object;
inProgress?: boolean;
className?: string;
}

export const Button: FC<Props> = ({
Expand All @@ -20,7 +21,7 @@ export const Button: FC<Props> = ({
}) => {
if (to) {
return (
<Link to={to}>
<Link to={to} className={props.className}>
<StyledButton disabled={disabled} type="button" {...props}>
{children}
</StyledButton>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/lib/hooks/api/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import {
} from 'generated-sources';
import { QUERY_REFETCH_OFF_OPTIONS } from 'lib/constants';

export function useAuthSettings() {
return useQuery(
['app', 'authSettings'],
() => api.getAuthenticationSettings(),
QUERY_REFETCH_OFF_OPTIONS
);
}

export function useAppInfo() {
return useQuery(
['app', 'info'],
Expand Down

0 comments on commit 6313aae

Please sign in to comment.