Skip to content

Commit

Permalink
🚸(frontend) show support toggle only if support is enabled
Browse files Browse the repository at this point in the history
Avoid misleading the user, if support is not enabled, as it's optional,
avoid displaying a useless control button.

Requested by Dutch counterparts.
  • Loading branch information
lebaudantoine committed Jan 29, 2025
1 parent 8eab45b commit 4ae3d96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { useTranslation } from 'react-i18next'
import { Crisp } from 'crisp-sdk-web'
import { useEffect, useState } from 'react'
import { ToggleButtonProps } from '@/primitives/ToggleButton'
import { useIsSupportEnabled } from '@/features/support/hooks/useSupport'

export const SupportToggle = ({ onPress, ...props }: ToggleButtonProps) => {
const { t } = useTranslation('rooms', { keyPrefix: 'controls' })

const [isOpened, setIsOpened] = useState(() => {
return window?.$crisp?.is?.('chat:opened') || false
})
Expand All @@ -28,6 +30,12 @@ export const SupportToggle = ({ onPress, ...props }: ToggleButtonProps) => {
}
}, [])

const isSupportEnabled = useIsSupportEnabled()

if (!isSupportEnabled) {
return
}

return (
<ToggleButton
square
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/src/features/support/hooks/useSupport.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from 'react'
import { Crisp } from 'crisp-sdk-web'
import { ApiUser } from '@/features/auth/api/ApiUser'
import { useConfig } from '@/api/useConfig'

export const initializeSupportSession = (user: ApiUser) => {
if (!Crisp.isCrispInjected()) return
Expand Down Expand Up @@ -29,3 +30,8 @@ export const useSupport = ({ id }: useSupportProps) => {

return null
}

export const useIsSupportEnabled = () => {
const { data } = useConfig()
return !!data?.support?.id
}

0 comments on commit 4ae3d96

Please sign in to comment.