Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Implementert error og loading håndtering
Browse files Browse the repository at this point in the history
  • Loading branch information
robertkittilsen committed Aug 30, 2023
1 parent 265c8e5 commit 6eb270e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
10 changes: 9 additions & 1 deletion src/demo/setup-demo-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
hentStandardInnsatsgruppe,
hentDemoState,
DemoData,
settArbeidssokerPeriode,
} from './demo-state';

import { telemetryUrl } from '../innhold/lenker';
Expand Down Expand Up @@ -175,7 +176,14 @@ export const demo_handlers = [

rest.get(REAKTIVERING_URL, reaktiveringGetResolver),
rest.post(REAKTIVERING_URL, reaktiveringPostResolver),
rest.post(FULLFOER_REAKTIVERING_URL, (req, res, ctx) => {
rest.post(FULLFOER_REAKTIVERING_URL, async (req, res, ctx) => {
const delay = new Promise((resolve) =>
setTimeout(() => {
settArbeidssokerPeriode('aktiv');
resolve(null);
}, 1000),
);
await delay;
return res(ctx.status(204));
}),

Expand Down
15 changes: 3 additions & 12 deletions src/komponenter/reaktivering/reaktivering-aktuelt.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Alert, BodyShort, Button, Heading, Link } from '@navikt/ds-react';
import { Alert, BodyShort, Heading, Link } from '@navikt/ds-react';

import { useAmplitudeData } from '../hent-initial-data/amplitude-provider';
import { useMeldeplikt } from '../../contexts/meldeplikt';
Expand All @@ -12,8 +12,7 @@ import SisteMeldekortVidereRegistrertValg from './siste-meldekort-videre-registr

import styles from '../../innhold/innhold.module.css';
import spacingStyles from '../../spacing.module.css';
import { fetchToJson } from '../../ducks/api-utils';
import { FULLFOER_REAKTIVERING_URL, requestConfig } from '../../ducks/api';
import ReaktiveringKnapp from './reaktivering-knapp';

interface Props {
handleIkkeReaktivering: (event: React.SyntheticEvent) => void;
Expand All @@ -30,12 +29,6 @@ const ReaktiveringAktuelt = (props: Props) => {
window.location.assign(dialogLenke);
};

const fullfoerReaktivering = async () =>
await fetchToJson(FULLFOER_REAKTIVERING_URL, {
...requestConfig(),
method: 'POST',
});

return (
<section className={`${styles.limit} ${spacingStyles.blokkM}`}>
<ErRendret loggTekst="Rendrer tema: kan reaktiveres" />
Expand All @@ -46,9 +39,7 @@ const ReaktiveringAktuelt = (props: Props) => {
<div>
<SisteMeldekortVidereRegistrertValg meldeplikt={meldeplikt} />
<BodyShort className={spacingStyles.blokkS}>
<Button variant="primary" onClick={fullfoerReaktivering}>
Registrer deg som arbeidssøker
</Button>
<ReaktiveringKnapp />
</BodyShort>
<BodyShort className={spacingStyles.blokkXs}>
<Link href={dialogLenke} onClick={handleIkkeReaktivering}>
Expand Down
40 changes: 40 additions & 0 deletions src/komponenter/reaktivering/reaktivering-knapp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { fetchToJson } from '../../ducks/api-utils';
import { FULLFOER_REAKTIVERING_URL, requestConfig } from '../../ducks/api';
import { Alert, Button } from '@navikt/ds-react';
import { useState } from 'react';
import spacing from '../../spacing.module.css';

const ReaktiveringsKnapp = () => {
const [showError, setShowError] = useState(false);
const [loading, setLoading] = useState(false);
const fullfoerReaktivering = async () => {
setLoading(true);
setShowError(false);
try {
await fetchToJson(FULLFOER_REAKTIVERING_URL, {
...requestConfig(),
method: 'POST',
});
window.location.reload();
} catch (e) {
setShowError(true);
} finally {
setLoading(false);
}
};

return (
<>
<Button variant="primary" onClick={fullfoerReaktivering} loading={loading}>
Registrer deg som arbeidssøker
</Button>
{showError && (
<Alert variant={'error'} className={spacing.mt1}>
Noe gikk dessverre galt. Prøv igjen.
</Alert>
)}
</>
);
};

export default ReaktiveringsKnapp;

0 comments on commit 6eb270e

Please sign in to comment.