Skip to content

Commit

Permalink
Involved parties now ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbjarnio committed Sep 27, 2024
1 parent 4ef591a commit f76e177
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { GetApplicationAttachmentsResponse } from '../models/getApplicationAttac
import { DeleteApplicationAttachmentInput } from '../models/deleteApplicationAttachment.input'
import type { User } from '@island.is/auth-nest-tools'
import { GetUserInvolvedPartiesResponse } from '../models/getUserInvolvedParties.response'
import { GetUserInvolvedPartiesInput } from '../models/getUserInvolvedParties.input'

@Scopes(ApiScope.internal)
@UseGuards(IdsUserGuard, ScopesGuard)
Expand Down Expand Up @@ -116,8 +117,8 @@ export class OfficialJournalOfIcelandApplicationResolver {
name: 'officialJournalOfIcelandApplicationGetUserInvolvedParties',
})
getUserInvolvedParties(
@Args('input', { type: () => GetCommentsInput })
input: GetCommentsInput,
@Args('input', { type: () => GetUserInvolvedPartiesInput })
input: GetUserInvolvedPartiesInput,
@CurrentUser() user: User,
) {
return this.ojoiApplicationService.getUserInvolvedParties(input, user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { DeleteApplicationAttachmentInput } from '../models/deleteApplicationAtt
import { LOGGER_PROVIDER } from '@island.is/logging'
import type { Logger } from '@island.is/logging'
import { User } from '@island.is/auth-nest-tools'
import { GetUserInvolvedPartiesInput } from '../models/getUserInvolvedParties.input'

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

Expand Down Expand Up @@ -167,10 +168,10 @@ export class OfficialJournalOfIcelandApplicationService {
}
}

async getUserInvolvedParties(input: GetCommentsInput, user: User) {
async getUserInvolvedParties(input: GetUserInvolvedPartiesInput, user: User) {
return this.ojoiApplicationService.getUserInvolvedParties(
{
id: input.id,
id: input.applicationId,
},
user,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Field, ID, InputType } from '@nestjs/graphql'

@InputType('GetUserInvolvedPartiesInput')
export class GetUserInvolvedPartiesInput {
@Field(() => ID)
applicationId!: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import {
AlertMessage,
AlertMessageProps,
Box,
SkeletonLoader,
Text,
} from '@island.is/island-ui/core'
import * as styles from './FormScreen.css'
import { useLocale } from '@island.is/localization'
import { general } from '../../lib/messages'
import { OJOI_INPUT_HEIGHT } from '../../lib/constants'

type WarningProps = {
type?: AlertMessageProps['type']
Expand All @@ -20,6 +22,7 @@ type Props = {
button?: React.ReactNode
warning?: WarningProps
children?: React.ReactNode
loading?: boolean
}

export const FormScreen = ({
Expand All @@ -28,6 +31,7 @@ export const FormScreen = ({
button,
children,
warning,
loading,
}: Props) => {
const { formatMessage } = useLocale()

Expand Down Expand Up @@ -61,7 +65,16 @@ export const FormScreen = ({
</Box>
)}
</Box>
<Box className={styles.childrenWrapper}>{children}</Box>
{loading ? (
<SkeletonLoader
height={OJOI_INPUT_HEIGHT}
repeat={3}
borderRadius="standard"
space={2}
/>
) : (
<Box className={styles.childrenWrapper}>{children}</Box>
)}
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
preview,
publishing,
summary,
involvedParty,
} from '../lib/messages'
export const Requirements: Form = buildForm({
id: 'OfficialJournalOfIcelandApplication',
Expand All @@ -41,7 +42,7 @@ export const Requirements: Form = buildForm({
}),
buildSection({
id: Routes.INVOLVED_PARTY,
title: 'Test',
title: involvedParty.general.section,
children: [
buildMultiField({
id: Routes.INVOLVED_PARTY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ export const DEPARTMENTS_QUERY = gql`
}
`

export const INVOLVED_PARTIES_QUERY = gql`
query InvolvedParties($input: GetUserInvolvedPartiesInput!) {
officialJournalOfIcelandApplicationGetUserInvolvedParties(input: $input) {
involvedParties {
id
title
slug
}
}
}
`

export const CATEGORIES_QUERY = gql`
query AdvertCategories($params: OfficialJournalOfIcelandQueryInput!) {
officialJournalOfIcelandCategories(params: $params) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useQuery } from '@apollo/client'
import { OfficialJournalOfIcelandApplicationGetUserInvolvedPartiesResponse } from '@island.is/api/schema'
import { INVOLVED_PARTIES_QUERY } from '../graphql/queries'

type Props = {
applicationId?: string
onComplete?: (data: InvolvedPartiesResponse) => void
onError?: (error: Error) => void
}

type InvolvedPartiesResponse = {
officialJournalOfIcelandApplicationGetUserInvolvedParties: OfficialJournalOfIcelandApplicationGetUserInvolvedPartiesResponse
}
export const useInvolvedParties = ({
applicationId,
onComplete,
onError,
}: Props) => {
const { data, loading, error } = useQuery<InvolvedPartiesResponse>(
INVOLVED_PARTIES_QUERY,
{
skip: !applicationId,
fetchPolicy: 'no-cache',
variables: {
input: {
applicationId: applicationId,
},
},
onCompleted: (data) => {
onComplete && onComplete(data)
},
onError: (error) => {
onError && onError(error)
},
},
)

return {
involvedParties:
data?.officialJournalOfIcelandApplicationGetUserInvolvedParties
.involvedParties,
loading,
error,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './publishing'
export * from './summary'
export * from './signatures'
export * from './comments'
export * from './involved-parties'
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { defineMessages } from 'react-intl'

export const involvedParty = {
general: defineMessages({
title: {
id: 'ojoi.application:original.general.title',
defaultMessage: 'Stofnun ',
description: 'Title of the involved party screen',
},
intro: {
id: 'ojoi.application:original.general.intro',
defaultMessage:
'Hér getur þú valið stofnun sem þú vilt tengja við umsóknina þína.',
description: 'Intro of the involved party form',
},
section: {
id: 'ojoi.application:original.general.section',
defaultMessage: 'Stofnanir',
description: 'Title of the involved party section',
},
}),
inputs: {
select: defineMessages({
placeholder: {
id: 'ojoi.application:original.inputs.select.placeholder',
defaultMessage: 'Veldu stofnun',
description: 'Placeholder for the select input',
},
}),
},

errors: defineMessages({
title: {
id: 'ojoi.application:original.error.title',
defaultMessage: 'Þú hefur ekki aðgang',
description: 'Title of the error message',
},
message: {
id: 'ojoi.application:original.error.message',
defaultMessage:
'Ekki tókst að sækja stofnanir fyrir aðganginn þinn, ef þú telur þig eiga að hafa aðgang, vinsamlegast hafðu samband við ritstjóra Stjórnartíðnda.',
description: 'Error message',
},
noDataTitle: {
id: 'ojoi.application:original.error.noDataTitle',
defaultMessage: 'Engar stofnanir',
description: 'Title of the no data message',
},
noDataMessage: {
id: 'ojoi.application:original.error.noDataMessage',
defaultMessage:
'Notandinn er ekki tengdur neinum stofnunum, vinsamlegast hafðu samband við ritstjóra Stjórnartíðnda.',
description: 'No data message',
},
}),
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const InputFields = {
categories: 'advert.categories',
channels: 'advert.channels',
message: 'advert.message',
involvedPartyId: 'advert.involvedPartyId',
},
[Routes.SIGNATURE]: {
regular: 'signatures.regular',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,107 @@
import { useLocale } from '@island.is/localization'
import { FormScreen } from '../components/form/FormScreen'
import { original } from '../lib/messages'
import { OJOIFieldBaseProps } from '../lib/types'
import { involvedParty } from '../lib/messages'
import { InputFields, OJOIFieldBaseProps } from '../lib/types'
import { useInvolvedParties } from '../hooks/useInvolvedParties'
import { OJOISelectController } from '../components/input/OJOISelectController'
import { AlertMessage, Box, Stack } from '@island.is/island-ui/core'
import { useApplication } from '../hooks/useUpdateApplication'
import { useFormContext } from 'react-hook-form'
import set from 'lodash/set'

export const InvolvedPartyScreen = (props: OJOIFieldBaseProps) => {
export const InvolvedPartyScreen = ({
application,
setSubmitButtonDisabled,
}: OJOIFieldBaseProps) => {
const { updateApplication } = useApplication({
applicationId: application.id,
})
const { formatMessage: f } = useLocale()
const { setValue } = useFormContext()

const { involvedParties, error, loading } = useInvolvedParties({
applicationId: application.id,
onError: () => {
setSubmitButtonDisabled && setSubmitButtonDisabled(true)
},
onComplete: (data) => {
const involvedParties =
data?.officialJournalOfIcelandApplicationGetUserInvolvedParties
.involvedParties

if (involvedParties.length === 0 || involvedParties.length > 1) {
setSubmitButtonDisabled && setSubmitButtonDisabled(true)
}

if (
data.officialJournalOfIcelandApplicationGetUserInvolvedParties
.involvedParties.length === 1
) {
const involvedParty =
data.officialJournalOfIcelandApplicationGetUserInvolvedParties
.involvedParties[0]

setValue(InputFields.advert.involvedPartyId, involvedParty.id)

const currentAnswers = structuredClone(application.answers)

const updatedAnswers = set(
currentAnswers,
InputFields.advert.involvedPartyId,
involvedParty.id,
)

updateApplication(updatedAnswers)
}
},
})

const options = involvedParties?.map((involvedParty) => ({
label: involvedParty.title,
value: involvedParty.id,
}))

const defaultValue = options && options.length === 1 ? options[0].value : ''

const disableSelect = options?.length === 1 || !!error

return (
<FormScreen
// title={f(original.general.title)}
// intro={f(original.general.intro)}
title="title"
intro="intro"
title={f(involvedParty.general.title)}
intro={f(involvedParty.general.intro)}
loading={loading}
>
hallo
<Stack space={2}>
{involvedParties?.length === 0 && (
<AlertMessage
type="warning"
title={f(involvedParty.errors.noDataTitle)}
message={f(involvedParty.errors.noDataMessage)}
/>
)}
{!!error && (
<AlertMessage
type="error"
title={f(involvedParty.errors.title)}
message={f(involvedParty.errors.message)}
/>
)}
</Stack>
<Box width="half">
<OJOISelectController
disabled={disableSelect}
loading={loading}
name={InputFields.advert.involvedPartyId}
label={f(involvedParty.general.section)}
options={options}
applicationId={application.id}
defaultValue={defaultValue}
placeholder={involvedParty.inputs.select.placeholder}
onChange={() =>
setSubmitButtonDisabled && setSubmitButtonDisabled(false)
}
/>
</Box>
</FormScreen>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export class OfficialJournalOfIcelandApplicationClientService {
}

async getUserInvolvedParties(params: GetInvolvedPartiesRequest, auth: Auth) {
return this.ojoiApplicationApiWithAuth(auth).getInvolvedParties(params)
const data = await this.ojoiApplicationApiWithAuth(auth).getInvolvedParties(
params,
)
console.log(data)
return data
}
}

0 comments on commit f76e177

Please sign in to comment.