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

Oikaisulaskujen liitteet #6247

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import { getAttachmentUrl } from 'citizen-frontend/attachments'
import { useUser } from 'citizen-frontend/auth/state'
import CollapsibleOrWholePageContainer from 'citizen-frontend/children/ResponsiveWholePageCollapsible'
import { useTranslation } from 'citizen-frontend/localization'
import {
Attachment,
PedagogicalDocumentCitizen
} from 'lib-common/generated/api-types/pedagogicaldocument'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import { PedagogicalDocumentCitizen } from 'lib-common/generated/api-types/pedagogicaldocument'
import { ChildId } from 'lib-common/generated/api-types/shared'
import { useMutation, useQuery, useQueryResult } from 'lib-common/query'
import { useUniqueId } from 'lib-common/utils/useUniqueId'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React, { useCallback } from 'react'

import { wrapResult } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
AttachmentId,
IncomeStatementId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { useCallback, useImperativeHandle, useMemo, useRef } from 'react'
import styled from 'styled-components'

import { Result } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import { IncomeStatementStatus } from 'lib-common/generated/api-types/incomestatement'
import {
AttachmentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, { useCallback } from 'react'
import { useNavigate } from 'react-router'
import styled from 'styled-components'

import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import { IncomeStatement } from 'lib-common/generated/api-types/incomestatement'
import {
ChildId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React, { useCallback } from 'react'

import { wrapResult } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
AttachmentId,
IncomeStatementId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import React, { useCallback, useImperativeHandle, useMemo, useRef } from 'react'
import styled from 'styled-components'

import { Result } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import {
required,
validate,
validateIf,
validInt
} from 'lib-common/form-validation'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
IncomeStatementStatus,
OtherIncome,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, { useCallback } from 'react'
import { useNavigate } from 'react-router'
import styled from 'styled-components'

import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
Accountant,
Entrepreneur,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import * as ApiTypes from 'lib-common/generated/api-types/incomestatement'
import {
IncomeSource,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/citizen-frontend/messages/MessageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import styled from 'styled-components'
import { ErrorMessageBox } from 'citizen-frontend/calendar/ChildSelector'
import { getDuplicateChildInfo } from 'citizen-frontend/utils/duplicated-child-utils'
import { Failure, Result, Success } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { useBoolean } from 'lib-common/form/hooks'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import { ChildAndPermittedActions } from 'lib-common/generated/api-types/children'
import {
AccountType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

import { InvoiceReplacementReason } from 'lib-common/generated/api-types/invoicing'

import { Page, Element, TextInput, Select } from '../../../utils/page'
import {
Page,
Element,
TextInput,
Select,
FileUpload
} from '../../../utils/page'

export class InvoiceDetailsPage {
headOfFamilySection: InvoiceHeadOfFamilySection
Expand Down Expand Up @@ -98,6 +104,7 @@ export class InvoiceRow extends Element {
export class InvoiceReplacementDraftSection extends Element {
reason = new Select(this.findByDataQa('replacement-reason'))
notes = new TextInput(this.findByDataQa('replacement-notes'))
attachments = new FileUpload(this.findByDataQa('attachments'))
markSentButton = this.findByDataQa('mark-sent')

async selectReason(value: InvoiceReplacementReason) {
Expand All @@ -108,6 +115,7 @@ export class InvoiceReplacementDraftSection extends Element {
export class InvoiceReplacementInfoSection extends Element {
reason = this.findByDataQa('replacement-reason')
notes = this.findByDataQa('replacement-notes')
attachments = this.findAllByDataQa('attachment')
sentAt = this.findByDataQa('sent-at')
sentBy = this.findByDataQa('sent-by')
}
2 changes: 2 additions & 0 deletions frontend/src/e2e-test/specs/4_finance/invoices.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,13 @@ describe('Invoices', () => {

await form.selectReason('ABSENCE')
await form.notes.fill('Unohtunut päiväkirjamerkintä')
await form.attachments.upload('src/e2e-test/assets/test_file.jpg')
await form.markSentButton.click()

const view = invoicePage.replacementInfo
await view.reason.assertTextEquals('Päiväkirjamerkintä')
await view.notes.assertTextEquals('Unohtunut päiväkirjamerkintä')
await view.attachments.assertCount(1)
await view.sentAt.assertTextEquals(now.format())
await view.sentBy.assertTextEquals(
`${financeAdmin.lastName} ${financeAdmin.firstName}`
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/e2e-test/utils/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export class Element {
get focused(): Promise<boolean> {
return this.locator.evaluate((el) => el === document.activeElement)
}

async assertFocused(focused: boolean): Promise<void> {
await waitUntilEqual(() => this.focused, focused)
}
Expand Down Expand Up @@ -372,6 +373,23 @@ export class FileInput extends Element {
}
}

export class FileUpload extends Element {
#input = new FileInput(this.findByDataQa('btn-upload-file'))
#uploadedFilesContainer = this.findByDataQa('uploaded-files')

async upload(path: string | string[]) {
const fileCountBefore = await this.#uploadedFilesContainer
.findAll('> * ')
.count()
await this.#input.setInputFiles(path)
await this.#uploadedFilesContainer
.find(
`:nth-child(${fileCountBefore + 1}) [data-qa="file-download-button"]`
)
.waitUntilVisible()
}
}

export class AsyncButton extends Element {
async status() {
return this.getAttribute('data-status')
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/employee-frontend/api/attachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ export async function saveIncomeAttachment(
)
}

export async function saveInvoiceAttachment(
invoiceId: UUID,
file: File,
onUploadProgress: (percentage: number) => void
): Promise<Result<AttachmentId>> {
return await doSaveAttachment(
{ path: `/employee/attachments/invoices/${invoiceId}` },
file,
onUploadProgress
)
}

export async function saveFeeAlterationAttachment(
feeAlterationId: UUID | null,
file: File,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useNavigate } from 'react-router'
import styled from 'styled-components'

import { combine, Result, wrapResult } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
Accountant,
Entrepreneur,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import React, { useCallback, useContext, useState } from 'react'
import styled from 'styled-components'

import { wrapResult } from 'lib-common/api'
import {
Attachment,
PedagogicalDocument
} from 'lib-common/generated/api-types/pedagogicaldocument'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import { PedagogicalDocument } from 'lib-common/generated/api-types/pedagogicaldocument'
import {
AttachmentId,
ChildId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
saveFeeAlterationAttachment
} from 'employee-frontend/api/attachments'
import { Result, Success, wrapResult } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import { FeeAlteration } from 'lib-common/generated/api-types/invoicing'
import {
AttachmentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import styled from 'styled-components'

import { getAttachmentUrl } from 'employee-frontend/api/attachments'
import { Result } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
FeeAlteration,
FeeAlterationWithPermittedActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import React from 'react'
import styled from 'styled-components'

import { wrapResult } from 'lib-common/api'
import { string } from 'lib-common/form/fields'
import { object, oneOf, required, validated } from 'lib-common/form/form'
import { useForm, useFormFields } from 'lib-common/form/hooks'
Expand All @@ -21,12 +22,18 @@ import {
FixedSpaceColumn,
FixedSpaceRow
} from 'lib-components/layout/flex-helpers'
import FileDownloadButton from 'lib-components/molecules/FileDownloadButton'
import FileUpload from 'lib-components/molecules/FileUpload'
import { InfoBox } from 'lib-components/molecules/MessageBoxes'
import { H3, Label, P } from 'lib-components/typography'

import { getAttachmentUrl, saveInvoiceAttachment } from '../../api/attachments'
import { deleteAttachment } from '../../generated/api-clients/attachment'
import { useTranslation } from '../../state/i18n'
import { markReplacementDraftSentMutation } from '../invoices/queries'

const deleteAttachmentResult = wrapResult(deleteAttachment)

const replacementDraftForm = validated(
object({
reason: required(oneOf<InvoiceReplacementReason>()),
Expand Down Expand Up @@ -85,6 +92,25 @@ export function ReplacementDraftForm({
</TextAreaWrapper>
</FixedSpaceColumn>
</FixedSpaceRow>
<FixedSpaceRow>
<FixedSpaceColumn>
<FileUpload
files={invoiceResponse.invoice.attachments}
onUpload={(file, onUploadProgress) =>
saveInvoiceAttachment(
invoiceResponse.invoice.id,
file,
onUploadProgress
)
}
onDelete={(attachmentId) =>
deleteAttachmentResult({ attachmentId })
}
getDownloadUrl={getAttachmentUrl}
data-qa="attachments"
/>
</FixedSpaceColumn>
</FixedSpaceRow>
<FixedSpaceRow justifyContent="flex-end">
<InfoBox message={i18n.invoice.form.replacement.sendInfo} />
</FixedSpaceRow>
Expand Down Expand Up @@ -118,7 +144,6 @@ export function ReplacementInfo({
return (
<FixedSpaceColumn data-qa="replacement-info">
<H3>{i18n.invoice.form.replacement.title}</H3>
<P>{i18n.invoice.form.replacement.info}</P>
<FixedSpaceRow spacing="L">
<FixedSpaceColumn>
<Label>{i18n.invoice.form.replacement.reason}</Label>
Expand All @@ -133,6 +158,28 @@ export function ReplacementInfo({
</NotesWrapper>
</FixedSpaceColumn>
</FixedSpaceRow>
{invoice.attachments.length > 0 ? (
<>
<FixedSpaceRow>
<FixedSpaceColumn>
<Label>{i18n.invoice.form.replacement.attachments}</Label>
</FixedSpaceColumn>
</FixedSpaceRow>
<FixedSpaceRow>
<FixedSpaceColumn spacing="xs">
{invoice.attachments.map((attachment) => (
<FileDownloadButton
key={attachment.id}
file={attachment}
getFileUrl={getAttachmentUrl}
icon
data-qa="attachment"
/>
))}
</FixedSpaceColumn>
</FixedSpaceRow>
</>
) : null}
<div>
<Label>{i18n.invoice.form.replacement.markedAsSent}</Label>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'
import styled from 'styled-components'

import { Failure, Result } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { useBoolean } from 'lib-common/form/hooks'
import { UpdateStateFn } from 'lib-common/form-state'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
AuthorizedMessageAccount,
DraftContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, { useContext, useMemo } from 'react'
import { Link } from 'react-router'
import styled from 'styled-components'

import { Attachment } from 'lib-common/api-types/attachment'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
Income,
IncomeTypeOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import React, { useCallback, useMemo, useState } from 'react'
import styled from 'styled-components'

import { Failure, Result, wrapResult } from 'lib-common/api'
import { Attachment } from 'lib-common/api-types/attachment'
import { incomeEffects } from 'lib-common/api-types/income'
import DateRange from 'lib-common/date-range'
import { Attachment } from 'lib-common/generated/api-types/attachment'
import {
Income,
IncomeCoefficient,
Expand Down
11 changes: 0 additions & 11 deletions frontend/src/lib-common/api-types/attachment.ts

This file was deleted.

1 change: 1 addition & 0 deletions frontend/src/lib-common/generated/action.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export type Invoice =
| 'MARK_SENT'
| 'READ'
| 'SEND'
| 'UPLOAD_ATTACHMENT'

export type InvoiceCorrection =
| 'DELETE'
Expand Down
Loading
Loading