Skip to content

Commit

Permalink
feat: auth page
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilumilak committed Dec 18, 2024
1 parent 8e78c51 commit b8161eb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AlertIcon from 'components/common/Icons/AlertIcon';
import { useNavigate } from 'react-router-dom';

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

Check failure on line 9 in frontend/src/components/AuthPage/SignIn/BasicSignIn/BasicSignIn.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

There should be at least one empty line between import groups
import { useQueryClient } from '@tanstack/react-query';

Check failure on line 10 in frontend/src/components/AuthPage/SignIn/BasicSignIn/BasicSignIn.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

`@tanstack/react-query` import should occur before import of `./BasicSignIn.styled`

interface FormValues {
username: string;
Expand All @@ -19,15 +20,16 @@ function BasicSignIn() {
});
const navigate = useNavigate();
const { mutateAsync } = useAuthenticate();
const client = useQueryClient();

const onSubmit = async (data: FormValues) => {
await mutateAsync(data, {
onSuccess(response) {
onSuccess: async (response) => {
if (response.raw.url.includes('error')) {
methods.setError('root', { message: 'error' });
} else {
await client.invalidateQueries({queryKey: ['app', 'info']});

Check warning on line 31 in frontend/src/components/AuthPage/SignIn/BasicSignIn/BasicSignIn.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `queryKey:·['app',·'info']` with `·queryKey:·['app',·'info']·`
navigate('/');
window.location.reload();
}
},
});
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/components/contexts/GlobalSettingsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ export const GlobalSettingsProvider: React.FC<
});

React.useEffect(() => {
if (info.data?.raw.url.includes('auth')) {
if (info.data?.redirect && !info.isFetching) {
navigate('auth');
return;
}

info.data?.value().then((res) => {
const features = res?.enabledFeatures || [];
const features = info?.data?.response.enabledFeatures

Check warning on line 30 in frontend/src/components/contexts/GlobalSettingsContext.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

Insert `;`

if (features) {
setValue({
hasDynamicConfig: features.includes(
ApplicationInfoEnabledFeaturesEnum.DYNAMIC_CONFIG
),
});
});
})

Check warning on line 37 in frontend/src/components/contexts/GlobalSettingsContext.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

Insert `;`
}
}, [info.data]);

return (
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/lib/hooks/api/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import {
ApplicationConfig,
ApplicationConfigPropertiesKafkaClusters,
ApplicationInfo,
} from 'generated-sources';
import { QUERY_REFETCH_OFF_OPTIONS } from 'lib/constants';

Expand All @@ -29,8 +30,21 @@ export function useAuthenticate() {
export function useAppInfo() {
return useQuery(

Check warning on line 31 in frontend/src/lib/hooks/api/appConfig.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `⏎····['app',·'info'],⏎···` with `['app',·'info'],`
['app', 'info'],
() => appConfig.getApplicationInfoRaw(),
QUERY_REFETCH_OFF_OPTIONS
async () => {
const data = await appConfig.getApplicationInfoRaw()

Check warning on line 34 in frontend/src/lib/hooks/api/appConfig.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `······const·data·=·await·appConfig.getApplicationInfoRaw()` with `····const·data·=·await·appConfig.getApplicationInfoRaw();`

let response: ApplicationInfo = {}

Check warning on line 36 in frontend/src/lib/hooks/api/appConfig.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `······let·response:·ApplicationInfo·=·{}` with `····let·response:·ApplicationInfo·=·{};`
try {

Check warning on line 37 in frontend/src/lib/hooks/api/appConfig.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `······` with `····`
response = await data.value()

Check warning on line 38 in frontend/src/lib/hooks/api/appConfig.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `········response·=·await·data.value()` with `······response·=·await·data.value();`
} catch {

Check warning on line 39 in frontend/src/lib/hooks/api/appConfig.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `······` with `····`
response = {}

Check warning on line 40 in frontend/src/lib/hooks/api/appConfig.ts

View workflow job for this annotation

GitHub Actions / build / build-and-test

Replace `········response·=·{}` with `······response·=·{};`
}

return {
redirect: data.raw.url.includes('auth'),
response,
}
},
);
}

Expand Down

0 comments on commit b8161eb

Please sign in to comment.