Skip to content

Commit 7aacbac

Browse files
committed
feat: implement useIsSecureConnection hook and integrate it into DocLink and HelpButton components
1 parent 2321d7d commit 7aacbac

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

src/Shared/Components/DocLink/DocLink.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MouseEvent } from 'react'
33
import { DOCUMENTATION_HOME_PAGE } from '@Common/Constants'
44
import { Button, ButtonComponentType, ButtonVariantType, Icon } from '@Shared/Components'
55
import { ComponentSizeType } from '@Shared/constants'
6+
import { useIsSecureConnection } from '@Shared/Hooks'
67
import { SidePanelTab, useMainContext } from '@Shared/Providers'
78

89
import { DocLinkProps } from './types'
@@ -24,6 +25,7 @@ export const DocLink = <T extends boolean = false>({
2425
}: DocLinkProps<T>) => {
2526
// HOOKS
2627
const { isEnterprise, setSidePanelConfig, isLicenseDashboard } = useMainContext()
28+
const isSecureConnection = useIsSecureConnection()
2729

2830
// CONSTANTS
2931
const documentationLink = getDocumentationUrl({
@@ -36,6 +38,7 @@ export const DocLink = <T extends boolean = false>({
3638
// HANDLERS
3739
const handleClick = (e: MouseEvent<HTMLAnchorElement>) => {
3840
if (
41+
isSecureConnection &&
3942
!isExternalLink &&
4043
!openInNewTab &&
4144
!e.metaKey &&

src/Shared/Components/Header/HelpButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SliderButton } from '@typeform/embed-react'
55
import { DOCUMENTATION_HOME_PAGE, MAX_LOGIN_COUNT, URLS } from '@Common/Constants'
66
import { handleAnalyticsEvent } from '@Shared/Analytics'
77
import { ComponentSizeType } from '@Shared/constants'
8+
import { useIsSecureConnection } from '@Shared/Hooks'
89
import { AppThemeType, SidePanelTab, useMainContext, useTheme } from '@Shared/Providers'
910
import { InstallationType } from '@Shared/types'
1011

@@ -54,6 +55,7 @@ export const HelpButton = ({ serverInfo, fetchingServerInfo, onClick, hideGettin
5455
showGettingStartedCard,
5556
} = useMainContext()
5657
const { appTheme } = useTheme()
58+
const isSecureConnection = useIsSecureConnection()
5759

5860
// REFS
5961
const typeFormSliderButtonRef = useRef(null)
@@ -73,7 +75,7 @@ export const HelpButton = ({ serverInfo, fetchingServerInfo, onClick, hideGettin
7375

7476
const handleViewDocumentationClick: HelpButtonActionMenuProps['onClick'] = (_, e) => {
7577
// Opens documentation in side panel when clicked normally, or in a new tab when clicked with the meta/command key
76-
if (!e.metaKey) {
78+
if (isSecureConnection && !e.metaKey) {
7779
e.preventDefault()
7880
setSidePanelConfig((prev) => ({
7981
...prev,

src/Shared/Hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
export * from './UseDownload'
1818
export * from './useForm'
1919
export * from './useGetResourceKindsOptions'
20+
export * from './useIsSecureConnection'
2021
export * from './useOneTimePrompt'
2122
export * from './UsePrompt'
2223
export * from './useStickyEvent'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useIsSecureConnection'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useEffect, useState } from 'react'
2+
3+
export const useIsSecureConnection = () => {
4+
const [isSecure, setIsSecure] = useState(false)
5+
6+
useEffect(() => {
7+
setIsSecure(window.location.protocol === 'https:')
8+
}, [])
9+
10+
return isSecure
11+
}

0 commit comments

Comments
 (0)