Skip to content

Commit

Permalink
fix(service-portal): Change download for pdf docs inbox (#16398)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thordurhhh and kodiakhq[bot] authored Oct 15, 2024
1 parent 2a7cb5b commit a4a05f8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import {
import { DocumentsScope } from '@island.is/auth/scopes'
import { DocumentClient } from '@island.is/clients/documents'
import { AuditService } from '@island.is/nest/audit'
import { Controller, Header, Param, Post, Res, UseGuards } from '@nestjs/common'
import {
Controller,
Header,
Param,
Post,
Res,
UseGuards,
Query,
} from '@nestjs/common'
import { ApiOkResponse, ApiTags } from '@nestjs/swagger'
import { Response } from 'express'

Expand All @@ -32,6 +40,7 @@ export class DocumentController {
@Param('pdfId') pdfId: string,
@CurrentUser() user: User,
@Res() res: Response,
@Query('action') action: string,
) {
const rawDocumentDTO = await this.documentClient.customersDocument({
kennitala: user.nationalId,
Expand All @@ -54,7 +63,9 @@ export class DocumentController {
res.header('Content-length', buffer.length.toString())
res.header(
'Content-Disposition',
`inline; filename=${rawDocumentDTO.fileName}.pdf`,
`${action === 'download' ? 'attachment' : 'inline'}; filename=${
rawDocumentDTO.fileName
}.pdf`,
)
res.header('Pragma: no-cache')
res.header('Cache-Control: no-cache')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,40 @@ export const DocumentActionBar: React.FC<DocumentActionBarProps> = ({
<LoadingDots />
</Box>
)}
{activeDocument && activeDocument.document.value && (
<Tooltip as="span" text={formatMessage(m.download)}>
<a
download={`${activeDocument.subject}${
activeDocument.document.type === 'HTML' ? '.html' : '.pdf'
}`}
href={getDocumentLink(
activeDocument,
activeDocument.document.type === 'HTML' ? 'html' : 'pdf',
)}
aria-label={formatMessage(m.getDocument)}
>
{activeDocument && activeDocument.document.value ? (
activeDocument.document.type === 'HTML' ? (
<Tooltip as="span" text={formatMessage(m.download)}>
<a
download={`${activeDocument.subject}.html`}
href={getDocumentLink(activeDocument, 'html')}
aria-label={formatMessage(m.getDocument)}
>
<Button
as="span"
unfocusable
circle
icon="download"
iconType="outline"
size="medium"
colorScheme="light"
/>
</a>
</Tooltip>
) : (
<Tooltip text={formatMessage(m.download)}>
<Button
as="span"
unfocusable
circle
icon="download"
iconType="outline"
iconType={'outline'}
onClick={() =>
downloadFile(activeDocument, userInfo, 'download')
}
size="medium"
colorScheme="light"
/>
</a>
</Tooltip>
)}
</Tooltip>
)
) : undefined}
{activeDocument && (
<Tooltip text={formatMessage(m.print)}>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const sendForm = async (id: string, url: string, userInfo: User) => {
export const downloadFile = async (
doc: ActiveDocumentType2,
userInfo: User,
query?: string,
) => {
let html: string | undefined = undefined
if (doc?.document.type === 'HTML') {
Expand Down Expand Up @@ -64,9 +65,11 @@ export const downloadFile = async (
form.appendChild(documentIdInput)
form.appendChild(tokenInput)

const url = query ? `${doc?.downloadUrl}?action=${query}` : doc?.downloadUrl

// Form values
form.method = 'post'
form.action = doc?.downloadUrl ?? ''
form.action = doc?.downloadUrl ? url : ''
form.target = '_blank'

// Document Id values
Expand Down

0 comments on commit a4a05f8

Please sign in to comment.