Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/feat/grant-slice' i…
Browse files Browse the repository at this point in the history
…nto feat/grant-slice
  • Loading branch information
thorkellmani committed Dec 18, 2024
2 parents 71a8d65 + b6b8ce4 commit 4f93471
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import router from 'next/router'
import { Box, Button } from '@island.is/island-ui/core'
import * as constants from '@island.is/judicial-system/consts'
import { formatDate } from '@island.is/judicial-system/formatters'
import { CourtSessionType } from '@island.is/judicial-system/types'
import { titles } from '@island.is/judicial-system-web/messages'
import {
CourtArrangements,
Expand Down Expand Up @@ -81,23 +82,26 @@ const Subpoena: FC = () => {
return
}

// If rescheduling after the court has met, then clear the current conclusion
const clearedConclusion =
isArraignmentScheduled && workingCase.indictmentDecision
? [
{
const additionalUpdates = [
{
// This should always be an arraignment type
courtSessionType: CourtSessionType.ARRAIGNMENT,
// if the case is being rescheduled after the court has met,
// then clear the current conclusion
...(isArraignmentScheduled && workingCase.indictmentDecision
? {
indictmentDecision: null,
courtSessionType: null,
courtDate: null,
postponedIndefinitelyExplanation: null,
indictmentRulingDecision: null,
mergeCaseId: null,
force: true,
},
]
: undefined
}
: {}),
},
]

const courtDateUpdated = await sendCourtDateToServer(clearedConclusion)
const courtDateUpdated = await sendCourtDateToServer(additionalUpdates)

if (!courtDateUpdated) {
setIsCreatingSubpoena(false)
Expand Down
40 changes: 36 additions & 4 deletions apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import React, { useEffect, useState } from 'react'
import { config, boostChatPanelEndpoints } from './config'
import React, { useEffect, useMemo, useState } from 'react'
import { useQuery } from '@apollo/client'

import { Query, QueryGetNamespaceArgs } from '@island.is/web/graphql/schema'
import { useNamespaceStrict } from '@island.is/web/hooks'
import { useI18n } from '@island.is/web/i18n'
import { GET_NAMESPACE_QUERY } from '@island.is/web/screens/queries'

import { ChatBubble } from '../ChatBubble'
import { BoostChatPanelProps } from '../types'
import { boostChatPanelEndpoints, config } from './config'

declare global {
interface Window {
Expand All @@ -16,6 +23,7 @@ export const BoostChatPanel: React.FC<
React.PropsWithChildren<BoostChatPanelProps>
> = ({ endpoint, pushUp = false }) => {
const [showButton, setShowButton] = useState(Boolean(window.boost)) // we show button when chat already loaded
const { activeLocale } = useI18n()

useEffect(() => {
// recreate the chat panel if we are on a different endpoint
Expand Down Expand Up @@ -60,19 +68,43 @@ export const BoostChatPanel: React.FC<
)

setShowButton(true)

const queryParam = new URLSearchParams(window.location.search).get(
'wa_lid',
)
if (queryParam && ['t10', 't11'].includes(queryParam)) {
window.boost.chatPanel.show()
}
})

el.src = boostChatPanelEndpoints[endpoint].url
el.id = 'boost-script'
document.body.appendChild(el)
}
}, [])
}, [endpoint])

const { data } = useQuery<Query, QueryGetNamespaceArgs>(GET_NAMESPACE_QUERY, {
variables: {
input: {
lang: activeLocale,
namespace: 'ChatPanels',
},
},
})

const namespace = useMemo(
() => JSON.parse(data?.getNamespace?.fields || '{}'),
[data?.getNamespace?.fields],
)

const n = useNamespaceStrict(namespace)

return (
<ChatBubble
text={'Hæ, get ég aðstoðað?'}
text={n('chatBubbleText', 'Hæ, get ég aðstoðað?')}
onClick={() => window.boost.chatPanel.show()}
isVisible={showButton}
pushUp={pushUp}
/>
)
}
Expand Down
202 changes: 170 additions & 32 deletions apps/web/pages/api/rss/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import format from 'date-fns/format'
import localeEN from 'date-fns/locale/en-GB'
import localeIS from 'date-fns/locale/is'
import type { NextApiRequest, NextApiResponse } from 'next'
import { parseAsString, parseAsStringEnum } from 'next-usequerystate'

import { defaultLanguage } from '@island.is/shared/constants'
import type { Locale } from '@island.is/shared/types'
import { FRONTPAGE_NEWS_TAG_ID } from '@island.is/web/constants'
import initApollo from '@island.is/web/graphql/client'
import {
ContentLanguage,
GetEventsQuery,
GetEventsQueryVariables,
GetGenericListItemsQuery,
GetGenericListItemsQueryVariables,
GetNewsQuery,
QueryGetNewsArgs,
} from '@island.is/web/graphql/schema'
import { linkResolver } from '@island.is/web/hooks'
import { isLocale } from '@island.is/web/i18n/I18n'
import { GET_NEWS_QUERY } from '@island.is/web/screens/queries'
import { GET_EVENTS_QUERY } from '@island.is/web/screens/queries/Events'
import { GET_GENERIC_LIST_ITEMS_QUERY } from '@island.is/web/screens/queries/GenericList'

interface Item {
date: string | null | undefined
fullUrl: string
title: string
description: string | null | undefined
}

const localeMap = {
is: localeIS,
en: localeEN,
}

const CONTENT_TYPES = ['news', 'genericList', 'event']
const PAGE_SIZE = 25

const extractTagsFromQuery = (query: NextApiRequest['query']) => {
if (typeof query?.tags === 'string') {
Expand All @@ -28,6 +53,15 @@ const extractTagsFromQuery = (query: NextApiRequest['query']) => {
return [FRONTPAGE_NEWS_TAG_ID]
}

const generateItemString = (item: Item) => {
return `<item>
<title>${item.title}</title>
<link>${item.fullUrl}</link>
${item.description ? `<description>${item.description}</description>` : ''}
${item.date ? ` <pubDate>${item.date}</pubDate>` : ''}
</item>`
}

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
Expand All @@ -37,48 +71,152 @@ export default async function handler(
? (req.query.lang as Locale)
: defaultLanguage
const organization = req.query?.organization as string | undefined
const organizationSubpageSlug = req.query?.organizationsubpageslug as
| string
| undefined

const apolloClient = initApollo({}, locale)
const contentType = parseAsStringEnum(CONTENT_TYPES)
.withDefault('news')
.parseServerSide(req.query?.contentType) as 'news' | 'genericList' | 'event'

const news = await apolloClient.query<GetNewsQuery, QueryGetNewsArgs>({
query: GET_NEWS_QUERY,
variables: {
input: {
lang: locale as ContentLanguage,
size: 25,
tags,
organization,
},
},
})
const apolloClient = initApollo({}, locale)

const host = req.headers?.host
const protocol = `http${host?.startsWith('localhost') ? '' : 's'}://`
const baseUrl = `${protocol}${host}`

const newsItem = (item: GetNewsQuery['getNews']['items'][0]) => {
const url = organization
? linkResolver('organizationnews', [organization, item.slug], locale).href
: linkResolver('news', [item.slug], locale).href
const date = new Date(item.date).toUTCString()

return `<item>
<title>${item.title}</title>
<link>${baseUrl}${url}</link>
<description>${item.intro}</description>
<pubDate>${date}</pubDate>
</item>`
let itemString = ''

if (contentType === 'news') {
const news = await apolloClient.query<GetNewsQuery, QueryGetNewsArgs>({
query: GET_NEWS_QUERY,
variables: {
input: {
lang: locale as ContentLanguage,
size: PAGE_SIZE,
tags,
organization,
},
},
})

itemString = (news?.data?.getNews?.items ?? [])
.map((item) =>
generateItemString({
date: item.date ? new Date(item.date).toUTCString() : '',
description: item.intro,
fullUrl: `${baseUrl}${
organization
? linkResolver(
'organizationnews',
[organization, item.slug],
locale,
).href
: linkResolver('news', [item.slug], locale).href
}`,
title: item.title,
}),
)
.join('')
}

if (contentType === 'genericList') {
const genericListId = parseAsString
.withDefault('')
.parseServerSide(req.query?.genericListId)

const listItems = await apolloClient.query<
GetGenericListItemsQuery,
GetGenericListItemsQueryVariables
>({
query: GET_GENERIC_LIST_ITEMS_QUERY,
variables: {
input: {
lang: locale as ContentLanguage,
size: PAGE_SIZE,
tags,
genericListId,
},
},
})

itemString = (listItems.data.getGenericListItems?.items ?? [])
.map((item) =>
generateItemString({
title: item.title,
description: '',
fullUrl:
organization && organizationSubpageSlug && item.slug
? `${baseUrl}${
linkResolver(
'organizationsubpagelistitem',
[organization, organizationSubpageSlug, item.slug],
locale,
).href
}`
: '',
date: item.date ? new Date(item.date).toUTCString() : '',
}),
)
.join('')
}

if (contentType === 'event') {
const events = await apolloClient.query<
GetEventsQuery,
GetEventsQueryVariables
>({
query: GET_EVENTS_QUERY,
variables: {
input: {
lang: locale as ContentLanguage,
size: PAGE_SIZE,
organization,
},
},
})

itemString = (events.data.getEvents?.items ?? [])
.map((item) => {
const formattedStartDate = format(
new Date(item.startDate),
'dd. MMMM yyyy',
{
locale: localeMap[locale],
},
)

return generateItemString({
title: item.title,
description: `${formattedStartDate} ${
item.time.startTime as string
} ${item.time.endTime ? '-' : ''} ${item.time.endTime as string}`,
fullUrl: organization
? `${baseUrl}${
linkResolver(
'organizationevent',
[organization, item.slug],
locale,
).href
}`
: '',
date: item.firstPublishedAt
? new Date(item.firstPublishedAt).toUTCString()
: '',
})
})
.join('')
}

const feed = `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>Ísland.is</title>
<link>${baseUrl}</link>
<description>Ísland.is</description>
${news?.data?.getNews?.items?.map((item) => newsItem(item)).join('')}
</channel>
</rss>`
<rss version="2.0">
<channel>
<title>Ísland.is</title>
<link>${baseUrl}</link>
<description>Ísland.is</description>
${itemString}
</channel>
</rss>`

res.setHeader('Content-Type', 'text/xml;charset=UTF-8')
return res.status(200).send(feed)
Expand Down
1 change: 1 addition & 0 deletions apps/web/screens/queries/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const GET_EVENTS_QUERY = gql`
title
slug
startDate
firstPublishedAt
time {
startTime
endTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const transformApplicationToNewPrimarySchoolDTO = (
},
email: parents.parent1.email,
phone: parents.parent1.phoneNumber,
role: 'parent',
role: 'guardian',
},
...(parents.parent2
? [
Expand All @@ -59,7 +59,7 @@ export const transformApplicationToNewPrimarySchoolDTO = (
},
email: parents.parent2.email,
phone: parents.parent2.phoneNumber,
role: 'parent',
role: 'guardian',
},
]
: []),
Expand Down
Loading

0 comments on commit 4f93471

Please sign in to comment.