Skip to content

Commit

Permalink
fix(service-portal): Add error toast to overveiw (#16021)
Browse files Browse the repository at this point in the history
* Add error toast to overveiw

* Remove console log

* Fix focus on checkmark inbox

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thordurhhh and kodiakhq[bot] authored Sep 16, 2024
1 parent 02e8a3c commit 97928c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import format from 'date-fns/format'
import { FC, useEffect, useRef, useState } from 'react'

import { DocumentV2, DocumentV2Content } from '@island.is/api/schema'
import { Box, Text, LoadingDots, Icon } from '@island.is/island-ui/core'
import { Box, Text, LoadingDots, Icon, toast } from '@island.is/island-ui/core'
import { dateFormat } from '@island.is/shared/constants'
import { m } from '@island.is/service-portal/core'
import * as styles from './DocumentLine.css'
Expand Down Expand Up @@ -75,7 +75,7 @@ export const DocumentLine: FC<Props> = ({
const avatarRef = useRef(null)

const isFocused = useIsChildFocusedorHovered(wrapperRef)
const isAvatarFocused = useIsChildFocusedorHovered(avatarRef)
const isAvatarFocused = useIsChildFocusedorHovered(avatarRef, false)

useEffect(() => {
setHasFocusOrHover(isFocused)
Expand Down Expand Up @@ -135,11 +135,14 @@ export const DocumentLine: FC<Props> = ({
}
},
onError: () => {
setDocumentDisplayError(
formatMessage(messages.documentFetchError, {
senderName: documentLine.sender?.name ?? '',
}),
)
const errorMessage = formatMessage(messages.documentFetchError, {
senderName: documentLine.sender?.name ?? '',
})
if (asFrame) {
toast.error(errorMessage, { toastId: 'overview-doc-error' })
} else {
setDocumentDisplayError(errorMessage)
}
},
})

Expand Down
13 changes: 10 additions & 3 deletions libs/service-portal/documents/src/hooks/useIsChildFocused.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { RefObject, useEffect, useState } from 'react'

export const useIsChildFocusedorHovered = (ref: RefObject<HTMLElement>) => {
export const useIsChildFocusedorHovered = (
ref: RefObject<HTMLElement>,
focus = true,
) => {
const [isFocused, setIsFocused] = useState(false)
const [isHovered, setIsHovered] = useState(false)

Expand All @@ -21,11 +24,15 @@ export const useIsChildFocusedorHovered = (ref: RefObject<HTMLElement>) => {
}
}

document.addEventListener('focusin', handleFocus)
if (focus) {
document.addEventListener('focusin', handleFocus)
}
document.addEventListener('mouseover', handleHover)

return () => {
document.removeEventListener('focusin', handleFocus)
if (focus) {
document.removeEventListener('focusin', handleFocus)
}
document.removeEventListener('mouseover', handleHover)
}
}, [ref])
Expand Down

0 comments on commit 97928c5

Please sign in to comment.