Skip to content

Commit f94a525

Browse files
Merge pull request #638 from devtron-labs/feat/activate-license
feat: add login banner and activate license
2 parents 2dfd797 + e097081 commit f94a525

File tree

20 files changed

+219
-23
lines changed

20 files changed

+219
-23
lines changed

src/Assets/IconV2/ic-calendar.svg

Lines changed: 19 additions & 0 deletions
Loading

src/Assets/IconV2/ic-quote.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Common/API/CoreAPI.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import { API_STATUS_CODES, APIOptions, FALLBACK_REQUEST_TIMEOUT, Host, ResponseType, ServerErrors } from '..'
1+
import { API_STATUS_CODES, APIOptions, FALLBACK_REQUEST_TIMEOUT, Host, noop, ResponseType, ServerErrors } from '..'
22
import { CoreAPIConstructorParamsType, FetchAPIParamsType, FetchInTimeParamsType } from './types'
33
import { handleServerError } from './utils'
44

55
class CoreAPI {
66
handleLogout: () => void
77

8+
handleRedirectToLicenseActivation?: () => void
9+
810
host: string
911

1012
timeout: number
1113

12-
constructor({ handleLogout, host, timeout }: CoreAPIConstructorParamsType) {
14+
constructor({ handleLogout, host, timeout, handleRedirectToLicenseActivation }: CoreAPIConstructorParamsType) {
1315
this.handleLogout = handleLogout
1416
this.host = host || Host
1517
this.timeout = timeout || FALLBACK_REQUEST_TIMEOUT
18+
this.handleRedirectToLicenseActivation = handleRedirectToLicenseActivation || noop
1619
}
1720

1821
private fetchAPI = async <K = object>({
@@ -21,6 +24,7 @@ class CoreAPI {
2124
data,
2225
signal,
2326
preventAutoLogout = false,
27+
preventLicenseRedirect = false,
2428
isMultipartRequest,
2529
}: FetchAPIParamsType<K>): Promise<ResponseType> => {
2630
const options: RequestInit = {
@@ -41,6 +45,18 @@ class CoreAPI {
4145
).then(
4246
// eslint-disable-next-line consistent-return
4347
async (response) => {
48+
const isLicenseInvalid = response.headers.get('X-License-Status') === 'inValid'
49+
50+
if (isLicenseInvalid && !preventLicenseRedirect) {
51+
this.handleRedirectToLicenseActivation()
52+
53+
return new Promise((resolve) => {
54+
setTimeout(() => {
55+
resolve({ code: API_STATUS_CODES.UNAUTHORIZED, status: 'Unauthorized', result: [] })
56+
}, 1000)
57+
})
58+
}
59+
4460
const contentType = response.headers.get('Content-Type')
4561
if (response.status === API_STATUS_CODES.UNAUTHORIZED) {
4662
if (preventAutoLogout) {
@@ -144,6 +160,7 @@ class CoreAPI {
144160
data,
145161
signal,
146162
preventAutoLogout: options?.preventAutoLogout || false,
163+
preventLicenseRedirect: options?.preventLicenseRedirect || false,
147164
isMultipartRequest,
148165
}),
149166
timeoutPromise,

src/Common/API/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import CoreAPI from './CoreAPI'
2-
import { handleDashboardLogout } from './utils'
2+
import { handleDashboardLogout, handleRedirectToLicenseActivation } from './utils'
33

44
const dashboardAPI = new CoreAPI({
55
handleLogout: handleDashboardLogout,
66
timeout: (window as any)?._env_?.GLOBAL_API_TIMEOUT,
7+
handleRedirectToLicenseActivation,
78
})
89

910
export const { post, put, patch, get, trash } = dashboardAPI

src/Common/API/types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { APIOptions } from '..'
22

33
export interface CoreAPIConstructorParamsType {
44
handleLogout: () => void
5+
handleRedirectToLicenseActivation?: () => void
56
/**
67
* @default Host
78
*/
@@ -20,10 +21,8 @@ export interface FetchInTimeParamsType<Data = object> {
2021
isMultipartRequest?: boolean
2122
}
2223

23-
export interface FetchAPIParamsType<Data = object> extends Omit<FetchInTimeParamsType<Data>, 'options'> {
24+
export interface FetchAPIParamsType<Data = object>
25+
extends Omit<FetchInTimeParamsType<Data>, 'options'>,
26+
Pick<APIOptions, 'preventAutoLogout' | 'preventLicenseRedirect'> {
2427
signal: AbortSignal
25-
/**
26-
* @default false
27-
*/
28-
preventAutoLogout?: boolean
2928
}

src/Common/API/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ export const handleDashboardLogout = () => {
4646
const continueParam = `${window.location.pathname.replace(window.__BASE_URL__, '')}${window.location.search}`
4747
window.location.href = `${window.location.origin}${window.__BASE_URL__}${URLS.LOGIN_SSO}?continue=${continueParam}`
4848
}
49+
50+
export const handleRedirectToLicenseActivation = () => {
51+
window.location.href = `${window.location.origin}${window.__BASE_URL__}${URLS.LICENSE_AUTH}`
52+
}

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const URLS = {
8080
RESOURCE_BROWSER: '/resource-browser',
8181
COMPARE_CLUSTERS: '/compare-clusters',
8282
CONFIG_DRIFT: 'config-drift',
83+
LICENSE_AUTH: '/license-auth',
8384
}
8485

8586
export const ROUTES = {

src/Common/Helper.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,3 +1077,6 @@ export const getHashedValue = async (value: string): Promise<string | null> => {
10771077
return null
10781078
}
10791079
}
1080+
1081+
export const getTTLInHumanReadableFormat = (ttl: number): string =>
1082+
moment.duration(Math.abs(ttl), 'seconds').humanize(false)

src/Common/Types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ export interface APIOptions {
6565
*/
6666
signal?: AbortSignal
6767
abortControllerRef?: MutableRefObject<AbortController>
68+
/**
69+
* @default false
70+
*/
6871
preventAutoLogout?: boolean
72+
/**
73+
* @default false
74+
*/
75+
preventLicenseRedirect?: boolean
6976
}
7077

7178
export interface OptionType<T = string, K = string> {

src/Shared/Components/DevtronLicenseCard/DevtronLicenseCard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { ClipboardButton } from '@Common/index'
1+
import { ClipboardButton, getTTLInHumanReadableFormat } from '@Common/index'
22
import { ReactComponent as ICChatSupport } from '@IconsV2/ic-chat-circle-dots.svg'
33
import { DevtronLicenseCardProps, ENTERPRISE_SUPPORT_LINK, LicenseStatus } from '@Shared/index'
44
import { Button, ButtonVariantType } from '../Button'
55
import { Icon } from '../Icon'
6-
import { getLicenseColorsAccordingToStatus, getTTLInHumanReadableFormat } from './utils'
6+
import { getLicenseColorsAccordingToStatus } from './utils'
77
import './licenseCard.scss'
88

99
export const DevtronLicenseCard = ({
@@ -21,7 +21,7 @@ export const DevtronLicenseCard = ({
2121

2222
return (
2323
<div className="flexbox-col p-8 br-16" style={{ backgroundColor: bgColor }}>
24-
<div className="license-card flexbox-col br-12 h-200 bg__tertiary">
24+
<div className="license-card border__secondary-translucent flexbox-col br-12 h-200 bg__tertiary">
2525
<div className="p-20 flexbox-col dc__content-space flex-grow-1">
2626
<div className="flexbox dc__align-items-center dc__content-space">
2727
<span className="font-merriweather cn-9 fs-16 fw-7 lh-1-5 dc__truncate">{enterpriseName}</span>
@@ -44,7 +44,7 @@ export const DevtronLicenseCard = ({
4444
</div>
4545
</div>
4646
{isTrial && (
47-
<span className="trial-license-badge flexbox dc__align-items-center px-20 py-6 cn-9 fs-11 fw-5 lh-1-5">
47+
<span className="trial-license-badge flexbox dc__align-items-center px-20 py-6 cn-9 fs-11 fw-5 lh-1-5 dc__bottom-radius-12">
4848
TRIAL LICENSE
4949
</span>
5050
)}

0 commit comments

Comments
 (0)