Skip to content

Commit

Permalink
feat(application-system): Custom text for next button in applications (
Browse files Browse the repository at this point in the history
…#15076)

* feat: nextButtonText for customField

* chore: remove code for dev purposes

* chore: remove console.log

* chore: remove line breaks

* fix: pr comments

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and lodmfjord committed Jun 14, 2024
1 parent b6c9b21 commit 99fe166
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
1 change: 0 additions & 1 deletion apps/application-system/form/src/routes/Application.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { useParams } from 'react-router-dom'

import { ApplicationForm, ErrorShell } from '@island.is/application/ui-shell'
Expand Down
2 changes: 2 additions & 0 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const extractCommonFields = (
title,
dataTestId,
width = 'full',
nextButtonText,
} = data

return {
Expand All @@ -77,6 +78,7 @@ const extractCommonFields = (
doesNotRequireAnswer,
title,
width,
nextButtonText,
}
}

Expand Down
1 change: 1 addition & 0 deletions libs/application/types/src/lib/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface FormItem extends TestSupport {
condition?: Condition
readonly type: string
readonly title: FormText
readonly nextButtonText?: FormText
}

export interface Section extends FormItem {
Expand Down
15 changes: 12 additions & 3 deletions libs/application/ui-shell/src/components/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ import React, {
useState,
} from 'react'
import { ApolloError, useMutation } from '@apollo/client'
import { formatText, mergeAnswers } from '@island.is/application/core'
import {
coreMessages,
formatText,
mergeAnswers,
} from '@island.is/application/core'
import {
Application,
Answer,
ExternalData,
FormItemTypes,
FormModes,
FormValue,
Schema,
BeforeSubmitCallback,
Section,
FormText,
} from '@island.is/application/types'
import {
Box,
Expand Down Expand Up @@ -50,6 +54,7 @@ import FormExternalDataProvider from './FormExternalDataProvider'
import { extractAnswersToSubmitFromScreen, findSubmitField } from '../utils'
import ScreenFooter from './ScreenFooter'
import RefetchContext from '../context/RefetchContext'
import { MessageDescriptor } from 'react-intl'

type ScreenProps = {
activeScreenIndex: number
Expand Down Expand Up @@ -113,6 +118,7 @@ const Screen: FC<React.PropsWithChildren<ScreenProps>> = ({
resolver({ formValue, context, formatMessage }),
context: { dataSchema, formNode: screen },
})

const [fieldLoadingState, setFieldLoadingState] = useState(false)
const [isSubmitting, setIsSubmitting] = useState(false)
const refetch = useContext<() => void>(RefetchContext)
Expand Down Expand Up @@ -258,6 +264,8 @@ const Screen: FC<React.PropsWithChildren<ScreenProps>> = ({
const { width } = useWindowSize()
const headerHeight = 85

const nextButtonText = screen.nextButtonText ?? coreMessages.buttonNext

useEffect(() => {
if (width < theme.breakpoints.md) {
return setIsMobile(true)
Expand Down Expand Up @@ -315,6 +323,7 @@ const Screen: FC<React.PropsWithChildren<ScreenProps>> = ({
screen.type === FormItemTypes.REPEATER ||
screen.type === FormItemTypes.EXTERNAL_DATA_PROVIDER
)

return (
<FormProvider {...hookFormData}>
<Box
Expand Down Expand Up @@ -391,7 +400,6 @@ const Screen: FC<React.PropsWithChildren<ScreenProps>> = ({
</GridColumn>

<ToastContainer hideProgressBar closeButton useKeyframeStyles={false} />

<ScreenFooter
submitButtonDisabled={submitButtonDisabled}
application={application}
Expand All @@ -404,6 +412,7 @@ const Screen: FC<React.PropsWithChildren<ScreenProps>> = ({
submitField={submitField}
loading={loading}
canProceed={!isLoadingOrPending}
nextButtonText={nextButtonText}
/>
</Box>
</FormProvider>
Expand Down
7 changes: 6 additions & 1 deletion libs/application/ui-shell/src/components/ScreenFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FormModes,
SubmitField,
CallToAction,
FormText,
} from '@island.is/application/types'

import * as styles from './ScreenFooter.css'
Expand All @@ -25,6 +26,7 @@ interface FooterProps {
shouldLastScreenButtonSubmit?: boolean
renderLastScreenBackButton?: boolean
submitButtonDisabled?: boolean
nextButtonText?: FormText
}

type SubmitButton = Omit<ButtonTypes, 'circle'> & {
Expand Down Expand Up @@ -65,6 +67,7 @@ export const ScreenFooter: FC<React.PropsWithChildren<FooterProps>> = ({
renderLastScreenButton,
renderLastScreenBackButton,
submitButtonDisabled,
nextButtonText,
}) => {
const { formatMessage } = useLocale()
const { userInfo: user } = useAuth()
Expand Down Expand Up @@ -168,7 +171,9 @@ export const ScreenFooter: FC<React.PropsWithChildren<FooterProps>> = ({
type="submit"
disabled={submitButtonDisabled}
>
{formatMessage(coreMessages.buttonNext)}
{nextButtonText
? formatText(nextButtonText, application, formatMessage)
: formatMessage(coreMessages.buttonNext)}
</Button>
</Box>
)}
Expand Down
1 change: 0 additions & 1 deletion libs/application/ui-shell/src/lib/FormShell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { FC, useEffect, useReducer, useState } from 'react'
import cn from 'classnames'

import {
Application,
Expand Down

0 comments on commit 99fe166

Please sign in to comment.