From 9f10844e32bc8e6de28815899753254ab47aaca2 Mon Sep 17 00:00:00 2001 From: Ivan Manzhosov Date: Mon, 11 Nov 2024 21:34:11 +0100 Subject: [PATCH] chore: npm prettier --- .../security/ChangeAuthProviderView.tsx | 235 +++++++++--------- .../component/security/Login/LoginRouter.tsx | 18 +- webapp/src/constants/links.tsx | 4 +- webapp/src/service/http/ApiHttpService.tsx | 30 ++- 4 files changed, 149 insertions(+), 138 deletions(-) diff --git a/webapp/src/component/security/ChangeAuthProviderView.tsx b/webapp/src/component/security/ChangeAuthProviderView.tsx index 61891eebf2..70bc697c1f 100644 --- a/webapp/src/component/security/ChangeAuthProviderView.tsx +++ b/webapp/src/component/security/ChangeAuthProviderView.tsx @@ -1,14 +1,14 @@ -import {DashboardPage} from "tg.component/layout/DashboardPage"; -import {CompactView} from "tg.component/layout/CompactView"; -import {Box, styled} from "@mui/material"; -import {T, useTranslate} from "@tolgee/react"; -import {LINKS} from "tg.constants/links"; -import LoadingButton from "tg.component/common/form/LoadingButton"; -import {globalContext} from "tg.globalContext/globalActions"; -import {useApiMutation, useApiQuery} from "tg.service/http/useQueryApi"; -import React from "react"; -import {Alert} from "tg.component/common/Alert"; -import {TranslatedError} from "tg.translationTools/TranslatedError"; +import { DashboardPage } from 'tg.component/layout/DashboardPage'; +import { CompactView } from 'tg.component/layout/CompactView'; +import { Box, styled } from '@mui/material'; +import { T, useTranslate } from '@tolgee/react'; +import { LINKS } from 'tg.constants/links'; +import LoadingButton from 'tg.component/common/form/LoadingButton'; +import { globalContext } from 'tg.globalContext/globalActions'; +import { useApiMutation, useApiQuery } from 'tg.service/http/useQueryApi'; +import React from 'react'; +import { Alert } from 'tg.component/common/Alert'; +import { TranslatedError } from 'tg.translationTools/TranslatedError'; const StyledContainer = styled('div')` padding: 28px 4px 0px 4px; @@ -37,118 +37,121 @@ const StyledDescription = styled('div')` const LOCAL_STORAGE_CHANGE_PROVIDER = 'change_provider'; function getProviderName(accountType?: string, authType?: string) { - if (accountType === "LOCAL") { - return 'username and password'; - } else if (accountType === "THIRD_PARTY") { - return authType || 'Third-Party Provider'; - } - return 'Unknown Provider'; + if (accountType === 'LOCAL') { + return 'username and password'; + } else if (accountType === 'THIRD_PARTY') { + return authType || 'Third-Party Provider'; + } + return 'Unknown Provider'; } export function ChangeAuthProviderView() { - const { t } = useTranslate(); - const requestIdString = localStorage.getItem(LOCAL_STORAGE_CHANGE_PROVIDER); - const requestId = requestIdString ? Number(requestIdString) : 0; - - const { data } = useApiQuery({ - url: '/api/public/auth-provider/get-request', - method: 'get', - query: { - requestId + const { t } = useTranslate(); + const requestIdString = localStorage.getItem(LOCAL_STORAGE_CHANGE_PROVIDER); + const requestId = requestIdString ? Number(requestIdString) : 0; + + const { data } = useApiQuery({ + url: '/api/public/auth-provider/get-request', + method: 'get', + query: { + requestId, + }, + }); + + const { error, isSuccess, isLoading, mutate } = useApiMutation({ + url: '/api/public/auth-provider/request-change', + method: 'post', + }); + + const currentProvider = getProviderName( + data?.oldAccountType, + data?.oldAuthType + ); + const newProvider = getProviderName(data?.newAccountType, data?.newAuthType); + + const confirmChange = () => { + mutate({ + content: { + 'application/json': { + changeRequestId: requestId, + isConfirmed: true, }, + }, }); - const {error, isSuccess, isLoading, mutate } = useApiMutation({ - url: '/api/public/auth-provider/request-change', - method: 'post', + if (isSuccess) { + globalContext.actions?.redirectTo(LINKS.LOGIN.build()); + } + }; + + const discardChange = () => { + mutate({ + content: { + 'application/json': { + changeRequestId: requestId, + isConfirmed: false, + }, + }, }); - const currentProvider = getProviderName(data?.oldAccountType, data?.oldAuthType); - const newProvider = getProviderName(data?.newAccountType, data?.newAuthType); - - const confirmChange = () => { - mutate({ - content: { - 'application/json': { - changeRequestId: requestId, - isConfirmed: true, - }, - }, - }); - - if(isSuccess) { - globalContext.actions?.redirectTo(LINKS.LOGIN.build()); + if (isSuccess) { + globalContext.actions?.redirectTo(LINKS.LOGIN.build()); + } + }; + + return ( + + + + + ) } - }; - - const discardChange = () => { - mutate({ - content: { - 'application/json': { - changeRequestId: requestId, - isConfirmed: false, - }, - }, - }); - - if(isSuccess) { - globalContext.actions?.redirectTo(LINKS.LOGIN.build()); + maxWidth={800} + windowTitle={t('slack_connect_title')} + primaryContent={ + + + + + + + + , + }} + /> + + + + + + + + + + + } - }; - - return ( - - - - - ) - } - maxWidth={800} - windowTitle={t('slack_connect_title')} - primaryContent={ - - - - - - - - - - }} - /> - - - - - - - - - - - - } - /> - - ) -} \ No newline at end of file + /> + + ); +} diff --git a/webapp/src/component/security/Login/LoginRouter.tsx b/webapp/src/component/security/Login/LoginRouter.tsx index 012475dc5c..692e3809db 100644 --- a/webapp/src/component/security/Login/LoginRouter.tsx +++ b/webapp/src/component/security/Login/LoginRouter.tsx @@ -1,14 +1,14 @@ -import {default as React, FunctionComponent} from 'react'; -import {Route, Switch} from 'react-router-dom'; +import { default as React, FunctionComponent } from 'react'; +import { Route, Switch } from 'react-router-dom'; -import {LINKS} from 'tg.constants/links'; +import { LINKS } from 'tg.constants/links'; -import {LoginView} from './LoginView'; -import {EmailVerificationHandler} from './EmailVerificationHandler'; -import {OAuthRedirectionHandler} from './OAuthRedirectionHandler'; -import {PublicOnlyRoute} from 'tg.component/common/PublicOnlyRoute'; -import {SsoRedirectionHandler} from 'tg.component/security/Sso/SsoRedirectionHandler'; -import {ChangeAuthProviderView} from "tg.component/security/ChangeAuthProviderView"; +import { LoginView } from './LoginView'; +import { EmailVerificationHandler } from './EmailVerificationHandler'; +import { OAuthRedirectionHandler } from './OAuthRedirectionHandler'; +import { PublicOnlyRoute } from 'tg.component/common/PublicOnlyRoute'; +import { SsoRedirectionHandler } from 'tg.component/security/Sso/SsoRedirectionHandler'; +import { ChangeAuthProviderView } from 'tg.component/security/ChangeAuthProviderView'; interface LoginRouterProps {} diff --git a/webapp/src/constants/links.tsx b/webapp/src/constants/links.tsx index 8244494b48..527ede6a9b 100644 --- a/webapp/src/constants/links.tsx +++ b/webapp/src/constants/links.tsx @@ -80,8 +80,8 @@ export class LINKS { ); static CHANGE_AUTH_PROVIDER = Link.ofParent( - LINKS.LOGIN, - 'change-auth-provider' + LINKS.LOGIN, + 'change-auth-provider' ); static OPENID_RESPONSE = Link.ofParent(LINKS.LOGIN, 'open-id/auth-callback'); diff --git a/webapp/src/service/http/ApiHttpService.tsx b/webapp/src/service/http/ApiHttpService.tsx index 3ed34eda80..819c444f1a 100644 --- a/webapp/src/service/http/ApiHttpService.tsx +++ b/webapp/src/service/http/ApiHttpService.tsx @@ -1,12 +1,12 @@ -import {LINKS} from 'tg.constants/links'; -import {GlobalError} from 'tg.error/GlobalError'; +import { LINKS } from 'tg.constants/links'; +import { GlobalError } from 'tg.error/GlobalError'; -import {tokenService} from '../TokenService'; -import {getUtmCookie} from 'tg.fixtures/utmCookie'; -import {handleApiError} from './handleApiError'; -import {ApiError} from './ApiError'; -import {errorAction} from './errorAction'; -import {globalContext} from 'tg.globalContext/globalActions'; +import { tokenService } from '../TokenService'; +import { getUtmCookie } from 'tg.fixtures/utmCookie'; +import { handleApiError } from './handleApiError'; +import { ApiError } from './ApiError'; +import { errorAction } from './errorAction'; +import { globalContext } from 'tg.globalContext/globalActions'; const LOCAL_STORAGE_CHANGE_PROVIDER = 'change_provider'; @@ -66,9 +66,17 @@ export class ApiHttpService { handleApiError(r, responseData, init, options) ); - if(r.status === 401 && responseData.code === 'username_already_exists') { - localStorage.setItem(LOCAL_STORAGE_CHANGE_PROVIDER, resultError.data?.params?.[0]); - globalContext.actions?.redirectToLink(LINKS.CHANGE_AUTH_PROVIDER); + if ( + r.status === 401 && + responseData.code === 'username_already_exists' + ) { + localStorage.setItem( + LOCAL_STORAGE_CHANGE_PROVIDER, + resultError.data?.params?.[0] + ); + globalContext.actions?.redirectToLink( + LINKS.CHANGE_AUTH_PROVIDER + ); } if (r.status === 400) {