Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ojoi): Repost failed applications #17411

Merged
merged 9 commits into from
Jan 7, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down Expand Up @@ -111,7 +116,18 @@ export const Submitted = (props: OJOIFieldBaseProps) => {
title={formatMessage(submitted.errors.caseErrorTitle)}
message={formatMessage(submitted.errors.caseErrorMessage)}
/>
<Inline justifyContent="flexEnd">
{postApplicationError && (
<AlertMessage
type="error"
title={formatMessage(
submitted.errors.postApplicationErrorTitle,
)}
message={formatMessage(
submitted.errors.postApplicationErrorMessage,
)}
/>
)}
<Inline justifyContent="spaceBetween">
<Button
variant="ghost"
size="small"
Expand All @@ -120,6 +136,20 @@ export const Submitted = (props: OJOIFieldBaseProps) => {
>
{formatMessage(submitted.buttons.reload)}
</Button>
<Button
loading={postApplicationLoading}
disabled={!!postApplicationError}
size="small"
icon="arrowUp"
iconType="outline"
onClick={() =>
postApplication(props.application.id, () =>
window.location.reload(),
)
}
>
Senda inn umsókn
</Button>
</Inline>
</Stack>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,9 @@ export const GET_PDF_QUERY = gql`
}
}
`

export const POST_APPLICATION_MUTATION = gql`
mutation OJOIAPostApplication($input: OJOIAIdInput!) {
OJOIAPostApplication(input: $input)
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand All @@ -118,6 +144,10 @@ export const useApplication = ({ applicationId }: OJOIUseApplicationParams) => {
updateLoading,
updateError,
isLoading: applicationLoading || updateLoading,
postApplication,
postApplicationData,
postApplicationError,
postApplicationLoading,
debouncedOnUpdateApplicationHandler,
updateApplication,
submitApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Loading