Skip to content

Commit

Permalink
Putt loader og feilhåndtering inni modal
Browse files Browse the repository at this point in the history
  • Loading branch information
joarau committed Oct 15, 2024
1 parent b22b433 commit bc1854f
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/stilling/stilling/analyse/AnalyserStillingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BodyShort, Label, Loader, Modal } from '@navikt/ds-react';
import { BodyShort, Label, Loader, Modal, Alert } from '@navikt/ds-react';
import css from './AnalyserStillingModal.module.css';
import { hentTittelFraStilling } from 'felles/domene/stilling/Stilling';
import { useStillingsanalyse } from '../../../api/stillings-api/stillingsanalyse';
Expand All @@ -19,7 +19,11 @@ const AnalyserStillingModal: React.FC<IAnalyserStillingModal> = ({ vis, onClose,
/*@ts-ignore: TODO: stilling og AdDataState brukes om hverandre, må ryddes opp, for eksempel ved at hentTittel tar inn parameterene som er */
const stillingstittel = hentTittelFraStilling(stilling);

const { stillingsanalyse, isLoading: isLoadingAnalyse } = useStillingsanalyse(
const {
stillingsanalyse,
isLoading: isLoadingAnalyse,
error,
} = useStillingsanalyse(
{
stillingsId: stillingsId || '',
stillingstype: stillingsinfo?.stillingskategori || 'Stilling',
Expand All @@ -29,18 +33,6 @@ const AnalyserStillingModal: React.FC<IAnalyserStillingModal> = ({ vis, onClose,
vis
);

if (isLoadingAnalyse) {
return <Loader size="medium" className={css.spinner} />;
}

/*if (isErrorStilling || isErrorAnalyse) {
return (
<Alert fullWidth variant="error" size="small">
Klarte ikke å laste inn stillingen eller analysere stillingen.
</Alert>
);
}*/

return (
<Modal
open={vis}
Expand All @@ -50,9 +42,21 @@ const AnalyserStillingModal: React.FC<IAnalyserStillingModal> = ({ vis, onClose,
heading: 'Analyser stilling',
}}
>
{stilling && stillingsanalyse && vis && (
<Modal.Body>
<div className={css.analyserstilling}>
<Modal.Body>
{isLoadingAnalyse && (
<div className={css.spinnerContainer}>
<Loader size="medium" className={css.spinner} />
</div>
)}

{error && (
<Alert variant="error" size="small" fullWidth>
Klarte ikke å analysere stillingen.
</Alert>
)}

{!isLoadingAnalyse && !error && stilling && stillingsanalyse && (
<div className={css.innhold}>
<div>
<Label>Sensitiv</Label>
Expand All @@ -74,9 +78,9 @@ const AnalyserStillingModal: React.FC<IAnalyserStillingModal> = ({ vis, onClose,
<BodyShort>{stillingsanalyse.tittelBegrunnelse}</BodyShort>
</div>
</div>
</Modal.Body>
)}
</div>
)}
</Modal.Body>
</Modal>
);
};
Expand Down

0 comments on commit bc1854f

Please sign in to comment.