Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(service-portal): Documents dl url & notifications api - hotfix #15255

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ const NotificationButton = ({
showMenu = false,
disabled,
}: Props) => {
const { formatMessage } = useLocale()
const { formatMessage, lang } = useLocale()
const [hasMarkedLocally, setHasMarkedLocally] = useState(false)
const [markAllAsSeen] = useMarkAllNotificationsAsSeenMutation()
const { width } = useWindowSize()
const isMobile = width < theme.breakpoints.md
const ref = useRef<HTMLButtonElement>(null)

const { data } = useGetUserNotificationsOverviewQuery({
const { data, refetch } = useGetUserNotificationsOverviewQuery({
variables: {
input: {
limit: 5,
},
locale: lang,
},
})

useEffect(() => {
refetch()
}, [lang, refetch])

const showBadge =
!!data?.userNotificationsOverview?.unseenCount && !hasMarkedLocally

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export const NotificationLine = ({ data, onClickCallback }: Props) => {
<AvatarImage
img={data.sender.logoUrl}
background={!isRead ? 'white' : 'blue100'}
as="div"
imageClass={styles.img}
/>
) : undefined}
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export const link = style({
overflow: 'hidden',
})

export const img = style({
height: 'auto',
width: 'auto',
display: 'flex',
maxHeight: 28,
maxWidth: 28,
})

globalStyle(`${link} > span`, {
boxShadow: 'none',
})
Expand Down
1 change: 1 addition & 0 deletions libs/api/domains/documents/src/lib/documentV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class DocumentServiceV2 {
publicationDate: document.date,
id: documentId,
name: document.fileName,
downloadUrl: `${this.downloadServiceConfig.baseUrl}/download/v1/electronic-documents/${documentId}`,
sender: {
id: document.senderNationalId,
name: document.senderName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from './notifications.model'
import type { Locale } from '@island.is/shared/types'
import { LOGGER_PROVIDER, type Logger } from '@island.is/logging'
import { FeatureFlag, Features } from '@island.is/nest/feature-flags'

const LOG_CATEGORY = 'notifications-resolver'
export const AUDIT_NAMESPACE = 'notifications-resolver'
Expand All @@ -22,7 +21,6 @@ export const AUDIT_NAMESPACE = 'notifications-resolver'
@Resolver()
@Audit({ namespace: AUDIT_NAMESPACE })
@Scopes(DocumentsScope.main)
@FeatureFlag(Features.ServicePortalNotificationsEnabled)
export class NotificationsResolver {
constructor(
private readonly service: NotificationsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import type { Locale } from '@island.is/shared/types'
import { LOGGER_PROVIDER, type Logger } from '@island.is/logging'
import { Loader } from '@island.is/nest/dataloader'
import { AUDIT_NAMESPACE } from './notifications.resolver'
import { FeatureFlag, Features } from '@island.is/nest/feature-flags'
import { DocumentsScope } from '@island.is/auth/scopes'

const LOG_CATEGORY = 'notification-list-resolver'
Expand All @@ -35,7 +34,6 @@ const LOG_CATEGORY = 'notification-list-resolver'
@Resolver(() => NotificationsResponse)
@Audit({ namespace: AUDIT_NAMESPACE })
@Scopes(DocumentsScope.main)
@FeatureFlag(Features.ServicePortalNotificationsEnabled)
export class NotificationsListResolver {
constructor(
private readonly service: NotificationsService,
Expand Down
17 changes: 13 additions & 4 deletions libs/api/domains/notifications/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { RenderedNotificationDto } from '@island.is/clients/user-notification'
import { Notification } from '../lib/notifications.model'

const cleanString = (str?: string) => {
if (!str) {
return ''
}
return str.replace(/\s+/g, ' ').trim()
}

export const notificationMapper = (
notification: RenderedNotificationDto,
): Notification => ({
Expand All @@ -20,10 +27,12 @@ export const notificationMapper = (
nationalId: undefined,
},
message: {
title: notification.title,
body: notification.body,
dataCopy: notification.dataCopy,
displayBody: notification.dataCopy ?? notification.body,
title: cleanString(notification.title),
body: cleanString(notification.body),
dataCopy: notification.dataCopy
? cleanString(notification.dataCopy)
: undefined,
displayBody: cleanString(notification.dataCopy ?? notification.body),
link: {
url: notification.clickActionUrl,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ export const avatar = style({
})

export const circleImg = style({
width: '28px',
height: 'auto',
width: 'auto',
display: 'flex',
maxHeight: 38,
maxWidth: 38,
})

export const button = style({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ interface Props {
avatar?: ReactNode
onClick?: (event: MouseEvent<HTMLElement>) => void
large?: boolean
as?: 'div' | 'button'
imageClass?: string
}

export const AvatarImage: FC<Props> = ({
img,
background,
avatar,
large,
imageClass,
as = 'button',
onClick,
}) => {
const { formatMessage } = useLocale()
Expand All @@ -38,14 +42,24 @@ export const AvatarImage: FC<Props> = ({
className={cn(styles.imageContainer, {
[styles.largeAvatar]: large,
})}
component="button"
aria-label={formatMessage(messages.markAsBulkSelection)}
component={as}
aria-label={
as === 'button'
? formatMessage(messages.markAsBulkSelection)
: undefined
}
onClick={onClick}
>
{avatar ? (
avatar
) : (
<img className={styles.image} src={img} alt="document" />
<img
className={cn(styles.image, {
[`${imageClass}`]: imageClass,
})}
src={img}
alt="document"
/>
)}
</Box>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ fragment NotificationDataFields on Notification {
}
}

query GetUserNotifications($input: NotificationsInput!) {
userNotifications(input: $input) {
query GetUserNotificationsList($input: NotificationsInput!, $locale: String) {
userNotifications(input: $input, locale: $locale) {
data {
...NotificationDataFields
recipient {
Expand All @@ -52,8 +52,11 @@ query GetUserNotifications($input: NotificationsInput!) {
}
}

query GetUserNotificationsOverview($input: NotificationsInput!) {
userNotificationsOverview: userNotifications(input: $input) {
query GetUserNotificationsOverview(
$input: NotificationsInput!
$locale: String
) {
userNotificationsOverview: userNotifications(input: $input, locale: $locale) {
data {
...NotificationDataFields
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
import {
Box,
Button,
Expand All @@ -17,7 +17,7 @@ import {
} from '@island.is/service-portal/core'

import {
useGetUserNotificationsQuery,
useGetUserNotificationsListQuery,
useMarkAllNotificationsAsReadMutation,
useMarkUserNotificationAsReadMutation,
} from './Notifications.generated'
Expand All @@ -32,7 +32,7 @@ const DEFAULT_PAGE_SIZE = 5

const UserNotifications = () => {
useNamespaces('sp.information-notifications')
const { formatMessage } = useLocale()
const { formatMessage, lang } = useLocale()
const [loadingMore, setLoadingMore] = useState(false)

const [postMarkAsRead] = useMarkUserNotificationAsReadMutation()
Expand All @@ -47,16 +47,21 @@ const UserNotifications = () => {
})

const { data, loading, error, refetch, fetchMore } =
useGetUserNotificationsQuery({
useGetUserNotificationsListQuery({
variables: {
input: {
limit: DEFAULT_PAGE_SIZE,
before: '',
after: '',
},
locale: lang,
},
})

useEffect(() => {
refetch()
}, [refetch, lang])

const loadMore = (cursor: string) => {
if (loadingMore) return
setLoadingMore(true)
Expand All @@ -67,6 +72,7 @@ const UserNotifications = () => {
before: '',
after: cursor,
},
locale: lang,
},
updateQuery: (prevResult, { fetchMoreResult }) => {
if (
Expand Down
Loading