Skip to content

Commit 23cea5e

Browse files
committed
feat: auth page
1 parent a7aae05 commit 23cea5e

File tree

16 files changed

+164
-105
lines changed

16 files changed

+164
-105
lines changed

contract/src/main/resources/swagger/kafbat-ui-api.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,10 @@ paths:
22562256

22572257
/auth:
22582258
post:
2259+
tags:
2260+
- ApplicationConfig
22592261
summary: Authenticate
2262+
operationId: authenticate
22602263
requestBody:
22612264
required: true
22622265
content:

frontend/src/components/AuthPage/AuthPage.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import { useAuthSettings } from 'lib/hooks/api/appConfig';
33

4-
import Footer from './Footer/Footer';
54
import Header from './Header/Header';
65
import SignIn from './SignIn/SignIn';
76
import * as S from './AuthPage.styled';
@@ -13,7 +12,6 @@ function AuthPage() {
1312
<S.AuthPageStyled>
1413
<Header />
1514
{data && <SignIn appAuthenticationSettings={data} />}
16-
<Footer />
1715
</S.AuthPageStyled>
1816
);
1917
}

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

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

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

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

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const Form = styled.form`
66
align-items: center;
77
justify-content: center;
88
gap: 40px;
9+
width: 100%;
910
1011
div {
1112
width: 100%;
@@ -19,6 +20,7 @@ export const Fieldset = styled.fieldset`
1920
justify-content: center;
2021
gap: 16px;
2122
border: none;
23+
width: 100%;
2224
`;
2325

2426
export const Field = styled.div`
@@ -35,3 +37,20 @@ export const Label = styled.label`
3537
font-weight: 500;
3638
line-height: 16px;
3739
`;
40+
41+
export const ErrorMessage = styled.div`
42+
display: flex;
43+
column-gap: 2px;
44+
align-items: center;
45+
justify-content: center;
46+
font-weight: 400;
47+
font-size: 14px;
48+
line-height: 20px;
49+
`;
50+
51+
export const ErrorMessageText = styled.span`
52+
${({ theme }) => theme.auth_page.signIn.errorMessage};
53+
font-weight: 400;
54+
font-size: 14px;
55+
line-height: 20px;
56+
`;

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

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React from 'react';
22
import { Button } from 'components/common/Button/Button';
33
import Input from 'components/common/Input/Input';
4-
import { FormProvider, useForm } from 'react-hook-form';
4+
import { Controller, FormProvider, useForm } from 'react-hook-form';
5+
import { useAuthenticate } from 'lib/hooks/api/appConfig';
6+
import AlertIcon from 'components/common/Icons/AlertIcon';
7+
import { useNavigate } from 'react-router-dom';
58

69
import * as S from './BasicSignIn.styled';
710

@@ -11,36 +14,78 @@ interface FormValues {
1114
}
1215

1316
function BasicSignIn() {
14-
const methods = useForm<FormValues>();
17+
const methods = useForm<FormValues>({
18+
defaultValues: { username: '', password: '' },
19+
});
20+
const navigate = useNavigate();
21+
const { mutateAsync } = useAuthenticate();
22+
23+
const onSubmit = async (data: FormValues) => {
24+
await mutateAsync(data, {
25+
onSuccess(response) {
26+
if (response.raw.url.includes('error')) {
27+
methods.setError('root', { message: 'error' });
28+
} else {
29+
navigate('/');
30+
}
31+
},
32+
});
33+
};
1534

1635
return (
1736
<FormProvider {...methods}>
18-
<S.Form style={{ width: '100%' }}>
19-
<S.Fieldset style={{ width: '100%' }}>
20-
<S.Field>
21-
<S.Label htmlFor="username">Username</S.Label>
22-
<Input
23-
name="username"
24-
id="username"
25-
placeholder="Enter your username"
26-
style={{ borderRadius: '8px' }}
27-
/>
28-
</S.Field>
29-
<S.Field>
30-
<S.Label htmlFor="password">Password</S.Label>
31-
<Input
32-
name="password"
33-
id="password"
34-
placeholder="Enter your password"
35-
style={{ borderRadius: '8px' }}
36-
/>
37-
</S.Field>
37+
<S.Form onSubmit={methods.handleSubmit(onSubmit)}>
38+
<S.Fieldset>
39+
{methods.formState.errors.root && (
40+
<S.ErrorMessage>
41+
<AlertIcon />
42+
<S.ErrorMessageText>
43+
Username or password entered incorrectly
44+
</S.ErrorMessageText>
45+
</S.ErrorMessage>
46+
)}
47+
<Controller
48+
name="username"
49+
control={methods.control}
50+
render={({ field }) => (
51+
<S.Field>
52+
<S.Label htmlFor={field.name}>Username</S.Label>
53+
<Input
54+
onChange={field.onChange}
55+
value={field.value}
56+
name={field.name}
57+
id={field.name}
58+
placeholder="Enter your username"
59+
style={{ borderRadius: '8px' }}
60+
/>
61+
</S.Field>
62+
)}
63+
/>
64+
<Controller
65+
name="password"
66+
control={methods.control}
67+
render={({ field }) => (
68+
<S.Field>
69+
<S.Label htmlFor={field.name}>Password</S.Label>
70+
<Input
71+
onChange={field.onChange}
72+
value={field.value}
73+
name={field.name}
74+
type="password"
75+
id={field.name}
76+
placeholder="Enter your password"
77+
style={{ borderRadius: '8px' }}
78+
/>
79+
</S.Field>
80+
)}
81+
/>
3882
</S.Fieldset>
3983
<Button
4084
buttonSize="L"
4185
buttonType="primary"
42-
onClick={() => console.log('click')}
86+
type="submit"
4387
style={{ width: '100%', borderRadius: '8px' }}
88+
disabled={!methods.formState.isValid}
4489
>
4590
Log in
4691
</Button>

frontend/src/components/AuthPage/SignIn/OAuthSignIn/AuthCard/AuthCard.styled.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import styled, { css } from 'styled-components';
22
import GitHubIcon from 'components/common/Icons/GitHubIcon';
3-
import { Link } from 'react-router-dom';
43
import { Button } from 'components/common/Button/Button';
54

65
export const AuthCardStyled = styled.div(
@@ -64,4 +63,4 @@ export const ServiceButton = styled(Button)`
6463
border-radius: 8px;
6564
font-size: 14px;
6665
text-decoration: none;
67-
`
66+
`;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ function OAuthSignIn({ oAuthProviders }: Props) {
2424
<AuthCard
2525
key={provider.clientName}
2626
authPath={provider.authorizationUri}
27-
Icon={ServiceIconMap[provider.clientName?.toLowerCase() || 'unknownService']}
27+
Icon={
28+
ServiceIconMap[
29+
provider.clientName?.toLowerCase() || 'unknownService'
30+
]
31+
}
2832
serviceName={provider.clientName || ''}
2933
/>
3034
))}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const SignInStyled = styled.div`
77
justify-content: center;
88
width: 320px;
99
gap: 56px;
10+
flex-grow: 1;
1011
`;
1112

1213
export const SignInTitle = styled.span(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ function SignInForm({ appAuthenticationSettings }: Props) {
1515
return (
1616
<S.SignInStyled>
1717
<S.SignInTitle>Sign in</S.SignInTitle>
18-
{(authType === AuthType.LDAP ||
19-
authType === AuthType.LOGIN_FORM) && <BasicSignIn />}
18+
{(authType === AuthType.LDAP || authType === AuthType.LOGIN_FORM) && (
19+
<BasicSignIn />
20+
)}
2021
{authType === AuthType.OAUTH2 && (
2122
<OAuthSignIn oAuthProviders={oAuthProviders} />
2223
)}

0 commit comments

Comments
 (0)