Skip to content

Commit

Permalink
ADD: logic for parsing and transforming of file from backend
Browse files Browse the repository at this point in the history
Co-authored-by: andregroseth <[email protected]>
  • Loading branch information
JeremiahUy and andregroseth committed Nov 19, 2024
1 parent c14b4b3 commit 14ac3db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@types/react-draft-wysiwyg": "^1.13.5",
"amplitude-js": "^8.21.9",
"axios": "^1.5.1",
"buffer": "^6.0.3",
"core-js": "^3.32.2",
"depcheck": "^1.4.7",
"draft-js": "^0.11.7",
Expand Down
18 changes: 17 additions & 1 deletion apps/frontend/src/api/BehandlingensLivslopApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios'
import { Buffer } from 'buffer'
import { useEffect, useState } from 'react'
import { IBehandlingensLivslop, IBehandlingensLivslopRequest, IPageResponse } from '../constants'
import { env } from '../util/env'
Expand Down Expand Up @@ -166,12 +167,27 @@ export const mapBehandlingensLivslopToFormValue = (
export const mapBehandlingensLivslopRequestToFormValue = (
behandlingensLivslop: Partial<IBehandlingensLivslop>
): IBehandlingensLivslopRequest => {
const filer: File[] = []
if (
behandlingensLivslop &&
behandlingensLivslop.filer &&
behandlingensLivslop.filer?.length > 0
) {
behandlingensLivslop.filer.forEach((fil) => {
const decodedBase64File = Buffer.from(fil.fil, 'base64')
const parsedFile = Uint8Array.from(decodedBase64File)
const blob = new Blob([parsedFile], { type: fil.filtype })
const file = new File([blob], fil.filnavn, { type: fil.filtype })
filer.push(file)
})
}

return {
id: behandlingensLivslop.id || '',
changeStamp: behandlingensLivslop.changeStamp || { lastModifiedDate: '', lastModifiedBy: '' },
version: -1,
etterlevelseDokumentasjonId: behandlingensLivslop.etterlevelseDokumentasjonId || '',
beskrivelse: behandlingensLivslop.beskrivelse || '',
filer: [],
filer: filer,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const CustomFileUpload = (props: IProps) => {
})
setFiles(initialFiles)
}
}, [])
}, [initialValues])

const removeFile = (fileToRemove: FileObject) => {
setFiles(files.filter((file) => file !== fileToRemove))
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/pages/BehandlingensLivslopPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const BehandlingensLivslopPage = () => {
behandlingsLivslop as IBehandlingensLivslop
)}
>
{({ initialValues, submitForm }) => (
{({ submitForm, initialValues }) => (
<Form>
<div className="pr-4 flex flex-1 flex-col gap-4 col-span-8">
<BodyShort>
Expand Down

0 comments on commit 14ac3db

Please sign in to comment.