🩹(frontend) prevent runtime error when Crisp is not initialized

Prevents runtime error when Crisp chat hasn't initialized before component mount
Previously caused crash since we assumed $crisp global was always available.
This commit is contained in:
lebaudantoine
2025-01-22 16:12:58 +01:00
committed by aleb_the_flash
parent 4347d87f33
commit 8eab45b6d5

View File

@@ -7,7 +7,9 @@ import { ToggleButtonProps } from '@/primitives/ToggleButton'
export const SupportToggle = ({ onPress, ...props }: ToggleButtonProps) => {
const { t } = useTranslation('rooms', { keyPrefix: 'controls' })
const [isOpened, setIsOpened] = useState($crisp.is('chat:opened'))
const [isOpened, setIsOpened] = useState(() => {
return window?.$crisp?.is?.('chat:opened') || false
})
useEffect(() => {
if (!Crisp) {