-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ef591a
commit f76e177
Showing
12 changed files
with
246 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...omains/official-journal-of-iceland-application/src/models/getUserInvolvedParties.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
libs/application/templates/official-journal-of-iceland/src/hooks/useInvolvedParties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
libs/application/templates/official-journal-of-iceland/src/lib/messages/involved-parties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 97 additions & 8 deletions
105
libs/application/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters