diff --git a/libs/api/domains/official-journal-of-iceland-application/src/lib/ojoiApplication.resolver.ts b/libs/api/domains/official-journal-of-iceland-application/src/lib/ojoiApplication.resolver.ts index f84eab477c40..ac8db22e0d5e 100644 --- a/libs/api/domains/official-journal-of-iceland-application/src/lib/ojoiApplication.resolver.ts +++ b/libs/api/domains/official-journal-of-iceland-application/src/lib/ojoiApplication.resolver.ts @@ -143,4 +143,14 @@ export class OfficialJournalOfIcelandApplicationResolver { ) { return this.ojoiApplicationService.getApplicationCase(input.id, user) } + + @Mutation(() => Boolean, { + name: 'OJOIAPostApplication', + }) + postApplication( + @Args('input') input: OJOIAIdInput, + @CurrentUser() user: User, + ) { + return this.ojoiApplicationService.postApplication(input, user) + } } diff --git a/libs/application/templates/official-journal-of-iceland/src/fields/Submitted.tsx b/libs/application/templates/official-journal-of-iceland/src/fields/Submitted.tsx index f7b0ccdceb18..314dacc73701 100644 --- a/libs/application/templates/official-journal-of-iceland/src/fields/Submitted.tsx +++ b/libs/application/templates/official-journal-of-iceland/src/fields/Submitted.tsx @@ -40,7 +40,12 @@ export const Submitted = (props: OJOIFieldBaseProps) => { const slug = ApplicationConfigurations[ApplicationTypes.OFFICIAL_JOURNAL_OF_ICELAND].slug - const { createApplication } = useApplication({ + const { + createApplication, + postApplication, + postApplicationError, + postApplicationLoading, + } = useApplication({ applicationId: props.application.id, }) @@ -111,7 +116,18 @@ export const Submitted = (props: OJOIFieldBaseProps) => { title={formatMessage(submitted.errors.caseErrorTitle)} message={formatMessage(submitted.errors.caseErrorMessage)} /> - + {postApplicationError && ( + + )} + + ) : ( diff --git a/libs/application/templates/official-journal-of-iceland/src/graphql/queries.ts b/libs/application/templates/official-journal-of-iceland/src/graphql/queries.ts index cfe4f70ab68b..095b069cb4cd 100644 --- a/libs/application/templates/official-journal-of-iceland/src/graphql/queries.ts +++ b/libs/application/templates/official-journal-of-iceland/src/graphql/queries.ts @@ -356,3 +356,9 @@ export const GET_PDF_QUERY = gql` } } ` + +export const POST_APPLICATION_MUTATION = gql` + mutation OJOIAPostApplication($input: OJOIAIdInput!) { + OJOIAPostApplication(input: $input) + } +` diff --git a/libs/application/templates/official-journal-of-iceland/src/hooks/useUpdateApplication.ts b/libs/application/templates/official-journal-of-iceland/src/hooks/useUpdateApplication.ts index c59ebd51bd41..20079cbd7980 100644 --- a/libs/application/templates/official-journal-of-iceland/src/hooks/useUpdateApplication.ts +++ b/libs/application/templates/official-journal-of-iceland/src/hooks/useUpdateApplication.ts @@ -12,6 +12,7 @@ import debounce from 'lodash/debounce' import { DEBOUNCE_INPUT_TIMER } from '../lib/constants' import { ApplicationTypes } from '@island.is/application/types' import { Application } from '@island.is/api/schema' +import { POST_APPLICATION_MUTATION } from '../graphql/queries' type OJOIUseApplicationParams = { applicationId?: string @@ -46,6 +47,15 @@ export const useApplication = ({ applicationId }: OJOIUseApplicationParams) => { const [createApplicationMutation] = useMutation(CREATE_APPLICATION) + const [ + postApplicationMutation, + { + data: postApplicationData, + error: postApplicationError, + loading: postApplicationLoading, + }, + ] = useMutation(POST_APPLICATION_MUTATION) + const updateApplication = async (input: partialSchema, cb?: () => void) => { await updateApplicationMutation({ variables: { @@ -94,6 +104,22 @@ export const useApplication = ({ applicationId }: OJOIUseApplicationParams) => { }) } + const postApplication = async (id: string, onComplete?: () => void) => { + await postApplicationMutation({ + variables: { + input: { + id: id, + }, + }, + onError: (error) => { + console.error(error) + }, + onCompleted: (data) => { + onComplete && onComplete() + }, + }) + } + const debouncedUpdateApplication = debounce( updateApplication, DEBOUNCE_INPUT_TIMER, @@ -118,6 +144,10 @@ export const useApplication = ({ applicationId }: OJOIUseApplicationParams) => { updateLoading, updateError, isLoading: applicationLoading || updateLoading, + postApplication, + postApplicationData, + postApplicationError, + postApplicationLoading, debouncedOnUpdateApplicationHandler, updateApplication, submitApplication, diff --git a/libs/application/templates/official-journal-of-iceland/src/lib/messages/submitted.tsx b/libs/application/templates/official-journal-of-iceland/src/lib/messages/submitted.tsx index 080620204778..41c87584a641 100644 --- a/libs/application/templates/official-journal-of-iceland/src/lib/messages/submitted.tsx +++ b/libs/application/templates/official-journal-of-iceland/src/lib/messages/submitted.tsx @@ -42,6 +42,17 @@ export const submitted = { 'Vinsamlegast reynið aftur síðar eða hafið samband við Stjórnartíðindi', description: 'Case error message', }, + postApplicationErrorTitle: { + id: 'ojoi.application:submitted.errors.postApplicationErrorTitle', + defaultMessage: 'Ekki tókst að senda inn umsókn', + description: 'Post application error message', + }, + postApplicationErrorMessage: { + id: 'ojoi.application:submitted.errors.postApplicationErrorMessage', + defaultMessage: + 'Vinsamlegast reynið aftur síðar eða hafið samband við Stjórnartíðindi', + description: 'Post application error message', + }, }), bullets: defineMessages({ first: {