Skip to content

Commit

Permalink
- Dokarkiv og Histark bugfix og merge
Browse files Browse the repository at this point in the history
#deploy-test-frontend
  • Loading branch information
stigus committed Dec 12, 2024
1 parent 32605a5 commit 2bcd566
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,6 @@ export const initialKursVerdier = {
export const initialSammendragVerdi =
'Trivelig person med kjærlighet for sau, som har tonnevis med allsidig kompetanse og fantastiske personlige egenskaper.'

export const initialHistark = {
dokumenter: [
{
tittel: '',
antallSider: -1,
skanner: '',
skannested: 'FREDRIKSTAD',
skanningsTidspunkt: new Date(),
temakoder: [],
enhetsnavn: '',
enhetsnummer: '',
startAar: new Date(),
sluttAar: new Date(),
fysiskDokument: '',
},
],
}

export const initialDigitalInnsending = {
tittel: '',
tema: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ export const DokarkivForm = () => {
<Kategori title={'Vedlegg'}>
<FileUploader filer={files} setFiler={setFiles} />
{files.length > 0 && (
<DokumentInfoListe handleChange={handleVedleggChange} filer={files} />
<DokumentInfoListe
handleChange={handleVedleggChange}
path={'dokarkiv.dokumenter'}
filer={files}
/>
)}
</Kategori>
</Kategori>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import { ErrorBoundary } from '@/components/ui/appError/ErrorBoundary'
import { DollyTextInput } from '@/components/ui/form/inputs/textInput/TextInput'
import { Vedlegg } from '@/components/fagsystem/dokarkiv/form/DokarkivForm'
Expand All @@ -8,12 +8,14 @@ import 'react-pdf/dist/esm/Page/AnnotationLayer.css'
import 'react-pdf/dist/esm/Page/TextLayer.css'
import styled from 'styled-components'
import Button from '@/components/ui/button/Button'
import { useFormContext } from 'react-hook-form'

pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`

type Data = {
filer: Vedlegg[]
handleChange: Function
path: string
isMultiple?: boolean
}

Expand All @@ -28,11 +30,20 @@ const PdfDocument = styled(Document)`
max-height: 90px;
margin-right: 10px;
`
export default ({ filer, handleChange, isMultiple = true }: Data) => {
export default ({ filer, handleChange, path, isMultiple = true }: Data) => {
const formMethods = useFormContext()
if (!filer || filer.length < 1) {
return null
}

useEffect(() => {
filer.forEach((fil: Vedlegg, index: number) => {
if (formMethods.watch(`${path}.${index}.tittel`) === '') {
formMethods.setValue(`${path}.${index}.tittel`, fil.name)
}
})
}, [filer])

const handleDeleteByIndex = (deleteIndex: number) =>
handleChange(filer.filter((fil, index) => index !== deleteIndex))

Expand All @@ -44,14 +55,11 @@ export default ({ filer, handleChange, isMultiple = true }: Data) => {
<DollyFieldArray data={filer} header={`Dokumentinfo`}>
{(fil: Vedlegg, index: number) => (
<div className="flexbox--space" key={fil.id + '-' + fil.name}>
<PdfDocument
options={{ isEvalSupported: false }}
file={'data:application/pdf;base64,' + fil.content.base64}
>
<PdfDocument file={'data:application/pdf;base64,' + fil.content.base64}>
<Page pageNumber={1} height={80} width={60} />
</PdfDocument>
<DollyTextInput
name={`histark.vedlegg.${index}.name`}
name={`${path}.${index}.tittel`}
label={`Tittel på dokument #${index + 1}`}
/>
<StyledSlettKnapp kind="trashcan" onClick={() => handleDeleteByIndex(index)} />
Expand All @@ -60,15 +68,12 @@ export default ({ filer, handleChange, isMultiple = true }: Data) => {
</DollyFieldArray>
) : (
<div className="flexbox" key={firstFile.id + '-' + firstFile.name}>
<PdfDocument
options={{ isEvalSupported: false }}
file={'data:application/pdf;base64,' + firstFile.content.base64}
>
<PdfDocument file={'data:application/pdf;base64,' + firstFile.content.base64}>
<Page pageNumber={1} height={80} width={60} />
</PdfDocument>
<DollyTextInput
name={`histark.vedlegg.0.name`}
defaultValue={firstFile.name}
name={`${path}.0.tittel`}
input={firstFile.name}
label={`Tittel på dokument`}
/>
<StyledSlettKnapp kind="trashcan" onClick={() => handleDeleteByIndex(0)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const histarkAttributt = 'histark'

export const HistarkForm = () => {
const formMethods = useFormContext()
if (!_.has(formMethods.getValues(), histarkAttributt)) {
if (!formMethods.getValues(histarkAttributt)) {
return null
}

Expand All @@ -56,7 +56,7 @@ export const HistarkForm = () => {
filer.forEach((fil: Vedlegg, index: number) => {
formMethods.setValue(`histark.dokumenter.${index}.tittel`, fil.dokNavn || fil.name)
formMethods.setValue(`histark.dokumenter.${index}.antallSider`, 1)
formMethods.setValue(`histark.dokumenter.${index}.fysiskDokument`, fil.content.base64)
formMethods.setValue(`histark.dokumenter.${index}.fysiskDokument`, fil.content?.base64)
})
formMethods.trigger('histark.dokumenter')
formMethods.trigger('histark.vedlegg')
Expand Down Expand Up @@ -142,6 +142,7 @@ export const HistarkForm = () => {
<FileUploader filer={files} setFiler={setFiles} isMultiple={false} />
{files.length > 0 && (
<DokumentInfoListe
path={'histark.dokumenter'}
handleChange={handleVedleggChange}
filer={files}
isMultiple={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ export const initialHistark = {
tittel: '',
antallSider: -1,
skanner: '',
skannested: '',
skannested: 'FREDRIKSTAD',
skanningsTidspunkt: new Date(),
temakoder: [],
enhetsnavn: '',
enhetsnummer: '',
startYear: 2000,
endYear: 2010,
startAar: new Date(),
sluttAar: new Date(),
fysiskDokument: '',
},
],
Expand Down
2 changes: 2 additions & 0 deletions apps/dolly-frontend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ spring:
authorization-grant-type: authorization_code
redirect-uri: 'http://localhost:3000/login/oauth2/code/{registrationId}'
scope: openid, offline_access, ${sm://azure-app-client-id}/.default
client-id: ${AZURE_APP_CLIENT_ID}
client-secret: ${AZURE_APP_CLIENT_SECRET}
provider:
aad:
authorization-uri: ${AAD_ISSUER_URI}/oauth2/v2.0/authorize
Expand Down

0 comments on commit 2bcd566

Please sign in to comment.