Skip to content

Commit 09f2070

Browse files
NilumilakHaarolean
authored andcommitted
feat: auth page
1 parent 3e61608 commit 09f2070

File tree

11 files changed

+91
-49
lines changed

11 files changed

+91
-49
lines changed

frontend/src/components/App.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Suspense, useContext } from 'react';
2-
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
2+
import { Routes, Route, Navigate, useMatch } from 'react-router-dom';
33
import {
44
accessErrorPage,
55
clusterPath,
@@ -50,17 +50,16 @@ const queryClient = new QueryClient({
5050
});
5151
const App: React.FC = () => {
5252
const { isDarkMode } = useContext(ThemeModeContext);
53-
const location = useLocation();
54-
const isAuthPage = location.pathname === '/auth';
53+
const isAuthRoute = useMatch('/auth/*');
5554

5655
return (
5756
<QueryClientProvider client={queryClient}>
58-
<GlobalSettingsProvider>
59-
<ThemeProvider theme={isDarkMode ? darkTheme : theme}>
60-
<Suspense fallback={<PageLoader fullSize />}>
61-
{isAuthPage ? (
62-
<AuthPage />
63-
) : (
57+
<ThemeProvider theme={isDarkMode ? darkTheme : theme}>
58+
{isAuthRoute ? (
59+
<AuthPage />
60+
) : (
61+
<GlobalSettingsProvider>
62+
<Suspense fallback={<PageLoader fullSize />}>
6463
<UserInfoRolesAccessProvider>
6564
<ConfirmContextProvider>
6665
<GlobalCSS />
@@ -100,10 +99,10 @@ const App: React.FC = () => {
10099
<ConfirmationModal />
101100
</ConfirmContextProvider>
102101
</UserInfoRolesAccessProvider>
103-
)}
104-
</Suspense>
105-
</ThemeProvider>
106-
</GlobalSettingsProvider>
102+
</Suspense>
103+
</GlobalSettingsProvider>
104+
)}
105+
</ThemeProvider>
107106
<ReactQueryDevtools initialIsOpen={false} position="bottom-right" />
108107
</QueryClientProvider>
109108
);

frontend/src/components/AuthPage/AuthPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import React from 'react';
2+
import { useAuthSettings } from 'lib/hooks/api/appConfig';
23

34
import Footer from './Footer/Footer';
45
import Header from './Header/Header';
56
import SignIn from './SignIn/SignIn';
67
import * as S from './AuthPage.styled';
78

89
function AuthPage() {
10+
const { data } = useAuthSettings();
11+
912
return (
1013
<S.AuthPageStyled>
1114
<Header />
12-
<SignIn type="service" />
15+
{data && <SignIn appAuthenticationSettings={data} />}
1316
<Footer />
1417
</S.AuthPageStyled>
1518
);

frontend/src/components/AuthPage/Footer/Footer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import { useLatestVersion } from 'lib/hooks/api/latestVersion';
55
import * as S from './Footer.styled';
66

77
function Footer() {
8-
const { data: latestVersionInfo = {} } = useLatestVersion();
9-
const { versionTag } = latestVersionInfo.latestRelease;
10-
const { commitId } = latestVersionInfo.build;
8+
// const { data: latestVersionInfo = {} } = useLatestVersion();
9+
// const { versionTag } = latestVersionInfo.latestRelease;
10+
// const { commitId } = latestVersionInfo.build;
1111

1212
return (
1313
<S.FooterStyledWrapper>
1414
<S.AppVersionStyled>
1515
<GitHubIcon />
1616
<S.AppVersionTextStyled>
17-
{versionTag} ({commitId})
17+
{/* {versionTag} ({commitId}) */}
1818
</S.AppVersionTextStyled>
1919
</S.AppVersionStyled>
2020
<S.InformationTextStyled>

frontend/src/components/AuthPage/SignIn/ServiceSignIn/AuthCard/AuthCard.styled.tsx renamed to frontend/src/components/AuthPage/SignIn/OAuthSignIn/AuthCard/AuthCard.styled.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import styled, { css } from 'styled-components';
22
import GitHubIcon from 'components/common/Icons/GitHubIcon';
3+
import { Link } from 'react-router-dom';
4+
import { Button } from 'components/common/Button/Button';
35

46
export const AuthCardStyled = styled.div(
57
({ theme }) => css`
@@ -56,3 +58,10 @@ export const ServiceTextStyled = styled.span(
5658
line-height: 16px;
5759
`
5860
);
61+
62+
export const ServiceButton = styled(Button)`
63+
width: 100%;
64+
border-radius: 8px;
65+
font-size: 14px;
66+
text-decoration: none;
67+
`

frontend/src/components/AuthPage/SignIn/ServiceSignIn/AuthCard/AuthCard.tsx renamed to frontend/src/components/AuthPage/SignIn/OAuthSignIn/AuthCard/AuthCard.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React, { ElementType } from 'react';
2-
import { Button } from 'components/common/Button/Button';
32
import ServiceImage from 'components/common/Icons/ServiceImage';
43

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

76
interface Props {
87
serviceName: string;
8+
authPath: string | undefined;
99
Icon?: ElementType;
1010
}
1111

12-
function AuthCard({ serviceName, Icon = ServiceImage }: Props) {
12+
function AuthCard({ serviceName, authPath, Icon = ServiceImage }: Props) {
1313
return (
1414
<S.AuthCardStyled>
1515
<S.ServiceData>
@@ -21,14 +21,13 @@ function AuthCard({ serviceName, Icon = ServiceImage }: Props) {
2121
</S.ServiceTextStyled>
2222
</S.ServiceDataTextContainer>
2323
</S.ServiceData>
24-
<Button
24+
<S.ServiceButton
2525
buttonSize="L"
2626
buttonType="primary"
27-
onClick={() => console.log('click')}
28-
style={{ borderRadius: '8px', fontSize: '14px' }}
27+
to={`http://localhost:8080${authPath}`}
2928
>
3029
Log in with {serviceName}
31-
</Button>
30+
</S.ServiceButton>
3231
</S.AuthCardStyled>
3332
);
3433
}

frontend/src/components/AuthPage/SignIn/ServiceSignIn/ServiceSignIn.styled.tsx renamed to frontend/src/components/AuthPage/SignIn/OAuthSignIn/OAuthSignIn.styled.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from 'styled-components';
22

3-
export const ServiceSignInStyled = styled.div`
3+
export const OAuthSignInStyled = styled.div`
44
display: flex;
55
flex-direction: column;
66
gap: 8px;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { ElementType } from 'react';
2+
import GitHubIcon from 'components/common/Icons/GitHubIcon';
3+
import GoogleIcon from 'components/common/Icons/GoogleIcon';
4+
import ServiceImage from 'components/common/Icons/ServiceImage';
5+
import { OAuthProvider } from 'generated-sources';
6+
7+
import * as S from './OAuthSignIn.styled';
8+
import AuthCard from './AuthCard/AuthCard';
9+
10+
interface Props {
11+
oAuthProviders: OAuthProvider[] | undefined;
12+
}
13+
14+
const ServiceIconMap: Record<string, ElementType> = {
15+
github: GitHubIcon,
16+
google: GoogleIcon,
17+
unknownService: ServiceImage,
18+
};
19+
20+
function OAuthSignIn({ oAuthProviders }: Props) {
21+
return (
22+
<S.OAuthSignInStyled>
23+
{oAuthProviders?.map((provider) => (
24+
<AuthCard
25+
key={provider.clientName}
26+
authPath={provider.authorizationUri}
27+
Icon={ServiceIconMap[provider.clientName?.toLowerCase() || 'unknownService']}
28+
serviceName={provider.clientName || ''}
29+
/>
30+
))}
31+
</S.OAuthSignInStyled>
32+
);
33+
}
34+
35+
export default OAuthSignIn;

frontend/src/components/AuthPage/SignIn/ServiceSignIn/ServiceSignIn.tsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

frontend/src/components/AuthPage/SignIn/SignIn.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import React from 'react';
2+
import { AppAuthenticationSettings, AuthType } from 'generated-sources';
23

34
import BasicSignIn from './BasicSignIn/BasicSignIn';
45
import * as S from './SignIn.styled';
5-
import ServiceSignIn from './ServiceSignIn/ServiceSignIn';
6+
import OAuthSignIn from './OAuthSignIn/OAuthSignIn';
67

78
interface Props {
8-
type: 'service' | 'basic';
9+
appAuthenticationSettings: AppAuthenticationSettings;
910
}
1011

11-
function SignInForm({ type }: Props) {
12+
function SignInForm({ appAuthenticationSettings }: Props) {
13+
const { authType, oAuthProviders } = appAuthenticationSettings;
14+
1215
return (
1316
<S.SignInStyled>
1417
<S.SignInTitle>Sign in</S.SignInTitle>
15-
{type === 'basic' && <BasicSignIn />}
16-
{type === 'service' && <ServiceSignIn />}
18+
{(authType === AuthType.LDAP ||
19+
authType === AuthType.LOGIN_FORM) && <BasicSignIn />}
20+
{authType === AuthType.OAUTH2 && (
21+
<OAuthSignIn oAuthProviders={oAuthProviders} />
22+
)}
1723
</S.SignInStyled>
1824
);
1925
}

frontend/src/components/common/Button/Button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface Props
99
ButtonProps {
1010
to?: string | object;
1111
inProgress?: boolean;
12+
className?: string;
1213
}
1314

1415
export const Button: FC<Props> = ({
@@ -20,7 +21,7 @@ export const Button: FC<Props> = ({
2021
}) => {
2122
if (to) {
2223
return (
23-
<Link to={to}>
24+
<Link to={to} className={props.className}>
2425
<StyledButton disabled={disabled} type="button" {...props}>
2526
{children}
2627
</StyledButton>

0 commit comments

Comments
 (0)