Skip to content

Commit

Permalink
New method that fetches case data for submitted applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbjarnio committed Oct 25, 2024
1 parent f138713 commit ea4ddfd
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { DeleteApplicationAttachmentInput } from '../models/deleteApplicationAtt
import type { User } from '@island.is/auth-nest-tools'
import { GetUserInvolvedPartiesResponse } from '../models/getUserInvolvedParties.response'
import { GetUserInvolvedPartiesInput } from '../models/getUserInvolvedParties.input'
import { OJOIAIdInput } from '../models/id.input'
import { OJOIAApplicationCaseResponse } from '../models/applicationCase.response'

@Scopes(ApiScope.internal)
@UseGuards(IdsUserGuard, ScopesGuard)
Expand Down Expand Up @@ -123,4 +125,14 @@ export class OfficialJournalOfIcelandApplicationResolver {
) {
return this.ojoiApplicationService.getUserInvolvedParties(input, user)
}

@Query(() => OJOIAApplicationCaseResponse, {
name: 'OJOIAGetApplicationCase',
})
getApplicationCase(
@Args('input') input: OJOIAIdInput,
@CurrentUser() user: User,
) {
return this.ojoiApplicationService.getApplicationCase(input.id, user)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
CommentDirection,
GetCommentsResponse,
} from '../models/getComments.response'
import { OJOIAApplicationCaseResponse } from '../models/applicationCase.response'

const LOG_CATEGORY = 'official-journal-of-iceland-application'

Expand Down Expand Up @@ -207,4 +208,34 @@ export class OfficialJournalOfIcelandApplicationService {
user,
)
}

async getApplicationCase(
id: string,
user: User,
): Promise<OJOIAApplicationCaseResponse> {
const { applicationCase } =
await this.ojoiApplicationService.getApplicationCase(
{
id,
},
user,
)

let title = 'Óþekkt'

if ('title' in applicationCase.status) {
title = applicationCase.status.title as string
}

const mapped: OJOIAApplicationCaseResponse = {
department: applicationCase.department.title,
type: applicationCase.type.title,
categories: applicationCase.categories.map((c) => c.title),
html: applicationCase.html,
status: title,
communicationStatus: applicationCase.communicationStatus.title,
}

return mapped
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Field, ObjectType } from '@nestjs/graphql'

@ObjectType('OJOIAApplicationCaseResponse')
export class OJOIAApplicationCaseResponse {
@Field()
department!: string

@Field()
type!: string

@Field()
status!: string

@Field()
communicationStatus!: string

@Field(() => [String])
categories!: string[]

@Field()
html!: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Field, InputType, ID } from '@nestjs/graphql'

@InputType('OJOIAIdInput', {
description: 'Input dto that represents the id of the application',
})
export class OJOIAIdInput {
@Field(() => ID)
id!: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,12 @@ import {
DEFAULT_REGULAR_SIGNATURE_COUNT,
DEFAULT_REGULAR_SIGNATURE_MEMBER_COUNT,
OJOI_INPUT_HEIGHT,
SignatureTypes,
} from '../lib/constants'
import set from 'lodash/set'
import {
getAdvertMarkup,
getCommitteeSignature,
getRegularSignature,
getSignaturesMarkup,
} from '../lib/utils'
import { getCommitteeSignature, getRegularSignature } from '../lib/utils'
import { HTMLEditor } from '../components/htmlEditor/HTMLEditor'
import { HTMLText } from '@island.is/regulations-tools/types'
import { useType } from '../hooks/useType'
import { useCategories } from '../hooks/useCategories'
import { useDepartment } from '../hooks/useDepartment'
import { useApplicationCase } from '../hooks/useApplicationCase'
export const Submitted = (props: OJOIFieldBaseProps) => {
const { formatMessage, locale } = useLocale()

Expand All @@ -46,20 +38,12 @@ export const Submitted = (props: OJOIFieldBaseProps) => {
const slug =
ApplicationConfigurations[ApplicationTypes.OFFICIAL_JOURNAL_OF_ICELAND].slug

const { createApplication, application: currentApplication } = useApplication(
{
applicationId: props.application.id,
},
)

const { categories, loading: categoriesLoading } = useCategories()

const { department, loading: departmentLoading } = useDepartment({
departmentId: currentApplication.answers.advert?.departmentId,
const { createApplication } = useApplication({
applicationId: props.application.id,
})

const { type, loading: typeLoading } = useType({
typeId: currentApplication.answers.advert?.typeId,
const { caseData, loading } = useApplicationCase({
applicationId: props.application.id,
})

const [updateApplicationMutation, { loading: updateLoading }] =
Expand Down Expand Up @@ -105,32 +89,6 @@ export const Submitted = (props: OJOIFieldBaseProps) => {
? `http://localhost:4200/minarsidur/umsoknir#${props.application.id}`
: `${path}/minarsidur/umsoknir#${props.application.id}`

const signatureMarkup = getSignaturesMarkup({
signatures: currentApplication.answers.signatures,
type: currentApplication.answers.misc?.signatureType as SignatureTypes,
})

const advertMarkup = getAdvertMarkup({
type: type?.title,
title: currentApplication.answers.advert?.title,
html: currentApplication.answers.advert?.html,
})

const hasMarkup =
!!currentApplication.answers.advert?.html ||
type?.title ||
currentApplication.answers.advert?.title

const combinedHtml = hasMarkup
? (`${advertMarkup}<br />${signatureMarkup}` as HTMLText)
: (`${signatureMarkup}` as HTMLText)

const activeCategories = categories?.filter((c) => {
return currentApplication.answers.advert?.categories?.includes(c.id)
})

const loading = categoriesLoading || typeLoading || departmentLoading

return (
<FormGroup>
<Box>
Expand All @@ -142,15 +100,18 @@ export const Submitted = (props: OJOIFieldBaseProps) => {
/>
) : (
<Inline space={1} flexWrap="wrap">
<Tag outlined variant="blue">
{type?.title}
<Tag disabled outlined variant="blue">
{caseData?.status}
</Tag>
<Tag disabled outlined variant="blueberry">
{caseData?.department}
</Tag>
<Tag outlined variant="blue">
{department?.title}
<Tag disabled outlined variant="darkerBlue">
{caseData?.type}
</Tag>
{activeCategories?.map((c) => (
<Tag outlined variant="blue" key={c.id}>
{c.title}
{caseData?.categories?.map((category, i) => (
<Tag disabled outlined variant="purple" key={i}>
{category}
</Tag>
))}
</Inline>
Expand All @@ -169,12 +130,12 @@ export const Submitted = (props: OJOIFieldBaseProps) => {
name="submitted.document"
readOnly={true}
hideWarnings={true}
value={combinedHtml}
value={caseData?.html as HTMLText}
config={{ toolbar: false }}
/>
</Box>
)}
<Box display="flex" justifyContent="spaceBetween">
<Box display="flex" marginY={4} justifyContent="spaceBetween">
<Button
loading={updateLoading}
onClick={() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,16 @@ export const POST_COMMENT_MUTATION = gql`
}
}
`

export const GET_APPLICATION_CASE_QUERY = gql`
query GetApplicationCase($input: OJOIAIdInput!) {
OJOIAGetApplicationCase(input: $input) {
department
type
status
communicationStatus
categories
html
}
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useQuery } from '@apollo/client'
import { GET_APPLICATION_CASE_QUERY } from '../graphql/queries'

type Params = {
applicationId: string
}

type GetApplicationCaseResponse = {
OJOIAGetApplicationCase: {
department: string
type: string
status: string
communicationStatus: string
categories: string[]
html: string
}
}

export const useApplicationCase = ({ applicationId }: Params) => {
const { data, loading, error } = useQuery<GetApplicationCaseResponse>(
GET_APPLICATION_CASE_QUERY,
{
variables: { input: { id: applicationId } },
},
)

return {
caseData: data?.OJOIAGetApplicationCase,
loading,
error,
}
}
Loading

0 comments on commit ea4ddfd

Please sign in to comment.