Skip to content

Commit

Permalink
skal kunne endre på dokumentTittel via journalFøringState
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorGSolberg committed Oct 17, 2023
1 parent a603aa8 commit e85994d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
44 changes: 22 additions & 22 deletions src/frontend/Komponenter/Journalføring/Standard/DokumentPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Dispatch, SetStateAction, useState } from 'react';
import React from 'react';
import { Button, ExpansionCard } from '@navikt/ds-react';
import styled from 'styled-components';
import { DokumentInfo, IJournalpost } from '../../../App/typer/journalføring';
Expand All @@ -7,6 +7,7 @@ import { FamilieReactSelect, ISelectOption } from '@navikt/familie-form-elements
import { dokumentTitlerMultiSelect, mapDokumentTittel } from '../Felles/utils';
import { ExternalLinkIcon } from '@navikt/aksel-icons';
import { åpneFilIEgenTab } from '../../../App/utils/utils';
import { JournalføringStateRequest } from '../../../App/hooks/useJournalføringState';

const ExpansionCardHeader = styled(ExpansionCard.Header)`
padding-bottom: 0.35rem;
Expand All @@ -23,29 +24,31 @@ const EksternLenkeKnapp = styled(Button)`
width: fit-content;
`;

const MultiSelect = styled(FamilieReactSelect)`
margin-bottom: -1rem;
`;

interface Props {
journalpost: IJournalpost;
journalpostState: JournalføringStateRequest;
dokument: DokumentInfo;
hentDokument: (dokumentInfoId: string) => void;
settDokumentTitler: Dispatch<SetStateAction<Record<string, string> | undefined>>;
}

const MultiSelect = styled(FamilieReactSelect)`
margin-bottom: -1rem;
`;

const utledDokumentTittel = (
gammelTittel: string | undefined,
nyTittel: string | undefined
): string => nyTittel || gammelTittel || 'ukjent';
const DokumentPanel: React.FC<Props> = ({ journalpost, journalpostState, dokument }) => {
const endreDokumentNavn = (dokumentInfoId: string, nyttDokumentNavn: string) => {
settDokumentTitler((prevState: Record<string, string> | undefined) => ({
...prevState,
[dokumentInfoId]: nyttDokumentNavn,
}));
};

const DokumentPanel: React.FC<Props> = ({ dokument, journalpost }) => {
const [nyDokumentTittel, settNyDokumentTittel] = useState<string | undefined>(undefined);
const [nyAnnetInnholdsliste, settNyAnnetInnholdsliste] = useState<string[]>([]);
const { dokumentTitler, settDokumentTitler } = journalpostState;

const erDokumentPanelValgt = dokument.dokumentInfoId === dokument.dokumentInfoId;
const defaultTittelValue = dokument.tittel ? mapDokumentTittel(dokument.tittel) : undefined;
const dokumentTittel = utledDokumentTittel(dokument.tittel, nyDokumentTittel);
const dokumentTittel =
(dokumentTitler && dokumentTitler[dokument.dokumentInfoId]) || dokument.tittel || 'Ukjent';
const defaultTittelValue = dokumentTittel ? mapDokumentTittel(dokumentTittel) : undefined;

return (
<ExpansionCard id={dokument.dokumentInfoId} size="small" aria-label="journalpost">
Expand All @@ -69,8 +72,9 @@ const DokumentPanel: React.FC<Props> = ({ dokument, journalpost }) => {
defaultValue={defaultTittelValue}
feil={null}
onChange={(value: unknown) => {
settNyDokumentTittel(
value ? (value as ISelectOption).value : undefined
endreDokumentNavn(
dokument.dokumentInfoId,
value ? (value as ISelectOption).value : ''
);
}}
/>
Expand All @@ -83,11 +87,7 @@ const DokumentPanel: React.FC<Props> = ({ dokument, journalpost }) => {
isDisabled={false}
defaultValue={undefined}
feil={null}
onChange={(values: unknown) => {
settNyAnnetInnholdsliste(
(values as ISelectOption[]).map((value) => value.value)
);
}}
onChange={(values: unknown) => {}}

Check failure on line 90 in src/frontend/Komponenter/Journalføring/Standard/DokumentPanel.tsx

View workflow job for this annotation

GitHub Actions / Bygg app og Docker image

'values' is declared but its value is never read.
/>
<EksternLenkeKnapp
type={'button'}
Expand Down
11 changes: 6 additions & 5 deletions src/frontend/Komponenter/Journalføring/Standard/Dokumenter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Dispatch, SetStateAction } from 'react';
import React from 'react';
import styled from 'styled-components';
import { IJournalpost } from '../../../App/typer/journalføring';
import DokumentPanel from './DokumentPanel';
import { JournalføringStateRequest } from '../../../App/hooks/useJournalføringState';

const Liste = styled.ul`
display: flex;
Expand All @@ -14,20 +15,20 @@ const Liste = styled.ul`

interface Props {
journalpost: IJournalpost;
journalpostState: JournalføringStateRequest;
hentDokument: (dokumentInfoId: string) => void;
settDokumentTitler: Dispatch<SetStateAction<Record<string, string> | undefined>>;
}

const Dokumenter: React.FC<Props> = ({ journalpost, hentDokument, settDokumentTitler }) => {
const Dokumenter: React.FC<Props> = ({ journalpost, journalpostState, hentDokument }) => {
return (
<Liste>
{journalpost.dokumenter.map((dokument) => (
<li key={dokument.dokumentInfoId}>
<DokumentPanel
dokument={dokument}
journalpost={journalpost}
hentDokument={hentDokument}
settDokumentTitler={settDokumentTitler}
journalpost={journalpost}
journalpostState={journalpostState}
/>
</li>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ const JournalføringSide: React.FC<JournalføringAppProps> = ({ oppgaveId, journ
Dokumenter
</Tittel>
<Dokumenter
journalpost={journalResponse.journalpost}
hentDokument={hentDokumentResponse.hentDokument}
settDokumentTitler={journalpostState.settDokumentTitler}
journalpost={journalResponse.journalpost}
journalpostState={journalpostState}
/>
</section>
</InnerContainer>
Expand Down

0 comments on commit e85994d

Please sign in to comment.