-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lagt inn kontaktinfo-komponentene og omstrukturert litt for å få samme design som i skissene for panelene.
- Loading branch information
Showing
5 changed files
with
87 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.informasjon-om-bedrift { | ||
margin: 2rem auto; | ||
margin: 24px auto; | ||
padding: 2rem; | ||
max-width: 60rem; | ||
width: 100%; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,81 @@ | ||
import React, {FunctionComponent, useContext, useEffect, useState} from 'react'; | ||
import {OrganisasjonsDetaljerContext} from '../OrganisasjonDetaljerProvider'; | ||
import {Enhet, hentOverordnetEnhet, hentUnderenhet} from '../../api/enhetsregisteretApi'; | ||
import React, { FunctionComponent, useContext, useEffect, useState } from 'react'; | ||
import { OrganisasjonsDetaljerContext } from '../OrganisasjonDetaljerProvider'; | ||
import { Enhet, hentOverordnetEnhet, hentUnderenhet } from '../../api/enhetsregisteretApi'; | ||
import Underenhet from './Underenhet/Underenhet'; | ||
import OverordnetEnhet from './OverordnetEnhet/OverordnetEnhet'; | ||
import Brodsmulesti from '../Brodsmulesti/Brodsmulesti'; | ||
import './InformasjonOmBedrift.css'; | ||
import {Panel} from "@navikt/ds-react"; | ||
import { Panel } from '@navikt/ds-react'; | ||
import { useKontaktinfo } from './Kontaktinfo'; | ||
|
||
interface Enheter { | ||
underenhet: Enhet; | ||
hovedenhet: Enhet; | ||
} | ||
|
||
const hentEnheter = async (orgnr: string): Promise<Enheter | undefined> => { | ||
const underenhet = await hentUnderenhet(orgnr) | ||
const underenhet = await hentUnderenhet(orgnr); | ||
if (underenhet === undefined) { | ||
return undefined | ||
return undefined; | ||
} | ||
if (underenhet.overordnetEnhet === undefined) { | ||
return undefined | ||
return undefined; | ||
} | ||
const hovedenhet = await hentOverordnetEnhet(underenhet.overordnetEnhet) | ||
const hovedenhet = await hentOverordnetEnhet(underenhet.overordnetEnhet); | ||
if (hovedenhet === undefined) { | ||
return undefined | ||
return undefined; | ||
} | ||
return {underenhet, hovedenhet} | ||
} | ||
return { underenhet, hovedenhet }; | ||
}; | ||
|
||
const Kontaktpanel = ({ children }: { children: React.ReactNode }) => ( | ||
<Panel className="informasjon-om-bedrift">{children}</Panel> | ||
); | ||
|
||
const InformasjonOmBedrift: FunctionComponent = () => { | ||
const {valgtOrganisasjon} = useContext(OrganisasjonsDetaljerContext); | ||
const { valgtOrganisasjon } = useContext(OrganisasjonsDetaljerContext); | ||
const [enheter, setEnheter] = useState<Enheter | undefined>(undefined); | ||
const orgnr = valgtOrganisasjon?.organisasjon.OrganizationNumber ?? ''; | ||
const orgnr = valgtOrganisasjon?.organisasjon.OrganizationNumber; | ||
|
||
useEffect(() => { | ||
if (orgnr !== '') { | ||
hentEnheter(orgnr).then(setEnheter) | ||
if (orgnr !== undefined) { | ||
hentEnheter(orgnr).then(setEnheter); | ||
} else { | ||
setEnheter(undefined) | ||
setEnheter(undefined); | ||
} | ||
}, [orgnr]); | ||
|
||
const kontaktinfo = useKontaktinfo(orgnr); | ||
|
||
return ( | ||
<> | ||
<Brodsmulesti brodsmuler={[{url: '/bedriftsinformasjon', title: 'Bedriftsprofil', handleInApp: true}]}/> | ||
<Panel className='informasjon-om-bedrift'> | ||
{enheter !== undefined ? ( | ||
<> | ||
<Underenhet underenhet={enheter.underenhet}/> | ||
<OverordnetEnhet overordnetenhet={enheter.hovedenhet}/> | ||
</> | ||
) : ( | ||
<Brodsmulesti | ||
brodsmuler={[ | ||
{ url: '/bedriftsinformasjon', title: 'Bedriftsprofil', handleInApp: true }, | ||
]} | ||
/> | ||
{enheter !== undefined ? ( | ||
<div className=""> | ||
<Kontaktpanel> | ||
<Underenhet | ||
underenhet={enheter.underenhet} | ||
kontaktinfo={kontaktinfo?.underenhet ?? null} | ||
/> | ||
</Kontaktpanel> | ||
<Kontaktpanel> | ||
<OverordnetEnhet | ||
overordnetenhet={enheter.hovedenhet} | ||
kontaktinfo={kontaktinfo?.hovedenhet ?? null} | ||
/> | ||
</Kontaktpanel> | ||
</div> | ||
) : ( | ||
<Kontaktpanel> | ||
<div>Kunne ikke hente informasjon</div> | ||
)} | ||
</Panel> | ||
</Kontaktpanel> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default InformasjonOmBedrift; | ||
export default InformasjonOmBedrift; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
.underenhet-info { | ||
margin-bottom: 1.5rem; | ||
} | ||
.underenhet-info__navn { | ||
display: flex; | ||
align-items: center; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters