Skip to content

Commit

Permalink
feat(ojoi): Repost failed applications (#17411)
Browse files Browse the repository at this point in the history
* Updated data schema to make less api calls, fixed bug when user selected a previous advert the inputs fields were not updating. Switched out controller components since we have our own.

* Revert "Updated data schema to make less api calls, fixed bug when user selected a previous advert the inputs fields were not updating. Switched out controller components since we have our own."

This reverts commit 081223e.

* Added repost application functionality if the application fails to post.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
jonbjarnio and kodiakhq[bot] authored Jan 7, 2025
1 parent 550571d commit 50422b0
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
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

0 comments on commit 50422b0

Please sign in to comment.