Skip to content

Commit

Permalink
Merge branch 'main' into j-s/case-files-added-notification
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 22, 2024
2 parents 4f8019b + e660494 commit e99213f
Show file tree
Hide file tree
Showing 26 changed files with 662 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Controller, Get, Inject, Query, UseGuards } from '@nestjs/common'
import {
Controller,
Get,
Inject,
Param,
Query,
UseGuards,
} from '@nestjs/common'
import { ApiOkResponse, ApiTags } from '@nestjs/swagger'

import { apiBasePath } from '@island.is/financial-aid/shared/lib'
Expand Down Expand Up @@ -44,4 +51,20 @@ export class OpenApiApplicationController {
state,
)
}

@Get('id/:id')
@ApiOkResponse({
type: ApplicationModel,
description: 'Get application',
})
async getById(
@Param('id') id: string,
@CurrentMunicipalityCode() municipalityCode: string,
) {
this.logger.info(
`Open api Application controller: Getting application by id ${id}`,
)

return this.applicationService.getbyID(municipalityCode, id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,77 @@ export class OpenApiApplicationService {
],
})
}

async getbyID(
municipalityCodes: string,
id: string,
): Promise<ApplicationModel> {
return this.applicationModel.findOne({
where: {
id: id,
municipalityCode: municipalityCodes,
state: {
[Op.or]: [ApplicationState.REJECTED, ApplicationState.APPROVED],
},
},
attributes: {
exclude: [
'staffId',
'applicationSystemId',
'interview',
'homeCircumstances',
'homeCircumstancesCustom',
'employment',
'employmentCustom',
'student',
'studentCustom',
],
},
order: [['modified', 'DESC']],
include: [
{
model: ApplicationFileModel,
as: 'files',
separate: true,
order: [['created', 'DESC']],
attributes: ['key', 'name', 'type'],
},
{
model: StaffModel,
as: 'staff',
attributes: ['name', 'nationalId'],
},
{
model: AmountModel,
as: 'amount',
attributes: [
'aidAmount',
'childrenAidAmount',
'decemberAidAmount',
'income',
'personalTaxCredit',
'tax',
'finalAmount',
'spousePersonalTaxCredit',
],
include: [
{
model: DeductionFactorsModel,
as: 'deductionFactors',
attributes: ['amount', 'description'],
},
],
separate: true,
order: [['created', 'DESC']],
},
{
model: DirectTaxPaymentModel,
as: 'directTaxPayments',
attributes: {
exclude: ['id', 'applicationId', 'created', 'modified'],
},
},
],
})
}
}
21 changes: 20 additions & 1 deletion apps/financial-aid/open-api/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Headers, Inject, Query } from '@nestjs/common'
import { Controller, Get, Headers, Inject, Param, Query } from '@nestjs/common'
import { ApiCreatedResponse } from '@nestjs/swagger'

import type { Logger } from '@island.is/logging'
Expand Down Expand Up @@ -34,4 +34,23 @@ export class AppController {
return applications
})
}

@Get('pdf')
@ApiCreatedResponse({
type: [ApplicationBackendModel],
description: 'Gets application',
})
async getPdf(
@Headers('API-Key') apiKey: string,
@Headers('Municipality-Code') municipalityCode: string,
@Query('id') id: string,
): Promise<ApplicationModel> {
this.logger.info('Gets one application and returns pdf')
return this.appService
.getApplication(apiKey, municipalityCode, id)
.then((application) => {
this.logger.info(`Application fetched`)
return application
})
}
}
26 changes: 26 additions & 0 deletions apps/financial-aid/open-api/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,30 @@ export class AppService {
return res.json()
})
}

async getApplication(
apiKey: string,
municipalityCode: string,
id: string,
): Promise<ApplicationModel> {
this.logger.info(
`trying to fetching all applications with municipalityCode ${municipalityCode}`,
id,
)

const url = new URL(
`${this.config.backend.url}/api/financial-aid/open-api-applications/id/${id}`,
)

return fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'API-Key': apiKey,
'Municipality-Code': municipalityCode,
},
}).then(async (res) => {
return res.json()
})
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ReactNode } from 'react'

import {
Box,
GridColumn,
Expand All @@ -17,7 +15,7 @@ import * as s from './OJOIHomeIntro.css'

export type OJOIHomeIntroProps = {
organization?: Organization
breadCrumbs: ReactNode
breadCrumbs: React.ReactNode
searchPlaceholder: string
quickLinks: Array<{ title: string; href: string; variant?: TagVariant }>
searchUrl: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import format from 'date-fns/format'
import is from 'date-fns/locale/is'

import { LinkV2, Table as T, Text } from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import { OfficialJournalOfIcelandAdvertsResponse } from '@island.is/web/graphql/schema'
import { useLinkResolver } from '@island.is/web/hooks'

import { formatDate } from './OJOIUtils'

export const OJOISearchListView = ({
adverts,
locale,
Expand All @@ -31,9 +30,7 @@ export const OJOISearchListView = ({
<T.Row key={ad.id}>
<T.Data>
<Text variant="small" whiteSpace="nowrap">
{format(new Date(ad.publicationDate), 'dd.MM.yyyy', {
locale: is,
})}
{formatDate(ad.publicationDate)}
</Text>
</T.Data>
<T.Data>
Expand Down
5 changes: 4 additions & 1 deletion apps/web/components/OfficialJournalOfIceland/OJOIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export const sortCategories = (cats: EntityOption[]) => {
})
}

export const formatDate = (date: string, df = 'dd.MM.yyyy') => {
export const formatDate = (date?: string, df = 'dd.MM.yyyy') => {
if (!date) {
return '-'
}
try {
return format(new Date(date), df, { locale: is })
} catch (e) {
Expand Down
46 changes: 45 additions & 1 deletion apps/web/components/OfficialJournalOfIceland/OJOIWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
BreadCrumbItem,
Breadcrumbs,
Button,
GridColumn,
GridContainer,
GridRow,
LinkV2,
Text,
} from '@island.is/island-ui/core'
Expand All @@ -28,6 +31,7 @@ type WrapperProps = {
sidebarContent?: ReactNode
goBackUrl?: string
hideTitle?: boolean
isHomePage?: boolean
}

export const OJOIWrapper = ({
Expand All @@ -40,6 +44,7 @@ export const OJOIWrapper = ({
sidebarContent,
goBackUrl,
hideTitle,
isHomePage,
}: WrapperProps) => {
const { width } = useWindowSize()
const [isMobile, setIsMobile] = useState<boolean | undefined>()
Expand Down Expand Up @@ -133,7 +138,46 @@ export const OJOIWrapper = ({
</SidebarLayout>
)}

{!sidebarContent && children}
{!sidebarContent && !isHomePage && (
<GridContainer>
<GridRow>
<GridColumn span="12/12">
{breadcrumbItems && (
<Breadcrumbs
items={breadcrumbItems ?? []}
renderLink={(link, item) => {
return item?.href ? (
<NextLink href={item?.href} legacyBehavior>
{link}
</NextLink>
) : (
link
)
}}
/>
)}

{!hideTitle && (
<Text as="h1" variant="h1" marginTop={2} marginBottom={3}>
{pageTitle}
</Text>
)}

{pageDescription && (
<Box className="rs_read" marginTop={3} paddingBottom={4}>
<Text variant="default">{pageDescription}</Text>
</Box>
)}

<Box className="rs_read" marginBottom={'containerGutter'}>
{children}
</Box>
</GridColumn>
</GridRow>
</GridContainer>
)}

{!sidebarContent && isHomePage && children}

<Box className="rs_read" background="blue100">
<WebFooter
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/Stepper/Stepper/Stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const getInitialStateAndAnswersByQueryParams = (
)

const stepQuestion = getStepQuestion(step)
if (stepQuestion) {
if (stepQuestion && stepType !== STEP_TYPES.INFORMATION) {
questionsAndAnswers.push({
question: stepQuestion,
answer: selectedOption.label,
Expand Down
11 changes: 11 additions & 0 deletions apps/web/pages/stjornartidindi/mal-i-vinnslu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import withApollo from '@island.is/web/graphql/withApollo'
import { withLocale } from '@island.is/web/i18n'
import OJOICasesInProgress from '@island.is/web/screens/OfficialJournalOfIceland/OJOICasesInProgress'
import { getServerSidePropsWrapper } from '@island.is/web/utils/getServerSidePropsWrapper'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore make web strict
const Screen = withApollo(withLocale('is')(OJOICasesInProgress))

export default Screen

export const getServerSideProps = getServerSidePropsWrapper(Screen)
27 changes: 23 additions & 4 deletions apps/web/screens/Manual/ManualChapter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef } from 'react'
import { useEffect, useMemo, useRef, useState } from 'react'
import { useQueryState } from 'next-usequerystate'
import { BLOCKS } from '@contentful/rich-text-types'

Expand Down Expand Up @@ -75,6 +75,9 @@ const ManualChapter: ManualScreen = ({ manual, manualChapter, namespace }) => {
const { activeLocale } = useI18n()

const [selectedItemId, setSelectedItemId] = useQueryState('selectedItemId')
const [expandedItemIds, setExpandedItemIds] = useState(
selectedItemId ? [selectedItemId] : [],
)
const initialScrollHasHappened = useRef(false)

useLocalLinkTypeResolver()
Expand Down Expand Up @@ -174,13 +177,29 @@ const ManualChapter: ManualScreen = ({ manual, manualChapter, namespace }) => {
key={item.id}
id={item.id}
label={item.title}
expanded={item.id === selectedItemId}
expanded={
expandedItemIds.includes(item.id) ||
item.id === selectedItemId
}
onToggle={(expanded) => {
initialScrollHasHappened.current = true
if (expanded) {
setExpandedItemIds((prev) => prev.concat(item.id))
setSelectedItemId(item.id)
} else if (selectedItemId === item.id) {
setSelectedItemId(null)
} else {
setExpandedItemIds((prev) => {
const updatedExpandedItemIds = prev.filter(
(id) => id !== item.id,
)
if (selectedItemId === item.id) {
setSelectedItemId(
updatedExpandedItemIds[
updatedExpandedItemIds.length - 1
] ?? null,
)
}
return updatedExpandedItemIds
})
}
}}
>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/screens/OfficialJournalOfIceland/OJOIAdvert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const OJOIAdvertPage: CustomScreen<OJOIAdvertProps> = ({

const breadcrumbItems = [
{
title: 'Ísland.is',
title: formatMessage(m.breadcrumb.frontpage),
href: linkResolver('homepage', [], locale).href,
},
{
Expand Down
Loading

0 comments on commit e99213f

Please sign in to comment.