Skip to content

Commit 7130706

Browse files
committed
feat: use fetch api params from api options
1 parent 621c277 commit 7130706

File tree

7 files changed

+17
-16
lines changed

7 files changed

+17
-16
lines changed

src/Common/API/CoreAPI.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class CoreAPI {
4949

5050
if (isLicenseInvalid && !preventLicenseRedirect) {
5151
this.handleRedirectToLicenseActivation()
52+
53+
return new Promise((resolve) => {
54+
setTimeout(() => {
55+
resolve({ code: API_STATUS_CODES.UNAUTHORIZED, status: 'Unauthorized', result: [] })
56+
}, 1000)
57+
})
5258
}
5359

5460
const contentType = response.headers.get('Content-Type')

src/Common/API/types.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@ export interface FetchInTimeParamsType<Data = object> {
2121
isMultipartRequest?: boolean
2222
}
2323

24-
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'> {
2527
signal: AbortSignal
26-
/**
27-
* @default false
28-
*/
29-
preventAutoLogout?: boolean
30-
/**
31-
* @default false
32-
*/
33-
preventLicenseRedirect?: boolean
3428
}

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export interface APIOptions {
6565
*/
6666
signal?: AbortSignal
6767
abortControllerRef?: MutableRefObject<AbortController>
68+
/**
69+
* @default false
70+
*/
6871
preventAutoLogout?: boolean
6972
/**
7073
* @default false

src/Shared/Components/DevtronLicenseCard/DevtronLicenseCard.tsx

Lines changed: 2 additions & 2 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 = ({
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export { default as DevtronLicenseCard } from './DevtronLicenseCard'
2-
export { getTTLInHumanReadableFormat } from './utils'

src/Shared/Components/DevtronLicenseCard/utils.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { LicenseStatus } from '@Shared/index'
2-
import moment from 'moment'
32

43
export const getLicenseColorsAccordingToStatus = (
54
licenseStatus: LicenseStatus,
@@ -13,6 +12,3 @@ export const getLicenseColorsAccordingToStatus = (
1312
return { bgColor: 'var(--R100)', textColor: 'var(--R500)' }
1413
}
1514
}
16-
17-
export const getTTLInHumanReadableFormat = (ttl: number): string =>
18-
moment.duration(Math.abs(ttl), 'seconds').humanize(false)

0 commit comments

Comments
 (0)