Skip to content

Commit 07ff04c

Browse files
committed
Indicate missing income statement attachments for employee
1 parent 062eca6 commit 07ff04c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

frontend/src/employee-frontend/components/IncomeStatementPage.tsx

+32-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: LGPL-2.1-or-later
44

55
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
6-
import React, { useCallback, useState } from 'react'
6+
import React, { useCallback, useMemo, useState } from 'react'
77
import { useNavigate } from 'react-router'
88
import styled from 'styled-components'
99

@@ -16,7 +16,7 @@ import {
1616
Gross,
1717
IncomeStatement,
1818
IncomeStatementAttachment,
19-
IncomeStatementAttachmentType,
19+
incomeStatementAttachmentTypes,
2020
SetIncomeStatementHandledBody
2121
} from 'lib-common/generated/api-types/incomestatement'
2222
import {
@@ -27,6 +27,10 @@ import {
2727
numAttachments,
2828
toIncomeStatementAttachments
2929
} from 'lib-common/income-statements/attachments'
30+
import {
31+
computeRequiredAttachments,
32+
fromIncomeStatement
33+
} from 'lib-common/income-statements/form'
3034
import { UUID } from 'lib-common/types'
3135
import { useIdRouteParam } from 'lib-common/useRouteParams'
3236
import { useApiState } from 'lib-common/utils/useRestApi'
@@ -189,6 +193,7 @@ function IncomeInfo({
189193
/>
190194
<HorizontalLine />
191195
<CitizenAttachments
196+
incomeStatement={incomeStatement}
192197
attachments={incomeStatement.attachments.filter(
193198
(attachment) => !attachment.uploadedByEmployee
194199
)}
@@ -405,6 +410,7 @@ function ChildIncomeInfo({
405410
/>
406411
<HorizontalLine />
407412
<CitizenAttachments
413+
incomeStatement={incomeStatement}
408414
attachments={incomeStatement.attachments.filter(
409415
(attachment) => !attachment.uploadedByEmployee
410416
)}
@@ -414,12 +420,18 @@ function ChildIncomeInfo({
414420
}
415421

416422
const CitizenAttachments = React.memo(function CitizenAttachments({
423+
incomeStatement,
417424
attachments
418425
}: {
426+
incomeStatement: IncomeStatement
419427
attachments: IncomeStatementAttachment[]
420428
}) {
421429
const { i18n } = useTranslation()
422430
const incomeStatementAttachments = toIncomeStatementAttachments(attachments)
431+
const requiredAttachments = useMemo(
432+
() => computeRequiredAttachments(fromIncomeStatement(incomeStatement)),
433+
[incomeStatement]
434+
)
423435
const noAttachments = numAttachments(incomeStatementAttachments) === 0
424436
return (
425437
<>
@@ -437,21 +449,34 @@ const CitizenAttachments = React.memo(function CitizenAttachments({
437449
) : (
438450
<Table>
439451
<Tbody>
440-
{Object.entries(incomeStatementAttachments.attachmentsByType).map(
441-
([type, attachments]) => {
442-
const attachmentType = type as IncomeStatementAttachmentType
452+
{incomeStatementAttachmentTypes.map((attachmentType) => {
453+
const attachments =
454+
incomeStatementAttachments.attachmentsByType[attachmentType]
455+
const attachmentMissing = !attachments?.length
456+
457+
if (
458+
attachmentMissing &&
459+
!requiredAttachments.has(attachmentType)
460+
) {
461+
return null
462+
} else {
443463
return (
444464
<Tr key={attachmentType}>
445465
<Td>
446466
{i18n.incomeStatement.attachmentNames[attachmentType]}
447467
</Td>
448468
<Td>
449-
<UploadedFiles files={attachments} />
469+
{attachmentMissing ? (
470+
i18n.incomeStatement.citizenAttachments
471+
.attachmentMissing
472+
) : (
473+
<UploadedFiles files={attachments} />
474+
)}
450475
</Td>
451476
</Tr>
452477
)
453478
}
454-
)}
479+
})}
455480
</Tbody>
456481
</Table>
457482
)}

frontend/src/lib-customizations/defaults/employee/i18n/fi.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,8 @@ export const fi = {
20832083

20842084
citizenAttachments: {
20852085
title: 'Tuloihin ja varhaiskasvatusmaksuihin liittyvät liitteet',
2086-
noAttachments: 'Ei liitteitä'
2086+
noAttachments: 'Ei liitteitä',
2087+
attachmentMissing: 'Liite puuttuu'
20872088
},
20882089

20892090
employeeAttachments: {

0 commit comments

Comments
 (0)