Skip to content

Commit

Permalink
fix(service-portal): Notifications - locale updates. Add cleanstring (#…
Browse files Browse the repository at this point in the history
…15239)

* Fix locale updates. Add cleanstring

* update string clean

* Update packagejson

* Update query

* Update query

* Add lang option

* Test

* Fix

* Add locale

* Test name update

* fix: force generated files

* chore: nx format:write update dirty files

* Revert test

* Remove ff

* fix: hash generated files

* fix(j-s): Null Service Reference (#15247)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* feat(native-app): Notifications final improvements (#15240)

* feat: buttons at top should not be sticky

* feat: add empty state for notifications

* fix: make sure to update unreadCount in inbox when fetching next page

* feat: add fallback icon for notifications

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* feat(consultation-portal): KAM-2522: PowerBI report added (#15251)

* fix: hash generated files (#15253)

* fix: hash generated files

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <builders@andes.is>

* fix: remove file

* Update __config.mjs

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: lommi <jonorn@gmail.com>
Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: Guðjón Guðjónsson <gudjon@kolibri.is>
Co-authored-by: Þórey Jóna <thoreyjona@gmail.com>
Co-authored-by: Karl Arnar Ægisson <korsbacka@gmail.com>
  • Loading branch information
7 people committed Jun 18, 2024
1 parent 62a579f commit a262483
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
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 @@ -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 @@ -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

0 comments on commit a262483

Please sign in to comment.