Skip to content

Commit

Permalink
feat: Change help link according to context data
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Sep 24, 2024
1 parent 44eacc8 commit 46cd2eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/components/HeroHeader/Corner.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ jest.mock(
jest.mock('cozy-flags', () => {
return jest.fn().mockReturnValue(null)
})
jest.mock('cozy-client', () => ({
...jest.requireActual('cozy-client'),
useInstanceInfo: jest
.fn()
.mockReturnValue({ isLoaded: true, context: { data: {} } })
}))

describe('Corner', () => {
it('should only render the log out button', () => {
Expand Down
13 changes: 10 additions & 3 deletions src/components/HeroHeader/HelpButton.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import React from 'react'

import HelpIcon from 'cozy-ui/transpiled/react/Icons/Help'
import { useI18n } from "cozy-ui/transpiled/react/providers/I18n"
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
import { useInstanceInfo } from 'cozy-client'

import CornerButton from './CornerButton'

const HelpButton = (): JSX.Element => {
const HelpButton = (): JSX.Element | null => {
const { t } = useI18n()

const { isLoaded, context } = useInstanceInfo()

if (!isLoaded) return null

const link = context.data?.help_link || t('help_link')

return (
<CornerButton
href={t('help_link')}
href={link}
icon={HelpIcon}
label={t('help')}
rel="noopener noreferrer"
Expand Down

0 comments on commit 46cd2eb

Please sign in to comment.