Skip to content

Commit f2cb727

Browse files
Merge pull request #2734 from devtron-labs/fix/login-page-loading
feat: detach dashboard access event from login list api
2 parents fdfc707 + 32293e4 commit f2cb727

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

src/components/login/Login.tsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import { TOKEN_COOKIE_NAME, URLS } from '../../config'
4343
import { getSSOConfigList } from '../../Pages/GlobalConfigurations/Authorization/SSOLoginServices/service'
4444
import { dashboardAccessed } from '../../services/service'
4545
import { LOGIN_CARD_ANIMATION_VARIANTS, SSOProvider } from './constants'
46-
import { SSOConfigLoginList } from './login.types'
4746
import { LoginForm } from './LoginForm'
4847

4948
import './login.scss'
@@ -54,13 +53,14 @@ const getTermsAndConditions = importComponentFromFELibrary('getTermsAndCondition
5453

5554
const Login = () => {
5655
const [continueUrl, setContinueUrl] = useState('')
57-
const [loginList, setLoginList] = useState<SSOConfigLoginList[]>([])
5856

5957
const { searchParams } = useSearchString()
6058
const location = useLocation()
6159
const history = useHistory()
6260

63-
const [initLoading, initResult] = useAsync(() => Promise.allSettled([getSSOConfigList(), dashboardAccessed()]), [])
61+
const [ssoListLoading, ssoListResponse] = useAsync(getSSOConfigList, [])
62+
63+
const loginList = ssoListResponse?.result ?? []
6464

6565
const setLoginNavigationURL = () => {
6666
let queryParam = searchParams.continue
@@ -96,26 +96,10 @@ const Login = () => {
9696

9797
useEffect(() => {
9898
setLoginNavigationURL()
99+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
100+
dashboardAccessed()
99101
}, [])
100102

101-
useEffect(() => {
102-
if (initResult && !initLoading) {
103-
const [ssoLoginListResponse, dashboardAccessesResponse] = initResult
104-
if (ssoLoginListResponse.status === 'fulfilled' && ssoLoginListResponse.value.result) {
105-
setLoginList(ssoLoginListResponse.value.result as SSOConfigLoginList[])
106-
}
107-
108-
if (
109-
typeof Storage !== 'undefined' &&
110-
!localStorage.getItem('isDashboardAccessed') &&
111-
dashboardAccessesResponse.status === 'fulfilled' &&
112-
dashboardAccessesResponse.value.result
113-
) {
114-
localStorage.setItem('isDashboardAccessed', 'true')
115-
}
116-
}
117-
}, [initLoading, initResult])
118-
119103
const onClickSSO = () => {
120104
if (typeof Storage !== 'undefined') {
121105
localStorage.setItem('isSSOLogin', 'true')
@@ -127,7 +111,7 @@ const Login = () => {
127111

128112
const renderSSOLoginPage = () => (
129113
<div className="flexbox-col dc__gap-12 p-36">
130-
{initLoading && !loginList.length && (
114+
{ssoListLoading && !loginList.length && (
131115
<Button
132116
variant={ButtonVariantType.secondary}
133117
text="Checking SSO"

src/components/login/login.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ export interface SSOConfigLoginList extends Pick<SSOConfigDTO, 'id' | 'active' |
2121
}
2222

2323
export interface LoginFormType {
24-
loginList: SSOConfigLoginList[]
24+
loginList: SSOConfigDTO[]
2525
}

src/services/service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,17 @@ export function getClusterListMinWithoutAuth(): Promise<ClusterListResponse> {
525525
return get(URL)
526526
}
527527

528-
export function dashboardAccessed() {
529-
return get(Routes.DASHBOARD_ACCESSED)
528+
export const dashboardAccessed = async () => {
529+
try {
530+
const isDashboardAccessed = localStorage.getItem('isDashboardAccessed')
531+
if (isDashboardAccessed) {
532+
return
533+
}
534+
await get(Routes.DASHBOARD_ACCESSED)
535+
localStorage.setItem('isDashboardAccessed', 'true')
536+
} catch {
537+
// do noting
538+
}
530539
}
531540

532541
export function dashboardLoggedIn() {

0 commit comments

Comments
 (0)