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

Parental leave - Review screen action buttons #2572

Merged
merged 26 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fdf6649
Add pencil icon
madebynoam Jan 12, 2021
d648354
Allow applicant to read all data from their application
madebynoam Jan 12, 2021
b3f39ec
Add new modal strings, update button and title strings
madebynoam Jan 12, 2021
1d9acf0
Create ReadOnlyReview.tsx
madebynoam Jan 12, 2021
0d17e9c
Update InReviewSteps with action buttons hooked up.
madebynoam Jan 12, 2021
a6a0b5c
Add ReadOnlyReview component
madebynoam Jan 12, 2021
ed78252
Update state machine to go back to edit/draft
madebynoam Jan 14, 2021
e10242f
Update last form screen to match design
madebynoam Jan 14, 2021
019682d
Update InReview.ts
madebynoam Jan 15, 2021
510605f
Merge branch 'main' into review-screen-action-buttons
madebynoam Jan 19, 2021
0cb10e9
Remove negative margin in Conclusion screen for now
madebynoam Jan 19, 2021
ca5b859
Remove temp field
madebynoam Jan 19, 2021
af130ae
Temp Icelandic strings
madebynoam Jan 19, 2021
e8b7bc0
Lint fixes
madebynoam Jan 19, 2021
5f98246
Merge branch 'main' into review-screen-action-buttons
madebynoam Jan 20, 2021
1d3f9f0
Refactor two review screens into one + markup clean up.
madebynoam Jan 21, 2021
6f7442e
Make other parent approval step be conditional.
madebynoam Jan 21, 2021
05a4eaf
Refetch instead of reload the page after switching back to 'draft'
madebynoam Jan 21, 2021
2c6b440
Merge branch 'main' into review-screen-action-buttons
madebynoam Jan 21, 2021
47c2cef
Fix lint errors and warnings
madebynoam Jan 21, 2021
916e206
Merge branch 'main' into review-screen-action-buttons
madebynoam Jan 21, 2021
431b378
Fix tests
madebynoam Jan 21, 2021
84946cc
Update messages.ts
madebynoam Jan 22, 2021
5e841ad
Refactor null checks to TS optional chaining
madebynoam Jan 22, 2021
33b4576
Add loader icon to ApplicationForm
madebynoam Jan 22, 2021
f31b912
Merge branch 'main' into review-screen-action-buttons
kodiakhq[bot] Jan 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/application/core/src/types/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface FieldBaseProps {
application: Application
showFieldName?: boolean
goToScreen?: (id: string) => void
refetch?: () => void
}

export type RepeaterProps = {
Expand Down
1 change: 1 addition & 0 deletions libs/application/core/src/types/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum DefaultEvents {
REJECT = 'REJECT',
SUBMIT = 'SUBMIT',
ABORT = 'ABORT',
EDIT = 'EDIT',
}

export type ReadWriteValues =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
import React, { FC } from 'react'
import React, { FC, useState } from 'react'
import { useMutation } from '@apollo/client'
import { useLocale } from '@island.is/localization'

import { FieldBaseProps } from '@island.is/application/core'
import { Box, Button, Text } from '@island.is/island-ui/core'
import {
FieldBaseProps,
getValueViaPath,
MessageFormatter,
} from '@island.is/application/core'
import {
Box,
Button,
DialogPrompt,
Text,
toast,
} from '@island.is/island-ui/core'
import ReviewSection, { reviewSectionState } from './ReviewSection'
import Review from '../Review'

import { mm } from '../../lib/messages'
import ReviewSection, { reviewSectionState } from './ReviewSection'
import { YES } from '../../constants'

import { SUBMIT_APPLICATION } from '@island.is/application/graphql'

function handleError(error: string, formatMessage: MessageFormatter): void {
toast.error(
formatMessage(
{
id: 'application.system:submit.error',
defaultMessage: 'Eitthvað fór úrskeiðis: {error}',
description: 'Error message on submit',
},
{ error },
),
)
}

type stateMapEntry = { [key: string]: reviewSectionState }
type statesMap = {
Expand All @@ -21,6 +49,7 @@ const statesMap: statesMap = {
vinnumalastofnunApproval: reviewSectionState.complete,
},
employer: {
employerWaitingToAssign: reviewSectionState.inProgress,
employerApproval: reviewSectionState.inProgress,
employerRequiresAction: reviewSectionState.requiresAction,
vinnumalastofnunApproval: reviewSectionState.complete,
Expand All @@ -32,64 +61,140 @@ const statesMap: statesMap = {
},
}

const InReviewSteps: FC<FieldBaseProps> = ({ application }) => {
const InReviewSteps: FC<FieldBaseProps> = ({ application, refetch }) => {
const [submitApplication, { loading: loadingSubmit }] = useMutation(
SUBMIT_APPLICATION,
{
onError: (e) => handleError(e.message, formatMessage),
},
)

const { formatMessage } = useLocale()
const [screenState, setScreenState] = useState<'steps' | 'viewApplication'>(
'steps',
)

const isRequestingRights =
(getValueViaPath(
application.answers,
'requestRights.isRequestingRights',
) as string) === YES

const steps = [
{
state: statesMap['otherParent'][application.state],
title: formatMessage(mm.reviewScreen.otherParentTitle),
description: formatMessage(mm.reviewScreen.otherParentDesc),
},
{
state: statesMap['employer'][application.state],
title: formatMessage(mm.reviewScreen.employerTitle),
description: formatMessage(mm.reviewScreen.employerDesc),
},
{
state: statesMap['vinnumalastofnun'][application.state],
title: formatMessage(mm.reviewScreen.deptTitle),
description: formatMessage(mm.reviewScreen.deptDesc),
},
]

if (!isRequestingRights) steps.shift()

return (
<Box marginBottom={10}>
<Box>
<Text as="div">
{formatMessage(mm.reviewScreen.desc)}{' '}
<Box display="flex" justifyContent="spaceBetween">
<Text>
{(screenState === 'steps' && formatMessage(mm.reviewScreen.desc)) ||
formatMessage(mm.reviewScreen.descReview)}
</Text>
<Box>
<Box display="inlineBlock" marginLeft={1} marginRight={2}>
<Button
colorScheme="default"
iconType="filled"
// TODO: Add onClick in next PR
onClick={() =>
setScreenState(
(screenState === 'steps' && 'viewApplication') || 'steps',
)
}
size="small"
type="button"
variant="text"
>
{formatMessage(mm.reviewScreen.buttonsView)}
{(screenState === 'steps' &&
formatMessage(mm.reviewScreen.buttonsView)) ||
formatMessage(mm.reviewScreen.buttonsViewProgress)}
</Button>
</Box>
<Box display="inlineBlock">
<Button
colorScheme="default"
iconType="filled"
// TODO: Add onClick in next PR
size="small"
type="button"
variant="text"
>
{formatMessage(mm.reviewScreen.buttonsEdit)}
</Button>
<DialogPrompt
baseId="editApplicationDialog"
title={formatMessage(mm.reviewScreen.editApplicationModalTitle)}
description={formatMessage(
mm.reviewScreen.editApplicationModalDesc,
)}
ariaLabel={formatMessage(
mm.reviewScreen.editApplicationModalAria,
)}
disclosureElement={
<Button
colorScheme="default"
iconType="filled"
size="small"
type="button"
variant="text"
icon="pencil"
loading={loadingSubmit}
disabled={loadingSubmit}
>
{formatMessage(mm.reviewScreen.buttonsEdit)}
</Button>
}
onConfirm={async () => {
const res = await submitApplication({
variables: {
input: {
id: application.id,
event: 'EDIT',
answers: application.answers,
},
},
})

if (res?.data) {
// Takes them back to the editable Review screen
refetch && refetch()
madebynoam marked this conversation as resolved.
Show resolved Hide resolved
}
}}
buttonTextConfirm={formatMessage(
mm.reviewScreen.editApplicationModalConfirmButton,
)}
buttonTextCancel={formatMessage(
mm.reviewScreen.editApplicationModalCancelButton,
)}
/>
</Box>
</Text>
</Box>
</Box>

<Box marginTop={7} marginBottom={8}>
<ReviewSection
application={application}
index={1}
state={statesMap['otherParent'][application.state]}
title={formatMessage(mm.reviewScreen.otherParentTitle)}
description={formatMessage(mm.reviewScreen.otherParentDesc)}
/>
<ReviewSection
application={application}
index={2}
state={statesMap['employer'][application.state]}
title={formatMessage(mm.reviewScreen.employerTitle)}
description={formatMessage(mm.reviewScreen.employerDesc)}
/>
<ReviewSection
application={application}
index={3}
state={statesMap['vinnumalastofnun'][application.state]}
title={formatMessage(mm.reviewScreen.deptTitle)}
description={formatMessage(mm.reviewScreen.deptDesc)}
/>
</Box>
{(screenState === 'steps' && (
<Box marginTop={7} marginBottom={8}>
{steps.map((step, index) => {
return (
<ReviewSection
key={index}
application={application}
index={index + 1}
{...step}
/>
)
})}
</Box>
)) || (
<Box marginTop={7} marginBottom={8}>
<Review application={application} editable={false} />
</Box>
)}
</Box>
)
}
Expand Down

Large diffs are not rendered by default.

Loading