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

fix(application-system): Possible to go back to hidden screens #17162

Merged
merged 13 commits into from
Dec 12, 2024
3 changes: 3 additions & 0 deletions libs/application/ui-shell/src/components/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type ScreenProps = {
renderLastScreenBackButton?: boolean
goToScreen: (id: string) => void
setUpdateForbidden: (value: boolean) => void
canGoBack: boolean
}

const getServerValidationErrors = (error: ApolloError | undefined) => {
Expand Down Expand Up @@ -107,6 +108,7 @@ const Screen: FC<React.PropsWithChildren<ScreenProps>> = ({
renderLastScreenBackButton,
screen,
sections,
canGoBack,
}) => {
const { answers: formValue, externalData, id: applicationId } = application
const { lang: locale, formatMessage } = useLocale()
Expand Down Expand Up @@ -416,6 +418,7 @@ const Screen: FC<React.PropsWithChildren<ScreenProps>> = ({
numberOfScreens={numberOfScreens}
mode={mode}
goBack={goBack}
canGoBack={canGoBack}
submitField={submitField}
loading={loading}
canProceed={!isLoadingOrPending}
Expand Down
5 changes: 3 additions & 2 deletions libs/application/ui-shell/src/components/ScreenFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface FooterProps {
renderLastScreenBackButton?: boolean
submitButtonDisabled?: boolean
nextButtonText?: FormText
canGoBack: boolean
}

type SubmitButton = Omit<ButtonTypes, 'circle'> & {
Expand Down Expand Up @@ -68,13 +69,13 @@ export const ScreenFooter: FC<React.PropsWithChildren<FooterProps>> = ({
renderLastScreenBackButton,
submitButtonDisabled,
nextButtonText,
canGoBack,
}) => {
const { formatMessage } = useLocale()
const user = useUserInfo()
const hasSubmitField = submitField !== undefined
const isLastScreen = activeScreenIndex === numberOfScreens - 1
const showGoBack =
activeScreenIndex > 0 && (!isLastScreen || renderLastScreenBackButton)
const showGoBack = canGoBack && (!isLastScreen || renderLastScreenBackButton)

if (
(isLastScreen && !renderLastScreenButton) ||
Expand Down
2 changes: 2 additions & 0 deletions libs/application/ui-shell/src/lib/FormShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '../reducer/ApplicationFormReducer'
import { ActionTypes } from '../reducer/ReducerTypes'
import * as styles from './FormShell.css'
import { canGoBack } from '../reducer/reducerUtils'

export const FormShell: FC<
React.PropsWithChildren<{
Expand Down Expand Up @@ -142,6 +143,7 @@ export const FormShell: FC<
payload,
})
}}
canGoBack={canGoBack(screens, activeScreen)}
prevScreen={() => dispatch({ type: ActionTypes.PREV_SCREEN })}
activeScreenIndex={activeScreen}
numberOfScreens={screens.length}
Expand Down
19 changes: 19 additions & 0 deletions libs/application/ui-shell/src/reducer/reducerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ export const moveToScreen = (
return screenIndex
}

export const canGoBack = (
screens: FormScreen[],
screenIndex: number,
): boolean => {
// Check if we're already at the start
if (screenIndex <= 0) {
return false
}

// Look for any navigable screen behind where we are
for (let i = screenIndex - 1; i >= 0; i--) {
if (screens[i].isNavigable) {
return true
}
}

return false
}

const convertFieldToScreen = (
field: Field,
answers: FormValue,
Expand Down
Loading